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

383 lines
14 KiB
React
Raw Normal View History

2016-12-23 16:26:22 +08:00
import React from 'react';
2018-01-08 14:17:18 +08:00
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';
2017-04-11 04:27:29 +08:00
import { defineMessages, injectIntl } from 'react-intl';
2016-12-23 16:26:22 +08:00
2017-06-03 03:25:02 +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'];
2017-06-03 03:25:02 +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'];
2017-06-03 03:25:02 +08:00
// an array of colors for both background and text
const COLORS = [
'#000000', '#7A7A7A', '#FF0000', '#FF8800',
'#88FF00', '#FFFFFF', '#00FFFF', '#0000FF',
'#8800FF', '#FF00FF',
];
2016-12-23 16:26:22 +08:00
2017-04-11 04:27:29 +08:00
const intlMessages = defineMessages({
closedCaptionsLabel: {
id: 'app.submenu.closedCaptions.closedCaptionsLabel',
description: 'Closed Captions label',
},
takeOwnershipLabel: {
id: 'app.submenu.closedCaptions.takeOwnershipLabel',
description: 'Take ownership label',
},
languageLabel: {
id: 'app.submenu.closedCaptions.languageLabel',
description: 'Language label',
},
localeOptionLabel: {
id: 'app.submenu.closedCaptions.localeOptionLabel',
description: 'Label for active locales',
},
noLocaleOptionLabel: {
id: 'app.submenu.closedCaptions.noLocaleOptionLabel',
description: 'Label for no active locales',
},
fontFamilyLabel: {
id: 'app.submenu.closedCaptions.fontFamilyLabel',
description: 'Label for type of Font family',
},
fontFamilyOptionLabel: {
id: 'app.submenu.closedCaptions.fontFamilyOptionLabel',
description: 'Font-family default choice option',
},
fontSizeLabel: {
id: 'app.submenu.closedCaptions.fontSizeLabel',
description: 'Font size label',
},
fontSizeOptionLabel: {
id: 'app.submenu.closedCaptions.fontSizeOptionLabel',
description: 'Choose Font size default option label',
},
backgroundColorLabel: {
id: 'app.submenu.closedCaptions.backgroundColorLabel',
description: 'Background color label',
},
fontColorLabel: {
id: 'app.submenu.closedCaptions.fontColorLabel',
description: 'Font color label',
},
});
class ClosedCaptionsMenu extends BaseMenu {
2016-12-23 16:26:22 +08:00
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
}
2017-06-03 03:25:02 +08:00
// clickhandler, opens a selected color picker (supports both of them)
2016-12-23 16:26:22 +08:00
handleColorPickerClick(fieldname) {
2017-06-03 03:25:02 +08:00
const obj = {};
2016-12-23 16:26:22 +08:00
obj[fieldname] = !this.state[fieldname];
this.setState(obj);
}
2017-06-03 03:25:02 +08:00
// closes color pickers
2016-12-23 16:26:22 +08:00
handleCloseColorPicker() {
2017-02-16 02:49:40 +08:00
this.setState({
displayBackgroundColorPicker: false,
2017-06-03 03:25:02 +08:00
displayFontColorPicker: false,
2017-02-16 02:49:40 +08:00
});
}
handleSelectChange(fieldname, options, e) {
2017-06-03 03:25:02 +08:00
const 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) {
2017-06-03 03:25:02 +08:00
const 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,
intl,
isModerator,
} = 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}>
2017-04-11 04:27:29 +08:00
<h3 className={styles.title}>{intl.formatMessage(intlMessages.closedCaptionsLabel)}</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} aria-hidden="true">
2017-02-16 02:49:40 +08:00
<div className={styles.formElement}>
<label className={styles.label}>
2017-04-11 04:27:29 +08:00
{intl.formatMessage(intlMessages.closedCaptionsLabel)}
2017-02-16 02:49:40 +08:00
</label>
</div>
</div>
<div className={styles.col}>
2017-04-25 19:59:52 +08:00
<div className={cx(styles.formElement, styles.pullContentRight)} >
2017-06-03 03:25:02 +08:00
<Toggle
icons={false}
defaultChecked={this.state.settings.enabled}
onChange={() => this.handleToggle('enabled')}
ariaLabelledBy="closedCaptions"
2017-06-03 03:25:02 +08:00
ariaLabel={intl.formatMessage(intlMessages.closedCaptionsLabel)}
/>
2017-02-16 02:49:40 +08:00
</div>
</div>
</div>
2017-05-05 02:42:55 +08:00
{ this.state.settings.enabled ?
<div>
{ isModerator ?
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.takeOwnershipLabel)}
</label>
</div>
2017-05-05 02:42:55 +08:00
</div>
<div className={styles.col}>
<div className={cx(styles.formElement, styles.pullContentRight)}>
<Checkbox
onChange={() => this.handleToggle('takeOwnership')}
checked={this.state.settings.takeOwnership}
ariaLabelledBy="takeOwnership"
2017-06-03 03:25:02 +08:00
ariaLabel={intl.formatMessage(intlMessages.takeOwnershipLabel)}
/>
</div>
2017-05-05 02:42:55 +08:00
</div>
</div>
: null }
2017-05-05 02:42:55 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.languageLabel)}
</label>
</div>
</div>
<div className={styles.col}>
2017-07-08 14:50:33 +08:00
<label
2017-05-05 02:42:55 +08:00
className={cx(styles.formElement, styles.pullContentRight)}
2017-06-03 03:25:02 +08:00
aria-label={intl.formatMessage(intlMessages.languageLabel)}
>
2017-05-05 02:42:55 +08:00
<select
defaultValue={locales ? locales.indexOf(this.state.settings.locale) : -1}
className={styles.select}
2017-06-03 03:25:02 +08:00
onChange={this.handleSelectChange.bind(this, 'locale', this.props.locales)}
>
2017-05-05 02:42:55 +08:00
<option>
{ this.props.locales &&
this.props.locales.length ?
intl.formatMessage(intlMessages.localeOptionLabel) :
intl.formatMessage(intlMessages.noLocaleOptionLabel) }
</option>
{this.props.locales ? this.props.locales.map((locale, index) =>
2017-06-03 03:25:02 +08:00
(<option key={index} value={index}>
2017-05-05 02:42:55 +08:00
{locale}
</option>)) : null }
2017-05-05 02:42:55 +08:00
</select>
2017-07-08 14:50:33 +08:00
</label>
2017-05-05 02:42:55 +08:00
</div>
2017-02-16 02:49:40 +08:00
</div>
2016-12-23 16:26:22 +08:00
2017-05-05 02:42:55 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.fontFamilyLabel)}
</label>
</div>
</div>
<div className={styles.col}>
2017-07-08 14:50:33 +08:00
<label
2017-05-05 02:42:55 +08:00
className={cx(styles.formElement, styles.pullContentRight)}
2017-06-03 03:25:02 +08:00
aria-label={intl.formatMessage(intlMessages.fontFamilyLabel)}
>
2017-05-05 02:42:55 +08:00
<select
defaultValue={FONT_FAMILIES.indexOf(this.state.settings.fontFamily)}
onChange={this.handleSelectChange.bind(this, 'fontFamily', FONT_FAMILIES)}
2017-06-03 03:25:02 +08:00
className={styles.select}
>
<option value="-1" disabled>
2017-05-05 02:42:55 +08:00
{intl.formatMessage(intlMessages.fontFamilyOptionLabel)}
2017-02-16 02:49:40 +08:00
</option>
2017-05-05 02:42:55 +08:00
{
FONT_FAMILIES.map((family, index) =>
2017-06-03 03:25:02 +08:00
(<option key={index} value={index}>
2017-05-05 02:42:55 +08:00
{family}
</option>))
2017-05-05 02:42:55 +08:00
}
</select>
2017-07-08 14:50:33 +08:00
</label>
2017-05-05 02:42:55 +08:00
</div>
2017-02-16 02:49:40 +08:00
</div>
2016-12-23 16:26:22 +08:00
2017-05-05 02:42:55 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.fontSizeLabel)}
</label>
</div>
</div>
<div className={styles.col}>
2017-07-08 14:50:33 +08:00
<label
2017-05-05 02:42:55 +08:00
className={cx(styles.formElement, styles.pullContentRight)}
2017-06-03 03:25:02 +08:00
aria-label={intl.formatMessage(intlMessages.fontSizeLabel)}
>
<select
defaultValue={FONT_SIZES.indexOf(this.state.settings.fontSize)}
onChange={this.handleSelectChange.bind(this, 'fontSize', FONT_SIZES)}
className={styles.select}
>
<option value="-1" disabled>
{intl.formatMessage(intlMessages.fontSizeOptionLabel)}
</option>
{
2017-05-05 02:42:55 +08:00
FONT_SIZES.map((size, index) =>
2017-06-03 03:25:02 +08:00
(<option key={index} value={index}>
2017-05-05 02:42:55 +08:00
{size}
</option>))
2017-05-05 02:42:55 +08:00
}
2017-06-03 03:25:02 +08:00
</select>
2017-07-08 14:50:33 +08:00
</label>
2017-05-05 02:42:55 +08:00
</div>
2017-02-16 02:49:40 +08:00
</div>
2016-12-23 16:26:22 +08:00
2017-05-05 02:42:55 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.backgroundColorLabel)}
</label>
2017-04-25 19:59:52 +08:00
</div>
</div>
2017-05-05 02:42:55 +08:00
<div className={styles.col}>
<div
className={cx(styles.formElement, styles.pullContentRight)}
2017-06-03 03:25:02 +08:00
aria-label={intl.formatMessage(intlMessages.backgroundColorLabel)}
>
2017-02-16 02:49:40 +08:00
<div
2017-06-03 03:25:02 +08:00
tabIndex="0"
className={styles.swatch}
2017-05-05 02:42:55 +08:00
onClick={
this.handleColorPickerClick.bind(this, 'displayBackgroundColorPicker')
2017-06-03 03:25:02 +08:00
}
>
2017-05-05 02:42:55 +08:00
<div
className={styles.swatchInner}
2017-06-03 03:25:02 +08:00
style={{ background: this.state.settings.backgroundColor }}
/>
2017-02-16 02:49:40 +08:00
</div>
2017-05-05 02:42:55 +08:00
{ this.state.displayBackgroundColorPicker ?
<div className={styles.colorPickerPopover}>
<div
className={styles.colorPickerOverlay}
2017-06-03 03:25:02 +08:00
onClick={this.handleCloseColorPicker.bind(this)}
/>
2017-05-05 02:42:55 +08:00
<GithubPicker
onChange={this.handleColorChange.bind(this, 'backgroundColor')}
color={this.state.settings.backgroundColor}
colors={COLORS}
width="140px"
triangle="top-right"
2017-05-05 02:42:55 +08:00
/>
</div>
: null }
2017-02-16 02:49:40 +08:00
</div>
2017-05-05 02:42:55 +08:00
</div>
2017-02-16 02:49:40 +08:00
</div>
2016-12-23 16:26:22 +08:00
2017-05-05 02:42:55 +08:00
<div className={cx(styles.row, styles.spacedLeft)}>
<div className={styles.col}>
<div className={styles.formElement}>
<label className={styles.label}>
{intl.formatMessage(intlMessages.fontColorLabel)}
</label>
2017-04-25 19:59:52 +08:00
</div>
</div>
2017-05-05 02:42:55 +08:00
<div className={styles.col}>
<div
className={cx(styles.formElement, styles.pullContentRight)}
2017-06-03 03:25:02 +08:00
aria-label={intl.formatMessage(intlMessages.fontColorLabel)}
>
2017-02-16 02:49:40 +08:00
<div
2017-06-03 03:25:02 +08:00
tabIndex="0"
className={styles.swatch}
onClick={this.handleColorPickerClick.bind(this, 'displayFontColorPicker')}
>
2017-05-05 02:42:55 +08:00
<div
className={styles.swatchInner}
2017-06-03 03:25:02 +08:00
style={{ background: this.state.settings.fontColor }}
/>
2017-02-16 02:49:40 +08:00
</div>
2017-05-05 02:42:55 +08:00
{ this.state.displayFontColorPicker ?
<div className={styles.colorPickerPopover}>
<div
className={styles.colorPickerOverlay}
2017-06-03 03:25:02 +08:00
onClick={this.handleCloseColorPicker.bind(this)}
/>
2017-05-05 02:42:55 +08:00
<GithubPicker
onChange={this.handleColorChange.bind(this, 'fontColor')}
color={this.state.settings.fontColor}
colors={COLORS}
width="140px"
triangle="top-right"
2017-05-05 02:42:55 +08:00
/>
</div>
: null }
2017-02-16 02:49:40 +08:00
</div>
2017-05-05 02:42:55 +08:00
</div>
</div>
<div
className={cx(styles.ccPreviewBox, styles.spacedLeft)}
2017-06-03 03:25:02 +08:00
role="presentation"
style={{ background: this.state.settings.backgroundColor }}
>
2017-05-05 02:42:55 +08:00
<span style={this.getPreviewStyle()}>
Etiam porta sem malesuada magna mollis euis-mod.
Donec ullamcorper nulla non metus auctor fringilla.
</span>
2017-02-16 02:49:40 +08:00
</div>
</div>
2017-05-05 02:42:55 +08:00
: null }
2016-12-23 16:26:22 +08:00
</div>
</div>
);
}
2017-06-03 03:25:02 +08:00
}
2017-04-11 04:27:29 +08:00
export default injectIntl(ClosedCaptionsMenu);