From 83d96d88ec28e84ef4f1272767b5b6a93597afca Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Mon, 13 Nov 2017 10:45:23 +0100 Subject: [PATCH] move on change to context --- src/interface/FormComponents.js | 12 +++--- src/interface/Settings.js | 72 ++++++++++++++++----------------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/interface/FormComponents.js b/src/interface/FormComponents.js index 4c70ed4..8776dcd 100644 --- a/src/interface/FormComponents.js +++ b/src/interface/FormComponents.js @@ -36,25 +36,25 @@ export const SelectField = (props, context) => ( props.onChange(props.name, value)} + onChange={(event, index, value) => context.onChange(props.name, value)} /> ); -SelectField.contextTypes = { state: PropTypes.object }; +SelectField.contextTypes = { state: PropTypes.object, onChange: PropTypes.func }; export const TextField = (props, context) => ( props.onChange(props.name, value)} + onChange={(event, value) => context.onChange(props.name, value)} /> ); -TextField.contextTypes = { state: PropTypes.object }; +TextField.contextTypes = { state: PropTypes.object, onChange: PropTypes.func }; export const Checkbox = (props, context) => ( props.onChange(props.name, value)} + onCheck={(event, value) => context.onChange(props.name, value)} /> ); -Checkbox.contextTypes = { state: PropTypes.object }; +Checkbox.contextTypes = { state: PropTypes.object, onChange: PropTypes.func }; diff --git a/src/interface/Settings.js b/src/interface/Settings.js index e0fc3c8..703cf30 100644 --- a/src/interface/Settings.js +++ b/src/interface/Settings.js @@ -51,7 +51,7 @@ class Settings extends React.Component { }; getChildContext() { - return { state: this.state }; + return { state: this.state, onChange: this.changeSettings }; } render() { @@ -61,17 +61,17 @@ class Settings extends React.Component {
- + {Object.entries(printers).map(([value, { title }]) => ( ))} - + {Object.entries(quality).map(([value, { title }]) => ( ))} - + {Object.entries(material).map(([value, { title }]) => ( ))} @@ -82,62 +82,62 @@ class Settings extends React.Component {
- - - + + +
- + - - + + - - + + - - - + + + - - - - + + + + - + - - + + - - + + - - - + + + - - + + - - - + + + - - + +
@@ -145,9 +145,7 @@ class Settings extends React.Component { ); } } -Settings.childContextTypes = { - state: PropTypes.object -}; +Settings.childContextTypes = { state: PropTypes.object, onChange: PropTypes.func }; Settings.propTypes = { classes: PropTypes.objectOf(PropTypes.string), onChange: PropTypes.func,