Refactor InputContainer

stable/1.0.x
Alex Gleason 2020-04-22 19:36:27 -05:00
rodzic c367aef6b4
commit 4801962988
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 34 dodań i 32 usunięć

Wyświetl plik

@ -4,6 +4,28 @@ import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
export const InputContainer = (props) => {
const containerClass = classNames('input', {
'with_label': props.label,
'required': props.required,
}, props.extraClass);
return (
<div className={containerClass}>
{props.children}
{props.hint && <span className='hint'>{props.hint}</span>}
</div>
);
};
InputContainer.propTypes = {
label: PropTypes.string,
hint: PropTypes.string,
required: PropTypes.bool,
children: PropTypes.node,
extraClass: PropTypes.string,
};
export const LabelInput = ({ label, ...props }) => { export const LabelInput = ({ label, ...props }) => {
const id = uuidv4(); const id = uuidv4();
return ( return (
@ -68,19 +90,12 @@ export class Checkbox extends ImmutablePureComponent {
} }
render() { render() {
const { label, required } = this.props; const Input = this.props.label ? LabelInput : 'input';
const containerClassNames = classNames('input', 'boolean', {
'with_label': label,
'required': required,
});
const Input = label ? LabelInput : 'input';
return ( return (
<div className={containerClassNames}> <InputContainer {...this.props} extraClass='boolean'>
<Input type='checkbox' {...this.props} /> <Input type='checkbox' {...this.props} />
</div> </InputContainer>
); );
} }
@ -194,19 +209,12 @@ export class TextInput extends ImmutablePureComponent {
} }
render() { render() {
const { label, required } = this.props; const Input = this.props.label ? LabelInput : 'input';
const containerClassNames = classNames('input', {
'with_label': label,
'required': required,
});
const Input = label ? LabelInput : 'input';
return ( return (
<div className={containerClassNames}> <InputContainer {...this.props}>
<Input type='text' {...this.props} /> <Input type='text' {...this.props} />
</div> </InputContainer>
); );
} }
@ -224,20 +232,13 @@ export class FileChooser extends ImmutablePureComponent {
} }
render() { render() {
const { label, hint, ...props } = this.props; const { hint, ...props } = this.props;
const Input = this.props.label ? LabelInput : 'input';
const containerClassNames = classNames('input', {
'with_label': label,
'required': this.props.required,
});
const Input = label ? LabelInput : 'input';
return ( return (
<div className={containerClassNames}> <InputContainer {...this.props}>
<Input type='file' {...props} /> <Input type='file' {...props} />
{hint && <span className='hint'>{hint}</span>} </InputContainer>
</div>
); );
} }

Wyświetl plik

@ -27,13 +27,14 @@ class SettingsCheckbox extends ImmutablePureComponent {
} }
render() { render() {
const { label, path, settings } = this.props; const { label, path, settings, ...props } = this.props;
return ( return (
<Checkbox <Checkbox
label={label} label={label}
checked={settings.getIn(path)} checked={settings.getIn(path)}
onChange={this.handleCheckboxSetting(path)} onChange={this.handleCheckboxSetting(path)}
{...props}
/> />
); );
} }