-
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 MP3 settings controls (#1343)
- Loading branch information
Showing
36 changed files
with
316 additions
and
13 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
34 changes: 34 additions & 0 deletions
34
src/lib/viewers/controls/media/MediaSettings/MediaSettingsAutoplay.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,34 @@ | ||
import React from 'react'; | ||
import MediaSettings, { Menu } from '.'; | ||
|
||
export type Props = { | ||
autoplay: boolean; | ||
onAutoplayChange: (autoplay: boolean) => void; | ||
}; | ||
|
||
export default function MediaSettingsMenuAutoplay({ autoplay, onAutoplayChange }: Props): JSX.Element { | ||
const { setActiveMenu } = React.useContext(MediaSettings.Context); | ||
|
||
const handleChange = (value: boolean): void => { | ||
setActiveMenu(Menu.MAIN); | ||
onAutoplayChange(value); | ||
}; | ||
|
||
return ( | ||
<MediaSettings.Menu name={Menu.AUTOPLAY}> | ||
<MediaSettings.MenuBack label={__('media_autoplay')} /> | ||
<MediaSettings.RadioItem | ||
isSelected={!autoplay} | ||
label={__('media_autoplay_disabled')} | ||
onChange={handleChange} | ||
value={false} | ||
/> | ||
<MediaSettings.RadioItem | ||
isSelected={autoplay} | ||
label={__('media_autoplay_enabled')} | ||
onChange={handleChange} | ||
value | ||
/> | ||
</MediaSettings.Menu> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
src/lib/viewers/controls/media/MediaSettings/MediaSettingsRate.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,32 @@ | ||
import React from 'react'; | ||
import MediaSettings, { Menu } from '.'; | ||
|
||
export type Props = { | ||
onRateChange: (rate: string) => void; | ||
rate: string; | ||
}; | ||
|
||
export default function MediaSettingsMenuRate({ rate, onRateChange }: Props): JSX.Element { | ||
const { setActiveMenu } = React.useContext(MediaSettings.Context); | ||
|
||
const handleChange = (value: string): void => { | ||
setActiveMenu(Menu.MAIN); | ||
onRateChange(value); | ||
}; | ||
|
||
return ( | ||
<MediaSettings.Menu name={Menu.RATE}> | ||
<MediaSettings.MenuBack label={__('media_speed')} /> | ||
<MediaSettings.RadioItem isSelected={rate === '0.5'} onChange={handleChange} value="0.5" /> | ||
<MediaSettings.RadioItem | ||
isSelected={rate === '1.0'} | ||
label={__('media_speed_normal')} | ||
onChange={handleChange} | ||
value="1.0" | ||
/> | ||
<MediaSettings.RadioItem isSelected={rate === '1.25'} onChange={handleChange} value="1.25" /> | ||
<MediaSettings.RadioItem isSelected={rate === '1.5'} onChange={handleChange} value="1.5" /> | ||
<MediaSettings.RadioItem isSelected={rate === '2.0'} onChange={handleChange} value="2.0" /> | ||
</MediaSettings.Menu> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
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
42 changes: 42 additions & 0 deletions
42
src/lib/viewers/controls/media/MediaSettings/__tests__/MediaSettingsAutoplay-test.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,42 @@ | ||
import React from 'react'; | ||
import { mount, ReactWrapper } from 'enzyme'; | ||
import MediaSettings, { Context, Menu } from '..'; | ||
import MediaSettingsAutoplay from '../MediaSettingsAutoplay'; | ||
|
||
describe('MediaSettingsAutoplay', () => { | ||
const getContext = (): Partial<Context> => ({ setActiveMenu: jest.fn() }); | ||
const getWrapper = (props = {}, context = getContext()): ReactWrapper => | ||
mount(<MediaSettingsAutoplay autoplay onAutoplayChange={jest.fn()} {...props} />, { | ||
wrappingComponent: MediaSettings.Context.Provider, | ||
wrappingComponentProps: { value: context }, | ||
}); | ||
|
||
describe('event handlers', () => { | ||
test('should surface the selected item on change', () => { | ||
const onAutoplayChange = jest.fn(); | ||
const wrapper = getWrapper({ onAutoplayChange }); | ||
|
||
wrapper.find({ value: true }).simulate('click'); | ||
|
||
expect(onAutoplayChange).toBeCalledWith(true); | ||
}); | ||
|
||
test('should reset the active menu on change', () => { | ||
const context = getContext(); | ||
const wrapper = getWrapper({}, context); | ||
|
||
wrapper.find({ value: true }).simulate('click'); | ||
|
||
expect(context.setActiveMenu).toBeCalledWith(Menu.MAIN); | ||
}); | ||
}); | ||
|
||
describe('render', () => { | ||
test('should return a valid wrapper', () => { | ||
const wrapper = getWrapper(); | ||
|
||
expect(wrapper.exists(MediaSettings.MenuBack)).toBe(true); | ||
expect(wrapper.exists(MediaSettings.RadioItem)).toBe(true); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions
42
src/lib/viewers/controls/media/MediaSettings/__tests__/MediaSettingsRate-test.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,42 @@ | ||
import React from 'react'; | ||
import { mount, ReactWrapper } from 'enzyme'; | ||
import MediaSettings, { Context, Menu } from '..'; | ||
import MediaSettingsRate from '../MediaSettingsRate'; | ||
|
||
describe('MediaSettingsRate', () => { | ||
const getContext = (): Partial<Context> => ({ setActiveMenu: jest.fn() }); | ||
const getWrapper = (props = {}, context = getContext()): ReactWrapper => | ||
mount(<MediaSettingsRate onRateChange={jest.fn()} rate="1.0" {...props} />, { | ||
wrappingComponent: MediaSettings.Context.Provider, | ||
wrappingComponentProps: { value: context }, | ||
}); | ||
|
||
describe('event handlers', () => { | ||
test('should surface the selected item on change', () => { | ||
const onRateChange = jest.fn(); | ||
const wrapper = getWrapper({ onRateChange }); | ||
|
||
wrapper.find({ value: '2.0' }).simulate('click'); | ||
|
||
expect(onRateChange).toBeCalledWith('2.0'); | ||
}); | ||
|
||
test('should reset the active menu on change', () => { | ||
const context = getContext(); | ||
const wrapper = getWrapper({}, context); | ||
|
||
wrapper.find({ value: '2.0' }).simulate('click'); | ||
|
||
expect(context.setActiveMenu).toBeCalledWith(Menu.MAIN); | ||
}); | ||
}); | ||
|
||
describe('render', () => { | ||
test('should return a valid wrapper', () => { | ||
const wrapper = getWrapper(); | ||
|
||
expect(wrapper.exists(MediaSettings.MenuBack)).toBe(true); | ||
expect(wrapper.exists(MediaSettings.RadioItem)).toBe(true); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
export * from './MediaSettings'; | ||
export * from './MediaSettingsContext'; | ||
export { default } from './MediaSettings'; |
3 changes: 0 additions & 3 deletions
3
src/lib/viewers/controls/media/MediaSettingsControls/index.ts
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import MediaSettings, { Menu } from '../controls/media/MediaSettings'; | ||
import MediaSettingsAutoplay, { Props as AutoplayProps } from '../controls/media/MediaSettings/MediaSettingsAutoplay'; | ||
import MediaSettingsRate, { Props as RateProps } from '../controls/media/MediaSettings/MediaSettingsRate'; | ||
|
||
export type Props = AutoplayProps & RateProps; | ||
|
||
export default function MP3Settings({ autoplay, onAutoplayChange, onRateChange, rate }: Props): JSX.Element { | ||
const autoValue = autoplay ? __('media_autoplay_enabled') : __('media_autoplay_disabled'); | ||
const rateValue = rate === '1.0' || !rate ? __('media_speed_normal') : rate; | ||
|
||
return ( | ||
<MediaSettings className="bp-MP3Settings"> | ||
<MediaSettings.Menu name={Menu.MAIN}> | ||
<MediaSettings.MenuItem label={__('media_autoplay')} target={Menu.AUTOPLAY} value={autoValue} /> | ||
<MediaSettings.MenuItem label={__('media_speed')} target={Menu.RATE} value={rateValue} /> | ||
</MediaSettings.Menu> | ||
|
||
<MediaSettingsAutoplay autoplay={autoplay} onAutoplayChange={onAutoplayChange} /> | ||
<MediaSettingsRate onRateChange={onRateChange} rate={rate} /> | ||
</MediaSettings> | ||
); | ||
} |
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.