{"version":3,"file":"Radio.mjs","sources":["../../../src/components/Radio/Radio.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React from 'react';\nimport type { ReactNode } from 'react';\n\nimport type { EitherInclusive } from '../../util/utility-types';\n\nimport Label from '../Label';\nimport Text from '../Text';\n\nimport styles from './Radio.module.css';\n\ntype RadioHTMLElementProps = Omit<\n  React.InputHTMLAttributes<HTMLInputElement>,\n  'checked' | 'id' | 'name'\n>;\n\ntype RadioInputProps = RadioHTMLElementProps & {\n  /**\n   * Whether checkbox is checked.\n   */\n  checked?: boolean;\n  /**\n   * Additional classnames passed in for styling.\n   */\n  className?: string;\n  /**\n   * Radio ID. Used to connect the input with a label for accessibility purposes.\n   */\n  id?: string;\n  /**\n   * Whether the radio button is in an error state\n   */\n  isError?: boolean;\n};\n\ntype RadioProps = RadioInputProps & {\n  // Component API\n  /**\n   * HTML id attribute. If not passed, this component\n   * will generate an id to use for accessibility.\n   */\n  id?: string;\n  /**\n   * The field name to use in a form\n   */\n  name?: string;\n  // Design API\n  /**\n   * Whether the radio button is in an error state\n   */\n  isError?: boolean;\n  /**\n   * Additional descriptive text below the primary label, adding additional detail\n   */\n  subLabel?: ReactNode;\n} & EitherInclusive<\n    {\n      /**\n       * Visible text label for the component.\n       */\n      label: ReactNode;\n    },\n    {\n      /**\n       * Aria-label to provide an accesible name for the text input if no visible label is provided.\n       */\n      'aria-label': string;\n    }\n  >;\n\n/**\n * Radio input element, exported for greater flexibility.\n * You must provide an `id` prop and connect it to a visible label.\n */\nconst RadioInput = ({\n  checked,\n  className,\n  disabled,\n  isError,\n  ...other\n}: RadioInputProps) => {\n  return (\n    <span className={styles['input__wrapper']}>\n      <input\n        checked={checked}\n        className={clsx(\n          className,\n          isError && styles['radio--error'],\n          styles['radio__input'],\n        )}\n        disabled={disabled}\n        type=\"radio\"\n        {...other}\n      />\n      <span className={styles['radio__container']}></span>\n      <span className={styles['radio__selected']}></span>\n    </span>\n  );\n};\n\n/**\n * ## Usage\n *\n * NOTE: This component requires a `label` or `aria-label` prop.\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Standard | A set of mutually exclusive options where only one can be selected. | Single-choice list of options. |\n * | Horizontal Radio Group | Lays out options in a horizontal row for compact use. | Filters in toolbars. Simple form choices. |\n * | Vertical Radio Group | Stacks options vertically for clarity and accessibility. | Longer option lists. Mobile-friendly forms. |\n * | Disabled | Non-interactive, styled to indicate unavailability. | Feature restrictions. Options based on permissions. |\n * | Preselected | One option is selected by default. | Guides user to the most common or recommended choice. |\n *\n * ### Best Practices\n *\n * * By default, radio buttons should have labels. They may have no visible label only if composed into another component, such as a table row. Like text inputs and select components, radio button group labels can include an \"optional\" or \"required\" hint.\n * * Use a radio button when only one item can be selected from a list. When more than one option can be selected, use a checkbox instead.\n * * The radio button group requires error text when `isError: true`.\n * * Radio buttons should never be standalone. Therefore, they should never include their own error text.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Use group labels to describe the action to be taken within groups of radio buttons (e.g. \"Select the topic that most interests you\").\n * * Use helper text to explain the action, or results of the action, when necessary.\n * * Use sentence case for group labels and helper text.\n * * Use end punctuation for helper text.\n * * Keep labels to a few words (ideally 3 or less).\n * * In error messages, describe the issue and what to do about it.\n *\n * ### Don'ts\n *\n * * Use helper text by default; consider better group labels first.\n * * Use end punctuation on group labels.\n * * Truncate labels.\n * * Use end punctuation on an error message that is a sentence fragment.\n */\nexport const Radio = ({\n  className,\n  disabled,\n  label,\n  id,\n  isError = false,\n  subLabel,\n  ...other\n}: RadioProps) => {\n  const generatedId = React.useId();\n  const radioId = id || generatedId;\n\n  const componentClassName = clsx(\n    styles['radio'],\n    isError && styles['radio--error'],\n    className,\n  );\n\n  return (\n    <div className={componentClassName}>\n      <RadioInput\n        disabled={disabled}\n        id={radioId}\n        isError={isError}\n        {...other}\n      />\n      {(label || subLabel) && (\n        <div className={styles['radio__labels']}>\n          {label && (\n            <Label disabled={disabled} htmlFor={radioId} text={label} />\n          )}\n          {subLabel && (\n            <Text\n              as=\"span\"\n              className={clsx(\n                styles['radio__sub-label'],\n                disabled && styles['radio--is-disabled'],\n              )}\n              preset=\"body-sm\"\n            >\n              {subLabel}\n            </Text>\n          )}\n        </div>\n      )}\n    </div>\n  );\n};\n\nRadio.displayName = 'Radio';\nRadioInput.displayName = 'Radio.Input';\n\nRadio.Input = RadioInput;\nRadio.Label = Label;\n"],"names":["React"],"mappings":";;;;;;AAsEA;;;AAGG;AACH,MAAM,UAAU,GAAG,CAAC,EAClB,OAAO,EACP,SAAS,EACT,QAAQ,EACR,OAAO,EACP,GAAG,KAAK,EACQ,KAAI;AACpB,IAAA,QACEA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAAA;AACvC,QAAAA,cAAA,CAAA,aAAA,CAAA,OAAA,EAAA,EACE,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,IAAI,CACb,SAAS,EACT,OAAO,IAAI,MAAM,CAAC,cAAc,CAAC,EACjC,MAAM,CAAC,cAAc,CAAC,CACvB,EACD,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,OAAO,EAAA,GACR,KAAK,EAAA,CACT;AACF,QAAAA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,MAAM,CAAC,kBAAkB,CAAC,EAAA,CAAS;QACpDA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC,EAAA,CAAS,CAC9C;AAEX,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;AACI,MAAM,KAAK,GAAG,CAAC,EACpB,SAAS,EACT,QAAQ,EACR,KAAK,EACL,EAAE,EACF,OAAO,GAAG,KAAK,EACf,QAAQ,EACR,GAAG,KAAK,EACG,KAAI;AACf,IAAA,MAAM,WAAW,GAAGA,cAAK,CAAC,KAAK,EAAE;AACjC,IAAA,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