{"version":3,"file":"FormHelperText.mjs","sources":["../../../../src/components/FormHelperText/FormHelperText.tsx"],"sourcesContent":["'use client'\n\nimport { forwardRef } from 'react'\n\nimport classNames from 'classnames'\n\nimport useMergeRefs from '~/src/hooks/useMergeRefs'\nimport { noop } from '~/src/utils/function'\nimport { isEmpty } from '~/src/utils/type'\n\nimport { useFormControlContext } from '~/src/components/FormControl'\nimport { Text } from '~/src/components/Text'\n\nimport type {\n  BaseHelperTextProps,\n  FormErrorMessageProps,\n  FormHelperTextProps,\n} from './FormHelperText.types'\n\nimport styles from './FormHelperText.module.scss'\n\n/**\n * @deprecated\n */\nconst FORM_HELPER_TEXT_TEST_ID = 'bezier-form-helper-text'\n\n/**\n * @deprecated\n */\nconst FORM_ERROR_MESSAGE_TEST_ID = 'bezier-form-error-message'\n\nconst BaseHelperText = forwardRef<HTMLSpanElement, BaseHelperTextProps>(\n  function BaseHelperText(props, forwardedRef) {\n    const { type, typo = '13', children, className, ...rest } = props\n\n    const contextValue = useFormControlContext()\n    const getProps =\n      type === 'info'\n        ? contextValue?.getHelperTextProps\n        : contextValue?.getErrorMessageProps\n\n    const {\n      visible,\n      ref,\n      className: formControlClassName,\n      ...ownProps\n    } = getProps?.(rest) ?? {\n      visible: true,\n      ref: noop,\n      className: undefined,\n      ...rest,\n    }\n\n    const mergedRef = useMergeRefs(ref, forwardedRef)\n\n    if (isEmpty(children) || !visible) {\n      return null\n    }\n\n    return (\n      <Text\n        ref={mergedRef}\n        as=\"p\"\n        className={classNames(\n          styles.FormHelperText,\n          formControlClassName,\n          className\n        )}\n        typo={typo}\n        align=\"left\"\n        {...ownProps}\n      >\n        {children}\n      </Text>\n    )\n  }\n)\n\n/**\n * `FormHelperText` is a component to show the description of the input element.\n * `FormControl` component can handle its layout by `position` props.\n * @example\n * ```tsx\n * <FormControl position=\"top\">\n *   <FormLabel>\n *     Password\n *   </FormLabel>\n *   <TextField />\n *   <FormHelperText>\n *     Please use at least 6 characters\n *   </FormHelperText>\n * </FormControl>\n * ```\n */\nexport const FormHelperText = forwardRef<HTMLSpanElement, FormHelperTextProps>(\n  function FormHelperText(props, forwardedRef) {\n    const { color = 'text-neutral-lighter', children, ...rest } = props\n\n    return (\n      <BaseHelperText\n        type=\"info\"\n        ref={forwardedRef}\n        color={color}\n        data-testid={FORM_HELPER_TEXT_TEST_ID}\n        {...rest}\n      >\n        {children}\n      </BaseHelperText>\n    )\n  }\n)\n\n/**\n * `FormErrorMessage` is a component to show error message when form values are invalid.\n * It should be used with `FormControl` component.\n * @example\n * ```tsx\n * <FormControl>\n *   <FormLabel>\n *     Password\n *   </FormLabel>\n *   <TextField />\n *   <FormErrorMessage>\n *     Password should be at least 6 characters\n *   </FormErrorMessage>\n * </FormControl>\n * ```\n */\nexport const FormErrorMessage = forwardRef<\n  HTMLSpanElement,\n  FormErrorMessageProps\n>(function FormErrorMessage(props, forwardedRef) {\n  const { color = 'text-accent-orange', children, ...rest } = props\n\n  return (\n    <BaseHelperText\n      aria-live=\"polite\"\n      type=\"error\"\n      ref={forwardedRef}\n      color={color}\n      data-testid={FORM_ERROR_MESSAGE_TEST_ID}\n      {...rest}\n    >\n      {children}\n    </BaseHelperText>\n  )\n})\n"],"names":["FORM_HELPER_TEXT_TEST_ID","FORM_ERROR_MESSAGE_TEST_ID","BaseHelperText","forwardRef","props","forwardedRef","_getProps","type","typo","children","className","rest","contextValue","useFormControlContext","getProps","getHelperTextProps","getErrorMessageProps","visible","ref","formControlClassName","ownProps","noop","undefined","mergedRef","useMergeRefs","isEmpty","_jsx","Text","as","classNames","styles","FormHelperText","align","color","FormErrorMessage"],"mappings":";;;;;;;;;;AAwBA,MAAMA,wBAAwB,GAAG,yBAAyB;;AAE1D;AACA;AACA;AACA,MAAMC,0BAA0B,GAAG,2BAA2B;AAE9D,MAAMC,cAAc,gBAAGC,UAAU,CAC/B,SAASD,cAAcA,CAACE,KAAK,EAAEC,YAAY,EAAE;AAAA,EAAA,IAAAC,SAAA;EAC3C,MAAM;IAAEC,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