-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
03e7b31
commit 86cb923
Showing
19 changed files
with
685 additions
and
391 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
159 changes: 159 additions & 0 deletions
159
src/components/cvaa-overlay/custom-captions-window/custom-captions-window.js
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,159 @@ | ||
//@flow | ||
import {Component} from 'preact'; | ||
import style from '../../styles/style.scss'; | ||
import {KeyMap} from 'utils/key-map'; | ||
import {Text} from 'preact-i18n'; | ||
import {h} from 'preact'; | ||
import {DropDownCaptionsStyle} from './drop-down-captions-style'; | ||
import {SliderCaptionsStyle} from './slider-captions-style'; | ||
import {withPlayer} from 'components/player'; | ||
|
||
@withPlayer | ||
|
||
/** | ||
* CustomCaptionsWindow component | ||
* @class CustomCaptionsWindow | ||
* @extends {Component} | ||
*/ | ||
class CustomCaptionsWindow extends Component { | ||
/** | ||
* after component mounted, set focus on default | ||
* | ||
* @returns {void} | ||
* @memberof CustomCaptionsWindow | ||
*/ | ||
componentDidMount(): void { | ||
this.props.focusOnDefault(); | ||
} | ||
|
||
/** | ||
* render component | ||
* | ||
* @param {*} props - component props | ||
* @returns {React$Element} - component element | ||
* @memberof CustomCaptionsWindow | ||
*/ | ||
render(props: any): React$Element<any> { | ||
const {player} = this.props; | ||
const fontFamily = player.TextStyle.FontFamily; | ||
const edgeStyles = player.TextStyle.EdgeStyles; | ||
const standardColors = player.TextStyle.StandardColors; | ||
|
||
const fontScaleOptions = player.TextStyle.FontSizes.map(scale => ({ | ||
value: scale.value, | ||
label: scale.label, | ||
active: props.customTextStyle.fontScale === scale.value | ||
})); | ||
|
||
const fontColorOptions = Object.keys(standardColors).map(key => ({ | ||
value: standardColors[key], | ||
label: key.charAt(0).toUpperCase() + key.toLowerCase().slice(1), | ||
active: props.customTextStyle.fontColor.every((value, index) => value === standardColors[key][index]) | ||
})); | ||
|
||
const fontFamilyOptions = Object.keys(fontFamily).map(key => ({ | ||
value: fontFamily[key], | ||
label: fontFamily[key], | ||
active: props.customTextStyle.fontFamily === fontFamily[key] | ||
})); | ||
|
||
const fontStyleOptions = Object.keys(edgeStyles).map(key => ({ | ||
value: edgeStyles[key], | ||
label: key.charAt(0).toUpperCase() + key.toLowerCase().slice(1), | ||
active: props.customTextStyle.fontEdge === edgeStyles[key] | ||
})); | ||
|
||
const backgroundColorOptions = Object.keys(standardColors).map(key => ({ | ||
value: standardColors[key], | ||
label: key.charAt(0).toUpperCase() + key.toLowerCase().slice(1), | ||
active: props.customTextStyle.backgroundColor.every((value, index) => value === standardColors[key][index]) | ||
})); | ||
|
||
return ( | ||
<div className={[style.overlayScreen, style.active].join(' ')}> | ||
<form className={[style.form, style.customCaptionForm].join(' ')}> | ||
<DropDownCaptionsStyle | ||
addAccessibleChild={props.addAccessibleChild} | ||
labelId="cvaa.size_label" | ||
options={fontScaleOptions} | ||
classNames={[style.formGroupRow, style.fontSize]} | ||
styleName="fontScale" | ||
changeCustomStyle={props.changeCustomStyle} | ||
/> | ||
<DropDownCaptionsStyle | ||
addAccessibleChild={props.addAccessibleChild} | ||
labelId="cvaa.font_color_label" | ||
options={fontColorOptions} | ||
classNames={[style.formGroupRow, style.fontColor]} | ||
styleName="fontColor" | ||
changeCustomStyle={props.changeCustomStyle} | ||
/> | ||
<DropDownCaptionsStyle | ||
addAccessibleChild={props.addAccessibleChild} | ||
labelId="cvaa.font_family_label" | ||
options={fontFamilyOptions} | ||
classNames={[style.formGroupRow, style.fontFamily]} | ||
styleName="fontFamily" | ||
changeCustomStyle={props.changeCustomStyle} | ||
/> | ||
<DropDownCaptionsStyle | ||
addAccessibleChild={props.addAccessibleChild} | ||
labelId="cvaa.font_style_label" | ||
options={fontStyleOptions} | ||
classNames={[style.formGroupRow, style.fontStyle]} | ||
styleName="fontEdge" | ||
changeCustomStyle={props.changeCustomStyle} | ||
/> | ||
<SliderCaptionsStyle | ||
addAccessibleChild={props.addAccessibleChild} | ||
labelId="cvaa.font_opacity_label" | ||
value={props.customTextStyle.fontOpacity} | ||
classNames={[style.formGroupRow, style.fontOpacity]} | ||
styleName="fontOpacity" | ||
changeCustomStyle={props.changeCustomStyle} | ||
/> | ||
<DropDownCaptionsStyle | ||
addAccessibleChild={props.addAccessibleChild} | ||
labelId="cvaa.background_color_label" | ||
options={backgroundColorOptions} | ||
classNames={[style.formGroupRow, style.backgroundColor]} | ||
styleName="backgroundColor" | ||
changeCustomStyle={props.changeCustomStyle} | ||
/> | ||
<SliderCaptionsStyle | ||
addAccessibleChild={props.addAccessibleChild} | ||
labelId="cvaa.background_opacity_label" | ||
value={props.customTextStyle.backgroundOpacity} | ||
classNames={[style.formGroupRow, style.backgroundOpacity]} | ||
styleName="backgroundOpacity" | ||
changeCustomStyle={props.changeCustomStyle} | ||
/> | ||
<div className={style.formGroupRow}> | ||
<a | ||
tabIndex="0" | ||
ref={el => { | ||
props.addAccessibleChild(el); | ||
}} | ||
onClick={() => props.changeCaptionsStyle(props.customTextStyle)} | ||
onKeyDown={e => { | ||
if (e.keyCode === KeyMap.ENTER) { | ||
props.changeCaptionsStyle(props.customTextStyle); | ||
} | ||
}} | ||
className={[style.btn, style.btnBranded, style.btnBlock].join(' ')}> | ||
<Text id={'cvaa.apply'} /> | ||
</a> | ||
</div> | ||
|
||
<div className={style.previewContainer}> | ||
<span style={props.getPreviewStyle()}> | ||
<Text id={'cvaa.caption_preview'} /> | ||
</span> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export {CustomCaptionsWindow}; |
32 changes: 32 additions & 0 deletions
32
src/components/cvaa-overlay/custom-captions-window/drop-down-captions-style.js
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 @@ | ||
//@flow | ||
import {Text} from 'preact-i18n'; | ||
import {DropDown} from 'components/dropdown'; | ||
import {h} from 'preact'; | ||
|
||
/** | ||
* renders a custom dropdown style option | ||
* @param {*} props - component props | ||
* @returns {React$Element} - component element | ||
*/ | ||
const DropDownCaptionsStyle = (props: Object): React$Element<any> => { | ||
return ( | ||
<div className={props.classNames.join(' ')}> | ||
<label> | ||
<Text id={props.labelId} /> | ||
</label> | ||
<DropDown | ||
pushRef={el => { | ||
props.addAccessibleChild(el); | ||
}} | ||
tabbable | ||
onMenuChosen={chosenOption => { | ||
let changedStyle = {}; | ||
changedStyle[props.styleName] = chosenOption; | ||
props.changeCustomStyle(changedStyle); | ||
}} | ||
options={props.options} | ||
/> | ||
</div> | ||
); | ||
}; | ||
export {DropDownCaptionsStyle}; |
39 changes: 39 additions & 0 deletions
39
src/components/cvaa-overlay/custom-captions-window/slider-captions-style.js
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,39 @@ | ||
//@flow | ||
import {Text} from 'preact-i18n'; | ||
import {h} from 'preact'; | ||
import {Slider} from 'components/slider'; | ||
|
||
/** | ||
* renders a custom slider style option | ||
* | ||
* @param {*} props - component props | ||
* @param {string} labelId - the label id to localize | ||
* @param {number} value - the current value of the slider | ||
* @param {classNames} classNames - the css classes to apply | ||
* @param {string} styleName - the property name to change | ||
* @returns {React$Element} - component element | ||
* @memberof CustomCaptionsWindow | ||
*/ | ||
const SliderCaptionsStyle = (props: Object): React$Element<any> => { | ||
return ( | ||
<div className={props.classNames.join(' ')}> | ||
<label> | ||
<Text id={props.labelId} /> | ||
</label> | ||
<Slider | ||
pushRef={el => { | ||
props.addAccessibleChild(el); | ||
}} | ||
min={0} | ||
max={100} | ||
value={props.value * 100} | ||
onChange={valueChanged => { | ||
let changedStyle = {}; | ||
changedStyle[props.styleName] = valueChanged / 100; | ||
props.changeCustomStyle(changedStyle); | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
export {SliderCaptionsStyle}; |
Oops, something went wrong.