| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import React from 'react';
- import PropTypes from 'prop-types';
- import FormGroup from 'react-bootstrap/es/FormGroup';
- import FormControl from 'react-bootstrap/es/FormControl';
- import ControlLabel from 'react-bootstrap/es/ControlLabel';
- import Button from 'react-bootstrap/es/Button';
- export default class EditorOptionsSelector extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- options: this.props.options,
- }
- this.availableThemes = [
- 'elegant', 'neo', 'mdn-like', 'material', 'monokai', 'twilight'
- ]
- this.onChangeTheme = this.onChangeTheme.bind(this);
- this.onClickStyleActiveLine = this.onClickStyleActiveLine.bind(this);
- }
- componentDidMount() {
- this.init();
- }
- init() {
- this.themeSelectorInputEl.value = this.state.options.theme || this.availableThemes[0];
- }
- onChangeTheme() {
- const newValue = this.themeSelectorInputEl.value;
- const newOpts = Object.assign(this.state.options, {theme: newValue});
- this.setState({options: newOpts});
- // dispatch event
- this.dispatchOnChange();
- }
- onClickStyleActiveLine(event) {
- const newValue = !this.state.options.styleActiveLine;
- console.log(newValue);
- const newOpts = Object.assign(this.state.options, {styleActiveLine: newValue});
- this.setState({options: newOpts});
- // dispatch event
- this.dispatchOnChange();
- }
- dispatchOnChange() {
- if (this.props.onChange != null) {
- this.props.onChange(this.state.options);
- }
- }
- renderThemeSelector() {
- const optionElems = this.availableThemes.map((theme) => {
- return <option key={theme} value={theme}>{theme}</option>;
- });
- return (
- <FormGroup controlId="formControlsSelect">
- <ControlLabel>Theme:</ControlLabel>
- <FormControl componentClass="select" placeholder="select"
- onChange={this.onChangeTheme}
- inputRef={ el => this.themeSelectorInputEl=el }>
- {optionElems}
- </FormControl>
- </FormGroup>
- )
- }
- renderStyleActiveLineSelector() {
- const bool = this.state.options.styleActiveLine || false;
- return (
- <FormGroup controlId="formControlsSelect">
- <Button active={bool} className="btn-style-active-line"
- onClick={this.onClickStyleActiveLine}
- ref="styleActiveLineButton">
- Active Line
- </Button>
- </FormGroup>
- )
- }
- render() {
- return <span>{this.renderThemeSelector()} {this.renderStyleActiveLineSelector()}</span>
- }
- }
- EditorOptionsSelector.propTypes = {
- options: PropTypes.object,
- onChange: PropTypes.func,
- };
|