{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "choice-cards",
  "title": "Choice Cards",
  "description": "One or several options drawn as cards on native radio and checkbox inputs, each with its title, a line of detail, an optional icon, a label and a value to compare, such as a price.",
  "registryDependencies": [
    "field",
    "https://www.dashboardblocks.com/r/radix/tag.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/choice-cards.tsx",
      "content": "'use client'\n\nimport { renderTag } from '@/registry/components/dashboardblocks/tag'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type ReactNode, useId } from 'react'\n\nimport { FieldLabel } from '@/components/ui/field'\n\nimport { cn } from '@/lib/utils'\n\ninterface ChoiceCardOption {\n  /** Right of the title, such as a price or a limit: a value people compare between cards. */\n  aside?: ReactNode\n  /** A short label beside the title, such as `Popular`; a string is drawn as a `Tag`. */\n  badge?: ReactNode\n  description?: ReactNode\n  disabled?: boolean\n  icon?: ReactNode\n  title: string\n  value: string\n}\n\ninterface ChoiceCardsBaseProps {\n  'aria-describedby'?: string\n  'aria-invalid'?: boolean\n  'aria-label'?: string\n  'aria-labelledby'?: string\n  /** Set the columns here, such as `@md:grid-cols-2`. */\n  className?: string\n  /** Given to the first option's input, so a label or validation can focus it. */\n  id?: string\n  name?: string\n  options: ChoiceCardOption[]\n}\n\ninterface SingleChoiceCardsProps extends ChoiceCardsBaseProps {\n  onValueChange: (value: string) => void\n  /** @default 'radio' */\n  type?: 'radio'\n  value: string\n}\n\ninterface MultipleChoiceCardsProps extends ChoiceCardsBaseProps {\n  onValueChange: (value: string[]) => void\n  type: 'checkbox'\n  value: readonly string[]\n}\n\ntype ChoiceCardsProps = SingleChoiceCardsProps | MultipleChoiceCardsProps\n\nfunction ChoiceCards(props: ChoiceCardsProps) {\n  const { className, id, name, options } = props\n  const generatedName = useId()\n  const multiple = props.type === 'checkbox'\n  const selected = props.type === 'checkbox' ? props.value : [props.value]\n\n  function change(value: string, checked: boolean) {\n    if (props.type === 'checkbox') {\n      const picked = props.value\n      props.onValueChange(\n        options\n          .map((option) => option.value)\n          .filter((item) => (item === value ? checked : picked.includes(item))),\n      )\n    } else if (checked) {\n      props.onValueChange(value)\n    }\n  }\n\n  return (\n    <div\n      data-slot='choice-cards'\n      role={multiple ? 'group' : 'radiogroup'}\n      aria-describedby={props['aria-describedby']}\n      aria-invalid={props['aria-invalid']}\n      aria-label={props['aria-label']}\n      aria-labelledby={props['aria-labelledby']}\n      className={cn('group/choice-cards grid gap-3', className)}\n    >\n      {options.map((option, index) => {\n        const checked = selected.includes(option.value)\n        const inputId = index === 0 && id ? id : `${generatedName}-${index}`\n        return (\n          <FieldLabel\n            key={option.value}\n            htmlFor={inputId}\n            className='group-aria-invalid/choice-cards:border-destructive/60 cursor-pointer has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50'\n          >\n            <span data-slot='field' className='flex w-full items-start gap-3'>\n              <input\n                id={inputId}\n                type={multiple ? 'checkbox' : 'radio'}\n                name={name ?? generatedName}\n                value={option.value}\n                checked={checked}\n                disabled={option.disabled}\n                data-checked={checked || undefined}\n                aria-labelledby={`${inputId}-title`}\n                aria-describedby={\n                  [\n                    option.aside ? `${inputId}-aside` : '',\n                    option.description ? `${inputId}-description` : '',\n                  ]\n                    .filter(Boolean)\n                    .join(' ') || undefined\n                }\n                onChange={(event) => change(option.value, event.target.checked)}\n                className='sr-only'\n              />\n              {option.icon && (\n                <span\n                  aria-hidden\n                  className='bg-muted text-foreground group-has-[:checked]/field-label:bg-primary group-has-[:checked]/field-label:text-primary-foreground flex size-9 shrink-0 items-center justify-center rounded-md transition-colors [&_svg]:size-4'\n                >\n                  {option.icon}\n                </span>\n              )}\n              <span className='flex min-w-0 flex-1 flex-col gap-1'>\n                <span className='flex flex-wrap items-center gap-x-2 gap-y-1'>\n                  <span id={`${inputId}-title`} className='text-sm font-medium'>\n                    {option.title}\n                  </span>\n                  {option.badge && renderTag(option.badge)}\n                  {option.aside && (\n                    <span\n                      id={`${inputId}-aside`}\n                      className='ms-auto text-end text-sm font-medium whitespace-nowrap tabular-nums'\n                    >\n                      {option.aside}\n                    </span>\n                  )}\n                </span>\n                {option.description && (\n                  <span\n                    id={`${inputId}-description`}\n                    className='text-muted-foreground group-has-[:checked]/field-label:text-foreground/70 text-sm leading-snug font-normal text-pretty'\n                  >\n                    {option.description}\n                  </span>\n                )}\n              </span>\n              <ChoiceIndicator multiple={multiple} />\n            </span>\n          </FieldLabel>\n        )\n      })}\n    </div>\n  )\n}\n\n/** The tick box or radio drawn for the input inside a `group/field-label`. */\nfunction ChoiceIndicator({\n  className,\n  multiple = false,\n}: {\n  className?: string\n  multiple?: boolean\n}) {\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        'border-input dark:bg-input/30 group-has-[:checked]/field-label:border-primary group-has-[:checked]/field-label:bg-primary dark:group-has-[:checked]/field-label:bg-primary text-primary-foreground mt-0.5 flex size-4 shrink-0 items-center justify-center border shadow-xs transition-colors',\n        multiple ? 'rounded-[4px]' : 'rounded-full',\n        className,\n      )}\n    >\n      {multiple ? (\n        <IconPlaceholder\n          lucide='CheckIcon'\n          tabler='IconCheck'\n          hugeicons='Tick02Icon'\n          phosphor='CheckIcon'\n          remixicon='RiCheckLine'\n          strokeWidth={3}\n          className='hidden size-3 group-has-[:checked]/field-label:block'\n        />\n      ) : (\n        <span className='bg-primary-foreground hidden size-1.5 rounded-full group-has-[:checked]/field-label:block' />\n      )}\n    </span>\n  )\n}\n\nexport { ChoiceCards, ChoiceIndicator }\n\nexport type { ChoiceCardOption, ChoiceCardsProps }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/choice-cards.tsx"
    }
  ],
  "type": "registry:component"
}
