bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/switch/component.jsx

55 lines
1.5 KiB
React
Raw Normal View History

2017-01-27 23:41:11 +08:00
import React from 'react';
import Toggle from 'react-toggle';
2017-03-01 20:22:11 +08:00
import classNames from 'classnames';
2017-01-27 23:41:11 +08:00
export default class Switch extends Toggle {
render() {
2017-03-09 22:34:33 +08:00
const {
className,
icons: _icons,
ariaLabelledBy,
ariaDescribedBy,
ariaLabel,
ariaDesc,
...inputProps,
} = this.props;
2017-01-27 23:41:11 +08:00
const classes = classNames('react-toggle', {
'react-toggle--checked': this.state.checked,
'react-toggle--focus': this.state.hasFocus,
'react-toggle--disabled': this.props.disabled,
2017-03-01 20:22:11 +08:00
}, className);
2017-01-27 23:41:11 +08:00
return (
<div className={classes}
onClick={this.handleClick}
onTouchStart={this.handleTouchStart}
onTouchMove={this.handleTouchMove}
onTouchEnd={this.handleTouchEnd}>
<div className='react-toggle-track'>
<div className='react-toggle-track-check'>
ON
</div>
<div className='react-toggle-track-x'>
OFF
</div>
</div>
<div className='react-toggle-thumb' />
<input
{...inputProps}
ref={ref => { this.input = ref }}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
className='react-toggle-screenreader-only'
2017-03-01 20:22:11 +08:00
type='checkbox'
2017-03-09 22:34:33 +08:00
tabIndex='0'
aria-labelledby={ariaLabelledBy}
aria-describedby={ariaDescribedBy}/>
<div id={ariaLabelledBy} hidden>{ariaLabel}</div>
<div id={ariaDescribedBy} hidden>{ariaDesc}</div>
2017-01-27 23:41:11 +08:00
</div>
);
}
};