{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "choice-list",
  "type": "registry:ui",
  "title": "Choice List",
  "description": "Radio or checkbox rows for answering a question.",
  "categories": [
    "forms"
  ],
  "dependencies": [
    "@hugeicons/core-free-icons@4.4.0",
    "@hugeicons/react@1.1.10"
  ],
  "registryDependencies": [
    "https://sprout.tulipfarm.ai/r/sprout-base.json",
    "https://sprout.tulipfarm.ai/r/badge.json"
  ],
  "files": [
    {
      "path": "registry/sprout/components/ui/choice-list.tsx",
      "type": "registry:ui",
      "target": "components/ui/choice-list.tsx",
      "content": "'use client';\n\nimport { useId, type ReactNode } from 'react';\nimport { CheckIcon } from '@/lib/sprout/icons/check-icon';\nimport { HelpCircleIcon } from '@/lib/sprout/icons/help-circle-icon';\nimport { cn } from '@/lib/sprout/classes';\nimport { Badge } from '@/components/ui/badge';\n\nexport const choiceListLayoutNames = ['stacked', 'compact'] as const;\n\nexport type ChoiceListLayout = (typeof choiceListLayoutNames)[number];\n\nexport interface ChoiceListOption {\n  id: string;\n  label: string;\n  recommended?: boolean | undefined;\n}\n\nexport interface ChoiceListTextOption {\n  value: string;\n  active: boolean;\n  onChange: (value: string) => void;\n  onFocus: () => void;\n  id?: string | undefined;\n  error: string | null;\n  label?: string | undefined;\n  placeholder?: string | undefined;\n}\n\nexport interface ChoiceListProps {\n  legend: string;\n  options: readonly ChoiceListOption[];\n  value: readonly string[];\n  onChange: (value: string[]) => void;\n  multiple?: boolean | undefined;\n  disabled?: boolean | undefined;\n  error?: string | undefined;\n  layout?: ChoiceListLayout | undefined;\n  textOption?: ChoiceListTextOption | undefined;\n  className?: string | undefined;\n}\n\nconst recommendedSuffix = /\\s*\\(recommended\\)\\s*$/i;\n\nexport function ChoiceList({\n  legend,\n  options,\n  value,\n  onChange,\n  multiple = false,\n  disabled = false,\n  error,\n  layout = 'stacked',\n  textOption,\n  className,\n}: ChoiceListProps) {\n  const name = useId();\n  const compact = layout === 'compact';\n  const errorId = `${name}-choices-error`;\n  const textId = `${name}-text`;\n  const textErrorId = `${name}-text-error`;\n  return (\n    <fieldset\n      data-slot=\"choice-list\"\n      data-layout={layout}\n      data-multiple={multiple || undefined}\n      disabled={disabled}\n      className={cn('sprout-choice-list', className)}\n    >\n      <legend className={compact && !multiple ? 'sprout-choice-list-sr-only' : 'sprout-choice-list-legend'}>\n        {legend}\n      </legend>\n      <div data-slot=\"choice-list-options\" className=\"sprout-choice-list-options\">\n        {options.map((option, index) => {\n          const checked = value.includes(option.id);\n          const recommended = option.recommended === true || recommendedSuffix.test(option.label);\n          const label = option.label.replace(recommendedSuffix, '');\n          return (\n            <label\n              key={option.id}\n              data-slot=\"choice-list-option\"\n              data-checked={checked || undefined}\n              data-disabled={disabled || undefined}\n              data-recommended={recommended || undefined}\n              className=\"sprout-choice-list-option\"\n            >\n              <input\n                type={multiple ? 'checkbox' : 'radio'}\n                name={name}\n                value={option.id}\n                checked={checked}\n                aria-invalid={error ? true : undefined}\n                aria-describedby={error ? errorId : undefined}\n                onChange={event =>\n                  onChange(\n                    multiple\n                      ? event.target.checked\n                        ? [...value, option.id]\n                        : value.filter(id => id !== option.id)\n                      : [option.id],\n                  )\n                }\n                className=\"sprout-choice-list-input\"\n              />\n              <span aria-hidden=\"true\" className=\"sprout-choice-list-mark\">\n                {checked ? <CheckIcon /> : compact ? index + 1 : null}\n              </span>\n              <span className=\"sprout-choice-list-label\">\n                {label}\n                {recommended && (\n                  <Badge variant=\"success\" className=\"sprout-choice-list-badge\">\n                    Recommended\n                  </Badge>\n                )}\n              </span>\n            </label>\n          );\n        })}\n      </div>\n      {error && (\n        <p id={errorId} className=\"sprout-choice-list-error\">\n          {error}\n        </p>\n      )}\n      {textOption && (!compact || textOption.active) && (\n        <div\n          id={textOption.id ?? `${name}-custom`}\n          data-slot=\"choice-list-text\"\n          data-checked={textOption.active || undefined}\n          data-invalid={textOption.error ? true : undefined}\n          className=\"sprout-choice-list-text\"\n        >\n          <span aria-hidden=\"true\" className=\"sprout-choice-list-mark\">\n            {textOption.active && <CheckIcon />}\n          </span>\n          <div className=\"sprout-choice-list-text-body\">\n            <label htmlFor={textId} className=\"sprout-choice-list-text-label\">\n              {textOption.label ?? 'Your answer'}\n            </label>\n            <textarea\n              id={textId}\n              autoFocus={compact}\n              rows={1}\n              value={textOption.value}\n              disabled={disabled}\n              placeholder={textOption.placeholder ?? 'Type a different answer…'}\n              aria-describedby={textOption.error ? textErrorId : undefined}\n              aria-invalid={textOption.error ? true : undefined}\n              onFocus={textOption.onFocus}\n              onChange={event => textOption.onChange(event.target.value)}\n              className=\"sprout-choice-list-textarea\"\n            />\n            {textOption.error && (\n              <p id={textErrorId} role=\"alert\" className=\"sprout-choice-list-error\">\n                {textOption.error}\n              </p>\n            )}\n          </div>\n        </div>\n      )}\n    </fieldset>\n  );\n}\n\nexport interface ChoiceSummaryProps {\n  prompt: string;\n  answer?: string | undefined;\n  className?: string | undefined;\n  children?: ReactNode;\n}\n\nexport function ChoiceSummary({ prompt, answer, className, children }: ChoiceSummaryProps) {\n  return (\n    <div data-slot=\"choice-summary\" className={cn('sprout-choice-summary', className)}>\n      <HelpCircleIcon aria-hidden=\"true\" className=\"sprout-choice-summary-icon\" />\n      <span className=\"sprout-choice-summary-prompt\">{prompt}</span>\n      {answer && (\n        <span className=\"sprout-choice-summary-answer\">\n          <CheckIcon aria-hidden=\"true\" className=\"sprout-choice-summary-check\" />\n          <span className=\"sprout-choice-summary-answer-text\">{answer}</span>\n        </span>\n      )}\n      {children}\n    </div>\n  );\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/check-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/check-icon.tsx",
      "content": "import { Tick02Icon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const CheckIcon = /* @__PURE__ */ createIcon(glyph, 'CheckIcon');\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/create-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/create-icon.tsx",
      "content": "import { HugeiconsIcon, type IconSvgElement } from '@hugeicons/react';\nimport type { ReactElement, Ref, SVGProps } from 'react';\n\nexport const iconSizes = {\n  xs: 12,\n  sm: 14,\n  md: 16,\n  lg: 18,\n  xl: 20,\n  '2xl': 24,\n} as const;\n\nexport type IconSize = keyof typeof iconSizes;\n\nexport const iconStrokeWidth = 1.5;\n\nexport type IconProps = Omit<SVGProps<SVGSVGElement>, 'ref'> & {\n  size?: IconSize | number;\n  ref?: Ref<SVGSVGElement>;\n};\n\nexport type IconComponent = (props: IconProps) => ReactElement;\n\nexport function createIcon(glyph: IconSvgElement, name: string): IconComponent {\n  const Icon = ({ size = '2xl', strokeWidth = iconStrokeWidth, ...props }: IconProps) => (\n    <HugeiconsIcon\n      icon={glyph}\n      size={typeof size === 'number' ? size : iconSizes[size]}\n      strokeWidth={Number(strokeWidth)}\n      {...props}\n    />\n  );\n  Icon.displayName = name;\n  return Icon;\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/help-circle-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/help-circle-icon.tsx",
      "content": "import { HelpCircleIcon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const HelpCircleIcon = /* @__PURE__ */ createIcon(glyph, 'HelpCircleIcon');\n"
    }
  ],
  "css": {
    "@layer components": {
      ".sprout-choice-list": {
        "min-width": "0",
        "color": "var(--sprout-text)",
        "border": "0",
        "gap": "6px",
        "margin": "0",
        "padding": "0",
        "font-family": "inherit",
        "display": "grid"
      },
      ".sprout-choice-list-legend": {
        "font-size": "var(--sprout-text-xs)",
        "color": "var(--sprout-muted)",
        "margin-bottom": "2px",
        "padding": "0",
        "line-height": "1rem"
      },
      ".sprout-choice-list-sr-only": {
        "clip-path": "inset(50%)",
        "white-space": "nowrap",
        "border": "0",
        "width": "1px",
        "height": "1px",
        "margin": "-1px",
        "padding": "0",
        "position": "absolute",
        "overflow": "hidden"
      },
      ".sprout-choice-list-options": {
        "gap": "6px",
        "min-width": "0",
        "display": "grid"
      },
      ".sprout-choice-list-option, .sprout-choice-list-text": {
        "box-sizing": "border-box",
        "border": "1px solid var(--sprout-input)",
        "border-radius": "var(--sprout-radius-panel)",
        "min-width": "0",
        "min-height": "44px",
        "font-size": "var(--sprout-text-sm)",
        "outline-offset": "0",
        "outline": "0 solid #0000",
        "gap": "12px",
        "padding": "8px 12px",
        "line-height": "1.25rem",
        "display": "flex",
        "position": "relative"
      },
      ".sprout-choice-list-option": {
        "cursor": "pointer",
        "user-select": "none",
        "-webkit-tap-highlight-color": "transparent",
        "align-items": "center"
      },
      ".sprout-choice-list-text": {
        "align-items": "flex-start"
      },
      "@media (hover: hover)": {
        ".sprout-choice-list-option:not([data-disabled]):hover, .sprout-choice-list-text:hover": {
          "background": "color-mix(in oklab, var(--sprout-hover) 60%, transparent)"
        }
      },
      ".sprout-choice-list-option:has(.sprout-choice-list-input:focus-visible), .sprout-choice-list-text:focus-within": {
        "outline": "var(--sprout-focus-width) solid var(--sprout-focus-ring)"
      },
      ".sprout-choice-list-option[data-checked], .sprout-choice-list-text[data-checked]": {
        "border-color": "color-mix(in oklab, var(--sprout-text) 35%, transparent)",
        "background": "var(--sprout-hover)"
      },
      ".sprout-choice-list-option[data-disabled]": {
        "cursor": "not-allowed",
        "opacity": ".5"
      },
      ".sprout-choice-list-option[data-disabled][data-checked]": {
        "border-color": "var(--sprout-input)",
        "background": "var(--sprout-secondary)"
      },
      ".sprout-choice-list-text:has(.sprout-choice-list-textarea:disabled)": {
        "opacity": ".5"
      },
      ".sprout-choice-list-text[data-invalid]": {
        "border-color": "var(--sprout-danger)"
      },
      ".sprout-choice-list-text[data-invalid]:focus-within": {
        "outline-color": "var(--sprout-danger)"
      },
      ".sprout-choice-list-input": {
        "z-index": "1",
        "opacity": "0",
        "width": "calc(100% + 2px)",
        "height": "calc(100% + 2px)",
        "cursor": "inherit",
        "margin": "0",
        "position": "absolute",
        "inset": "-1px"
      },
      ".sprout-choice-list-mark": {
        "box-sizing": "border-box",
        "border": "1px solid var(--sprout-border)",
        "background": "var(--sprout-surface)",
        "width": "20px",
        "height": "20px",
        "color": "var(--sprout-primary)",
        "border-radius": "999px",
        "flex-shrink": "0",
        "place-items": "center",
        "display": "grid"
      },
      ".sprout-choice-list[data-multiple] .sprout-choice-list-mark": {
        "border-radius": "4px"
      },
      ".sprout-choice-list-text .sprout-choice-list-mark": {
        "border-radius": "999px"
      },
      ".sprout-choice-list-mark svg": {
        "width": "13px",
        "height": "13px"
      },
      ":is(.sprout-choice-list-option, .sprout-choice-list-text)[data-checked] .sprout-choice-list-mark": {
        "border-color": "var(--sprout-primary)",
        "background": "var(--sprout-primary)",
        "color": "var(--sprout-primary-foreground, #fff)"
      },
      ".sprout-choice-list:not([data-multiple]) .sprout-choice-list-option[data-checked] .sprout-choice-list-mark svg": {
        "display": "none"
      },
      ".sprout-choice-list:not([data-multiple]) .sprout-choice-list-option[data-checked] .sprout-choice-list-mark:after": {
        "content": "\"\"",
        "background": "var(--sprout-primary-foreground, #fff)",
        "border-radius": "999px",
        "width": "8px",
        "height": "8px"
      },
      ".sprout-choice-list-option[data-disabled] .sprout-choice-list-mark": {
        "border-color": "var(--sprout-border)",
        "background": "var(--sprout-secondary)"
      },
      ".sprout-choice-list-label": {
        "overflow-wrap": "anywhere",
        "flex": "1",
        "min-width": "0"
      },
      ".sprout-choice-list-badge": {
        "margin-inline-start": "8px"
      },
      ".sprout-choice-list-error": {
        "font-size": "var(--sprout-text-xs)",
        "color": "var(--sprout-danger)",
        "margin": "0",
        "line-height": "1rem"
      },
      ".sprout-choice-list-text-body": {
        "flex": "1",
        "min-width": "0"
      },
      ".sprout-choice-list-text-label": {
        "font-size": "var(--sprout-text-xs)",
        "color": "var(--sprout-muted)",
        "font-weight": "500",
        "line-height": "1rem",
        "display": "block"
      },
      ".sprout-choice-list-textarea": {
        "box-sizing": "border-box",
        "width": "100%",
        "min-height": "24px",
        "max-height": "160px",
        "font": "inherit",
        "color": "inherit",
        "resize": "vertical",
        "field-sizing": "content",
        "background": "none",
        "border": "0",
        "outline": "none",
        "margin": "0",
        "padding": "2px 0",
        "display": "block"
      },
      ".sprout-choice-list-textarea::placeholder": {
        "color": "var(--sprout-muted)"
      },
      ".sprout-choice-list-textarea:disabled": {
        "cursor": "not-allowed"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-options": {
        "overscroll-behavior": "contain",
        "grid-auto-rows": "max-content",
        "gap": "0",
        "max-height": "max(76px, min(224px, 34dvh - 96px))",
        "padding": "2px",
        "overflow-y": "auto"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option": {
        "border-radius": "var(--sprout-radius-control)",
        "border-color": "#0000",
        "width": "100%",
        "min-height": "36px",
        "padding": "4px 8px"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option[data-checked]": {
        "border-color": "#0000"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option[data-disabled][data-checked]": {
        "border-color": "var(--sprout-input)"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option + .sprout-choice-list-option:before": {
        "content": "\"\"",
        "background": "color-mix(in oklab, var(--sprout-text) 8%, transparent)",
        "height": "1px",
        "position": "absolute",
        "top": "-1px",
        "left": "8px",
        "right": "8px"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option[data-checked]:before, .sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option[data-checked] + .sprout-choice-list-option:before": {
        "visibility": "hidden"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option .sprout-choice-list-mark": {
        "border-radius": "var(--sprout-radius-control)",
        "background": "var(--sprout-secondary)",
        "width": "24px",
        "height": "24px",
        "font-size": "var(--sprout-text-xs)",
        "font-variant-numeric": "tabular-nums",
        "color": "var(--sprout-muted)",
        "border": "0",
        "line-height": "1rem"
      },
      ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option[data-checked] .sprout-choice-list-mark": {
        "background": "var(--sprout-primary)",
        "color": "var(--sprout-primary-foreground, #fff)"
      },
      ".sprout-choice-list[data-layout=\"compact\"]:not([data-multiple]) .sprout-choice-list-option[data-checked] .sprout-choice-list-mark svg": {
        "display": "block"
      },
      ".sprout-choice-list[data-layout=\"compact\"]:not([data-multiple]) .sprout-choice-list-option[data-checked] .sprout-choice-list-mark:after": {
        "content": "none"
      },
      "@media (any-pointer: coarse)": {
        ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-options": {
          "max-height": "max(94px, min(224px, 40dvh - 128px))"
        },
        ".sprout-choice-list[data-layout=\"compact\"] .sprout-choice-list-option": {
          "min-height": "44px"
        }
      },
      ".sprout-choice-summary": {
        "min-width": "0",
        "font-size": "var(--sprout-text-sm)",
        "color": "var(--sprout-text)",
        "flex-wrap": "wrap",
        "align-items": "center",
        "gap": "4px 8px",
        "padding-inline-start": "24px",
        "line-height": "1.25rem",
        "display": "flex",
        "position": "relative"
      },
      ".sprout-choice-summary-icon": {
        "top": "3px",
        "width": "16px",
        "height": "16px",
        "color": "var(--sprout-muted)",
        "position": "absolute",
        "inset-inline-start": "0"
      },
      ".sprout-choice-summary-prompt": {
        "overflow-wrap": "anywhere",
        "min-width": "0",
        "color": "var(--sprout-muted)"
      },
      ".sprout-choice-summary-answer": {
        "border": "1px solid var(--sprout-line)",
        "border-radius": "var(--sprout-radius-control)",
        "background": "var(--sprout-secondary)",
        "align-items": "center",
        "gap": "4px",
        "min-width": "0",
        "padding": "2px 8px",
        "font-weight": "500",
        "display": "inline-flex"
      },
      ".sprout-choice-summary-check": {
        "width": "14px",
        "height": "14px",
        "color": "var(--sprout-success)",
        "flex-shrink": "0"
      },
      ".sprout-choice-summary-answer-text": {
        "white-space": "pre-wrap",
        "overflow-wrap": "anywhere",
        "min-width": "0"
      },
      "@media (prefers-reduced-motion: no-preference)": {
        ".sprout-choice-list-option, .sprout-choice-list-text, .sprout-choice-list-mark": {
          "transition": "background-color var(--sprout-motion-normal, .18s) var(--sprout-motion-ease, ease-out),\n        border-color var(--sprout-motion-normal, .18s) var(--sprout-motion-ease, ease-out),\n        color var(--sprout-motion-fast, .12s) var(--sprout-motion-ease, ease-out)"
        },
        ".sprout-choice-list-mark svg, .sprout-choice-summary-check": {
          "animation": "sprout-choice-pop var(--sprout-motion-normal, .15s) ease-out both"
        }
      },
      "@keyframes sprout-choice-pop": {
        "from": {
          "opacity": "0",
          "transform": "scale(.6)"
        }
      },
      "@media (forced-colors: active)": {
        ".sprout-choice-list-option[data-checked], .sprout-choice-list-text[data-checked], .sprout-choice-list-option[data-checked] .sprout-choice-list-mark": {
          "border-color": "highlight"
        },
        ".sprout-choice-list-option:has(.sprout-choice-list-input:focus-visible), .sprout-choice-list-text:focus-within": {
          "outline-color": "highlight"
        }
      }
    }
  },
  "docs": "Docs and examples: https://sprout.tulipfarm.ai/components/choice-list/",
  "meta": {
    "source": "packages/sprout/src/components/choice-list.tsx"
  }
}
