{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "jsonforms-boolean-toggle-control",
  "description": "JSONForms switch/toggle renderer for boolean fields. Activated by setting options.toggle to true in the UISchema.",
  "dependencies": [
    "@jsonforms/core",
    "@jsonforms/react"
  ],
  "registryDependencies": [
    "https://mksingh.dev/r/typography.json",
    "switch",
    "label"
  ],
  "files": [
    {
      "path": "registry/forms/renderers/boolean-toggle-control.tsx",
      "content": "import { useState } from 'react';\n\nimport { and, ControlProps, isBooleanControl, optionIs, rankWith } from '@jsonforms/core';\nimport { withJsonFormsControlProps } from '@jsonforms/react';\n\nimport Typography from '~/components/ui/typography';\nimport { Label } from '~/components/ui/label';\nimport { Switch } from '~/components/ui/switch';\nimport { shouldShowError } from '~/components/forms/utils';\n\nconst BooleanToggleControlRenderer = (props: ControlProps) => {\n    const { label, data, handleChange, path, visible, enabled, id, errors, config } = props;\n    const [touched, setTouched] = useState(false);\n\n    if (!visible) return null;\n\n    return (\n        <div className=\"flex flex-col gap-1 py-2\">\n            <div className=\"flex items-center gap-2\">\n                <Switch\n                    id={id}\n                    checked={data ?? false}\n                    onCheckedChange={checked => handleChange(path, checked)}\n                    onBlur={() => setTouched(true)}\n                    disabled={!enabled}\n                />\n                {label && (\n                    <Label htmlFor={id} className=\"text-xs font-medium text-foreground cursor-pointer\">\n                        {label}\n                    </Label>\n                )}\n            </div>\n            {shouldShowError(config, touched) && errors && <Typography variant=\"error\">{errors.split(\"\\n\")[0]}</Typography>}\n        </div>\n    );\n};\n\nexport const booleanToggleControlTester = rankWith(3, and(isBooleanControl, optionIs('toggle', true)));\nexport default withJsonFormsControlProps(BooleanToggleControlRenderer);\n",
      "type": "registry:component",
      "target": "components/forms/renderers/boolean-toggle-control.tsx"
    }
  ],
  "type": "registry:component"
}