sforkowany z mirror/soapbox
Refactor InputContainer
rodzic
c367aef6b4
commit
4801962988
|
@ -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>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue