ThemeSelector.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import FormGroup from 'react-bootstrap/es/FormGroup';
  4. import FormControl from 'react-bootstrap/es/FormControl';
  5. import ControlLabel from 'react-bootstrap/es/ControlLabel';
  6. export default class ThemeSelector extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.availableThemes = [
  10. 'elegant', 'neo', 'mdn-like', 'material', 'monokai', 'twilight'
  11. ]
  12. this.onChange = this.onChange.bind(this);
  13. }
  14. componentDidMount() {
  15. this.init(this.props.value || this.availableThemes[0]);
  16. }
  17. init(value) {
  18. this.inputEl.value = value;
  19. }
  20. onChange() {
  21. if (this.props.onChange != null) {
  22. this.props.onChange(this.inputEl.value);
  23. }
  24. }
  25. render() {
  26. const options = this.availableThemes.map((theme) => {
  27. return <option key={theme} value={theme}>{theme}</option>;
  28. });
  29. return (
  30. <FormGroup controlId="formControlsSelect" bsClass="theme-selector">
  31. <ControlLabel>Theme:</ControlLabel>
  32. <FormControl componentClass="select" placeholder="select"
  33. onChange={this.onChange}
  34. inputRef={ el => this.inputEl=el }>
  35. {options}
  36. </FormControl>
  37. </FormGroup>
  38. )
  39. }
  40. }
  41. ThemeSelector.propTypes = {
  42. value: PropTypes.string,
  43. onChange: PropTypes.func,
  44. };