{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-group",
  "title": "RadioGroup",
  "description": "Accessible fieldset/legend radio group built on native radio inputs with vertical/horizontal orientation and Field context support.",
  "registryDependencies": [
    "https://frame12.dev/r/frame12-styles.json",
    "https://frame12.dev/r/field.json"
  ],
  "files": [
    {
      "path": "ui/radio-group.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { useFieldContext } from './field';\n\nexport type RadioGroupDensity = 'comfortable' | 'compact';\nexport type RadioGroupOrientation = 'vertical' | 'horizontal';\n\nexport interface RadioOption {\n  value: string;\n  label: React.ReactNode;\n  hint?: React.ReactNode;\n  disabled?: boolean;\n}\n\ninterface RadioGroupContextValue {\n  name?: string;\n  fallbackName: string;\n  value?: string;\n  isControlled: boolean;\n  defaultValue?: string;\n  disabled?: boolean;\n  required?: boolean;\n  form?: string;\n  density: RadioGroupDensity;\n  invalid?: boolean;\n  onSelect: (nextValue: string) => void;\n}\n\nconst RadioGroupContext = React.createContext<RadioGroupContextValue | null>(null);\n\nconst useIsomorphicLayoutEffect =\n  typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;\n\nfunction encodeRadioValueForId(value: string): string {\n  if (value.length === 0) return '_empty_';\n  let out = '';\n  for (let i = 0; i < value.length; i++) {\n    const ch = value[i];\n    if (/[a-zA-Z0-9-]/.test(ch)) {\n      out += ch;\n    } else if (ch === '_') {\n      out += '__';\n    } else {\n      const cp = value.codePointAt(i)!;\n      out += `_${cp.toString(16)}_`;\n      if (cp > 0xffff) i++;\n    }\n  }\n  return out;\n}\n\nexport interface RadioGroupProps extends Omit<React.FieldsetHTMLAttributes<HTMLFieldSetElement>, 'onChange'> {\n  name?: string;\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  options?: RadioOption[];\n  label?: React.ReactNode;\n  hint?: React.ReactNode;\n  error?: React.ReactNode;\n  density?: RadioGroupDensity;\n  orientation?: RadioGroupOrientation;\n  disabled?: boolean;\n  required?: boolean;\n}\n\nexport const RadioGroup = React.forwardRef<HTMLFieldSetElement, RadioGroupProps>(\n  function RadioGroup(\n    {\n      id,\n      name,\n      value: controlledValue,\n      defaultValue,\n      onValueChange,\n      options,\n      label,\n      hint,\n      error,\n      density,\n      orientation = 'vertical',\n      disabled,\n      required,\n      form,\n      className = '',\n      children,\n      'aria-describedby': userDescribedBy,\n      ...rest\n    },\n    ref,\n  ) {\n    const fieldCtx = useFieldContext();\n    const autoId = React.useId().replace(/:/g, '');\n    const groupId = id || fieldCtx?.id || `f12-radiogroup-${autoId}`;\n    const fallbackName = `${groupId}-name`;\n    const isControlled = controlledValue !== undefined;\n\n    const registerRadioGroup = fieldCtx?.registerRadioGroup;\n    const registerControlId = fieldCtx?.registerControlId;\n    useIsomorphicLayoutEffect(() => {\n      registerRadioGroup?.();\n      return registerControlId?.(autoId, id);\n    }, [registerRadioGroup, registerControlId, autoId, id]);\n\n    const effectiveDensity: RadioGroupDensity = density ?? fieldCtx?.density ?? 'comfortable';\n    const isCompact = effectiveDensity === 'compact';\n    const effectiveDisabled = disabled ?? fieldCtx?.disabled;\n    const effectiveRequired = required ?? fieldCtx?.required;\n    const effectiveLabel = label ?? (fieldCtx?.isRadioGroup ? fieldCtx.label : undefined);\n    const legendId = label && !fieldCtx?.isRadioGroup ? undefined : fieldCtx?.labelId;\n    const showOwnHint = Boolean(hint && !fieldCtx?.hintId);\n    const showOwnError = Boolean(error && !fieldCtx?.errorId);\n    const hintId = showOwnHint ? `${groupId}-hint` : undefined;\n    const errorId = showOwnError ? `${groupId}-error` : undefined;\n    const describedBy =\n      [userDescribedBy, fieldCtx?.describedBy, hintId, errorId].filter(Boolean).join(' ') ||\n      undefined;\n    const effectiveInvalid = Boolean(error || fieldCtx?.invalid);\n\n    const handleSelect = React.useCallback(\n      (nextValue: string) => {\n        onValueChange?.(nextValue);\n      },\n      [onValueChange],\n    );\n\n    const ctxValue = React.useMemo<RadioGroupContextValue>(\n      () => ({\n        name,\n        fallbackName,\n        value: controlledValue,\n        isControlled,\n        defaultValue,\n        disabled: effectiveDisabled,\n        required: effectiveRequired,\n        form,\n        density: effectiveDensity,\n        invalid: effectiveInvalid,\n        onSelect: handleSelect,\n      }),\n      [\n        name,\n        fallbackName,\n        controlledValue,\n        isControlled,\n        defaultValue,\n        effectiveDisabled,\n        effectiveRequired,\n        form,\n        effectiveDensity,\n        effectiveInvalid,\n        handleSelect,\n      ],\n    );\n\n    return (\n      <RadioGroupContext.Provider value={ctxValue}>\n        <fieldset\n          ref={ref}\n          id={groupId}\n          role=\"radiogroup\"\n          disabled={effectiveDisabled}\n          form={form}\n          aria-required={effectiveRequired || undefined}\n          aria-invalid={effectiveInvalid || undefined}\n          aria-describedby={describedBy}\n          className={`f12-radio-group${isCompact ? ' f12-radio-group-compact' : ''}${orientation === 'horizontal' ? ' f12-radio-group-horizontal' : ''}${className ? ` ${className}` : ''}`}\n          data-density={isCompact ? 'compact' : undefined}\n          data-orientation={orientation}\n          {...rest}\n        >\n          {effectiveLabel && (\n            <legend id={legendId} className=\"f12-label f12-radio-legend\">\n              {effectiveLabel}\n              {effectiveRequired && (\n                <span className=\"f12-field-req\" aria-hidden=\"true\">\n                  {' '}\n                  *\n                </span>\n              )}\n            </legend>\n          )}\n          <div className=\"f12-radio-items\">\n            {options\n              ? options.map((opt) => (\n                  <RadioGroupItem\n                    key={opt.value}\n                    id={`${groupId}-${encodeRadioValueForId(opt.value)}`}\n                    value={opt.value}\n                    label={opt.label}\n                    hint={opt.hint}\n                    disabled={opt.disabled}\n                  />\n                ))\n              : children}\n          </div>\n          {showOwnHint && (\n            <p id={hintId} className=\"f12-hint\">\n              {hint}\n            </p>\n          )}\n          {showOwnError && (\n            <p id={errorId} className=\"f12-error\" role=\"alert\">\n              <span className=\"f12-error-flag\" aria-hidden=\"true\">\n                !\n              </span>\n              <span>{error}</span>\n            </p>\n          )}\n        </fieldset>\n      </RadioGroupContext.Provider>\n    );\n  },\n);\n\n(RadioGroup as unknown as { f12IsGroup?: boolean }).f12IsGroup = true;\n\nexport interface RadioGroupItemProps\n  extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'value'> {\n  value: string;\n  label?: React.ReactNode;\n  hint?: React.ReactNode;\n  density?: RadioGroupDensity;\n}\n\nexport const RadioGroupItem = React.forwardRef<HTMLInputElement, RadioGroupItemProps>(\n  function RadioGroupItem(\n    {\n      id,\n      value,\n      label,\n      hint,\n      density,\n      disabled,\n      checked: itemChecked,\n      defaultChecked: itemDefaultChecked,\n      name: itemName,\n      required: itemRequired,\n      form: itemForm,\n      className = '',\n      onChange,\n      children,\n      'aria-describedby': userDescribedBy,\n      'aria-invalid': userAriaInvalid,\n      ...rest\n    },\n    ref,\n  ) {\n    const groupCtx = React.useContext(RadioGroupContext);\n    const autoId = React.useId().replace(/:/g, '');\n    const itemId = id || `f12-radio-${autoId}`;\n    const hintId = hint ? `${itemId}-hint` : undefined;\n    const effectiveDensity: RadioGroupDensity =\n      density ?? groupCtx?.density ?? 'comfortable';\n    const isCompact = effectiveDensity === 'compact';\n    const isDisabled = Boolean(disabled ?? groupCtx?.disabled);\n    const resolvedChecked = groupCtx\n      ? groupCtx.isControlled\n        ? groupCtx.value === value\n        : undefined\n      : itemChecked;\n    const resolvedDefaultChecked = groupCtx\n      ? !groupCtx.isControlled\n        ? groupCtx.defaultValue !== undefined\n          ? groupCtx.defaultValue === value\n          : itemDefaultChecked\n        : undefined\n      : itemDefaultChecked;\n    const describedBy =\n      [userDescribedBy, hintId].filter(Boolean).join(' ') || undefined;\n    const displayLabel = label ?? children;\n\n    return (\n      <div\n        className={`f12-radio-item${isCompact ? ' f12-radio-item-compact' : ''}`}\n        data-disabled={isDisabled ? '' : undefined}\n      >\n        <div className=\"f12-check-row\">\n          <span className=\"f12-radio-control\">\n            <input\n              ref={ref}\n              id={itemId}\n              type=\"radio\"\n              name={groupCtx?.name ?? itemName ?? groupCtx?.fallbackName}\n              value={value}\n              checked={resolvedChecked}\n              defaultChecked={resolvedDefaultChecked}\n              disabled={isDisabled}\n              required={groupCtx?.required ?? itemRequired}\n              form={groupCtx?.form ?? itemForm}\n              aria-describedby={describedBy}\n              aria-invalid={groupCtx?.invalid ? true : userAriaInvalid}\n              className={`f12-radio-input${isCompact ? ' f12-radio-compact' : ''}${className ? ` ${className}` : ''}`}\n              onChange={(e) => {\n                onChange?.(e);\n                if (e.target.checked) {\n                  groupCtx?.onSelect(value);\n                }\n              }}\n              {...rest}\n            />\n            <svg\n              className=\"f12-radio-mark\"\n              viewBox=\"0 0 16 16\"\n              fill=\"none\"\n              aria-hidden=\"true\"\n            >\n              <circle cx=\"8\" cy=\"8\" r=\"4\" fill=\"currentColor\" />\n            </svg>\n          </span>\n          {displayLabel && (\n            <label htmlFor={itemId} className=\"f12-check-label\">\n              {displayLabel}\n            </label>\n          )}\n        </div>\n        {hint && (\n          <p id={hintId} className=\"f12-hint f12-check-meta\">\n            {hint}\n          </p>\n        )}\n      </div>\n    );\n  },\n);\n",
      "type": "registry:ui",
      "target": "components/frame12/radio-group.tsx"
    }
  ],
  "type": "registry:ui"
}