diff --git a/CHANGELOG.md b/CHANGELOG.md index 53bb11cb..adab4b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - When loading a style into localStorage that causes a QuotaExceededError, purge localStorage and retry - Remove react-autobind dependency - Remove usage of legacy `childContextTypes` API +- Refactor Field components to use arrow function syntax - Replace react-autocomplete with Downshift in the autocomplete component - _...Add new stuff here..._ diff --git a/src/components/FieldArray.tsx b/src/components/FieldArray.tsx index 9b1475d3..51d1b740 100644 --- a/src/components/FieldArray.tsx +++ b/src/components/FieldArray.tsx @@ -1,4 +1,3 @@ -import React from 'react' import InputArray, { FieldArrayProps as InputArrayProps } from './InputArray' import Fieldset from './Fieldset' @@ -9,10 +8,12 @@ type FieldArrayProps = InputArrayProps & { } }; -export default class FieldArray extends React.Component { - render() { - return
- +const FieldArray: React.FC = (props) => { + return ( +
+
- } -} + ); +}; + +export default FieldArray; diff --git a/src/components/FieldAutocomplete.tsx b/src/components/FieldAutocomplete.tsx index beb2e5a6..71fae196 100644 --- a/src/components/FieldAutocomplete.tsx +++ b/src/components/FieldAutocomplete.tsx @@ -1,4 +1,3 @@ -import React from 'react' import Block from './Block' import InputAutocomplete, { InputAutocompleteProps } from './InputAutocomplete' @@ -8,10 +7,12 @@ type FieldAutocompleteProps = InputAutocompleteProps & { }; -export default class FieldAutocomplete extends React.Component { - render() { - return - +const FieldAutocomplete: React.FC = (props) => { + return ( + + - } -} + ); +}; + +export default FieldAutocomplete; diff --git a/src/components/FieldCheckbox.tsx b/src/components/FieldCheckbox.tsx index 50f1d25a..5338cc42 100644 --- a/src/components/FieldCheckbox.tsx +++ b/src/components/FieldCheckbox.tsx @@ -1,4 +1,3 @@ -import React from 'react' import Block from './Block' import InputCheckbox, {InputCheckboxProps} from './InputCheckbox' @@ -8,10 +7,12 @@ type FieldCheckboxProps = InputCheckboxProps & { }; -export default class FieldCheckbox extends React.Component { - render() { - return - +const FieldCheckbox: React.FC = (props) => { + return ( + + - } -} + ); +}; + +export default FieldCheckbox; diff --git a/src/components/FieldColor.tsx b/src/components/FieldColor.tsx index 094cd7fb..e2c534d5 100644 --- a/src/components/FieldColor.tsx +++ b/src/components/FieldColor.tsx @@ -1,4 +1,3 @@ -import React from 'react' import Block from './Block' import InputColor, {InputColorProps} from './InputColor' @@ -11,10 +10,12 @@ type FieldColorProps = InputColorProps & { }; -export default class FieldColor extends React.Component { - render() { - return - +const FieldColor: React.FC = (props) => { + return ( + + - } -} + ); +}; + +export default FieldColor; diff --git a/src/components/FieldComment.tsx b/src/components/FieldComment.tsx index 7a53419c..4c84ddbc 100644 --- a/src/components/FieldComment.tsx +++ b/src/components/FieldComment.tsx @@ -10,29 +10,31 @@ type FieldCommentInternalProps = { error: {message: string} } & WithTranslation; -class FieldCommentInternal extends React.Component { - render() { - const t = this.props.t; - const fieldSpec = { - doc: t("Comments for the current layer. This is non-standard and not in the spec."), - }; +const FieldCommentInternal: React.FC = (props) => { + const t = props.t; + const fieldSpec = { + doc: t( + "Comments for the current layer. This is non-standard and not in the spec." + ), + }; - return - } -} + ); +}; const FieldComment = withTranslation()(FieldCommentInternal); export default FieldComment; diff --git a/src/components/FieldDocLabel.tsx b/src/components/FieldDocLabel.tsx index bee5006b..e32fc21e 100644 --- a/src/components/FieldDocLabel.tsx +++ b/src/components/FieldDocLabel.tsx @@ -9,57 +9,45 @@ type FieldDocLabelProps = { onToggleDoc?(...args: unknown[]): unknown }; -type FieldDocLabelState = { - open: boolean -}; -export default class FieldDocLabel extends React.Component { - constructor (props: FieldDocLabelProps) { - super(props); - this.state = { - open: false, +const FieldDocLabel: React.FC = (props) => { + const [open, setOpen] = React.useState(false); + + const onToggleDoc = (state: boolean) => { + setOpen(state); + if (props.onToggleDoc) { + props.onToggleDoc(state); } - } + }; - onToggleDoc = (open: boolean) => { - this.setState({ - open, - }, () => { - if (this.props.onToggleDoc) { - this.props.onToggleDoc(this.state.open); - } - }); - } + const { label, fieldSpec } = props; + const { doc } = fieldSpec || {}; - render() { - const {label, fieldSpec} = this.props; - const {doc} = fieldSpec || {}; - - if (doc) { - return