import React from 'react'; import PropTypes from 'proptypes'; import _ from 'lodash'; import { Tabs, Tab } from 'material-ui/Tabs'; import MenuItem from 'material-ui/MenuItem'; import injectSheet from 'react-jss'; import { SelectField, TextField, Checkbox } from './FormComponents.js'; import { grey800, cyan500 } from 'material-ui/styles/colors'; const styles = { textFieldRow: { display: 'flex' }, text: { fontWeight: 'bold' }, container: { width: '100%', flexGrow: 1, overflowY: 'auto' } }; class Settings extends React.Component { static childContextTypes = { state: PropTypes.object, onChange: PropTypes.func, disabled: PropTypes.bool }; static defaultProps: { disabled: false }; static propTypes = { classes: PropTypes.objectOf(PropTypes.string), onChange: PropTypes.func, printers: PropTypes.object.isRequired, defaultPrinter: PropTypes.string, quality: PropTypes.object.isRequired, defaultQuality: PropTypes.string.isRequired, material: PropTypes.object.isRequired, defaultMaterial: PropTypes.string.isRequired, initialSettings: PropTypes.object.isRequired, disabled: PropTypes.bool.isRequired }; constructor(props) { super(); this.state = { settings: props.initialSettings, printers: props.defaultPrinter, quality: props.defaultQuality, material: props.defaultMaterial }; } changeSettings = (fieldName, value) => { const { onChange } = this.props; let state; switch (fieldName) { case 'printers': case 'quality': case 'material': state = { [fieldName]: value, settings: _.merge({}, this.state.settings, this.props[fieldName][value]) }; break; default: state = _.set(_.cloneDeep(this.state), fieldName, value); break; } if (onChange) onChange(state); if (state) this.setState(state); }; getChildContext() { return { state: this.state, onChange: this.changeSettings, disabled: this.props.disabled }; } render() { const { classes, printers, quality, material, disabled } = this.props; return (
{Object.entries(printers).map(([value, { title }]) => ( ))} {Object.entries(material).map(([value, { title }]) => ( ))}

Printer Setup

{Object.entries(quality).map(([value, { title }]) => ( ))}

Printer dimensions

Nozzle

Bed

Material

Thickness

Retraction

Travel

Inner shell

Outer shell

Inner infill

Outer infill

Brim

First layer

); } } export default injectSheet(styles)(Settings);