{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-group",
  "type": "registry:component",
  "title": "Radio Group",
  "description": "One choice from a short list, with every option visible and the arrow keys moving between them.",
  "dependencies": [
    "@base-ui/react",
    "tailwind-variants"
  ],
  "registryDependencies": [],
  "cssVars": {
    "light": {
      "success": "oklch(0.696 0.17 162.48)",
      "info": "oklch(0.623 0.214 259.815)"
    },
    "dark": {
      "success": "oklch(0.696 0.17 162.48)",
      "info": "oklch(0.623 0.214 259.815)"
    }
  },
  "files": [
    {
      "path": "components/panelui/radio-group.tsx",
      "type": "registry:component",
      "target": "@components/panelui/radio-group.tsx",
      "content": "'use client';\n\n/**\n * Radio Group — one choice from a short list, all of it visible at once.\n *\n * ```tsx\n * <RadioGroup defaultValue=\"standard\" aria-label=\"Delivery\">\n *   <Label><Radio value=\"standard\" /><Label.Text>Standard</Label.Text></Label>\n *   <Label><Radio value=\"express\" /><Label.Text>Express</Label.Text></Label>\n * </RadioGroup>\n * ```\n *\n * ## The dot lands\n *\n * The chosen radio's centre grows in with a small overshoot, and the ring\n * thickens to meet it, so the choice reads as something being set down\n * rather than a colour changing. The one it leaves shrinks back at the same\n * time. With reduced motion both happen at once.\n *\n * ## Arrow keys move the choice\n *\n * The group is one stop for Tab. Inside it, the arrow keys move the choice\n * from one radio to the next, as a native radio group does.\n *\n * ## As cards\n *\n * `RadioGroup.Card` puts each option in a card of its own, with a title, a\n * line of description and something at the far end such as a price, and the\n * radio drawn inside it. The whole card is the target. It comes in three\n * versions: `outline` rings the chosen card in its colour, `filled` tints\n * it, and `dither` fills it from the far edge with an ordered dither in its\n * colour, densest at the edge and thinning towards the text, which sweeps in\n * as the card is chosen and back out as it is left.\n *\n * ## When to use something else\n *\n * For two to five options that each need a line of explanation, ChoiceCards\n * lays them out as cards. For more than about seven, a Select keeps the form\n * short. For a choice that takes effect at once, without a form to submit,\n * Tabs or a ButtonGroup read better.\n */\nimport { Radio as BaseRadio } from '@base-ui/react/radio';\nimport { RadioGroup as BaseRadioGroup } from '@base-ui/react/radio-group';\nimport type { ComponentProps, CSSProperties, ReactNode } from 'react';\nimport { tv } from 'tailwind-variants';\nimport { mergeProps } from '@base-ui/react/merge-props';\nimport { useRender } from '@base-ui/react/use-render';\nimport type { ElementType as RenderElementType } from 'react';\n\n/** Draws a part as another element, or composes it with a component: `render={<a href=\"/\" />}`. */\ntype RenderProp<Tag extends RenderElementType> = { render?: useRender.ComponentProps<Tag>['render'] };\n\nexport type RadioSize = 'sm' | 'md' | 'lg';\nexport type RadioColor = 'primary' | 'success' | 'info' | 'destructive';\n\nconst radioVariants = tv({\n  slots: {\n    group:\n      'flex gap-3 data-[orientation=vertical]:flex-col data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:flex-wrap',\n    root: [\n      'group/radio relative inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full border outline-none',\n      'border-input bg-background shadow-xs dark:bg-input/30',\n      'transition-[border-color,border-width,box-shadow] duration-200',\n      'hover:not-data-disabled:border-[color-mix(in_oklab,var(--input),var(--foreground)_25%)]',\n      'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',\n      'data-checked:border-(--radio-color)',\n      'aria-invalid:border-destructive',\n      'data-disabled:cursor-not-allowed data-disabled:opacity-50',\n      \"after:absolute after:-inset-2 after:content-['']\",\n    ],\n    indicator: [\n      'pointer-events-none size-[46%] rounded-full bg-(--radio-color)',\n      'scale-0 transition-transform duration-300 ease-[cubic-bezier(0.3,1.6,0.5,1)]',\n      'data-checked:scale-100 motion-reduce:transition-none',\n    ],\n  },\n  variants: {\n    size: {\n      sm: { root: 'size-3.5' },\n      md: { root: 'size-4 data-checked:border-[1.5px]' },\n      lg: { root: 'size-5 data-checked:border-2' },\n    },\n    color: {\n      primary: { root: '[--radio-color:var(--primary)]' },\n      success: { root: '[--radio-color:var(--success)]' },\n      info: { root: '[--radio-color:var(--info)]' },\n      destructive: { root: '[--radio-color:var(--destructive)]' },\n    },\n  },\n  defaultVariants: { size: 'md', color: 'primary' },\n});\n\nexport interface RadioGroupProps extends Omit<BaseRadioGroup.Props<string>, 'className'> {\n  /** Whether the radios stack or sit in a row. Also sets which arrow keys move the choice. Default `vertical`. */\n  orientation?: 'vertical' | 'horizontal';\n  className?: string;\n}\n\n/** Holds one value for the radios inside it. Takes `value`/`onValueChange` or `defaultValue`, and `name` for a form. */\nfunction RadioGroupRoot({ orientation = 'vertical', className, ...props }: RadioGroupProps) {\n  return (\n    <BaseRadioGroup\n      data-slot=\"radio-group\"\n      data-orientation={orientation}\n      aria-orientation={orientation}\n      className={radioVariants().group({ className })}\n      {...props}\n    />\n  );\n}\nRadioGroupRoot.displayName = 'RadioGroup';\n\nexport interface RadioProps extends Omit<BaseRadio.Root.Props<string>, 'className' | 'color'> {\n  /** Default `md`. */\n  size?: RadioSize;\n  /** The colour of the chosen radio. `primary` by default. */\n  color?: RadioColor;\n  /** What a screen reader calls it, when there is no visible label tied to it. */\n  label?: string;\n  className?: string;\n  style?: CSSProperties;\n}\n\n/** One option. `value` is what the group's value becomes when it is chosen. */\nfunction Radio({ size = 'md', color, label, className, ...props }: RadioProps) {\n  const slots = radioVariants({ size, color });\n  return (\n    <BaseRadio.Root\n      data-slot=\"radio\"\n      data-size={size}\n      aria-label={label}\n      className={slots.root({ className })}\n      {...props}\n    >\n      <BaseRadio.Indicator data-slot=\"radio-indicator\" keepMounted className={slots.indicator()} />\n    </BaseRadio.Root>\n  );\n}\nRadio.displayName = 'RadioGroup.Item';\n\n/** The 4×4 Bayer matrix, as thresholds 0–15. */\nconst BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];\n\n/** Masks an element to an even ordered dither at `level` of 16, in 2px cells. */\nfunction ditherMask(level: number): CSSProperties {\n  let rects = '';\n  BAYER.forEach((threshold, index) => {\n    if (threshold < level) rects += `<rect x='${index % 4}' y='${Math.floor(index / 4)}' width='1' height='1'/>`;\n  });\n  const image = `url(\"data:image/svg+xml,${encodeURIComponent(\n    `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 4' shape-rendering='crispEdges'>${rects}</svg>`\n  )}\")`;\n  return { maskImage: image, WebkitMaskImage: image, maskSize: '8px 8px', WebkitMaskSize: '8px 8px' };\n}\n\n/** The dither ramp's bands, from the far edge in: how wide each reaches, and how dense it is. */\nconst RAMP = [\n  { reach: '9%', level: 12 },\n  { reach: '17%', level: 7 },\n  { reach: '25%', level: 3 },\n  { reach: '32%', level: 1 },\n].map((band) => ({ ...band, style: ditherMask(band.level) }));\n\nexport type RadioCardAppearance = 'outline' | 'filled' | 'dither';\n\nconst cardVariants = tv({\n  slots: {\n    card: [\n      'group/card relative flex w-full min-w-0 cursor-pointer items-start gap-3 overflow-hidden rounded-xl border p-3.5 text-start outline-none select-none',\n      'border-border bg-background shadow-xs transition-[border-color,background-color,box-shadow] duration-200 dark:bg-input/20',\n      'hover:not-data-disabled:border-[color-mix(in_oklab,var(--border),var(--foreground)_18%)]',\n      'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',\n      'data-disabled:cursor-not-allowed data-disabled:opacity-50',\n    ],\n    dot: [\n      'relative z-10 mt-0.5 inline-flex size-4 shrink-0 items-center justify-center rounded-full border border-input bg-background',\n      'transition-[border-color,border-width] duration-200 group-data-checked/card:border-[1.5px] group-data-checked/card:border-(--radio-color)',\n    ],\n    dotFill: [\n      'size-[46%] rounded-full bg-(--radio-color) scale-0 transition-transform duration-300 ease-[cubic-bezier(0.3,1.6,0.5,1)]',\n      'group-data-checked/card:scale-100 motion-reduce:transition-none',\n    ],\n    body: 'relative z-10 flex min-w-0 flex-1 flex-col gap-0.5',\n    title: 'text-sm font-medium leading-5 text-foreground',\n    description: 'text-[0.8125rem] leading-5 text-muted-foreground',\n    aside: 'relative z-10 ms-auto shrink-0 text-sm font-medium tabular-nums text-foreground',\n    ramp: 'pointer-events-none absolute inset-0',\n    band: [\n      'absolute inset-y-0 end-0 bg-(--radio-color)',\n      // Hidden by sliding its clip to the far edge, so the sweep runs from there inwards.\n      '[clip-path:inset(0_0_0_100%)] rtl:[clip-path:inset(0_100%_0_0)] transition-[clip-path] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)]',\n      'group-data-checked/card:[clip-path:inset(0_0_0_0)] motion-reduce:transition-none',\n    ],\n    cards: 'grid gap-2',\n  },\n  variants: {\n    appearance: {\n      outline: {\n        card: 'data-checked:border-(--radio-color) data-checked:shadow-[0_0_0_1px_var(--radio-color)]',\n      },\n      filled: {\n        card: [\n          'data-checked:border-[color-mix(in_oklab,var(--radio-color)_45%,var(--background))]',\n          'data-checked:bg-[color-mix(in_oklab,var(--radio-color)_9%,var(--background))] dark:data-checked:bg-[color-mix(in_oklab,var(--radio-color)_16%,var(--background))]',\n        ],\n      },\n      dither: {\n        card: 'data-checked:border-[color-mix(in_oklab,var(--radio-color)_55%,var(--background))]',\n      },\n    },\n    color: {\n      primary: { card: '[--radio-color:var(--primary)]' },\n      success: { card: '[--radio-color:var(--success)]' },\n      info: { card: '[--radio-color:var(--info)]' },\n      destructive: { card: '[--radio-color:var(--destructive)]' },\n    },\n  },\n  defaultVariants: { appearance: 'outline', color: 'primary' },\n});\n\nexport interface RadioCardProps extends Omit<BaseRadio.Root.Props<string>, 'className' | 'color' | 'children'> {\n  /**\n   * How the chosen card is marked: a ring, a tint, or a dither ramp from the\n   * far edge. The ramp draws where `RadioGroup.CardAside` would sit, so leave\n   * the aside out of a `dither` card. Default `outline`.\n   */\n  appearance?: RadioCardAppearance;\n  /** The colour the chosen card is marked in. `primary` by default. */\n  color?: RadioColor;\n  className?: string;\n  style?: CSSProperties;\n  /** `RadioGroup.CardTitle`, `RadioGroup.CardDescription` and `RadioGroup.CardAside`. */\n  children?: ReactNode;\n}\n\n/** One option drawn as a card, with its radio inside. The whole card is pressed to choose it. */\nfunction RadioCard({ appearance = 'outline', color, className, children, ...props }: RadioCardProps) {\n  const slots = cardVariants({ appearance, color });\n  return (\n    <BaseRadio.Root\n      data-slot=\"radio-card\"\n      data-appearance={appearance}\n      className={slots.card({ className })}\n      {...props}\n    >\n      {appearance === 'dither' ? (\n        <span aria-hidden=\"true\" className={slots.ramp()}>\n          {RAMP.map((band) => (\n            <span key={band.level} className={slots.band()} style={{ width: band.reach, ...band.style }} />\n          ))}\n        </span>\n      ) : null}\n      <span data-slot=\"radio-card-indicator\" aria-hidden=\"true\" className={slots.dot()}>\n        <span className={slots.dotFill()} />\n      </span>\n      {children}\n    </BaseRadio.Root>\n  );\n}\nRadioCard.displayName = 'RadioGroup.Card';\n\n/** Holds a card's title and description, beside the radio. */\nfunction RadioCardBody({ className, render, ...props }: ComponentProps<'span'> & RenderProp<'span'>) {\n  return useRender({\n    defaultTagName: 'span',\n    render,\n    props: mergeProps({ 'data-slot': 'radio-card-body', className: cardVariants().body({ className }) }, props),\n  });\n}\nRadioCardBody.displayName = 'RadioGroup.CardBody';\n\n/** The option's name. */\nfunction RadioCardTitle({ className, render, ...props }: ComponentProps<'span'> & RenderProp<'span'>) {\n  return useRender({\n    defaultTagName: 'span',\n    render,\n    props: mergeProps({ 'data-slot': 'radio-card-title', className: cardVariants().title({ className }) }, props),\n  });\n}\nRadioCardTitle.displayName = 'RadioGroup.CardTitle';\n\n/** A line under the name saying what the option means. */\nfunction RadioCardDescription({ className, render, ...props }: ComponentProps<'span'> & RenderProp<'span'>) {\n  return useRender({\n    defaultTagName: 'span',\n    render,\n    props: mergeProps(\n      { 'data-slot': 'radio-card-description', className: cardVariants().description({ className }) },\n      props\n    ),\n  });\n}\nRadioCardDescription.displayName = 'RadioGroup.CardDescription';\n\n/** Pushed to the far end of the card: a price, a duration, a badge. */\nfunction RadioCardAside({ className, render, ...props }: ComponentProps<'span'> & RenderProp<'span'>) {\n  return useRender({\n    defaultTagName: 'span',\n    render,\n    props: mergeProps({ 'data-slot': 'radio-card-aside', className: cardVariants().aside({ className }) }, props),\n  });\n}\nRadioCardAside.displayName = 'RadioGroup.CardAside';\n\nexport const RadioGroup = Object.assign(RadioGroupRoot, {\n  Item: Radio,\n  Card: RadioCard,\n  CardBody: RadioCardBody,\n  CardTitle: RadioCardTitle,\n  CardDescription: RadioCardDescription,\n  CardAside: RadioCardAside,\n});\n\nexport {\n  Radio,\n  Radio as RadioGroupItem,\n  RadioCard,\n  RadioCard as RadioGroupCard,\n  RadioCardBody as RadioGroupCardBody,\n  RadioCardTitle as RadioGroupCardTitle,\n  RadioCardDescription as RadioGroupCardDescription,\n  RadioCardAside as RadioGroupCardAside,\n};\n"
    }
  ]
}
