import React from 'react'; import PropTypes from 'proptypes'; import _ from 'lodash'; import baseSettings from '../settings/default.yml'; import printerSettings from '../settings/printer.yml'; import materialSettings from '../settings/material.yml'; import qualitySettings from '../settings/quality.yml'; import { Tabs, Tab } from 'material-ui/Tabs'; import MenuItem from 'material-ui/MenuItem'; import injectSheet from 'react-jss'; import { SettingsGroup, SelectField, TextField, Checkbox } from './FormComponents.js'; import { grey500 } from 'material-ui/styles/colors'; const styles = { textFieldRow: { display: 'flex' }, content: { maxHeight: '300px', overflowY: 'scroll' } }; const DEFAULT_PRINTER = 'ultimaker2'; const DEFAULT_MATERIAL = 'pla'; const DEFAULT_QUALITY = 'medium'; const DEFAULT_SETTINGS = { 'printer': printerSettings, 'quality': qualitySettings, 'material': materialSettings }; class Settings extends React.Component { constructor(props) { super(props); this.state = { settings: { ...baseSettings, ...printerSettings[DEFAULT_PRINTER], ...qualitySettings[DEFAULT_MATERIAL], ...materialSettings[DEFAULT_MATERIAL], title: null }, printer: DEFAULT_PRINTER, quality: DEFAULT_QUALITY, material: DEFAULT_MATERIAL }; } changeSettings = (fieldName, value) => { switch (fieldName) { case 'printer': case 'quality': case 'material': this.setState({ [fieldName]: value, settings: { ...this.state.settings, ...DEFAULT_SETTINGS[fieldName][value], title: null } }); break; default: this.setState(_.set(this.state, fieldName, value)); break; } }; getChildContext() { return { state: this.state }; } render() { const { classes } = this.props; return (
{Object.entries(printerSettings).map(([value, { title }]) => ( ))} {Object.entries(qualitySettings).map(([value, { title }]) => ( ))} {Object.entries(materialSettings).map(([value, { title }]) => ( ))}
); } } Settings.childContextTypes = { state: PropTypes.object }; Settings.propTypes = { classes: PropTypes.objectOf(PropTypes.string), onChange: PropTypes.func }; export default injectSheet(styles)(Settings);