bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/settings/submenus/closed-captions/component.jsx

301 lines
11 KiB
React
Raw Normal View History

2016-12-23 16:26:22 +08:00
import React from 'react';
import Modal from 'react-modal';
import styles from '../styles';
2017-02-16 02:49:40 +08:00
import cx from 'classnames';
import BaseMenu from '../base/component';
import Toggle from '/imports/ui/components/switch/component';
import Checkbox from '/imports/ui/components/checkbox/component';
2017-03-09 22:34:33 +08:00
import { GithubPicker } from 'react-color';
2016-12-23 16:26:22 +08:00
//an array of font-families
2017-02-16 02:49:40 +08:00
const FONT_FAMILIES = ['Arial', 'Calibri', 'Time New Roman', 'Sans-serif'];
2016-12-23 16:26:22 +08:00
//an array of different font-sizes
2017-02-16 02:49:40 +08:00
const FONT_SIZES = ['12px', '14px', '18px', '24px', '32px', '42px'];
2016-12-23 16:26:22 +08:00
//an array of colors for both background and text
2017-02-16 02:49:40 +08:00
const COLORS = [
'#000000', '#7A7A7A', '#FF0000', '#FF8800',
'#88FF00', '#FFFFFF', '#00FFFF', '#0000FF',
'#8800FF', '#FF00FF',
];
2016-12-23 16:26:22 +08:00
export default class ClosedCaptionsMenu extends BaseMenu {
constructor(props) {
super(props);
this.state = {
2017-02-16 02:49:40 +08:00
settingsName: 'cc',
settings: {
backgroundColor: props.settings ? props.settings.backgroundColor : '#f3f6f9',
fontColor: props.settings ? props.settings.fontColor : '#000000',
2017-04-06 19:46:15 +08:00
enabled: props.settings ? props.settings.enabled : false,
fontFamily: props.settings ? props.settings.fontFamily : 'Calibri',
fontSize: props.settings ? props.settings.fontSize : -1,
locale: props.settings ? props.settings.locale : -1,
takeOwnership: props.settings ? props.settings.takeOwnership : false,
},
2017-02-16 02:49:40 +08:00
};
2016-12-23 16:26:22 +08:00
}
2017-02-16 02:49:40 +08:00
getPreviewStyle() {
return {
fontFamily: this.state.settings.fontFamily,
fontSize: this.state.settings.fontSize,
color: this.state.settings.fontColor,
2017-02-16 02:49:40 +08:00
};
2016-12-23 16:26:22 +08:00
}
//clickhandler, opens a selected color picker (supports both of them)
handleColorPickerClick(fieldname) {
let obj = {};
obj[fieldname] = !this.state[fieldname];
this.setState(obj);
}
//closes color pickers
handleCloseColorPicker() {
2017-02-16 02:49:40 +08:00
this.setState({
displayBackgroundColorPicker: false,
displayFontColorPicker:false,
});
}
handleSelectChange(fieldname, options, e) {
let obj = this.state;
obj.settings[fieldname] = options[e.target.value];
2017-02-16 02:49:40 +08:00
this.setState(obj);
this.handleUpdateSettings('cc', obj.settings);
2016-12-23 16:26:22 +08:00
}
handleColorChange(fieldname, color) {
let obj = this.state;
obj.settings[fieldname] = color.hex;
2017-02-16 02:49:40 +08:00
2016-12-23 16:26:22 +08:00
this.setState(obj);
this.handleUpdateSettings('cc', obj.settings);
2017-03-09 22:34:33 +08:00
this.handleCloseColorPicker();
2016-12-23 16:26:22 +08:00
}
2017-02-16 02:49:40 +08:00
render() {
const {
locales,
} = this.props;
2016-12-23 16:26:22 +08:00
return (
2017-02-16 02:49:40 +08:00
<div className={styles.tabContent}>
<div className={styles.header}>
<h3 className={styles.title}>Closed Captions</h3>
2016-12-23 16:26:22 +08:00
</div>
2017-02-16 02:49:40 +08:00
<div className={styles.form}>
<div className={styles.row}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
Closed captions
</label>
</div>
</div>
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
<Toggle
icons={false}
2017-04-06 19:46:15 +08:00
defaultChecked={this.state.settings.enabled}
onChange={() => this.handleToggle('enabled')} />
2017-02-16 02:49:40 +08:00
</div>
</div>
</div>
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
Take ownership
</label>
</div>
</div>
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
<Checkbox
onChange={() => this.handleToggle('takeOwnership')}
checked={this.state.settings.takeOwnership}/>
2017-02-16 02:49:40 +08:00
</div>
</div>
</div>
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
Language
</label>
</div>
</div>
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
<select
defaultValue={locales ? locales.indexOf(this.state.settings.locale) : -1}
2017-02-16 02:49:40 +08:00
className={styles.select}
onChange={this.handleSelectChange.bind(this, 'locale', this.props.locales)}>
<option>
{ this.props.locales &&
this.props.locales.length ?
'Choose language' :
'No active locales' }
</option>
2016-12-23 16:26:22 +08:00
{this.props.locales ? this.props.locales.map((locale, index) =>
2017-02-16 02:49:40 +08:00
<option key={index} value={index}>
{locale}
</option>
) : null }
</select>
</div>
</div>
2016-12-23 16:26:22 +08:00
</div>
2017-02-16 02:49:40 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
Font family
</label>
</div>
</div>
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
<select
defaultValue={FONT_FAMILIES.indexOf(this.state.settings.fontFamily)}
2017-02-16 02:49:40 +08:00
onChange={this.handleSelectChange.bind(this, 'fontFamily', FONT_FAMILIES)}
className={styles.select}>
<option value='-1' disabled>Choose Font-family</option>
{
FONT_FAMILIES.map((family, index) =>
<option key={index} value={index}>
{family}
</option>
)
}
</select>
</div>
</div>
2016-12-23 16:26:22 +08:00
</div>
2017-02-16 02:49:40 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
Font size
</label>
</div>
</div>
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
<select
defaultValue={FONT_SIZES.indexOf(this.state.settings.fontSize)}
2017-02-16 02:49:40 +08:00
onChange={this.handleSelectChange.bind(this, 'fontSize', FONT_SIZES)}
className={styles.select}>
<option value='-1' disabled>Choose Font-size</option>
{
FONT_SIZES.map((size, index) =>
<option key={index} value={index}>
{size}
</option>
)
}
</select>
</div>
</div>
2016-12-23 16:26:22 +08:00
</div>
2017-02-16 02:49:40 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
Background color
</label>
</div>
2016-12-23 16:26:22 +08:00
</div>
2017-02-16 02:49:40 +08:00
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
2016-12-23 16:26:22 +08:00
<div
2017-02-16 02:49:40 +08:00
tabIndex='12'
className={ styles.swatch }
onClick={ this.handleColorPickerClick.bind(this, 'displayBackgroundColorPicker') }>
<div
className={styles.swatchInner}
style={ { background: this.state.settings.backgroundColor } }>
2017-02-16 02:49:40 +08:00
</div>
</div>
{ this.state.displayBackgroundColorPicker ?
<div className={styles.colorPickerPopover}>
<div
className={styles.colorPickerOverlay}
onClick={ this.handleCloseColorPicker.bind(this) }
>
</div>
2017-03-09 22:34:33 +08:00
<GithubPicker
2017-02-16 02:49:40 +08:00
onChange={this.handleColorChange.bind(this, 'backgroundColor')}
color={this.state.settings.backgroundColor}
2017-02-16 02:49:40 +08:00
colors={COLORS}
width={'140px'}
triangle={'top-right'}
/>
</div>
: null }
</div>
</div>
2016-12-23 16:26:22 +08:00
</div>
2017-02-16 02:49:40 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
Font color
</label>
</div>
2016-12-23 16:26:22 +08:00
</div>
2017-02-16 02:49:40 +08:00
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
2016-12-23 16:26:22 +08:00
<div
2017-02-16 02:49:40 +08:00
tabIndex='12'
className={ styles.swatch }
onClick={ this.handleColorPickerClick.bind(this, 'displayFontColorPicker') }>
<div
className={styles.swatchInner}
style={ { background: this.state.settings.fontColor } }>
2017-02-16 02:49:40 +08:00
</div>
</div>
{ this.state.displayFontColorPicker ?
<div className={styles.colorPickerPopover}>
<div
className={styles.colorPickerOverlay}
onClick={ this.handleCloseColorPicker.bind(this) }
>
</div>
2017-03-09 22:34:33 +08:00
<GithubPicker
2017-02-16 02:49:40 +08:00
onChange={this.handleColorChange.bind(this, 'fontColor')}
color={this.state.settings.fontColor}
2017-02-16 02:49:40 +08:00
colors={COLORS}
width={'140px'}
triangle={'top-right'}
/>
</div>
: null }
</div>
</div>
</div>
<div
className={cx(styles.ccPreviewBox, styles.spacedLeft)}
role='presentation'
style={ { background: this.state.settings.backgroundColor } }>
2017-02-16 02:49:40 +08:00
<span style={this.getPreviewStyle()}>
Etiam porta sem malesuada magna mollis euis-mod.
Donec ullamcorper nulla non metus auctor fringilla.
</span>
2016-12-23 16:26:22 +08:00
</div>
</div>
</div>
);
}
};