import { useId } from 'react'; import { ConditionalWrapper, HintText } from '../../common'; import ErrorMessage from '../ErrorMessage'; import { QuestionProps } from './types'; import clsx from 'clsx'; const Question = function ({ children, className, errorMessage, hasError, hintText, legend, tagName = 'div', ...props }: QuestionProps) { const errorMessageId = `error-message-${useId()}` const hintTextId = `hint-text-${useId()}`; const describedbys: string[] = []; if (hintText) { describedbys.push(hintTextId) }; if (errorMessage) { describedbys.push(errorMessageId) }; return (
{children}
} > {legend && {legend}} {hintText && {hintText}} {hasError && errorMessage && {errorMessage}} {children}
); }; Question.displayName = 'Question'; export default Question;