import clsx from 'clsx'; import React, { useState } from 'react'; import { v4 as uuidv4 } from 'uuid'; import { Select } from '../../components/ui'; interface IInputContainer { label?: React.ReactNode hint?: React.ReactNode required?: boolean type?: string extraClass?: string error?: boolean children: React.ReactNode } export const InputContainer: React.FC = (props) => { const containerClass = clsx('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 children: 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 }) => (