From 9743361e0d691708493153d4aae90afe6fb05ae0 Mon Sep 17 00:00:00 2001 From: orangemug Date: Sat, 19 Oct 2019 12:16:56 +0100 Subject: [PATCH] Added back in 'light position' and 'center' with fixes for This also improves the usage of *-translate which uses the --- src/components/fields/PropertyGroup.jsx | 2 +- src/components/inputs/ArrayInput.jsx | 73 ++++++++++++++++++++++--- src/components/inputs/NumberInput.jsx | 3 +- src/components/inputs/StringInput.jsx | 5 +- src/components/modals/SettingsModal.jsx | 21 +++++++ 5 files changed, 92 insertions(+), 12 deletions(-) diff --git a/src/components/fields/PropertyGroup.jsx b/src/components/fields/PropertyGroup.jsx index efb567b..3557724 100644 --- a/src/components/fields/PropertyGroup.jsx +++ b/src/components/fields/PropertyGroup.jsx @@ -59,7 +59,7 @@ export default class PropertyGroup extends React.Component { onChange={this.onPropertyChange} key={fieldName} fieldName={fieldName} - value={fieldValue === undefined ? fieldSpec.default : fieldValue} + value={fieldValue} fieldSpec={fieldSpec} /> }) diff --git a/src/components/inputs/ArrayInput.jsx b/src/components/inputs/ArrayInput.jsx index 5a8a4f5..bb406d8 100644 --- a/src/components/inputs/ArrayInput.jsx +++ b/src/components/inputs/ArrayInput.jsx @@ -17,27 +17,84 @@ class ArrayInput extends React.Component { default: [], } + constructor (props) { + super(props); + this.state = { + value: this.props.value.slice(0), + // This is so we can compare changes in getDerivedStateFromProps + initialPropsValue: this.props.value.slice(0), + }; + } + + static getDerivedStateFromProps(props, state) { + const value = []; + const initialPropsValue = state.initialPropsValue.slice(0); + + Array(props.length).fill(null).map((_, i) => { + if (props.value[i] === state.initialPropsValue[i]) { + value[i] = state.value[i]; + } + else { + value[i] = state.value[i]; + initialPropsValue[i] = state.value[i]; + } + }) + + return { + value, + initialPropsValue, + }; + } + + isComplete (value) { + return Array(this.props.length).fill(null).every((_, i) => { + const val = value[i] + return !(val === undefined || val === ""); + }); + } + changeValue(idx, newValue) { - console.log(idx, newValue) - const values = this.props.value.slice(0) - values[idx] = newValue - this.props.onChange(values) + const value = this.state.value.slice(0); + value[idx] = newValue; + + this.setState({ + value, + }, () => { + if (this.isComplete(value)) { + this.props.onChange(value); + } + else { + // Unset until complete + this.props.onChange(undefined); + } + }); } render() { + const {value} = this.state; + + const containsValues = ( + value.length > 0 && + !value.every(val => { + return (val === "" || val === undefined) + }) + ); + const inputs = Array(this.props.length).fill(null).map((_, i) => { if(this.props.type === 'number') { return } else { return } diff --git a/src/components/inputs/NumberInput.jsx b/src/components/inputs/NumberInput.jsx index f2fa3ce..1c8326d 100644 --- a/src/components/inputs/NumberInput.jsx +++ b/src/components/inputs/NumberInput.jsx @@ -83,9 +83,10 @@ class NumberInput extends React.Component { spellCheck="false" className="maputnik-number" placeholder={this.props.default} - value={this.state.value || ""} + value={this.state.value === undefined ? "" : this.state.value} onChange={e => this.changeValue(e.target.value)} onBlur={this.resetValue} + required={this.props.required} /> } } diff --git a/src/components/inputs/StringInput.jsx b/src/components/inputs/StringInput.jsx index 875a454..2819cc0 100644 --- a/src/components/inputs/StringInput.jsx +++ b/src/components/inputs/StringInput.jsx @@ -50,7 +50,7 @@ class StringInput extends React.Component { spellCheck: !(tag === "input"), className: classes.join(" "), style: this.props.style, - value: this.state.value, + value: this.state.value === undefined ? "" : this.state.value, placeholder: this.props.default, onChange: e => { this.setState({ @@ -63,7 +63,8 @@ class StringInput extends React.Component { this.setState({editing: false}); this.props.onChange(this.state.value); } - } + }, + required: this.props.required, }); } } diff --git a/src/components/modals/SettingsModal.jsx b/src/components/modals/SettingsModal.jsx index 5b918b7..de4ced5 100644 --- a/src/components/modals/SettingsModal.jsx +++ b/src/components/modals/SettingsModal.jsx @@ -139,6 +139,16 @@ class SettingsModal extends React.Component { /> + + + + + + + +