import React from 'react'; import ImmutablePureComponent from 'react-immutable-pure-component'; 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 = { children: PropTypes.node, onSubmit: PropTypes.func, } static defaultProps = { onSubmit: e => e.preventDefault(), } render() { const { children, onSubmit } = this.props; return (
{children}
); } } export class FieldsGroup extends ImmutablePureComponent { static propTypes = { children: PropTypes.node, } render() { const { children } = this.props; return (
{children}
); } } export class Checkbox extends ImmutablePureComponent { static propTypes = { label: PropTypes.string, } render() { const { label, required } = this.props; const containerClassNames = classNames('input', 'boolean', { 'with_label': label, 'required': required, }); const Input = label ? LabelInput : 'input'; return (
); } } export class RadioGroup extends ImmutablePureComponent { static propTypes = { label: PropTypes.string, children: PropTypes.node, } render() { const { label, children, onChange } = this.props; const childrenWithProps = React.Children.map(children, child => React.cloneElement(child, { onChange }) ); return (
); } } export class RadioItem extends ImmutablePureComponent { static propTypes = { label: PropTypes.string, hint: PropTypes.string, value: PropTypes.string.isRequired, checked: PropTypes.bool.isRequired, onChange: PropTypes.func, } static defaultProps = { checked: false, } render() { const { label, hint, value, checked, onChange } = this.props; const id = uuidv4(); return (
  • ); } } 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(); return (
    ); } } export class TextInput extends ImmutablePureComponent { static propTypes = { label: PropTypes.string, } render() { const { label, required } = this.props; const containerClassNames = classNames('input', { 'with_label': label, 'required': required, }); const Input = 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 { label, hint, ...props } = this.props; const containerClassNames = classNames('input', { 'with_label': label, 'required': this.props.required, }); const Input = label ? LabelInput : 'input'; return (
    {hint && {hint}}
    ); } }