{"version":3,"file":"RadioGroup.mjs","sources":["../../src/radioGroup/RadioGroup.tsx"],"sourcesContent":["import { useState } from 'react';\n\nimport Radio from '../radio';\nimport { RadioProps } from '../radio/Radio';\nimport { useInputAttributes, WithInputAttributesProps } from '../inputs/contexts';\n\nexport type RadioGroupRadio<T extends string | number = string> = Omit<\n  RadioProps<T>,\n  'name' | 'checked' | 'onChange' | 'className'\n>;\n\nexport interface RadioGroupProps<T extends string | number = string> {\n  name: string;\n  radios: readonly RadioGroupRadio<T>[];\n  selectedValue?: T; // TODO: `NoInfer<T>` from TypeScript 5.4\n  onChange: NonNullable<RadioProps<T>['onChange']>;\n  UNSAFE_inputAttributes?: WithInputAttributesProps['inputAttributes'];\n}\n\nexport default function RadioGroup<T extends string | number = never>({\n  name,\n  radios,\n  selectedValue: controlledValue,\n  onChange,\n  UNSAFE_inputAttributes,\n}: RadioGroupProps<T>) {\n  const inputAttributes = useInputAttributes({ nonLabelable: true });\n\n  const [uncontrolledValue, setUncontrolledValue] = useState(controlledValue);\n\n  return radios.length > 0 ? (\n    <div\n      role=\"radiogroup\"\n      {...inputAttributes}\n      {...UNSAFE_inputAttributes}\n      className=\"wds-radio-group\"\n    >\n      {radios.map(({ value = '' as T, ...restProps }, index) => (\n        <Radio\n          // eslint-disable-next-line react/no-array-index-key\n          key={index}\n          {...restProps}\n          name={name}\n          value={value}\n          checked={value === uncontrolledValue}\n          onChange={(nextValue) => {\n            setUncontrolledValue(nextValue);\n            onChange(nextValue);\n          }}\n        />\n      ))}\n    </div>\n  ) : null;\n}\n"],"names":["RadioGroup","name","radios","selectedValue","controlledValue","onChange","UNSAFE_inputAttributes","inputAttributes","useInputAttributes","nonLabelable","uncontrolledValue","setUncontrolledValue","useState","length","_jsx","role","className","children","map","value","restProps","index","Radio","checked","nextValue"],"mappings":";;;;;AAmBc,SAAUA,UAAUA,CAAoC;EACpEC,IAAI;EACJC,MAAM;AACNC,EAAAA,aAAa,EAAEC,eAAe;EAC9BC,QAAQ;AACRC,EAAAA;AAAsB,CACH,EAAA;EACnB,MAAMC,eAAe,GAAGC,kBAAkB,CAAC;AAAEC,IAAAA,YAAY,EAAE;AAAI,GAAE,CAAC;EAElE,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGC,QAAQ,CAACR,eAAe,CAAC;AAE3E,EAAA,OAAOF,MAAM,CAACW,MAAM,GAAG,CAAC,gBACtBC,GAAA,CAAA,KAAA,EAAA;AACEC,IAAAA,IAAI,EAAC,YAAY;AAAA,IAAA,GACbR,eAAe;AAAA,IAAA,GACfD,sBAAsB;AAC1BU,IAAAA,SAAS,EAAC,iBAAiB;AAAAC,IAAAA,QAAA,EAE1Bf,MAAM,CAACgB,GAAG,CAAC,CAAC;AAAEC,MAAAA,KAAK,GAAG,EAAO;MAAE,GAAGC;AAAS,KAAE,EAAEC,KAAK,kBACnDP,GAAA,CAACQ;AACC;AAAA,MAAA;AAAA,MAAA,GAEIF,SAAS;AACbnB,MAAAA,IAAI,EAAEA,IAAK;AACXkB,MAAAA,KAAK,EAAEA,KAAM;MACbI,OAAO,EAAEJ,KAAK,KAAKT,iBAAkB;MACrCL,QAAQ,EAAGmB,SAAS,IAAI;QACtBb,oBAAoB,CAACa,SAAS,CAAC;QAC/BnB,QAAQ,CAACmB,SAAS,CAAC;AACrB,MAAA;AAAE,KAAA,EARGH,KAQH,CAEL;GACE,CAAC,GACJ,IAAI;AACV;;;;"}