From 252b3fbf51024673625125d495e68184f4608df9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 22 Apr 2020 23:01:36 -0500 Subject: [PATCH] Refactor LabelInputContainer --- app/gabsocial/features/forms/index.js | 119 ++++++++++---------------- 1 file changed, 46 insertions(+), 73 deletions(-) diff --git a/app/gabsocial/features/forms/index.js b/app/gabsocial/features/forms/index.js index 973994fa8..c92e2ead6 100644 --- a/app/gabsocial/features/forms/index.js +++ b/app/gabsocial/features/forms/index.js @@ -28,18 +28,33 @@ InputContainer.propTypes = { extraClass: PropTypes.string, }; -export const LabelInput = ({ label, ...props }) => { +export const LabelInputContainer = ({ label, children, ...props }) => { const id = uuidv4(); + const childrenWithProps = React.Children.map(children, child => ( + React.cloneElement(child, { id: id }) + )); + return (
- + {childrenWithProps}
); }; +LabelInputContainer.propTypes = { + label: PropTypes.string.isRequired, + children: PropTypes.node, +}; + +export const LabelInput = ({ label, ...props }) => ( + + + +); + LabelInput.propTypes = { label: PropTypes.string.isRequired, }; @@ -64,46 +79,26 @@ export class SimpleInput extends ImmutablePureComponent { } -export class SimpleForm extends ImmutablePureComponent { +export const SimpleForm = ({ children, onSubmit }) => ( +
{children}
+); - static propTypes = { - children: PropTypes.node, - onSubmit: PropTypes.func, - } +SimpleForm.propTypes = { + children: PropTypes.node, + onSubmit: PropTypes.func, +}; - static defaultProps = { - onSubmit: e => e.preventDefault(), - } +SimpleForm.defaultProps = { + onSubmit: e => e.preventDefault(), +}; - render() { - const { children, onSubmit } = this.props; +export const FieldsGroup = ({ children }) => ( +
{children}
+); - return ( -
- {children} -
- ); - } - -} - -export class FieldsGroup extends ImmutablePureComponent { - - static propTypes = { - children: PropTypes.node, - } - - render() { - const { children } = this.props; - - return ( -
- {children} -
- ); - } - -} +FieldsGroup.propTypes = { + children: PropTypes.node, +}; export const Checkbox = props => ( @@ -126,7 +121,7 @@ export class RadioGroup extends ImmutablePureComponent { return (
- +
    {childrenWithProps}
@@ -150,20 +145,13 @@ export class RadioItem extends ImmutablePureComponent { } render() { - const { label, hint, value, checked, onChange } = this.props; + const { label, hint, ...props } = this.props; const id = uuidv4(); return (
  • @@ -177,35 +165,20 @@ export class SelectDropdown extends ImmutablePureComponent { static propTypes = { label: PropTypes.string, items: PropTypes.object.isRequired, - defaultValue: PropTypes.string, - onChange: PropTypes.func, } render() { - const { label, items, defaultValue, onChange } = this.props; - const id = uuidv4(); + const { label, items, ...props } = this.props; - return ( -
    -
    - -
    - -
    -
    -
    - ); + const optionElems = Object.keys(items).map(item => ( + + )); + + const selectElem = ; + + return label ? ( + {selectElem} + ) : selectElem; } }