Skip to content

Commit 3a96c92

Browse files
committed
Update VideoThumbnail button
1 parent 2ee5c5d commit 3a96c92

File tree

6 files changed

+60
-57
lines changed

6 files changed

+60
-57
lines changed

.changeset/nine-bobcats-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Update the `VideoThumbnail` play button user experience

polaris-react/src/components/VideoThumbnail/VideoThumbnail.scss

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@ $progress-bar-height: 6px;
1111
background-repeat: no-repeat;
1212
width: 100%;
1313
height: 100%;
14+
}
1415

15-
&.WithPlayer {
16-
position: absolute;
17-
z-index: 1;
18-
top: 0;
19-
left: 0;
20-
width: 100%;
21-
height: 100%;
22-
padding-bottom: auto;
23-
}
16+
.ThumbnailContainer {
17+
position: relative;
18+
height: 100%;
2419
}
2520

2621
.PlayButton {
2722
--pc-play-button-focused-state-overlay: rgba(223, 227, 232, 0.3);
23+
--timestamp-background-hover: rgba(0, 0, 0, 0.8);
24+
2825
position: absolute;
2926
top: 0;
3027
left: 0;
@@ -33,50 +30,42 @@ $progress-bar-height: 6px;
3330
padding: 0;
3431
border: none;
3532
background: transparent;
36-
opacity: 0.8;
3733
transition: opacity var(--p-duration-200) var(--p-ease-in);
3834
cursor: pointer;
3935

40-
&:hover,
41-
&:focus {
42-
opacity: 1;
43-
}
44-
4536
&:focus {
4637
outline: none;
4738
box-shadow: inset 2px 0 0 var(--p-focused);
4839
background-image: linear-gradient(
4940
var(--pc-play-button-focused-state-overlay),
5041
var(--pc-play-button-focused-state-overlay)
5142
);
43+
44+
.Timestamp {
45+
background-color: var(--timestamp-background-hover);
46+
}
47+
}
48+
49+
&:hover .Timestamp {
50+
background-color: var(--timestamp-background-hover);
5251
}
5352
}
5453

5554
.PlayIcon {
56-
position: absolute;
57-
top: 50%;
58-
left: 50%;
59-
width: $start-button-size;
60-
height: $start-button-size;
61-
margin-top: -$start-button-size * 0.5;
62-
margin-left: -$start-button-size * 0.5;
55+
fill: var(--p-icon-on-interactive);
6356
}
6457

6558
.Timestamp {
6659
position: absolute;
6760
bottom: 0;
68-
padding: 0 var(--p-space-1);
69-
margin-bottom: var(--p-space-2);
70-
margin-left: var(--p-space-2);
61+
padding: var(--p-space-1) var(--p-space-2) var(--p-space-1) var(--p-space-1);
62+
margin-bottom: var(--p-space-4);
63+
margin-left: var(--p-space-4);
7164
border-radius: var(--p-border-radius-1);
72-
color: var(--p-text);
73-
background-color: var(--p-surface);
74-
opacity: 0.8;
65+
color: var(--p-text-on-interactive);
66+
background-color: rgba(0, 0, 0, 0.6);
7567
text-align: center;
76-
}
77-
78-
.withProgress {
79-
margin-bottom: var(--p-space-3);
68+
transition: background-color var(--p-duration-200) var(--p-ease-in);
8069
}
8170

8271
.Progress {

polaris-react/src/components/VideoThumbnail/VideoThumbnail.tsx

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import React from 'react';
2+
import {PlayMinor} from '@shopify/polaris-icons';
23

34
import {useI18n} from '../../utilities/i18n';
4-
import {classNames} from '../../utilities/css';
55
import {
66
secondsToTimeComponents,
77
secondsToTimestamp,
88
secondsToDurationTranslationKey,
99
} from '../../utilities/duration';
10+
import {useMediaQuery} from '../../utilities/media-query';
11+
import {Icon} from '../Icon';
12+
import {Stack} from '../Stack';
13+
import {Text} from '../Text';
1014

11-
import {PlayIcon} from './illustrations';
1215
import styles from './VideoThumbnail.scss';
1316

1417
export interface VideoThumbnailProps {
@@ -49,6 +52,7 @@ export function VideoThumbnail({
4952
onBeforeStartPlaying,
5053
}: VideoThumbnailProps) {
5154
const i18n = useI18n();
55+
const {isNavigationCollapsed} = useMediaQuery();
5256
let buttonLabel;
5357

5458
if (accessibilityLabel) {
@@ -73,13 +77,19 @@ export function VideoThumbnail({
7377
}
7478

7579
const timeStampMarkup = videoLength ? (
76-
<p
77-
className={classNames(
78-
styles.Timestamp,
79-
showVideoProgress && styles.withProgress,
80-
)}
81-
>
82-
{secondsToTimestamp(videoLength)}
80+
<p className={styles.Timestamp}>
81+
<Stack alignment="center" spacing="extraTight">
82+
<span className={styles.PlayIcon}>
83+
<Icon source={PlayMinor} />
84+
</span>
85+
<Text
86+
variant={isNavigationCollapsed ? 'bodyLg' : 'bodyMd'}
87+
as="p"
88+
fontWeight="semibold"
89+
>
90+
{secondsToTimestamp(videoLength)}
91+
</Text>
92+
</Stack>
8393
</p>
8494
) : null;
8595

@@ -109,10 +119,11 @@ export function VideoThumbnail({
109119
}
110120

111121
return (
112-
<div
113-
className={styles.Thumbnail}
114-
style={{backgroundImage: `url(${thumbnailUrl})`}}
115-
>
122+
<div className={styles.ThumbnailContainer}>
123+
<div
124+
className={styles.Thumbnail}
125+
style={{backgroundImage: `url(${thumbnailUrl})`}}
126+
/>
116127
<button
117128
type="button"
118129
className={styles.PlayButton}
@@ -122,9 +133,8 @@ export function VideoThumbnail({
122133
onFocus={onBeforeStartPlaying}
123134
onTouchStart={onBeforeStartPlaying}
124135
>
125-
<img className={styles.PlayIcon} src={PlayIcon} alt="" />
136+
{timeStampMarkup}
126137
</button>
127-
{timeStampMarkup}
128138
{progressMarkup}
129139
</div>
130140
);

polaris-react/src/components/VideoThumbnail/illustrations/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

polaris-react/src/components/VideoThumbnail/illustrations/play.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

polaris-react/src/components/VideoThumbnail/tests/VideoThumbnail.test.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
33

44
import {VideoThumbnail} from '../VideoThumbnail';
5+
import {Text} from '../../Text';
56

67
describe('<VideoThumbnail />', () => {
78
const spyClick = jest.fn();
@@ -29,8 +30,8 @@ describe('<VideoThumbnail />', () => {
2930
const videoThumbnail = mountWithApp(
3031
<VideoThumbnail {...mockProps} videoLength={undefined} />,
3132
);
32-
expect(videoThumbnail).not.toContainReactComponent('p', {
33-
className: 'Timestamp',
33+
expect(videoThumbnail).not.toContainReactComponent(Text, {
34+
fontWeight: 'semibold',
3435
});
3536
});
3637

@@ -39,8 +40,8 @@ describe('<VideoThumbnail />', () => {
3940
<VideoThumbnail {...mockProps} videoLength={45} />,
4041
);
4142

42-
expect(videoThumbnail).toContainReactComponent('p', {
43-
className: 'Timestamp',
43+
expect(videoThumbnail).toContainReactComponent(Text, {
44+
fontWeight: 'semibold',
4445
children: '0:45',
4546
});
4647
});
@@ -49,8 +50,8 @@ describe('<VideoThumbnail />', () => {
4950
const videoThumbnail = mountWithApp(
5051
<VideoThumbnail {...mockProps} videoLength={135} />,
5152
);
52-
expect(videoThumbnail).toContainReactComponent('p', {
53-
className: 'Timestamp',
53+
expect(videoThumbnail).toContainReactComponent(Text, {
54+
fontWeight: 'semibold',
5455
children: '2:15',
5556
});
5657
});
@@ -59,8 +60,8 @@ describe('<VideoThumbnail />', () => {
5960
const videoThumbnail = mountWithApp(
6061
<VideoThumbnail {...mockProps} videoLength={3745} />,
6162
);
62-
expect(videoThumbnail).toContainReactComponent('p', {
63-
className: 'Timestamp',
63+
expect(videoThumbnail).toContainReactComponent(Text, {
64+
fontWeight: 'semibold',
6465
children: '1:02:25',
6566
});
6667
});

0 commit comments

Comments
 (0)