ThemeSelector.js 1.2 KB

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