{"version":3,"sources":["../../src/components/radio.tsx"],"sourcesContent":["\"use client\";\n\nimport React, {\n  ComponentProps,\n  createContext,\n  FunctionComponent,\n  useContext,\n} from \"react\";\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\nimport { clx } from \"../utils\";\n\ntype RadioSize = \"small\" | \"medium\" | \"large\";\nconst DEFAULT_SIZE = \"medium\";\n\n/**\n * Extends Radix UI's RadioGroup.Root props.\n * @see https://www.radix-ui.com/primitives/docs/components/radio-group#root\n */\nexport interface RadioProps\n  extends React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root> {\n  size?: RadioSize;\n}\n\nconst RadioContext = createContext<\n  Required<Pick<RadioProps, \"size\" | \"disabled\">>\n>({\n  size: DEFAULT_SIZE,\n  disabled: false,\n});\n\n// An item needs it's own context because labels and radio buttons need to be\n// aware if only the specific item was disabled.\nconst RadioItemContext = createContext<\n  Required<Pick<ComponentProps<typeof RadioItem>, \"disabled\">>\n>({ disabled: false });\n\n/**\n * Uses RadixUI's RadioGroup.Root API.\n * @see https://www.radix-ui.com/primitives/docs/components/radio-group#api-reference\n */\nconst Radio = React.forwardRef<\n  React.ElementRef<typeof RadioGroupPrimitive.Root>,\n  RadioProps\n>(({ className, size = DEFAULT_SIZE, disabled = false, ...props }, ref) => {\n  return (\n    <RadioContext.Provider value={{ size, disabled }}>\n      <RadioGroupPrimitive.Root\n        className={clx(\"grid gap-3\", className)}\n        disabled={disabled}\n        ref={ref}\n        {...props}\n      />\n    </RadioContext.Provider>\n  );\n});\nRadio.displayName = \"Radio\";\n\nconst RadioItem: FunctionComponent<\n  ComponentProps<\"div\"> & { disabled?: boolean }\n> = ({ className, children, ...props }) => {\n  const { disabled } = useContext(RadioContext);\n  return (\n    <RadioItemContext.Provider value={{ disabled: props.disabled ?? disabled }}>\n      <div className={clx(\"flex items-center gap-3\", className)} {...props}>\n        {children}\n      </div>\n    </RadioItemContext.Provider>\n  );\n};\nRadioItem.displayName = \"RadioItem\";\n\n/**\n * Uses RadixUI's RadioGroup.Item API.\n * @see https://www.radix-ui.com/primitives/docs/components/radio-group#item\n */\nconst RadioButton = React.forwardRef<\n  React.ElementRef<typeof RadioGroupPrimitive.Item>,\n  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>\n>(({ className, ...props }, ref) => {\n  const { size } = useContext(RadioContext);\n  const { disabled } = useContext(RadioItemContext);\n  return (\n    <RadioGroupPrimitive.Item\n      ref={ref}\n      className={clx(\n        \"shadow-button hover:border-otl-gray-300 border-otl-gray-200 aspect-square rounded-full border\",\n        \"focus-visible:ring-fr-primary focus:outline-none focus-visible:ring-4 focus-visible:ring-opacity-40\",\n        \"disabled:bg-bg-washed disabled:cursor-not-allowed\",\n        \"data-[state=checked]:bg-primary-600 data-[state=checked]:border-none\",\n        \"data-[state=checked]:disabled:bg-primary-600 data-[state=checked]:disabled:opacity-30\",\n        size === \"small\" && \"w-4\",\n        size === \"medium\" && \"w-5\",\n        size === \"large\" && \"w-5\",\n        className,\n      )}\n      disabled={props.disabled ?? disabled}\n      {...props}\n    >\n      <RadioGroupPrimitive.Indicator className=\"flex items-center justify-center\">\n        <div\n          className=\"bg-bg-white aspect-square w-2/5 rounded-full\"\n          aria-hidden=\"true\"\n        />\n      </RadioGroupPrimitive.Indicator>\n    </RadioGroupPrimitive.Item>\n  );\n});\nRadioButton.displayName = \"RadioButton\";\n\nconst RadioLabel = ({\n  className,\n  children,\n  ...props\n}: ComponentProps<\"label\">) => {\n  const { size } = useContext(RadioContext);\n  const { disabled } = useContext(RadioItemContext);\n  return (\n    <label\n      className={clx(\n        \"text-txt-black-700 font-medium\",\n        size === \"small\" && \"text-body-sm\",\n        size === \"medium\" && \"text-body-md\",\n        size === \"large\" && \"text-lg\",\n        disabled && \"text-txt-black-disabled\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </label>\n  );\n};\nRadioLabel.displayName = \"RadioLabel\";\n\nconst RadioHintText = ({\n  className,\n  children,\n  ...props\n}: ComponentProps<\"label\">) => {\n  const { size } = useContext(RadioContext);\n  const { disabled } = useContext(RadioItemContext);\n  return (\n    <label\n      className={clx(\n        \"text-txt-black-500\",\n        size === \"small\" && \"text-xs\",\n        size === \"medium\" && \"text-body-sm\",\n        size === \"large\" && \"text-body-md\",\n        disabled && \"text-otl-gray-300\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </label>\n  );\n};\nRadioHintText.displayName = \"RadioHintText\";\n\nexport { Radio, RadioItem, RadioButton, RadioLabel, RadioHintText };\n"],"mappings":"0GAEA,OAAOA,GAEL,iBAAAC,EAEA,cAAAC,MACK,QACP,UAAYC,MAAyB,8BAsC/B,cAAAC,MAAA,oBAlCN,IAAMC,EAAe,SAWfC,EAAeC,EAEnB,CACA,KAAMF,EACN,SAAU,EACZ,CAAC,EAIKG,EAAmBD,EAEvB,CAAE,SAAU,EAAM,CAAC,EAMfE,EAAQC,EAAM,WAGlB,CAACC,EAAgEC,IAAQ,CAAxE,IAAAC,EAAAF,EAAE,WAAAG,EAAW,KAAAC,EAAOV,EAAc,SAAAW,EAAW,EA3ChD,EA2CGH,EAAuDI,EAAAC,EAAvDL,EAAuD,CAArD,YAAW,OAAqB,aACnC,OACET,EAACE,EAAa,SAAb,CAAsB,MAAO,CAAE,KAAAS,EAAM,SAAAC,CAAS,EAC7C,SAAAZ,EAAqB,OAApBe,EAAA,CACC,UAAWC,EAAI,aAAcN,CAAS,EACtC,SAAUE,EACV,IAAKJ,GACDK,EACN,EACF,CAEJ,CAAC,EACDR,EAAM,YAAc,QAEpB,IAAMY,EAEDV,GAAsC,CAAtC,IAAAE,EAAAF,EAAE,WAAAG,EAAW,SAAAQ,CA3DlB,EA2DKT,EAA0BI,EAAAC,EAA1BL,EAA0B,CAAxB,YAAW,aA3DlB,IAAAF,EA4DE,GAAM,CAAE,SAAAK,CAAS,EAAIO,EAAWjB,CAAY,EAC5C,OACEF,EAACI,EAAiB,SAAjB,CAA0B,MAAO,CAAE,UAAUG,EAAAM,EAAM,W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,GAIQ,CAJR,IAAAE,EAAAF,EACrB,WAAAG,EACA,SAAAQ,CAxIF,EAsIuBT,EAGlBI,EAAAC,EAHkBL,EAGlB,CAFH,YACA,aAGA,GAAM,CAAE,KAAAE,CAAK,EAAIQ,EAAWjB,CAAY,EAClC,CAAE,SAAAU,CAAS,EAAIO,EAAWf,CAAgB,EAChD,OACEJ,EAAC,QAAAoB,EAAAL,EAAA,CACC,UAAWC,EACT,qBACAL,IAAS,SAAW,UACpBA,IAAS,UAAY,eACrBA,IAAS,SAAW,eACpBC,GAAY,oBACZF,CACF,GACIG,GATL,CAWE,SAAAK,GACH,CAEJ,EACAK,EAAc,YAAc","names":["React","createContext","useContext","RadioGroupPrimitive","jsx","DEFAULT_SIZE","RadioContext","createContext","RadioItemContext","Radio","React","_a","ref","_b","className","size","disabled","props","__objRest","__spreadValues","clx","RadioItem","children","useContext","__spreadProps","RadioButton","RadioLabel","RadioHintText"]}