From a6de9d5e0040f275f3a36771f7d267337150a4a3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 22 Apr 2020 22:02:56 -0500 Subject: [PATCH] Refactor SimpleInput --- app/gabsocial/features/forms/index.js | 90 ++++++++++----------------- 1 file changed, 34 insertions(+), 56 deletions(-) diff --git a/app/gabsocial/features/forms/index.js b/app/gabsocial/features/forms/index.js index 13932efa7..973994fa8 100644 --- a/app/gabsocial/features/forms/index.js +++ b/app/gabsocial/features/forms/index.js @@ -8,6 +8,7 @@ export const InputContainer = (props) => { const containerClass = classNames('input', { 'with_label': props.label, 'required': props.required, + 'boolean': props.type === 'checkbox', }, props.extraClass); return ( @@ -22,6 +23,7 @@ InputContainer.propTypes = { label: PropTypes.string, hint: PropTypes.string, required: PropTypes.bool, + type: PropTypes.string, children: PropTypes.node, extraClass: PropTypes.string, }; @@ -42,6 +44,26 @@ LabelInput.propTypes = { label: PropTypes.string.isRequired, }; +export class SimpleInput extends ImmutablePureComponent { + + static propTypes = { + label: PropTypes.string, + hint: PropTypes.string, + } + + render() { + const { hint, ...props } = this.props; + const Input = this.props.label ? LabelInput : 'input'; + + return ( + + + + ); + } + +} + export class SimpleForm extends ImmutablePureComponent { static propTypes = { @@ -83,23 +105,9 @@ export class FieldsGroup extends ImmutablePureComponent { } -export class Checkbox extends ImmutablePureComponent { - - static propTypes = { - label: PropTypes.string, - } - - render() { - const Input = this.props.label ? LabelInput : 'input'; - - return ( - - - - ); - } - -} +export const Checkbox = props => ( + +); export class RadioGroup extends ImmutablePureComponent { @@ -202,44 +210,14 @@ export class SelectDropdown extends ImmutablePureComponent { } -export class TextInput extends ImmutablePureComponent { +export const TextInput = props => ( + +); - static propTypes = { - label: PropTypes.string, - } +export const FileChooser = props => ( + +); - render() { - const Input = this.props.label ? LabelInput : 'input'; - - return ( - - - - ); - } - -} - -export class FileChooser extends ImmutablePureComponent { - - static propTypes = { - label: PropTypes.string, - hint: PropTypes.string, - } - - static defaultProps = { - accept: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'], - } - - render() { - const { hint, ...props } = this.props; - const Input = this.props.label ? LabelInput : 'input'; - - return ( - - - - ); - } - -} +FileChooser.defaultProps = { + accept: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'], +};