{"version":3,"file":"RadioGroup.mjs","sources":["../../../../src/components/RadioGroup/RadioGroup.tsx"],"sourcesContent":["'use client'\n\nimport { forwardRef } from 'react'\nimport * as React from 'react'\n\nimport * as RadioGroupPrimitive from '@radix-ui/react-radio-group'\nimport classNames from 'classnames'\n\nimport useId from '~/src/hooks/useId'\nimport { getFormFieldSizeClassName } from '~/src/types/props-helpers'\n\nimport { BaseButton } from '~/src/components/BaseButton'\nimport { useFormFieldProps } from '~/src/components/FormControl'\nimport { Stack } from '~/src/components/Stack'\nimport { Text } from '~/src/components/Text'\n\nimport { type RadioGroupProps, type RadioProps } from './RadioGroup.types'\n\nimport styles from './RadioGroup.module.scss'\n\nfunction RadioGroupImpl<Value extends string>(\n  {\n    children,\n    spacing = 0,\n    direction = 'vertical',\n    ...rest\n  }: RadioGroupProps<Value>,\n  forwardedRef: React.Ref<HTMLDivElement>\n) {\n  const { hasError, ...formFieldProps } = useFormFieldProps(rest)\n\n  return (\n    <RadioGroupPrimitive.Root\n      asChild\n      {...formFieldProps}\n    >\n      <Stack\n        ref={forwardedRef}\n        justify=\"start\"\n        align=\"stretch\"\n        spacing={spacing}\n        direction={direction}\n      >\n        {children}\n      </Stack>\n    </RadioGroupPrimitive.Root>\n  )\n}\n\n/**\n * `RadioGroup` is a set of checkable buttons, known as radio buttons.\n *\n * `RadioGroup` is a context of the `Radio` components. also, it renders an element which has the 'radiogroup' role.\n * It controls all the parts of a radio group.\n * @example\n *\n * ```tsx\n * // Anatomy of the RadioGroup\n * <RadioGroup>\n *  <Radio />\n * </RadioGroup>\n * ```\n */\nexport const RadioGroup = forwardRef(RadioGroupImpl) as <Value extends string>(\n  props: RadioGroupProps<Value> & { ref?: React.ForwardedRef<HTMLDivElement> }\n) => ReturnType<typeof RadioGroupImpl<Value>>\n\nfunction RadioImpl<Value extends string>(\n  { children, className, id: idProp, ...rest }: RadioProps<Value>,\n  forwardedRef: React.Ref<HTMLButtonElement>\n) {\n  const id = useId(idProp, 'bezier-radio')\n\n  return (\n    <RadioGroupPrimitive.Item\n      asChild\n      className={classNames(\n        styles.RadioGroupItem,\n        getFormFieldSizeClassName('m'),\n        className\n      )}\n      ref={forwardedRef}\n      id={id}\n      {...rest}\n    >\n      <BaseButton>\n        {children && (\n          <Text\n            className={styles.Label}\n            as=\"label\"\n            /* FIXME(@ed): Delete after applying polymorphic props */\n            /* @ts-ignore */\n            htmlFor={id}\n            typo=\"14\"\n            color=\"text-neutral\"\n          >\n            {children}\n          </Text>\n        )}\n      </BaseButton>\n    </RadioGroupPrimitive.Item>\n  )\n}\n\n/**\n * `Radio` is a checkable button, known as a radio button.\n * It should be a child of `RadioGroup`.\n */\nexport const Radio = forwardRef(RadioImpl) as <Value extends string>(\n  props: RadioProps<Value> & { ref?: React.ForwardedRef<HTMLButtonElement> }\n) => ReturnType<typeof RadioImpl<Value>>\n"],"names":["RadioGroupImpl","children","spacing","direction","rest","forwardedRef","hasError","formFieldProps","useFormFieldProps","_jsx","RadioGroupPrimitive","asChild","Stack","ref","justify","align","RadioGroup","forwardRef","RadioImpl","className","id","idProp","useId","classNames","styles","RadioGroupItem","getFormFieldSizeClassName","BaseButton","Text","Label","as","htmlFor","typo","color","Radio"],"mappings":";;;;;;;;;;;;AAoBA,SAASA,cAAcA,CACrB;EACEC,QAAQ;AACRC,EAAAA,OAAO,GAAG,CAAC;AACXC,EAAAA,SAAS,GAAG,UAAU;EACtB,GAAGC;AACmB,CAAC,EACzBC,YAAuC,EACvC;EACA,MAAM;IAAEC,QAAQ;IAAE,GAAGC;AAAe,GAAC,GAAGC,iBAAiB,CAACJ,IAAI,CAAC;AAE/D,EAAA,oBACEK,GAAA,CAACC,KAAwB,EAAA;IACvBC,OAAO,EAAA,IAAA;AAAA,IAAA,GACHJ,cAAc;IAAAN,QAAA,eAElBQ,GAAA,CAACG,KAAK,EAAA;AACJC,MAAAA,GAAG,EAAER,YAAa;AAClBS,MAAAA,OAAO,EAAC,OAAO;AACfC,MAAAA,KAAK,EAAC,SAAS;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