{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"radio-group","type":"registry:ui","title":"RadioGroup","description":"A set of mutually exclusive options, built on real input type=radio elements sharing one name so the browser gives the roving tab stop and keyboard navigation for free.","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["forms"],"registryDependencies":["https://fancy-ui.rama.app/r/internals.json","https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/sound.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/radio-group/RadioGroup.tsx","content":"\"use client\";\n\nimport { forwardRef, useCallback, useMemo, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { cn } from \"../../utils\";\nimport { useField } from \"../../internals/field\";\nimport { useFancyId } from \"../../internals/use-id\";\nimport { useSoundCue } from \"../../sound/use-sound\";\nimport { RADIO_GROUP_KEY } from \"./types\";\nimport type { RadioGroupContext } from \"./types\";\n\nexport type RadioGroupOrientation = \"horizontal\" | \"vertical\";\n\ninterface RadioGroupOwnProps {\n\t/**\n\t * The selected value. `\"\"` means nothing is selected. Controlled when\n\t * supplied: pair it with `onValueChange`, the React counterpart of the\n\t * Svelte source's `bind:value`. Left out, the group keeps the selection\n\t * itself and starts at `\"\"`.\n\t */\n\tvalue?: string;\n\t/** Called with the new value whenever the selection changes. */\n\tonValueChange?: (value: string) => void;\n\t/**\n\t * The `name` shared by every item's native radio input. Generated when\n\t * omitted — see the README — so two groups on the same page never fight\n\t * over each other's selection.\n\t */\n\tname?: string;\n\t/** Disables every item in the group. */\n\tdisabled?: boolean;\n\t/** Marks the group required for native form validation. */\n\trequired?: boolean;\n\t/** Marks the group invalid — sets `aria-invalid` on the group. */\n\tinvalid?: boolean;\n\t/** The list's stacking axis. */\n\torientation?: RadioGroupOrientation;\n\t/**\n\t * Accessible name for the group, standalone. Inside a `FormField` that\n\t * rendered its own label, `field.labelId` wins instead — see the\n\t * README — since this root is a `<div role=\"radiogroup\">`, not\n\t * something `<label for>` can target; only a FormField with no\n\t * `label` of its own falls back to this prop.\n\t */\n\tlabel?: string;\n\t/** The `RadioGroupItem`s. */\n\tchildren?: ReactNode;\n\t/** Additional CSS classes. */\n\tclassName?: string;\n\t/**\n\t * Plays the matching interface cue through the sound controller. Off\n\t * by default; only audible once the user has enabled sound.\n\t */\n\tsound?: boolean;\n}\n\nexport interface RadioGroupProps\n\textends\n\t\tOmit<\n\t\t\tComponentPropsWithoutRef<\"div\">,\n\t\t\tkeyof RadioGroupOwnProps | \"role\" | \"defaultValue\" | \"defaultChecked\"\n\t\t>,\n\t\tRadioGroupOwnProps {}\n\n/**\n * A set of `RadioGroupItem`s sharing one selection and one native radio\n * `name`.\n *\n * The root element arrives through the ref channel rather than a `ref`\n * prop, per PORTING.md — the Svelte source declares `ref = $bindable(null)`.\n *\n * Rest props are not spread: the Svelte source reads only these props off\n * `$props()` and has no `...restProps`, so the port carries no wider\n * attribute surface than the component it mirrors.\n */\nexport const RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(function RadioGroup(\n\t{\n\t\tvalue,\n\t\tonValueChange,\n\t\tname,\n\t\tdisabled = false,\n\t\trequired = false,\n\t\tinvalid = false,\n\t\torientation = \"vertical\",\n\t\tlabel,\n\t\tchildren,\n\t\tclassName,\n\t\tsound = false,\n\t\tid,\n\t\t\"aria-label\": ariaLabel,\n\t\t\"aria-labelledby\": ariaLabelledby,\n\t\t\"aria-describedby\": ariaDescribedby,\n\t\t\"aria-invalid\": ariaInvalid,\n\t\t\"aria-required\": ariaRequired,\n\t\t...rest\n\t},\n\tref\n) {\n\t// Standalone by default; a surrounding FormField wins for id, described-by,\n\t// invalid, required and disabled so a caller never wires those by hand.\n\tconst field = useField();\n\n\t// `internals/use-id.js`'s `uid()` is client-only by design (its counter\n\t// can't agree between server and client) — deferring name generation to\n\t// an effect until mount would leave every radio without a `name` at\n\t// all until hydration, and this component's own README asks for the\n\t// opposite: two same-page groups must stay independent from first\n\t// paint, not just after JS runs. `useFancyId()` gives the same\n\t// one-generator-per-instance guarantee safely during SSR, and it is\n\t// already how FormField (this same wave's other id-generating form\n\t// primitive) solves this exact problem, for the same reason.\n\tconst uid = useFancyId();\n\tconst generatedName = `${uid}-name`;\n\n\tconst resolvedName = name ?? generatedName;\n\n\t// `value = $bindable(\"\")` on the Svelte side. A supplied prop wins and\n\t// the consumer owns the value; with nothing supplied the component owns\n\t// it, starting at the same `\"\"` the Svelte default uses.\n\tconst [uncontrolledValue, setUncontrolledValue] = useState(\"\");\n\tconst isControlled = value !== undefined;\n\tconst currentValue = isControlled ? value : uncontrolledValue;\n\n\tconst effectiveDisabled = field?.disabled ?? disabled;\n\tconst effectiveRequired = field?.required ?? required;\n\tconst effectiveInvalid = field?.invalid ?? invalid;\n\n\tconst playCue = useSoundCue(sound);\n\n\t// The only place `value` changes. A plain function called from an\n\t// item's event handler, not an effect — writing `value` there would\n\t// mean reading and writing the same state in one pass, and would fight a\n\t// caller's own controlled write.\n\tconst select = useCallback(\n\t\t(itemValue: string) => {\n\t\t\tif (effectiveDisabled) return;\n\t\t\tconst changed = currentValue !== itemValue;\n\t\t\tif (!isControlled) setUncontrolledValue(itemValue);\n\t\t\t// The `sound &&` half of the Svelte guard lives inside `useSoundCue`.\n\t\t\tif (changed) playCue(\"select\");\n\t\t\tonValueChange?.(itemValue);\n\t\t},\n\t\t[effectiveDisabled, currentValue, isControlled, playCue, onValueChange]\n\t);\n\n\t// Rebuilt when any of its inputs actually changes — that rebuild is what\n\t// re-renders the items reading it, and it is the React counterpart of the\n\t// Svelte context's live getters.\n\tconst context = useMemo<RadioGroupContext>(\n\t\t() => ({\n\t\t\tname: resolvedName,\n\t\t\tvalue: currentValue,\n\t\t\tdisabled: effectiveDisabled,\n\t\t\trequired: effectiveRequired,\n\t\t\tinvalid: effectiveInvalid,\n\t\t\tisSelected(itemValue: string) {\n\t\t\t\treturn currentValue === itemValue;\n\t\t\t},\n\t\t\tselect,\n\t\t}),\n\t\t[resolvedName, currentValue, effectiveDisabled, effectiveRequired, effectiveInvalid, select]\n\t);\n\n\tconst classes = cn(\n\t\t\"ft-radio-group inline-flex\",\n\t\torientation === \"vertical\"\n\t\t\t? \"flex-col gap-[10px]\"\n\t\t\t: \"flex-row flex-wrap gap-x-[20px] gap-y-[10px]\",\n\t\tclassName\n\t);\n\n\treturn (\n\t\t<RADIO_GROUP_KEY.Provider value={context}>\n\t\t\t{/*\n\t\t\t\t`controlId`/`<label for>` cannot label this element — a div with\n\t\t\t\trole=\"radiogroup\" is not one of the elements `for` can target, ARIA role\n\t\t\t\tor not — so `field.labelId` (the id of the label FormField actually\n\t\t\t\trendered) drives `aria-labelledby` instead. `field.labelId` is\n\t\t\t\t`undefined` both outside a FormField and inside one that rendered no\n\t\t\t\tlabel of its own, and in both of those cases the own `label` prop is\n\t\t\t\twhat has to carry the accessible name — so `aria-label` only renders\n\t\t\t\twhen there is no `labelId` to point at, never both at once.\n\t\t\t*/}\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tref={ref}\n\t\t\t\tid={field?.controlId ?? id}\n\t\t\t\tclassName={classes}\n\t\t\t\trole=\"radiogroup\"\n\t\t\t\tdata-orientation={orientation}\n\t\t\t\taria-label={field?.labelId ? undefined : (label ?? ariaLabel)}\n\t\t\t\taria-labelledby={field?.labelId ?? ariaLabelledby}\n\t\t\t\taria-describedby={\n\t\t\t\t\t[field?.describedBy, ariaDescribedby].filter(Boolean).join(\" \") || undefined\n\t\t\t\t}\n\t\t\t\taria-invalid={effectiveInvalid ? \"true\" : ariaInvalid}\n\t\t\t\taria-required={effectiveRequired ? \"true\" : ariaRequired}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t</RADIO_GROUP_KEY.Provider>\n\t);\n});\n\nRadioGroup.displayName = \"RadioGroup\";\n","type":"registry:ui","target":"@ui/fancy/components/radio-group/RadioGroup.tsx"},{"path":"react/src/components/radio-group/RadioGroupItem.tsx","content":"\"use client\";\n\nimport { forwardRef, useContext } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { cn } from \"../../utils\";\nimport { RADIO_GROUP_KEY } from \"./types\";\nimport \"./radio-group-item.css\";\n\ninterface RadioGroupItemOwnProps {\n\t/** This item's value — what the group's `value` becomes when it is picked. */\n\tvalue: string;\n\t/** Disables just this item, independent of the group's own `disabled`. */\n\tdisabled?: boolean;\n\t/** Visible label text, rendered next to the control. Falls back to `children`, then to `value`. */\n\tlabel?: string;\n\t/** Custom content rendered in place of `label`, e.g. richer markup. */\n\tchildren?: ReactNode;\n\t/** Additional CSS classes, merged onto the wrapping `<label>`. */\n\tclassName?: string;\n}\n\nexport interface RadioGroupItemProps\n\textends\n\t\tOmit<\n\t\t\tComponentPropsWithoutRef<\"input\">,\n\t\t\tkeyof RadioGroupItemOwnProps | \"type\" | \"checked\" | \"defaultChecked\" | \"role\"\n\t\t>,\n\t\tRadioGroupItemOwnProps {}\n\n/**\n * One item of a `RadioGroup` — a real `<input type=\"radio\">` inside the\n * `<label>` that names it.\n *\n * The native input arrives through the ref channel rather than a `ref` prop,\n * per PORTING.md — the Svelte source declares `ref = $bindable(null)`.\n */\nexport const RadioGroupItem = forwardRef<HTMLInputElement, RadioGroupItemProps>(\n\tfunction RadioGroupItem(\n\t\t{ value, disabled = false, label, children, className, onChange, name, required, ...rest },\n\t\tref\n\t) {\n\t\t// Undefined outside a RadioGroup: the item then has no selection or\n\t\t// shared `name` to take part in, and renders as a plain, unchecked,\n\t\t// standalone radio rather than throwing.\n\t\tconst group = useContext(RADIO_GROUP_KEY);\n\n\t\tconst isDisabled = disabled || (group?.disabled ?? false);\n\t\tconst isChecked = group?.isSelected(value) ?? false;\n\n\t\t// Deliberately no `tabindex` anywhere on the input below. That is what\n\t\t// leaves the browser's own sequential-focus-navigation algorithm for\n\t\t// same-`name` radio groups in charge: the first item is the tab stop\n\t\t// while none is checked, and the checked one becomes the tab stop the\n\t\t// instant a selection exists — for free, and correctly, as long as\n\t\t// nothing here overrides it.\n\t\t//\n\t\t// The native `disabled` attribute below is the real gate, but a change\n\t\t// synthesised straight at the element — as a test does, and as some\n\t\t// assistive tech does — walks straight past it, so the handler repeats\n\t\t// the guard itself.\n\t\tfunction handleChange(event: ChangeEvent<HTMLInputElement>) {\n\t\t\tif (isDisabled) return;\n\t\t\tgroup?.select(value);\n\t\t\tonChange?.(event);\n\t\t}\n\n\t\tconst labelClasses = cn(\n\t\t\t\"ft-radio-item inline-flex items-center gap-[10px] text-[13px] cursor-pointer\",\n\t\t\tisDisabled && \"cursor-not-allowed opacity-50\",\n\t\t\tclassName\n\t\t);\n\n\t\t// Echoes the group's invalid state on the still-unselected ring; the\n\t\t// error text itself (with its own icon) lives in the surrounding\n\t\t// FormField, so this border tint is a secondary cue, never the only one.\n\t\t// Plain semantic Tailwind tokens, same as every other border on this\n\t\t// input — only the brand accent below gets a local fallback, because\n\t\t// unlike `--input`/`--destructive` it has no conventionally-named token a\n\t\t// consumer's theme is likely to already define.\n\t\tconst controlClasses = cn(\n\t\t\t\"ft-radio-item-control\",\n\t\t\tgroup?.invalid && !isChecked ? \"border-destructive\" : \"border-input\"\n\t\t);\n\n\t\treturn (\n\t\t\t<label className={labelClasses}>\n\t\t\t\t{/*\n\t\t\t\t\tControlled only inside a group. Outside one there is nothing to\n\t\t\t\t\tcontrol: a `checked` prop React can restore would undo the\n\t\t\t\t\tbrowser's own local check right after the click, where the Svelte\n\t\t\t\t\tsource leaves it standing. `defaultChecked` keeps the standalone\n\t\t\t\t\titem behaving as the plain radio it is.\n\t\t\t\t*/}\n\t\t\t\t<input\n\t\t\t\t\t{...rest}\n\t\t\t\t\tref={ref}\n\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\tclassName={controlClasses}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\t{...(group ? { checked: isChecked } : { defaultChecked: false })}\n\t\t\t\t\tdisabled={isDisabled}\n\t\t\t\t\trequired={group?.required || required}\n\t\t\t\t\tname={group?.name ?? name}\n\t\t\t\t\tonChange={handleChange}\n\t\t\t\t/>\n\t\t\t\t{children != null ? children : (label ?? value)}\n\t\t\t</label>\n\t\t);\n\t}\n);\n\nRadioGroupItem.displayName = \"RadioGroupItem\";\n","type":"registry:ui","target":"@ui/fancy/components/radio-group/RadioGroupItem.tsx"},{"path":"react/src/components/radio-group/index.ts","content":"\"use client\";\n\nexport { RadioGroup } from \"./RadioGroup\";\nexport type { RadioGroupProps, RadioGroupOrientation } from \"./RadioGroup\";\nexport { RadioGroupItem } from \"./RadioGroupItem\";\nexport type { RadioGroupItemProps } from \"./RadioGroupItem\";\nexport { RADIO_GROUP_KEY } from \"./types\";\nexport type { RadioGroupContext } from \"./types\";\n","type":"registry:ui","target":"@ui/fancy/components/radio-group/index.ts"},{"path":"react/src/components/radio-group/radio-group-item.css","content":"/*\n * Ported from the `<style>` block of `RadioGroupItem.svelte`. Every rule is\n * already anchored on `.ft-radio-item-control`, the class the component puts\n * on its native `<input>`, so no port-added anchor class is needed.\n */\n\n.ft-radio-item-control {\n\t--ft-radio-accent: var(\n\t\t--ft-accent,\n\t\tlight-dark(oklch(0.5432 0.2528 300.22), oklch(0.604 0.2606 301.75))\n\t);\n\tappearance: none;\n\tflex: none;\n\twidth: 18px;\n\theight: 18px;\n\tmargin: 0;\n\tborder-radius: 50%;\n\tborder-style: solid;\n\tborder-width: 1.5px;\n\tposition: relative;\n\tcursor: pointer;\n\t/* 150ms = tokens.DURATIONS.fast, cubic-bezier(0.4, 0, 0.2, 1) = tokens.EASINGS.inout.\n\t   Colour is a state change, not motion, so it stays outside the\n\t   reduced-motion query — only the dot below travels. */\n\ttransition: border-color var(--ft-duration-fast, 150ms)\n\t\tvar(--ft-ease-inout, cubic-bezier(0.4, 0, 0.2, 1));\n}\n\n.ft-radio-item-control:disabled {\n\tcursor: not-allowed;\n}\n\n.ft-radio-item-control:checked {\n\tborder-color: var(--ft-radio-accent);\n}\n\n/*\n * The filled center is a pseudo-element, not a second DOM node — the\n * native input stays the only focusable, checkable element, per the\n * \"restyle, don't replace\" rule. It is also a shape change, not only a\n * colour change, so the checked state still reads without colour.\n *\n * The pseudo exists in both states, scaled to nothing while unchecked,\n * rather than only while `:checked` — a pseudo-element that does not\n * exist yet has no previous value to travel from, so a dot created on\n * selection could only ever appear, never grow.\n */\n.ft-radio-item-control::after {\n\tcontent: \"\";\n\tposition: absolute;\n\tinset: 0;\n\tmargin: auto;\n\twidth: 9px;\n\theight: 9px;\n\tborder-radius: 50%;\n\tbackground: var(--ft-radio-accent);\n\ttransform: scale(0);\n}\n\n.ft-radio-item-control:checked::after {\n\ttransform: scale(1);\n}\n\n/*\n * `--ft-ease-out` and not `inout`: the dot arrives, it does not toggle\n * back and forth in place — what leaves is the previously-selected\n * item's own dot, one element over. Outside this query the two\n * `transform` rules above still apply, so reduced motion gets the dot\n * at full size the instant the item is selected.\n */\n@media (prefers-reduced-motion: no-preference) {\n\t.ft-radio-item-control::after {\n\t\t/* 150ms = tokens.DURATIONS.fast, cubic-bezier(0.16, 1, 0.3, 1) = tokens.EASINGS.out */\n\t\ttransition: transform var(--ft-radio-dot-duration, var(--ft-duration-fast, 150ms))\n\t\t\tvar(--ft-ease-out, cubic-bezier(0.16, 1, 0.3, 1));\n\t}\n}\n\n.ft-radio-item-control:focus-visible {\n\toutline: none;\n\tbox-shadow: 0 0 0 3px color-mix(in oklab, var(--ft-radio-accent) 35%, transparent);\n}\n","type":"registry:ui","target":"@ui/fancy/components/radio-group/radio-group-item.css"},{"path":"react/src/components/radio-group/types.ts","content":"\"use client\";\n\n/**\n * The contract between the radio group root and its items.\n *\n * Unlike ToggleGroup, this context does not reimplement roving focus,\n * arrow-key navigation or the tab stop: every item is a real\n * `<input type=\"radio\">` sharing one `name`, and the browser already gives\n * all three away for free, correctly, on every platform. This context only\n * carries what the browser cannot infer on its own — which value is\n * selected, the shared `name` those inputs must all carry, and the\n * group-level `disabled`/`required` an item's own attributes fold into.\n */\n\nimport { createContext } from \"react\";\n\n/** What the root publishes. Items read it; only the root writes it. */\nexport interface RadioGroupContext {\n\t/**\n\t * The `name` every item's native radio must share so the browser treats\n\t * them as one group. Always a real string, generated per instance with\n\t * `useFancyId()` when the caller omits `name` — see `RadioGroup` — so it\n\t * is correct from the very first server-rendered paint, not just once\n\t * hydrated.\n\t */\n\treadonly name: string;\n\t/** The selected value, or `\"\"` when nothing is selected. */\n\treadonly value: string;\n\t/** Disables every item, regardless of its own `disabled` prop. */\n\treadonly disabled: boolean;\n\t/** Marks every item's native radio `required`, so the group counts as one required control for native form validation. */\n\treadonly required: boolean;\n\t/** Whether the group (or its surrounding FormField) is in an error state. */\n\treadonly invalid: boolean;\n\t/** Whether `itemValue` is the current selection. */\n\tisSelected(itemValue: string): boolean;\n\t/** Makes `itemValue` the selection and fires the group's `onValueChange`. */\n\tselect(itemValue: string): void;\n}\n\n/**\n * The context a `RadioGroupItem` reads to learn the shared `name`, the\n * selection and the group-level flags. The Svelte source publishes it under a\n * `Symbol` context key; React's own context object plays that role here, so\n * the exported name is kept and the value is a `React.Context` rather than a\n * symbol:\n *\n * ```tsx\n * const group = useContext(RADIO_GROUP_KEY);\n * ```\n *\n * Read it as optional — an item rendered outside a `RadioGroup` gets\n * `undefined` rather than throwing, and renders as a plain, unchecked,\n * standalone radio.\n */\nexport const RADIO_GROUP_KEY = createContext<RadioGroupContext | undefined>(undefined);\nRADIO_GROUP_KEY.displayName = \"RadioGroupContext\";\n","type":"registry:ui","target":"@ui/fancy/components/radio-group/types.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/radio-group?framework=react"}}