{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-group",
  "title": "RadioGroup",
  "description": "A group of radios under one legend, on the Field contract, for picking exactly one choice: pass `legend`, and `options` (or `Radio` children).",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/field",
    "@ouro/lib-control-ref",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-page-direction",
    "@ouro/lib-refs",
    "@ouro/lib-touch-target",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-field"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/radio-group/radio-group-styles.ts",
      "content": "export { dotClass, radioClass };\n\n// Class strings for Radio, apart from the components so each component file exports only\n// components (React Fast Refresh). Class strings are literal so the app's Tailwind finds\n// them when it compiles.\n\n/**\n * The radio: a 20px circle on touch screens, beside a 24px label line, stepping down to\n * 16px beside a 20px line from the `sm` breakpoint with a fine pointer, so a landscape phone\n * keeps the phone size. Either way it sits 2px down, centered on the label's first line. It\n * fills with the primary color when chosen, presses in, and its hit area is 44px on touch\n * screens.\n *\n * @internal\n * @claim \"The radio: a 20px circle on\" registry/ouro/components/ouro/radio-group/radio-group.touch.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.touch.test.tsx::picks on a tap on a label, and keeps the phone size on a landscape phone) verify:fileLine(registry/ouro/components/ouro/radio-group/radio-group-styles.ts, /size-5 shrink-0 items-center justify-center p-0 sm:pointer-fine:size-4/)\n * @claim \"It fills with the primary color\" registry/ouro/components/ouro/radio-group/radio-group.touch.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.touch.test.tsx::keeps each radio's 44px hit area clear of its neighbors')\n * @claim \"It fills with the primary color\" registry/ouro/components/ouro/radio-group/radio-group.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.test.tsx::RadioGroup > fills the chosen radio with the primary color and shows its dot)\n * @claim \"Either way it sits 2px down\" registry/ouro/components/ouro/radio-group/radio-group-styles.ts verify:fileLine(registry/ouro/components/ouro/radio-group/radio-group-styles.ts, /press\\srelative\\sm-0\\smt-0\\.5\\sbox-border\\sinline-flex\\ssize-5/)\n */\nconst radioClass =\n  \"press relative m-0 mt-0.5 box-border inline-flex size-5 shrink-0 items-center justify-center p-0 sm:pointer-fine:size-4 \" +\n  \"[--corner-shape:round] [corner-shape:round] rounded-full border border-solid border-muted-foreground bg-transparent dark:not-data-checked:bg-input/30 \" +\n  \"data-checked:border-primary data-checked:bg-primary \" +\n  \"aria-invalid:border-destructive \" +\n  \"cursor-default select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"not-aria-invalid:not-data-disabled:not-data-checked:pointer-fine:hover:border-foreground \" +\n  \"motion-safe:not-data-disabled:active:scale-(--ouro-press-scale) \" +\n  \"data-disabled:cursor-not-allowed data-disabled:opacity-50\";\n\n/**\n * The dot in a chosen radio: it grows in from 95% as it fades in, and with reduced motion only fades.\n *\n * @internal\n * @claim \"The dot in a chosen radio\" registry/ouro/components/ouro/radio-group/radio-group.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.test.tsx::RadioGroup > grows the dot in from 95% as it fades in, never from nothing, and only fades with reduced motion)\n */\nconst dotClass =\n  \"pointer-events-none block size-2 [--corner-shape:round] [corner-shape:round] rounded-full bg-primary-foreground sm:pointer-fine:size-1.5 \" +\n  \"scale-95 opacity-0 data-checked:scale-100 data-checked:opacity-100 \" +\n  \"motion-safe:[transition:scale_var(--ouro-duration-fast)_var(--ouro-ease-out),opacity_var(--ouro-duration-fast)_var(--ouro-ease-out)] \" +\n  \"motion-reduce:scale-100 motion-reduce:transition-opacity motion-reduce:duration-(--ouro-duration-fast)\";\n",
      "type": "registry:ui",
      "target": "@components/ouro/radio-group/radio-group-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/radio-group/radio-group.tsx",
      "content": "\"use client\";\n\nimport { Radio as BaseRadio } from \"@base-ui/react/radio\";\nimport { RadioGroup as BaseRadioGroup } from \"@base-ui/react/radio-group\";\nimport { useRef, type JSX, type ReactNode, type Ref } from \"react\";\nimport { Field } from \"@/registry/ouro/components/ouro/field/field\";\nimport { choicesClass, contractWarnings } from \"@/registry/ouro/components/ouro/field/field-styles\";\nimport { devThrow } from \"@/registry/ouro/lib/ouro/dev\";\nimport { controlRef } from \"@/registry/ouro/lib/ouro/control-ref\";\nimport { TouchTarget } from \"@/registry/ouro/lib/ouro/touch-target\";\nimport { FieldOwnerContext, useField, type ReadonlyErrorMessages } from \"@/registry/ouro/lib/ouro/use-field\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { PageDirection } from \"@/registry/ouro/lib/ouro/page-direction\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { dotClass, radioClass } from \"@/registry/ouro/components/ouro/radio-group/radio-group-styles\";\n\n/** One choice in a {@link RadioGroup}'s `options`. */\nexport interface RadioGroupOption {\n  /** What the group submits when this choice is picked, and the group's `value` then. */\n  value: string;\n  /** The choice's name, shown to the right of its radio. */\n  label: string;\n  /** Supporting text under the label, read after it. */\n  description?: ReactNode | undefined;\n  /** Disables this one radio; the arrow keys skip it. */\n  disabled?: boolean | undefined;\n}\n\n/** The props RadioGroup takes whichever way its choices are given. */\nexport interface RadioGroupOwnProps {\n  /**\n   * What is being chosen, shown above the choices and read as the group's name. Required: a\n   * group of controls needs a name. To hide it visually, keep it and add `hideLegend`.\n   */\n  legend: string;\n  /** Hides the legend visually; screen readers still read it as the group's name. */\n  hideLegend?: boolean | undefined;\n  /** Supporting text under the legend, read after it through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /**\n   * What is wrong, from your server action or client check, shown under the choices; every\n   * radio gets `aria-invalid`. A message is text or a React node (one with a link); an empty string or array means valid.\n   * @claim \"What is wrong, from your server\" registry/ouro/components/ouro/radio-group/radio-group.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.test.tsx::RadioGroup > disables every radio with disabled, and marks them invalid with error)\n   */\n  error?: ReadonlyErrorMessages | undefined;\n  /** A choice must be picked to submit the form: the group gets `aria-required`, and the legend a marker. */\n  required?: boolean | undefined;\n  /**\n   * Disables every radio and fades the group.\n   *\n   * @claim \"Disables every radio and fades the\" registry/ouro/components/ouro/radio-group/radio-group.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.test.tsx::RadioGroup > disables every radio with disabled, and marks them invalid with error)\n   */\n  disabled?: boolean | undefined;\n  /** The form field name the chosen value submits under. */\n  name?: string | undefined;\n  /** The chosen value, for a controlled group; pair it with `onValueChange`. */\n  value?: string | undefined;\n  /** The value chosen at first, for an uncontrolled group. Unset, nothing is chosen. */\n  defaultValue?: string | undefined;\n  /** Called with the chosen value when another radio is picked. */\n  onValueChange?: ((value: string) => void) | undefined;\n  /** `vertical` stacks the choices; `horizontal` puts short ones in a row that wraps. @default \"vertical\" */\n  orientation?: \"vertical\" | \"horizontal\" | undefined;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Appearance classes\n   * warn in development; style radios in your theme.\n   */\n  className?: string | undefined;\n  /** The group element, a `<div role=\"radiogroup\">`. */\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. A group is named by its `legend`: `<RadioGroup legend=\"Size\">`. */\n  label?: { 'Use <RadioGroup legend=\"Size\">': never };\n  /** Not a prop. Ouro UI uses `onValueChange`, which gets the chosen value: `onValueChange={setSize}`. */\n  onChange?: { 'Use onValueChange={setValue}': never };\n  /** Not a prop. Ouro UI uses `options`: `options={[{ value: \"small\", label: \"Small\" }]}`. */\n  items?: { 'Use options={[{ value: \"small\", label: \"Small\" }]}': never };\n  /** Not a prop. Ouro UI uses `error`: `<RadioGroup error=\"Required.\">`. */\n  errorMessage?: { 'Use <RadioGroup error=\"Required.\">': never };\n  /** Not a prop. Ouro UI uses `description`: `<RadioGroup description=\"...\">`. */\n  helperText?: { 'Use <RadioGroup description=\"...\">': never };\n  /** Not a prop. `error` marks the group invalid: `<RadioGroup error=\"What is wrong\">`. */\n  isInvalid?: { 'Use <RadioGroup error=\"What is wrong\">': never };\n  /** Not a prop. `error` marks the group invalid: `<RadioGroup error=\"What is wrong\">`. */\n  invalid?: { 'Use <RadioGroup error=\"What is wrong\">': never };\n  /** Not a prop. Ouro UI uses `required`: `<RadioGroup required>`. */\n  isRequired?: { 'Use <RadioGroup required>': never };\n  /** Not a prop. Ouro UI uses `disabled`: `<RadioGroup disabled>`. */\n  isDisabled?: { 'Use <RadioGroup disabled>': never };\n}\n\n/** Props for {@link RadioGroup}: the choices as `options`, or as `Radio` children, not both. */\nexport type RadioGroupProps = RadioGroupOwnProps &\n  (\n    | {\n        /**\n         * The choices, one radio each, in order.\n         *\n         * @claim \"The choices, one radio each, in\" registry/ouro/components/ouro/radio-group/radio-group.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.test.tsx::RadioGroup > renders a radio for each option, each named by its label and described by its description)\n         */\n        options: RadioGroupOption[];\n        /** Not with `options`: pass the choices one way. */\n        children?: never;\n      }\n    | {\n        /** The choices as `Radio` elements, for a layout `options` cannot express. */\n        children: ReactNode;\n        /** Not with children: pass the choices one way. */\n        options?: never;\n      }\n  );\n\n/** Props for {@link Radio}. */\nexport interface RadioProps {\n  /** What the group submits when this radio is picked, and the group's `value` then. */\n  value: string;\n  /**\n   * The choice's name, shown to the right of the radio. Required: every control needs a name.\n   *\n   * @claim \"Required: every control needs a name\" registry/ouro/components/ouro/radio-group/radio-group.test-d.ts verify:fileLine(registry/ouro/components/ouro/radio-group/radio-group.test-d.ts, /expectTypeOf<\\{\\svalue:\\s\"small\"\\s\\}>\\(\\)\\.not\\.toExtend<RadioProps>/)\n   */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the radio's name. */\n  hideLabel?: boolean | undefined;\n  /** Supporting text under the label, read after it through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /** Disables this one radio; the arrow keys skip it. */\n  disabled?: boolean | undefined;\n  /** Layout only: margins, width, grid placement. Appearance classes warn in development. */\n  className?: string | undefined;\n  /** The radio element, a `<button role=\"radio\">`, which the label names with `for`. */\n  ref?: Ref<HTMLElement> | undefined;\n\n  /** Not a prop. The group's `value` picks the radio: `<RadioGroup value=\"small\">`. */\n  checked?: { 'Use <RadioGroup value=\"small\">': never };\n  /**\n   * Not a prop. The group's `name` applies to every radio: `<RadioGroup name=\"size\">`.\n   *\n   * @claim \"The group's `name` applies to every\" registry/ouro/components/ouro/radio-group/radio-group.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.test.tsx::RadioGroup > submits name=value for the chosen radio)\n   * @claim \"The group's `name` applies to every\" registry/ouro/components/ouro/radio-group/radio-group.test-d.ts verify:fileLine(registry/ouro/components/ouro/radio-group/radio-group.test-d.ts, /expectTypeOf<\\{\\svalue:\\s\"small\";\\slabel:\\s\"Small\";\\sname:\\s\"size\"\\s\\}>\\(\\)\\.not\\.toExtend<RadioProps>/)\n   */\n  name?: { 'Use <RadioGroup name=\"size\">': never };\n}\n\n/** Field's messages and root name RadioGroup, and use the label as the group's legend. */\nconst groupOwner = { name: \"RadioGroup\", data: \"radio-group\", layout: \"group\" } as const;\n/** Field's messages and root name Radio, and put the radio before its label. */\nconst radioOwner = { name: \"Radio\", data: \"radio\", layout: \"inline\" } as const;\n/** Marks the hidden input that Base UI submits a radio with. */\nconst markInput = controlRef(\"radio-group\", \"hidden-input\");\n\n/** The radio, inside its Field item: it takes its name and description ids from the field. */\nfunction RadioCircle({ value, ref }: { value: string; ref: Ref<HTMLElement> | undefined }): JSX.Element {\n  const field = useField()!;\n  return (\n    <BaseRadio.Root\n      value={value}\n      ref={ref}\n      // A real button, so the label's `for` names it and not the hidden input: its label finds one control.\n      nativeButton\n      render={<button />}\n      inputRef={markInput}\n      data-ouro-control=\"radio-group\"\n      data-ouro-part=\"circle\"\n      // Set here, not left to Base UI's effects, so the server HTML names and describes the radio.\n      aria-labelledby={field.labelId}\n      aria-describedby={field.describedBy}\n      aria-invalid={field.invalid || undefined}\n      className={radioClass}\n    >\n      <TouchTarget />\n      <BaseRadio.Indicator keepMounted data-ouro-radio-dot=\"\" className={dotClass} />\n    </BaseRadio.Root>\n  );\n}\n\n/**\n * One choice in a `RadioGroup`, with its label to its right. Pass the choices as the group's\n * `options` unless you need a layout they cannot express, such as a choice with a rich\n * description; then render `Radio` children.\n *\n * Use `Checkbox` inside a `CheckboxGroup` instead when several choices may be picked.\n *\n * @group Forms\n * @example\n * <RadioGroup legend=\"Size\" name=\"size\">\n *   <Radio value=\"small\" label=\"Small\" description=\"Serves 2.\" />\n *   <Radio value=\"large\" label=\"Large\" description=\"Serves 6.\" />\n * </RadioGroup>\n */\nexport function Radio(props: RadioProps): JSX.Element {\n  const { value, label, hideLabel, description, disabled, className, ref, checked, name } = props;\n  if (useField()?.group !== \"RadioGroup\") {\n    devThrow(\n      \"Radio\",\n      \"must be rendered inside <RadioGroup>\",\n      process.env.NODE_ENV !== \"production\"\n        ? `<RadioGroup legend=\"Size\"><Radio value=\"${value}\" label=\"${label}\" /></RadioGroup>`\n        : /* istanbul ignore next @preserve -- production only */ \"\",\n    );\n  }\n  useDevWarnings(\n    \"Radio\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [checked !== undefined && [\"checked is not a prop; the group's value picks the radio\", `<RadioGroup value=\"${value}\">`]]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  return (\n    <FieldOwnerContext.Provider value={radioOwner}>\n      {/* `name` reaches Field only so it can point the misuse to the group. */}\n      <Field label={label} hideLabel={hideLabel} description={description} disabled={disabled} name={name as string | undefined} className={className}>\n        <RadioCircle value={value} ref={ref} />\n      </Field>\n    </FieldOwnerContext.Provider>\n  );\n}\n\n/** The group, inside the Field: it takes its name, description and required state from the field. */\nfunction Choices(props: {\n  value: string | undefined;\n  defaultValue: string | undefined;\n  onValueChange: ((value: string) => void) | undefined;\n  orientation: \"vertical\" | \"horizontal\";\n  ref: Ref<HTMLDivElement> | undefined;\n  children: ReactNode;\n}): JSX.Element {\n  const { value, defaultValue, onValueChange, orientation, ref, children } = props;\n  const group = useRef<HTMLDivElement>(null);\n  const merged = useMergedRef(ref, group);\n  const field = useField()!;\n  const directed = (\n    <BaseRadioGroup\n      ref={merged}\n      value={value}\n      defaultValue={defaultValue}\n      onValueChange={onValueChange && ((next) => onValueChange(next as string))}\n      required={field.required}\n      // Set here, not left to Base UI's effects, so the server HTML names and describes the group.\n      aria-labelledby={field.labelId}\n      aria-describedby={field.describedBy}\n      className={choicesClass[orientation]}\n    >\n      {children}\n    </BaseRadioGroup>\n  );\n  return <PageDirection of={group}>{directed}</PageDirection>;\n}\n\n/**\n * A group of radios under one legend, on the Field contract, for picking exactly one\n * choice: pass `legend`, and `options` (or `Radio` children). The group is one tab stop;\n * the arrow keys move between radios and pick as they go. With `name`, the chosen value\n * submits as `name=value` with its form. `error` and `required` apply to the whole group.\n *\n * Use `CheckboxGroup` instead when several choices may be picked, `Select` for a long list,\n * and `Switch` for on or off.\n * In a right-to-left page (`dir=\"rtl\"`) a row of radios follows it: ArrowLeft moves to the next.\n *\n *\n * @group Forms\n * @claim \"In a right-to-left page\" registry/ouro/components/ouro/radio-group/radio-group.test.tsx verify:testExists(registry/ouro/components/ouro/radio-group/radio-group.test.tsx::RadioGroup > moves to the next radio with ArrowLeft in a right-to-left page, laid out in a row)\n * @see https://ui.ouroboros.bot/docs/radio-group\n *\n * @example\n * <RadioGroup\n *   legend=\"Size\"\n *   name=\"size\"\n *   defaultValue=\"medium\"\n *   options={[\n *     { value: \"small\", label: \"Small\", description: \"Serves 2.\" },\n *     { value: \"medium\", label: \"Medium\", description: \"Serves 4.\" },\n *   ]}\n * />\n */\nexport function RadioGroup(props: RadioGroupProps): JSX.Element {\n  const {\n    legend,\n    hideLegend,\n    description,\n    error,\n    required,\n    disabled,\n    name,\n    value,\n    defaultValue,\n    onValueChange,\n    orientation = \"vertical\",\n    options,\n    children,\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    label,\n    onChange,\n    items,\n    errorMessage,\n    helperText,\n    isInvalid,\n    invalid,\n    isRequired,\n    isDisabled,\n  } = props;\n  if (options !== undefined && children !== undefined) {\n    devThrow(\n      \"RadioGroup\",\n      \"takes options or Radio children, not both\",\n      process.env.NODE_ENV !== \"production\"\n        ? `<RadioGroup legend=\"${legend}\" options={options} />, or <RadioGroup legend=\"${legend}\"><Radio value=\"small\" label=\"Small\" /></RadioGroup>`\n        : /* istanbul ignore next @preserve -- production only */ \"\",\n    );\n  }\n\n  useDevWarnings(\n    \"RadioGroup\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          ...contractWarnings(\"RadioGroup\", { errorMessage, helperText, isInvalid, invalid, isRequired, isDisabled }),\n          label !== undefined && [\"label is not a prop; a group is named by its legend\", `<RadioGroup legend=\"${String(label)}\">`],\n          onChange !== undefined && [\"onChange is not a prop; onValueChange gets the chosen value\", \"<RadioGroup onValueChange={(value) => setValue(value)}>\"],\n          items !== undefined && [\"items is not a prop\", '<RadioGroup options={[{ value: \"small\", label: \"Small\" }]}>'],\n          value !== undefined && !onValueChange && [\"value without onValueChange never changes\", \"<RadioGroup value={value} onValueChange={setValue}>, or defaultValue\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  return (\n    <FieldOwnerContext.Provider value={groupOwner}>\n      <Field\n        label={legend}\n        hideLabel={hideLegend}\n        description={description}\n        error={error}\n        required={required}\n        disabled={disabled}\n        name={name}\n        className={className}\n      >\n        <Choices value={value} defaultValue={defaultValue} onValueChange={onValueChange} orientation={orientation} ref={ref}>\n          {options\n            ? options.map((option) => (\n                <Radio key={option.value} value={option.value} label={option.label} description={option.description} disabled={option.disabled} />\n              ))\n            : children}\n        </Choices>\n      </Field>\n    </FieldOwnerContext.Provider>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/radio-group/radio-group.tsx"
    }
  ],
  "docs": "A group of radios under one legend, on the Field contract, for picking exactly one choice: pass `legend`, and `options` (or `Radio` children). Import: import { RadioGroup } from \"@/components/ouro/radio-group/radio-group\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: field, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/radio-group.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}