From c367aef6b42c88d9b3d8725dc391c4622385a3b2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 22 Apr 2020 19:09:40 -0500 Subject: [PATCH] Refactor LabelInput --- app/gabsocial/features/forms/index.js | 99 +++++++++++---------------- app/styles/gabsocial/forms.scss | 4 +- 2 files changed, 43 insertions(+), 60 deletions(-) diff --git a/app/gabsocial/features/forms/index.js b/app/gabsocial/features/forms/index.js index 2ce37cbb0..a1f890eb7 100644 --- a/app/gabsocial/features/forms/index.js +++ b/app/gabsocial/features/forms/index.js @@ -4,6 +4,22 @@ import PropTypes from 'prop-types'; import classNames from 'classnames'; import { v4 as uuidv4 } from 'uuid'; +export const LabelInput = ({ label, ...props }) => { + const id = uuidv4(); + return ( +
+ +
+ +
+
+ ); +}; + +LabelInput.propTypes = { + label: PropTypes.string.isRequired, +}; + export class SimpleForm extends ImmutablePureComponent { static propTypes = { @@ -49,38 +65,21 @@ export class Checkbox extends ImmutablePureComponent { static propTypes = { label: PropTypes.string, - name: PropTypes.string, - checked: PropTypes.bool, - onChange: PropTypes.func, - } - - static defaultProps = { - checked: false, } render() { - const { label, name, checked, onChange } = this.props; - const id = uuidv4(); + const { label, required } = this.props; + + const containerClassNames = classNames('input', 'boolean', { + 'with_label': label, + 'required': required, + }); + + const Input = label ? LabelInput : 'input'; return ( -
-
- -
- -
-
+
+
); } @@ -102,7 +101,7 @@ export class RadioGroup extends ImmutablePureComponent { ); return ( -
+
    {childrenWithProps}
@@ -195,30 +194,18 @@ export class TextInput extends ImmutablePureComponent { } render() { - const { label, ...props } = this.props; - const id = uuidv4(); + const { label, required } = this.props; const containerClassNames = classNames('input', { 'with_label': label, - 'required': this.props.required, + 'required': required, }); - const InputWithLabel = () => ( -
- -
- -
-
- ); - - const Input = () => ( - - ); + const Input = label ? LabelInput : 'input'; return (
- {label ? : } +
); } @@ -238,22 +225,18 @@ export class FileChooser extends ImmutablePureComponent { render() { const { label, hint, ...props } = this.props; - const id = uuidv4(); + + const containerClassNames = classNames('input', { + 'with_label': label, + 'required': this.props.required, + }); + + const Input = label ? LabelInput : 'input'; return ( -
-
- -
- -
-
- {hint} +
+ + {hint && {hint}}
); } diff --git a/app/styles/gabsocial/forms.scss b/app/styles/gabsocial/forms.scss index 97bbf87ec..2ca94297e 100644 --- a/app/styles/gabsocial/forms.scss +++ b/app/styles/gabsocial/forms.scss @@ -63,9 +63,9 @@ code { position: static; } - label.checkbox { + input[type="checkbox"] { position: absolute; - top: 2px; + top: 3px; left: 0; }