Skip to content

Commit f3d1a91

Browse files
committed
Add play buttons to sound library tiles for touch
Add prop to library items to show a play button. If a play button is present the ‘play on hover’ only applies over the icon rather than the full tile.
1 parent a72a420 commit f3d1a91

File tree

6 files changed

+117
-7
lines changed

6 files changed

+117
-7
lines changed
Lines changed: 27 additions & 0 deletions
Loading

src/components/library-item/library-item.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
align-items: center;
88
justify-content: flex-start;
99
flex-basis: 160px;
10+
position: relative;
1011
height: 160px;
1112
max-width: 160px;
1213
margin: $space;
@@ -200,3 +201,45 @@
200201
[dir="rtl"] .coming-soon-text {
201202
transform: translate(calc(-2 * $space), calc(2 * $space));
202203
}
204+
205+
.play-button {
206+
display: flex;
207+
align-items: center;
208+
justify-content: center;
209+
210+
overflow: hidden; /* Mask the icon animation */
211+
width: 1.5rem;
212+
height: 1.5rem;
213+
background-color: $motion-primary;
214+
color: $ui-white;
215+
border-radius: 50%;
216+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
217+
user-select: none;
218+
cursor: pointer;
219+
transition: all 0.15s ease-out;
220+
}
221+
222+
.play-button {
223+
position: absolute;
224+
position: absolute;
225+
top: 0.125rem;
226+
z-index: auto;
227+
}
228+
229+
.play-button:focus {
230+
outline: none;
231+
}
232+
233+
.play-icon {
234+
width: 50%;
235+
}
236+
237+
[dir="ltr"] .play-button {
238+
right: 0.125rem;
239+
padding-left: .125rem;
240+
}
241+
242+
[dir="rtl"] .play-button {
243+
left: 0.125rem;
244+
padding-right: .125rem;
245+
}

src/components/library-item/library-item.jsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import classNames from 'classnames';
88

99
import bluetoothIconURL from './bluetooth.svg';
1010
import internetConnectionIconURL from './internet-connection.svg';
11+
import playIcon from './icon--play.svg';
12+
13+
const preventClick = e => {
14+
e.stopPropagation();
15+
};
1116

1217
/* eslint-disable react/prefer-stateless-function */
1318
class LibraryItemComponent extends React.PureComponent {
@@ -115,19 +120,39 @@ class LibraryItemComponent extends React.PureComponent {
115120
onClick={this.props.onClick}
116121
onFocus={this.props.onFocus}
117122
onKeyPress={this.props.onKeyPress}
118-
onMouseEnter={this.props.onMouseEnter}
119-
onMouseLeave={this.props.onMouseLeave}
123+
onMouseEnter={this.props.showPlayButton ? null : this.props.onMouseEnter}
124+
onMouseLeave={this.props.showPlayButton ? null : this.props.onMouseLeave}
120125
>
121126
{/* Layers of wrapping is to prevent layout thrashing on animation */}
122127
<Box className={styles.libraryItemImageContainerWrapper}>
123-
<Box className={styles.libraryItemImageContainer}>
128+
<Box
129+
className={styles.libraryItemImageContainer}
130+
onMouseEnter={this.props.showPlayButton ? this.props.onMouseEnter : null}
131+
onMouseLeave={this.props.showPlayButton ? this.props.onMouseLeave : null}
132+
>
124133
<img
125134
className={styles.libraryItemImage}
126135
src={this.props.iconURL}
127136
/>
128137
</Box>
129138
</Box>
130139
<span className={styles.libraryItemName}>{this.props.name}</span>
140+
{this.props.showPlayButton ? (
141+
<div
142+
aria-label="Play"
143+
className={styles.playButton}
144+
role="button"
145+
tabIndex="0"
146+
onClick={preventClick}
147+
onMouseDown={this.props.onPlay}
148+
>
149+
<img
150+
className={styles.playIcon}
151+
draggable={false}
152+
src={playIcon}
153+
/>
154+
</div>
155+
) : null}
131156
</Box>
132157
);
133158
}
@@ -158,11 +183,14 @@ LibraryItemComponent.propTypes = {
158183
onFocus: PropTypes.func.isRequired,
159184
onKeyPress: PropTypes.func.isRequired,
160185
onMouseEnter: PropTypes.func.isRequired,
161-
onMouseLeave: PropTypes.func.isRequired
186+
onMouseLeave: PropTypes.func.isRequired,
187+
onPlay: PropTypes.func.isRequired,
188+
showPlayButton: PropTypes.bool
162189
};
163190

164191
LibraryItemComponent.defaultProps = {
165-
disabled: false
192+
disabled: false,
193+
showPlayButton: false
166194
};
167195

168196
export default LibraryItemComponent;

src/components/library/library.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class LibraryComponent extends React.Component {
187187
internetConnectionRequired={dataItem.internetConnectionRequired}
188188
key={typeof dataItem.name === 'string' ? dataItem.name : dataItem.rawURL}
189189
name={dataItem.name}
190+
showPlayButton={this.props.showPlayButton}
190191
onMouseEnter={this.handleMouseEnter}
191192
onMouseLeave={this.handleMouseLeave}
192193
onSelect={this.handleSelect}
@@ -227,12 +228,14 @@ LibraryComponent.propTypes = {
227228
onItemMouseLeave: PropTypes.func,
228229
onItemSelected: PropTypes.func,
229230
onRequestClose: PropTypes.func,
231+
showPlayButton: PropTypes.bool,
230232
tags: PropTypes.arrayOf(PropTypes.shape(TagButton.propTypes)),
231233
title: PropTypes.string.isRequired
232234
};
233235

234236
LibraryComponent.defaultProps = {
235-
filterable: true
237+
filterable: true,
238+
showPlayButton: false
236239
};
237240

238241
export default injectIntl(LibraryComponent);

src/containers/library-item.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class LibraryItem extends React.PureComponent {
1515
'handleKeyPress',
1616
'handleMouseEnter',
1717
'handleMouseLeave',
18+
'handlePlay',
1819
'rotateIcon',
1920
'startRotatingIcons',
2021
'stopRotatingIcons'
@@ -62,6 +63,10 @@ class LibraryItem extends React.PureComponent {
6263
}, this.stopRotatingIcons);
6364
}
6465
}
66+
handlePlay (e) {
67+
e.stopPropagation(); // To prevent from bubbling back to handleClick
68+
this.props.onMouseEnter(this.props.id);
69+
}
6570
startRotatingIcons () {
6671
this.rotateIcon();
6772
this.intervalId = setInterval(this.rotateIcon, 300);
@@ -105,12 +110,14 @@ class LibraryItem extends React.PureComponent {
105110
insetIconURL={this.props.insetIconURL}
106111
internetConnectionRequired={this.props.internetConnectionRequired}
107112
name={this.props.name}
113+
showPlayButton={this.props.showPlayButton}
108114
onBlur={this.handleBlur}
109115
onClick={this.handleClick}
110116
onFocus={this.handleFocus}
111117
onKeyPress={this.handleKeyPress}
112118
onMouseEnter={this.handleMouseEnter}
113119
onMouseLeave={this.handleMouseLeave}
120+
onPlay={this.handlePlay}
114121
/>
115122
);
116123
}
@@ -143,7 +150,8 @@ LibraryItem.propTypes = {
143150
]),
144151
onMouseEnter: PropTypes.func.isRequired,
145152
onMouseLeave: PropTypes.func.isRequired,
146-
onSelect: PropTypes.func.isRequired
153+
onSelect: PropTypes.func.isRequired,
154+
showPlayButton: PropTypes.bool
147155
};
148156

149157
export default injectIntl(LibraryItem);

src/containers/sound-library.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class SoundLibrary extends React.PureComponent {
141141

142142
return (
143143
<LibraryComponent
144+
showPlayButton
144145
data={soundLibraryThumbnailData}
145146
id="soundLibrary"
146147
tags={soundTags}

0 commit comments

Comments
 (0)