import classNames from 'classnames'; import React, { useState, useRef } from 'react'; import { FormattedMessage } from 'react-intl'; import { v4 as uuidv4 } from 'uuid'; import { Text, Select } from '../../components/ui'; interface IInputContainer { label?: React.ReactNode, hint?: React.ReactNode, required?: boolean, type?: string, extraClass?: string, error?: boolean, } export const InputContainer: React.FC = (props) => { const containerClass = classNames('input', { 'with_label': props.label, 'required': props.required, 'boolean': props.type === 'checkbox', 'field_with_errors': props.error, }, props.extraClass); return (
{props.children} {props.hint && {props.hint}}
); }; interface ILabelInputContainer { label?: React.ReactNode, hint?: React.ReactNode, } export const LabelInputContainer: React.FC = ({ label, hint, children }) => { const [id] = useState(uuidv4()); const childrenWithProps = React.Children.map(children, child => ( // @ts-ignore: not sure how to get the right type here React.cloneElement(child, { id: id, key: id }) )); return (
{childrenWithProps}
{hint && {hint}}
); }; interface ILabelInput { label?: React.ReactNode, } export const LabelInput: React.FC = ({ label, ...props }) => ( ); interface ILabelTextarea { label?: React.ReactNode, } export const LabelTextarea: React.FC = ({ label, ...props }) => (