-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controls): Add Subtitles menu for Dash (#1400)
* feat(controls): Add Subtitles menu for Dash * chore: address pr comments * chore: add unit tests * chore: fix linting issues * chore: pr comments Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2ffb42e
commit 6d04ebc
Showing
18 changed files
with
628 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/lib/viewers/controls/media/MediaSettingsMenuSubtitles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import Settings, { Menu } from '../settings'; | ||
import { SUBTITLES_OFF } from '../../../constants'; | ||
|
||
export type Subtitle = { | ||
displayLanguage: string; | ||
id: number; | ||
}; | ||
|
||
export type Props = { | ||
onSubtitleChange?: (id: number) => void; | ||
subtitle?: number; | ||
subtitles?: Array<Subtitle>; | ||
}; | ||
|
||
export const getDisplayLanguage = (subtitle?: number, subtitles: Array<Subtitle> = []): string => { | ||
const { displayLanguage } = subtitles.find(({ id }) => subtitle === id) || { | ||
displayLanguage: __('off'), | ||
}; | ||
|
||
return displayLanguage; | ||
}; | ||
|
||
export default function MediaSettingsMenuSubtitles({ | ||
onSubtitleChange, | ||
subtitle, | ||
subtitles = [], | ||
}: Props): JSX.Element | null { | ||
const { setActiveMenu } = React.useContext(Settings.Context); | ||
|
||
if (!subtitles.length || !onSubtitleChange) { | ||
return null; | ||
} | ||
|
||
const handleChange = (value: number): void => { | ||
setActiveMenu(Menu.MAIN); | ||
onSubtitleChange(value); | ||
}; | ||
|
||
return ( | ||
<Settings.Menu name={Menu.SUBTITLES}> | ||
<Settings.MenuBack label={`${__('subtitles')}/CC`} /> | ||
<Settings.RadioItem | ||
isSelected={subtitle === SUBTITLES_OFF} | ||
label={__('off')} | ||
onChange={handleChange} | ||
value={SUBTITLES_OFF} | ||
/> | ||
{subtitles.map(({ displayLanguage, id }) => ( | ||
<Settings.RadioItem | ||
key={id} | ||
isSelected={subtitle === id} | ||
label={displayLanguage} | ||
onChange={handleChange} | ||
value={id} | ||
/> | ||
))} | ||
</Settings.Menu> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@import './styles'; | ||
|
||
.bp-SubtitlesToggle { | ||
@include bp-MediaButton; | ||
|
||
&[aria-pressed='true'] { | ||
.bp-SubtitlesToggle-text { | ||
color: $white; | ||
background-color: $box-blue; | ||
} | ||
} | ||
} | ||
|
||
.bp-SubtitlesToggle-text { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 24px; | ||
height: 24px; | ||
color: $white; | ||
font-weight: bold; | ||
font-size: 12px; | ||
letter-spacing: .1em; | ||
background-color: rgba($black, .3); // Anything less than .3 looks too transparent on IE/Edge | ||
border-radius: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import noop from 'lodash/noop'; | ||
import MediaToggle from './MediaToggle'; | ||
import { Subtitle } from './MediaSettingsMenuSubtitles'; | ||
import './SubtitlesToggle.scss'; | ||
|
||
export type Props = { | ||
isShowingSubtitles?: boolean; | ||
onSubtitlesToggle?: (isShowingSubtitles: boolean) => void; | ||
subtitles?: Array<Subtitle>; | ||
}; | ||
|
||
export default function SubtitlesToggle({ | ||
isShowingSubtitles, | ||
onSubtitlesToggle = noop, | ||
subtitles = [], | ||
}: Props): JSX.Element | null { | ||
if (!subtitles.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<MediaToggle | ||
aria-pressed={isShowingSubtitles} | ||
className="bp-SubtitlesToggle" | ||
data-testid="bp-media-cc-button" | ||
onClick={(): void => onSubtitlesToggle(!isShowingSubtitles)} | ||
title={__('media_subtitles_cc')} | ||
> | ||
<div className="bp-SubtitlesToggle-text">CC</div> | ||
</MediaToggle> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const subtitles = [ | ||
{ id: 0, displayLanguage: 'English' }, | ||
{ id: 1, displayLanguage: 'Spanish' }, | ||
]; | ||
|
||
export default subtitles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.