import React, { useState } from 'react'; import ImmutablePureComponent from 'react-immutable-pure-component'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { v4 as uuidv4 } from 'uuid'; import { SketchPicker } from 'react-color'; import Overlay from 'react-overlays/lib/Overlay'; import { isMobile } from '../../is_mobile'; import detectPassiveEvents from 'detect-passive-events'; const FormPropTypes = { label: PropTypes.oneOfType([ PropTypes.string, PropTypes.object, PropTypes.node, ]), }; const listenerOptions = detectPassiveEvents.hasSupport ? { passive: true } : false; export const InputContainer = (props) => { const containerClass = classNames('input', { 'with_label': props.label, 'required': props.required, 'boolean': props.type === 'checkbox', }, props.extraClass); return (
{props.children} {props.hint && {props.hint}}
); }; InputContainer.propTypes = { label: FormPropTypes.label, hint: PropTypes.node, required: PropTypes.bool, type: PropTypes.string, children: PropTypes.node, extraClass: PropTypes.string, }; export const LabelInputContainer = ({ label, hint, children, ...props }) => { const [id] = useState(uuidv4()); const childrenWithProps = React.Children.map(children, child => ( React.cloneElement(child, { id: id, key: id }) )); return (
{childrenWithProps}
{hint && {hint}}
); }; LabelInputContainer.propTypes = { label: FormPropTypes.label.isRequired, hint: PropTypes.node, children: PropTypes.node, }; export const LabelInput = ({ label, dispatch, ...props }) => ( ); LabelInput.propTypes = { label: FormPropTypes.label.isRequired, dispatch: PropTypes.func, }; export const LabelTextarea = ({ label, dispatch, ...props }) => (