{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-group",
  "type": "registry:ui",
  "title": "Radio Group",
  "description": "Radio Group is an accessible grouping layer for mutually exclusive radio options with legend, helper text, and errors.",
  "author": "Skrewww",
  "dependencies": [],
  "registryDependencies": [
    "@skrewww/radio",
    "@skrewww/validation-message",
    "@skrewww/foundation"
  ],
  "docs": "Host requirements (assumed already present, not installed by this command): react, react-dom.",
  "files": [
    {
      "path": "components/ui/RadioGroup.tsx",
      "content": "/** @skrewww-component radio-group */\n\"use client\";\n\nimport { useId } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useControllableState } from \"@/lib/use-controllable\";\nimport { Radio } from \"@/components/ui/Radio\";\nimport { ValidationMessage } from \"@/components/ui/ValidationMessage\";\nimport styles from \"@/components/ui/radio.module.css\";\n\nexport type RadioGroupOption = {\n  value: string;\n  label: string;\n  disabled?: boolean;\n};\n\nexport type RadioGroupProps = {\n  name?: string;\n  label: string;\n  options: RadioGroupOption[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  required?: boolean;\n  disabled?: boolean;\n  supportingText?: string;\n  error?: string;\n  className?: string;\n};\n\nexport function RadioGroup({\n  name: nameProp,\n  label,\n  options,\n  value,\n  defaultValue,\n  onValueChange,\n  required = false,\n  disabled = false,\n  supportingText,\n  error,\n  className,\n}: RadioGroupProps) {\n  const generatedName = useId();\n  const name = nameProp ?? generatedName.replace(/:/g, \"\");\n  const groupId = `${name}-group`;\n  const supportingId = supportingText ? `${groupId}-supporting` : undefined;\n  const errorId = error ? `${groupId}-error` : undefined;\n  const describedBy = [errorId, !error ? supportingId : undefined].filter(Boolean).join(\" \");\n\n  const [selected, setSelected] = useControllableState({\n    value,\n    defaultValue,\n    onChange: onValueChange,\n  });\n\n  return (\n    <fieldset\n      className={cn(styles.group, className)}\n      aria-describedby={describedBy || undefined}\n      aria-invalid={error ? true : undefined}\n      aria-required={required || undefined}\n      disabled={disabled || undefined}\n    >\n      <legend className={styles.legend}>\n        {label}\n        {required ? (\n          <>\n            <span className={styles.required} aria-hidden=\"true\">\n              *\n            </span>\n            <span className=\"sr-only\"> (required)</span>\n          </>\n        ) : null}\n      </legend>\n\n      <div className={styles.options} role=\"presentation\">\n        {options.map((option) => (\n          <Radio\n            key={option.value}\n            name={name}\n            value={option.value}\n            label={option.label}\n            checked={selected === option.value}\n            disabled={disabled || option.disabled}\n            aria-invalid={error ? true : undefined}\n            onChange={() => setSelected(option.value)}\n          />\n        ))}\n      </div>\n\n      {error ? (\n        <ValidationMessage id={errorId} type=\"error\" announce=\"off\">\n          {error}\n        </ValidationMessage>\n      ) : supportingText ? (\n        <p id={supportingId} className={styles.supporting}>\n          {supportingText}\n        </p>\n      ) : null}\n    </fieldset>\n  );\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/RadioGroup.tsx"
    },
    {
      "path": "lib/cn.ts",
      "content": "export function cn(...classes: Array<string | false | null | undefined>): string {\n  return classes.filter(Boolean).join(\" \");\n}\n",
      "type": "registry:lib",
      "target": "~/lib/cn.ts"
    },
    {
      "path": "lib/use-controllable.ts",
      "content": "import { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport function useControllableState<T>({\n  value,\n  defaultValue,\n  onChange,\n  controlled: controlledProp,\n  valueProvided,\n}: {\n  value?: T;\n  defaultValue?: T;\n  onChange?: (next: T) => void;\n  /** Explicit controlled override — prefer `valueProvided` from the component root. */\n  controlled?: boolean;\n  /** True when the parent passed a `value` prop, including `undefined`. */\n  valueProvided?: boolean;\n}) {\n  const [uncontrolled, setUncontrolled] = useState(defaultValue as T);\n  const isControlled = controlledProp ?? valueProvided ?? value !== undefined;\n  const current = isControlled ? (value as T) : uncontrolled;\n  const wasControlledRef = useRef(isControlled);\n\n  useEffect(() => {\n    if (process.env.NODE_ENV !== \"development\") return;\n    if (wasControlledRef.current !== isControlled) {\n      console.warn(\n        \"[Skrewww] A component changed between controlled and uncontrolled modes. Keep `value` or `defaultValue` usage consistent across renders.\",\n      );\n    }\n    wasControlledRef.current = isControlled;\n  }, [isControlled]);\n\n  const setValue = useCallback(\n    (next: T) => {\n      if (!isControlled) setUncontrolled(next);\n      onChange?.(next);\n    },\n    [isControlled, onChange],\n  );\n\n  return [current, setValue] as const;\n}\n",
      "type": "registry:lib",
      "target": "~/lib/use-controllable.ts"
    }
  ]
}
