@eifi1/ui-kit 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -33
- package/dist/chart.d.ts +1 -0
- package/dist/components/account-settings.js +3 -2
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +3 -0
- package/dist/components/amount-input.js +6 -4
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +33 -6
- package/dist/components/autocomplete.js +62 -16
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/calculator.d.ts +3 -0
- package/dist/components/calculator.js +2 -1
- package/dist/components/calculator.js.map +1 -1
- package/dist/components/chart-zoom.js +2 -1
- package/dist/components/chart-zoom.js.map +1 -1
- package/dist/components/chart.d.ts +33 -2
- package/dist/components/chart.js +20 -8
- package/dist/components/chart.js.map +1 -1
- package/dist/components/chip.d.ts +34 -14
- package/dist/components/chip.js +63 -28
- package/dist/components/chip.js.map +1 -1
- package/dist/components/choice-card.d.ts +18 -1
- package/dist/components/choice-card.js +21 -8
- package/dist/components/choice-card.js.map +1 -1
- package/dist/components/combobox-core.d.ts +61 -2
- package/dist/components/combobox-core.js +68 -17
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.d.ts +11 -7
- package/dist/components/combobox.js +51 -28
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/currency-select.js +3 -3
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/danger-confirm.d.ts +30 -6
- package/dist/components/danger-confirm.js +51 -32
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/data-table-filter-popover.d.ts +1 -1
- package/dist/components/data-table-filters.d.ts +1 -1
- package/dist/components/data-table-pagination.d.ts +6 -3
- package/dist/components/data-table-pagination.js +6 -5
- package/dist/components/data-table-pagination.js.map +1 -1
- package/dist/components/data-table.d.ts +1 -1
- package/dist/components/data-table.js +332 -248
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.js +17 -7
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/dialog-frame.d.ts +28 -3
- package/dist/components/dialog-frame.js +47 -11
- package/dist/components/dialog-frame.js.map +1 -1
- package/dist/components/disclosure.d.ts +22 -2
- package/dist/components/disclosure.js +41 -8
- package/dist/components/disclosure.js.map +1 -1
- package/dist/components/dropdown.d.ts +7 -3
- package/dist/components/dropdown.js +6 -2
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +17 -8
- package/dist/components/entity-combobox.js +7 -5
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/file-button.d.ts +36 -5
- package/dist/components/file-button.js +23 -2
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.d.ts +9 -5
- package/dist/components/file-dropzone.js +14 -19
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/grouped-picker.js +2 -2
- package/dist/components/grouped-picker.js.map +1 -1
- package/dist/components/hover-menu.d.ts +8 -3
- package/dist/components/hover-menu.js +88 -4
- package/dist/components/hover-menu.js.map +1 -1
- package/dist/components/icon-picker.d.ts +10 -1
- package/dist/components/icon-picker.js +5 -1
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/measured-grid.d.ts +165 -0
- package/dist/components/measured-grid.js +559 -0
- package/dist/components/measured-grid.js.map +1 -0
- package/dist/components/mini-calendar.js +7 -8
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/month-picker.js +13 -9
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.js +2 -2
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.d.ts +9 -1
- package/dist/components/multi-select.js +22 -8
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-field.d.ts +3 -0
- package/dist/components/number-input.d.ts +3 -0
- package/dist/components/number-input.js +3 -3
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +3 -0
- package/dist/components/numpad-sheet.js +3 -3
- package/dist/components/numpad-sheet.js.map +1 -1
- package/dist/components/picker-sheet.js +1 -1
- package/dist/components/picker-sheet.js.map +1 -1
- package/dist/components/popover.js +11 -2
- package/dist/components/popover.js.map +1 -1
- package/dist/components/series-chart-ticks.d.ts +13 -0
- package/dist/components/series-chart-ticks.js +29 -0
- package/dist/components/series-chart-ticks.js.map +1 -0
- package/dist/components/series-chart.js +33 -27
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/swatch-picker.d.ts +10 -1
- package/dist/components/swatch-picker.js +2 -0
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/swipeable-row.d.ts +11 -2
- package/dist/components/swipeable-row.js +5 -3
- package/dist/components/swipeable-row.js.map +1 -1
- package/dist/components/tile-radio.js +5 -7
- package/dist/components/tile-radio.js.map +1 -1
- package/dist/components/toggle-group.d.ts +13 -3
- package/dist/components/toggle-group.js +21 -1
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle-legend.js +1 -2
- package/dist/components/toggle-legend.js.map +1 -1
- package/dist/components/treemap.d.ts +6 -1
- package/dist/components/treemap.js +16 -6
- package/dist/components/treemap.js.map +1 -1
- package/dist/components/ui.d.ts +31 -7
- package/dist/components/ui.js +26 -18
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-anchor-dir.d.ts +15 -0
- package/dist/components/use-anchor-dir.js +14 -0
- package/dist/components/use-anchor-dir.js.map +1 -0
- package/dist/components/use-mobile-reveal.d.ts +8 -1
- package/dist/components/use-mobile-reveal.js +3 -2
- package/dist/components/use-mobile-reveal.js.map +1 -1
- package/dist/components/use-table-state.d.ts +4 -4
- package/dist/components/use-table-state.js +12 -5
- package/dist/components/use-table-state.js.map +1 -1
- package/dist/{data-table-filters-DM1auUfH.d.ts → data-table-filters-noy0Abvi.d.ts} +40 -7
- package/dist/data-table.d.ts +1 -1
- package/dist/data-table.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +22 -3
- package/dist/feedback/feedback-attachment.js +15 -7
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-dialog.d.ts +3 -2
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback.d.ts +1 -1
- package/dist/hooks/use-windowed-rows.d.ts +29 -0
- package/dist/hooks/use-windowed-rows.js +31 -0
- package/dist/hooks/use-windowed-rows.js.map +1 -0
- package/dist/i18n/defaults.d.ts +3 -0
- package/dist/i18n/defaults.js +5 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +5 -0
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH.d.ts +43 -0
- package/dist/i18n/locales/de-CH.js +21 -0
- package/dist/i18n/locales/de-CH.js.map +1 -0
- package/dist/i18n/locales/de.d.ts +43 -0
- package/dist/i18n/locales/de.js +344 -0
- package/dist/i18n/locales/de.js.map +1 -0
- package/dist/i18n/locales/es.d.ts +43 -0
- package/dist/i18n/locales/es.js +339 -0
- package/dist/i18n/locales/es.js.map +1 -0
- package/dist/i18n/locales/fr.d.ts +43 -0
- package/dist/i18n/locales/fr.js +344 -0
- package/dist/i18n/locales/fr.js.map +1 -0
- package/dist/i18n/locales/hu.d.ts +43 -0
- package/dist/i18n/locales/hu.js +343 -0
- package/dist/i18n/locales/hu.js.map +1 -0
- package/dist/i18n/locales/it.d.ts +43 -0
- package/dist/i18n/locales/it.js +342 -0
- package/dist/i18n/locales/it.js.map +1 -0
- package/dist/i18n/locales/zh.d.ts +43 -0
- package/dist/i18n/locales/zh.js +338 -0
- package/dist/i18n/locales/zh.js.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/direction.d.ts +24 -0
- package/dist/lib/direction.js +19 -0
- package/dist/lib/direction.js.map +1 -0
- package/dist/rhf/form.js.map +1 -1
- package/dist/search/command-palette.d.ts +5 -0
- package/dist/search/command-palette.js +80 -50
- package/dist/search/command-palette.js.map +1 -1
- package/dist/shell/app-shell.d.ts +13 -1
- package/dist/shell/app-shell.js +133 -84
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/topbar-action-menu.js +1 -1
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell/topbar-controls.d.ts +7 -3
- package/dist/shell/topbar-controls.js +38 -31
- package/dist/shell/topbar-controls.js.map +1 -1
- package/dist/theme/chart-palette.d.ts +7 -1
- package/dist/theme/chart-palette.js +2 -1
- package/dist/theme/chart-palette.js.map +1 -1
- package/dist/tour/tour.d.ts +11 -5
- package/dist/tour/tour.js +124 -58
- package/dist/tour/tour.js.map +1 -1
- package/dist/wizard/use-wizard.js +30 -13
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/wizard-summary.js +1 -1
- package/dist/wizard/wizard-summary.js.map +1 -1
- package/package.json +12 -2
- package/src/components/account-settings.tsx +6 -2
- package/src/components/amount-input.tsx +10 -8
- package/src/components/autocomplete.tsx +110 -24
- package/src/components/calculator.tsx +5 -1
- package/src/components/chart-zoom.tsx +8 -1
- package/src/components/chart.tsx +68 -7
- package/src/components/chip.tsx +131 -49
- package/src/components/choice-card.tsx +77 -36
- package/src/components/combobox-core.tsx +147 -20
- package/src/components/combobox.tsx +100 -44
- package/src/components/currency-select.tsx +6 -6
- package/src/components/danger-confirm.tsx +90 -36
- package/src/components/data-table-pagination.tsx +32 -19
- package/src/components/data-table.tsx +198 -36
- package/src/components/date-picker.tsx +24 -7
- package/src/components/dialog-frame.tsx +97 -22
- package/src/components/disclosure.tsx +75 -13
- package/src/components/dropdown.tsx +17 -5
- package/src/components/entity-combobox.tsx +26 -13
- package/src/components/file-button.tsx +74 -5
- package/src/components/file-dropzone.tsx +44 -35
- package/src/components/grouped-picker.tsx +2 -2
- package/src/components/hover-menu.tsx +139 -10
- package/src/components/icon-picker.tsx +14 -1
- package/src/components/measured-grid.tsx +852 -0
- package/src/components/mini-calendar.tsx +11 -8
- package/src/components/month-picker.tsx +18 -11
- package/src/components/multi-entity-combobox.tsx +2 -2
- package/src/components/multi-select.tsx +34 -7
- package/src/components/number-input.tsx +4 -4
- package/src/components/numpad-sheet.tsx +5 -3
- package/src/components/picker-sheet.tsx +1 -1
- package/src/components/popover.tsx +18 -3
- package/src/components/series-chart-ticks.ts +52 -0
- package/src/components/series-chart.tsx +39 -31
- package/src/components/swatch-picker.tsx +11 -0
- package/src/components/swipeable-row.tsx +21 -6
- package/src/components/tile-radio.tsx +5 -7
- package/src/components/toggle-group.tsx +39 -3
- package/src/components/toggle-legend.tsx +5 -2
- package/src/components/treemap.tsx +28 -5
- package/src/components/ui.tsx +74 -30
- package/src/components/use-anchor-dir.ts +20 -0
- package/src/components/use-mobile-reveal.ts +10 -2
- package/src/components/use-table-state.ts +44 -7
- package/src/data-table.ts +1 -0
- package/src/feedback/feedback-attachment.tsx +36 -9
- package/src/feedback/feedback-dialog.tsx +3 -2
- package/src/hooks/use-windowed-rows.ts +69 -0
- package/src/i18n/defaults.ts +4 -0
- package/src/i18n/kit-labels.tsx +4 -0
- package/src/i18n/locales/de-CH.ts +30 -0
- package/src/i18n/locales/de.ts +365 -0
- package/src/i18n/locales/es.ts +358 -0
- package/src/i18n/locales/fr.ts +371 -0
- package/src/i18n/locales/hu.ts +359 -0
- package/src/i18n/locales/it.ts +360 -0
- package/src/i18n/locales/zh.ts +348 -0
- package/src/index.ts +10 -1
- package/src/lib/direction.ts +37 -0
- package/src/rhf/form.tsx +21 -0
- package/src/search/command-palette.tsx +77 -19
- package/src/shell/app-shell.tsx +200 -129
- package/src/shell/topbar-action-menu.tsx +1 -1
- package/src/shell/topbar-controls.tsx +19 -8
- package/src/theme/chart-palette.ts +9 -2
- package/src/tour/tour.tsx +119 -18
- package/src/wizard/use-wizard.ts +55 -17
- package/src/wizard/wizard-summary.tsx +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/chip.tsx"],"sourcesContent":["import { forwardRef, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, MouseEvent, ReactNode } from \"react\";\nimport { X } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { FIELD_INVALID } from \"./ui\";\nimport { DEFAULT_COMMON_LABELS, useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\n\n/**\n * A chip: a compact pill carrying one value.\n *\n * Three jobs, deliberately one component. A chip can be inert (a tag on a row), a link\n * (a jump to a section), or a toggle (a filter that is on or off) — and the difference is\n * which prop you pass, not which component you pick. Keeping them together is what stops\n * an app growing three near-identical pills that drift apart; it is the shape this kit\n * already uses for `Button`, which is a link when it is given an href.\n *\n * A chip is not a `Button`. It is smaller, it is rounded to a pill, and it reads as a\n * VALUE rather than as an action — which matters because a row of eight buttons says\n * \"choose one of eight things to do\" and a row of eight chips says \"here are eight\n * things\". Using `Button` for both is the mistake this exists to prevent.\n */\n\nexport type ChipTone =\n | \"neutral\"\n | \"brand\"\n | \"danger\"\n | \"warning\"\n | \"success\"\n | \"info\"\n | \"income\"\n | \"expense\";\n/** `lg` is the 44px touch target (`min-h-11`) a phone surface wants; `md` is ~28px. */\nexport type ChipSize = \"sm\" | \"md\" | \"lg\";\n\nconst TONE: Record<ChipTone, { idle: string; selected: string }> = {\n neutral: {\n idle: \"border-[var(--border)] bg-[var(--bg-surface-2)] text-[var(--text-secondary)]\",\n selected: \"border-[var(--border-strong)] bg-[var(--bg-active)] text-[var(--text-primary)]\",\n },\n brand: {\n idle: \"border-[var(--border)] bg-[var(--brand-bg)] text-[var(--brand-muted)]\",\n selected: \"border-[var(--brand)] bg-[var(--brand)] text-[var(--brand-contrast)]\",\n },\n danger: {\n idle: \"border-[var(--danger-border)] bg-[var(--danger-bg)] text-[var(--danger)]\",\n selected: \"border-[var(--danger)] bg-[var(--danger)] text-[var(--danger-contrast)]\",\n },\n warning: {\n idle: \"border-[var(--warning-border)] bg-[var(--warning-bg)] text-[var(--warning)]\",\n selected: \"border-[var(--warning)] bg-[var(--warning-bg)] text-[var(--warning)]\",\n },\n success: {\n idle: \"border-[var(--success-border)] bg-[var(--success-bg)] text-[var(--success)]\",\n selected: \"border-[var(--success)] bg-[var(--success-bg)] text-[var(--success)]\",\n },\n info: {\n idle: \"border-[var(--info-border)] bg-[var(--info-bg)] text-[var(--info)]\",\n selected: \"border-[var(--info)] bg-[var(--info-bg)] text-[var(--info)]\",\n },\n // The money pair (Keksdose's direction toggle). Only the TEXT and the BORDER carry\n // the tint, on the neutral chip's own surfaces: the money tokens are chosen for text\n // contrast, and a filled amber pill beside an amber figure reads as one smear.\n // `border-current` takes its hue from the text, so the two cannot drift apart.\n income: {\n idle: \"border-current/40 bg-[var(--bg-surface-2)] text-[var(--money-income)]\",\n selected: \"border-current bg-[var(--bg-active)] text-[var(--money-income)]\",\n },\n expense: {\n idle: \"border-current/40 bg-[var(--bg-surface-2)] text-[var(--money-expense)]\",\n selected: \"border-current bg-[var(--bg-active)] text-[var(--money-expense)]\",\n },\n};\n\nconst SIZE: Record<ChipSize, { body: string; icon: string; remove: string }> = {\n sm: { body: \"gap-1 px-2 py-0.5 text-xs\", icon: \"size-3\", remove: \"size-3\" },\n md: { body: \"gap-1.5 px-2.5 py-1 text-sm\", icon: \"size-3.5\", remove: \"size-3.5\" },\n lg: { body: \"min-h-11 gap-2 px-4 py-2 text-sm\", icon: \"size-4\", remove: \"size-4\" },\n};\n\nconst CHIP_BASE =\n \"inline-flex max-w-full items-center rounded-full border transition-colors \" +\n // `focus-visible`, not `focus`: a chip commonly receives focus programmatically (the\n // ChipInput moves focus onto one after a removal) and a ring that appears on a\n // pointer click reads as a stuck selection.\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--bg-surface)]\";\n\nexport interface ChipProps {\n children: ReactNode;\n tone?: ChipTone;\n size?: ChipSize;\n icon?: LucideIcon;\n /**\n * Marks the chip as the current one — `aria-current` on a link, `aria-pressed` on a\n * toggle.\n *\n * On a toggle, keep the LABEL the same in both states and let `selected` carry the\n * state. A label that flips with it (\"Skip this month\" / \"Ask again this month\") is\n * announced together with \"pressed\", and then says the opposite of what it does.\n */\n selected?: boolean;\n /** Renders the chip as a link. Mutually exclusive with `onClick`. */\n href?: string;\n /** Renders the chip as a toggle button. Mutually exclusive with `href`. Receives the\n * click, so a chip inside a clickable row can `stopPropagation()`. */\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\n /** Renders a dismiss affordance. Works alongside `href`/`onClick` — see the note below. */\n onRemove?: () => void;\n /** Accessible name for the dismiss button. Default: `common.remove` from the\n * {@link UiKitProvider}, else \"Remove\". */\n removeLabel?: string;\n disabled?: boolean;\n className?: string;\n /**\n * Roving focus, for a container that manages a row of chips (see {@link ChipInput}).\n * A chip with no `href`/`onClick` is inert and unfocusable by default; give it a\n * `tabIndex` and a `role` and it becomes the thing arrow keys move between.\n */\n tabIndex?: number;\n role?: string;\n onKeyDown?: (e: KeyboardEvent<HTMLElement>) => void;\n onFocus?: () => void;\n /** Accessible name, when the visible text is not the whole story. */\n \"aria-label\"?: string;\n /** Any other ARIA attribute — `aria-describedby`, `aria-expanded`, `aria-controls`,\n * `aria-haspopup` — reaches the chip's interactive element. */\n [key: `aria-${string}`]: string | boolean | number | undefined;\n /** A test id, a `data-tour` anchor, or any other data attribute. */\n [key: `data-${string}`]: unknown;\n id?: string;\n /** A native tooltip. For anything a user must read, prefer the kit's `Tooltip`. */\n title?: string;\n}\n\n/**\n * Note on `onRemove` with `href`/`onClick`: a button cannot be nested inside a button or\n * a link, so when both are present the chip renders a wrapper holding TWO siblings — the\n * interactive body and the dismiss control. That is why the outer element is not always\n * the interactive one, and why the focus ring is drawn on the body rather than the\n * wrapper.\n */\nexport const Chip = forwardRef<HTMLElement, ChipProps>(function Chip(\n {\n children,\n tone = \"neutral\",\n size = \"md\",\n icon: Icon,\n selected = false,\n href,\n onClick,\n onRemove,\n removeLabel,\n disabled = false,\n className,\n tabIndex,\n role,\n onKeyDown,\n onFocus,\n ...rest\n },\n ref,\n) {\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS, { remove: removeLabel });\n const s = SIZE[size];\n const palette = TONE[tone];\n const interactive = !!href || !!onClick;\n const look = cn(\n CHIP_BASE,\n s.body,\n selected ? palette.selected : palette.idle,\n interactive && !disabled && \"cursor-pointer hover:brightness-[0.97] dark:hover:brightness-110\",\n disabled && \"cursor-default opacity-50\",\n className,\n );\n\n const body = (\n <>\n {Icon && <Icon className={cn(s.icon, \"shrink-0\")} aria-hidden />}\n <span className=\"min-w-0 truncate\">{children}</span>\n </>\n );\n\n const remove = onRemove ? (\n <button\n type=\"button\"\n // The name carries WHAT is being removed, not just \"Remove\" — a screen-reader user\n // tabbing a row of eight dismiss buttons otherwise hears the same word eight times\n // with no way to tell which one they are on.\n // Composed through `common.fieldValue` because the punctuation between the two\n // halves is the language's, not ours. A chip whose content is not plain text\n // has no value to name, and gets the bare verb rather than a dangling colon.\n aria-label={\n typeof children === \"string\" && children\n ? common.fieldValue(common.remove, children)\n : common.remove\n }\n onClick={(e) => {\n // The chip may itself be a link; removing it must not also follow it.\n e.preventDefault();\n e.stopPropagation();\n onRemove();\n }}\n disabled={disabled}\n className={cn(\n \"-mr-0.5 ml-0.5 shrink-0 rounded-full p-0.5 transition-colors\",\n \"hover:bg-[var(--bg-active)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]\",\n disabled && \"pointer-events-none\",\n )}\n >\n <X className={s.remove} aria-hidden />\n </button>\n ) : null;\n\n // ── The three shapes.\n if (href && !disabled) {\n const link = (\n <a\n ref={ref as React.Ref<HTMLAnchorElement>}\n href={href}\n aria-current={selected ? \"true\" : undefined}\n className={cn(look, remove && \"pr-1.5\")}\n {...rest}\n >\n {body}\n {!remove && null}\n </a>\n );\n return remove ? (\n <span className=\"inline-flex items-center\">\n {link}\n {remove}\n </span>\n ) : (\n link\n );\n }\n\n if (onClick) {\n const button = (\n <button\n ref={ref as React.Ref<HTMLButtonElement>}\n type=\"button\"\n onClick={onClick}\n disabled={disabled}\n aria-pressed={selected}\n className={cn(look, remove && \"pr-1.5\")}\n {...rest}\n >\n {body}\n </button>\n );\n return remove ? (\n <span className=\"inline-flex items-center\">\n {button}\n {remove}\n </span>\n ) : (\n button\n );\n }\n\n return (\n <span\n ref={ref as React.Ref<HTMLSpanElement>}\n className={look}\n tabIndex={tabIndex}\n role={role}\n onKeyDown={onKeyDown}\n onFocus={onFocus}\n {...rest}\n >\n {body}\n {remove}\n </span>\n );\n});\n\n/* ── ChipInput ────────────────────────────────────────────────────────────── */\n\nexport interface ChipInputLabels {\n /** Announced after a value is added. Receives the value. */\n added: (value: string) => string;\n /** Announced after a value is removed. Receives the value. */\n removed: (value: string) => string;\n /** Accessible name for each chip's dismiss button. */\n remove: string;\n /** Shown when `max` is reached. Receives the limit. */\n atLimit: (max: number) => string;\n /** Shown when a duplicate is rejected. Receives the value. */\n duplicate: (value: string) => string;\n}\n\nexport const DEFAULT_CHIP_INPUT_LABELS: ChipInputLabels = {\n added: (v) => `${v} added`,\n removed: (v) => `${v} removed`,\n remove: \"Remove\",\n atLimit: (max) => `Limit of ${max} reached`,\n duplicate: (v) => `${v} is already in the list`,\n};\n\nexport function resolveChipInputLabels(labels?: Partial<ChipInputLabels>): ChipInputLabels {\n return labels ? { ...DEFAULT_CHIP_INPUT_LABELS, ...labels } : DEFAULT_CHIP_INPUT_LABELS;\n}\n\n/**\n * `onChange` is the field's own — the whole LIST, not a DOM event — so the wrapper\n * div's `onChange` is omitted rather than shadowed. `placeholder` is likewise this\n * component's, forwarded to the inner `<input>`; the div has none of its own.\n */\nexport interface ChipInputProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"placeholder\" | \"children\"> {\n value: string[];\n onChange: (next: string[]) => void;\n placeholder?: string;\n /** Visible label, rendered above the field. Without one, name the field with\n * `aria-label`. */\n label?: string;\n /**\n * @deprecated Pass `aria-label` instead — the DOM spelling the rest of this kit\n * now uses. Still honoured, and still second to `aria-label` when both are given.\n */\n ariaLabel?: string;\n /** Reject or rewrite a value on commit. Return a string to reject WITH that message. */\n validate?: (raw: string) => string | null;\n /** Characters that commit the current text, besides Enter. Default: comma. */\n separators?: string[];\n allowDuplicates?: boolean;\n max?: number;\n tone?: ChipTone;\n size?: ChipSize;\n disabled?: boolean;\n invalid?: boolean;\n /** Error text. Wires `aria-describedby` and implies `invalid`. */\n error?: ReactNode;\n labels?: Partial<ChipInputLabels>;\n className?: string;\n}\n\n/**\n * A field whose value is a LIST, entered as chips.\n *\n * The keyboard model is the whole component; the pills are the easy part. Per the WAI\n * pattern for a \"tag\" input:\n *\n * Enter, or any separator commit the typed text\n * Backspace on empty text move focus to the last chip (does NOT delete it)\n * ← → while on a chip move between chips\n * Backspace / Delete remove the focused chip, focus its neighbour\n * Escape clear what is typed but keep the committed chips\n * paste splits on the separators, so a pasted CSV becomes chips\n *\n * The Backspace-on-empty behaviour is the one worth arguing about. Deleting immediately\n * is more common and is a trap: it is a destructive action with no feedback on a key\n * people hit by reflex, and the value it destroys may have taken a while to type. Moving\n * focus first makes the second Backspace a deliberate one, and it is what lets a\n * keyboard user reach a chip at all.\n */\nexport function ChipInput({\n value,\n onChange,\n placeholder,\n label,\n ariaLabel,\n validate,\n separators = [\",\"],\n allowDuplicates = false,\n max,\n tone = \"neutral\",\n size = \"md\",\n disabled = false,\n invalid = false,\n error,\n labels,\n className,\n \"aria-label\": ariaLabelAttr,\n ...rest\n}: ChipInputProps) {\n // `labels` over the provider's `chipInput` over English — the same order\n // `resolveChipInputLabels` gives outside a provider.\n const text = useKitLabels(\"chipInput\", DEFAULT_CHIP_INPUT_LABELS, labels);\n // A batch of pasted values is announced as one list, joined the way the language\n // joins a list in a sentence (\"a, b and c added\") — hence the long conjunction,\n // where a trigger's summary would use the narrow one.\n const locale = useKitLocale();\n const [draft, setDraft] = useState(\"\");\n const [message, setMessage] = useState(\"\");\n const [focusedChip, setFocusedChip] = useState<number | null>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const chipRefs = useRef<Array<HTMLElement | null>>([]);\n const id = useId();\n const listId = `${id}-list`;\n const errorId = `${id}-error`;\n const isInvalid = invalid || !!error;\n\n const focusChip = (index: number | null) => {\n setFocusedChip(index);\n if (index === null) inputRef.current?.focus();\n else chipRefs.current[index]?.focus();\n };\n\n /**\n * Try to add every candidate, as ONE change.\n *\n * Batched rather than looped for a reason that bites immediately: `commit` closes over\n * `value`, so calling it once per pasted item makes every call compute its result from\n * the list as it was BEFORE the paste, and each `onChange` overwrites the last. A\n * pasted \"one,two,three\" left only \"three\". Accumulating locally and emitting once is\n * also the correct behaviour for an undo stack — a paste is one action.\n */\n const commitMany = (raws: string[]): { added: string[]; rejection: string | null } => {\n const next = [...value];\n const added: string[] = [];\n let rejection: string | null = null;\n\n for (const raw of raws) {\n const candidate = raw.trim();\n if (!candidate) continue;\n if (max !== undefined && next.length >= max) {\n rejection ??= text.atLimit(max);\n break;\n }\n if (!allowDuplicates && next.includes(candidate)) {\n rejection ??= text.duplicate(candidate);\n continue;\n }\n const invalidReason = validate?.(candidate);\n if (invalidReason) {\n rejection ??= invalidReason;\n continue;\n }\n next.push(candidate);\n added.push(candidate);\n }\n\n if (added.length) onChange(next);\n // A rejection is the more useful thing to say: \"three added\" is obvious from the\n // chips appearing, whereas \"already in the list\" is the only sign of what did not.\n const addedList = new Intl.ListFormat(locale, { type: \"conjunction\", style: \"long\" });\n setMessage(rejection ?? (added.length ? text.added(addedList.format(added)) : \"\"));\n return { added, rejection };\n };\n\n const commit = (raw: string): boolean => commitMany([raw]).added.length > 0;\n\n const removeAt = (index: number) => {\n const removed = value[index];\n onChange(value.filter((_, i) => i !== index));\n setMessage(text.removed(removed));\n // Focus the neighbour that takes its place, or the input when the list empties —\n // dropping focus to <body> here is how a keyboard user loses the field entirely.\n const next = index >= value.length - 1 ? null : index;\n requestAnimationFrame(() => focusChip(value.length - 1 === 0 ? null : next));\n };\n\n const onInputKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\") {\n // Only when there is something to commit: an empty Enter belongs to the form.\n if (draft.trim()) {\n e.preventDefault();\n if (commit(draft)) setDraft(\"\");\n }\n return;\n }\n if (separators.includes(e.key)) {\n e.preventDefault();\n if (commit(draft)) setDraft(\"\");\n return;\n }\n if (e.key === \"Escape\" && draft) {\n e.preventDefault();\n setDraft(\"\");\n return;\n }\n if (e.key === \"Backspace\" && !draft && value.length) {\n e.preventDefault();\n focusChip(value.length - 1);\n }\n };\n\n const onChipKeyDown = (e: KeyboardEvent<HTMLElement>, index: number) => {\n if (e.key === \"Backspace\" || e.key === \"Delete\") {\n e.preventDefault();\n removeAt(index);\n return;\n }\n if (e.key === \"ArrowLeft\" && index > 0) {\n e.preventDefault();\n focusChip(index - 1);\n return;\n }\n if (e.key === \"ArrowRight\") {\n e.preventDefault();\n focusChip(index === value.length - 1 ? null : index + 1);\n return;\n }\n if (e.key === \"Escape\") {\n e.preventDefault();\n focusChip(null);\n }\n };\n\n return (\n // The rest lands on the OUTER box — the thing a `data-tour` step or a test id\n // wants to point at — while the accessible name below goes on the `<input>`,\n // because that is what a screen-reader user actually lands in. Spreading the two\n // to the same element would have named a decorative wrapper and left the field\n // anonymous.\n <div {...rest} className={cn(\"space-y-1\", className)}>\n {label && (\n <label htmlFor={`${id}-input`} className=\"block text-sm text-[var(--text-secondary)]\">\n {label}\n </label>\n )}\n <div\n // `relative` so the live region below can be `sr-only` without escaping to the\n // initial containing block and inflating the document height.\n className={cn(\n \"relative flex flex-wrap items-center gap-1.5 rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-2 py-1.5 shadow-sm\",\n \"focus-within:border-[var(--brand)] focus-within:ring-1 focus-within:ring-[var(--brand)]\",\n disabled && \"cursor-default bg-[var(--bg-surface-2)]\",\n isInvalid && FIELD_INVALID,\n )}\n onClick={() => !disabled && inputRef.current?.focus()}\n >\n {/* `display: contents` on the wrappers so the chips participate in the field's\n own flex wrap rather than forming a nested row. The list semantics are\n restored with explicit roles, because `contents` removes the ul/li boxes from\n the accessibility tree in several engines. */}\n {/* eslint-disable-next-line jsx-a11y/no-redundant-roles -- NOT redundant here: the\n `contents` display below removes the ul and li boxes from the box tree, and\n several engines drop the list semantics with them. The explicit role is what\n puts \"list, 3 items\" back. */}\n <ul id={listId} role=\"list\" className=\"contents\">\n {value.map((v, i) => (\n <li key={`${v}-${i}`} role=\"presentation\" className=\"contents\">\n <Chip\n ref={(el: HTMLElement | null) => {\n chipRefs.current[i] = el;\n }}\n tone={tone}\n size={size}\n disabled={disabled}\n removeLabel={text.remove}\n onRemove={disabled ? undefined : () => removeAt(i)}\n // A ROVING tabIndex: only the focused chip is tabbable, so Tab leaves\n // the field instead of walking through every value in it — the reason a\n // list of twenty tags is otherwise a twenty-stop detour for a keyboard.\n tabIndex={focusedChip === i ? 0 : -1}\n role=\"listitem\"\n aria-label={v}\n onKeyDown={(e) => onChipKeyDown(e, i)}\n onFocus={() => setFocusedChip(i)}\n data-chip-index={i}\n >\n {v}\n </Chip>\n </li>\n ))}\n </ul>\n <input\n id={`${id}-input`}\n ref={inputRef}\n value={draft}\n onChange={(e) => {\n setDraft(e.target.value);\n setMessage(\"\");\n }}\n onKeyDown={onInputKeyDown}\n onBlur={() => {\n // Commit on blur: a value typed and then clicked away from is a value the\n // user meant to add, and losing it silently is the commonest complaint\n // about this pattern.\n if (draft.trim() && commit(draft)) setDraft(\"\");\n }}\n onPaste={(e) => {\n const pasted = e.clipboardData.getData(\"text\");\n const pattern = new RegExp(`[${separators.map((s) => `\\\\${s}`).join(\"\")}\\n\\r]`);\n if (!pattern.test(pasted)) return;\n e.preventDefault();\n if (commitMany(pasted.split(pattern)).added.length) setDraft(\"\");\n }}\n placeholder={value.length ? undefined : placeholder}\n disabled={disabled}\n // A visible `label` is already wired through `htmlFor`, so adding a name\n // here would give the field two. Failing that, the DOM spelling wins and\n // the deprecated `ariaLabel` is the fallback.\n aria-label={label ? undefined : (ariaLabelAttr ?? ariaLabel)}\n aria-describedby={error ? errorId : undefined}\n aria-invalid={isInvalid || undefined}\n className=\"min-w-[6rem] flex-1 bg-transparent py-0.5 text-sm text-[var(--text-primary)] outline-none placeholder:text-[var(--text-placeholder)] disabled:cursor-default\"\n />\n {/* Additions, removals and rejections move no focus, so nothing would announce\n them. `sr-only-fixed` rather than `sr-only`: this sits inside a consumer's\n markup and must not extend the document height. */}\n <span role=\"status\" aria-live=\"polite\" aria-atomic className=\"sr-only-fixed\">\n {message}\n </span>\n </div>\n {error && (\n <p id={errorId} className=\"text-xs text-[var(--danger)]\">\n {error}\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";AAgLI,mBACW,KADX;AAhLJ,SAAS,YAAY,OAAO,QAAQ,gBAAgB;AAEpD,SAAS,SAAS;AAElB,SAAS,UAAU;AACnB,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB,cAAc,oBAAoB;AA6BlE,MAAM,OAA6D;AAAA,EACjE,SAAS;AAAA,IACP,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA,EACA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA,EACA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AACF;AAEA,MAAM,OAAyE;AAAA,EAC7E,IAAI,EAAE,MAAM,6BAA6B,MAAM,UAAU,QAAQ,SAAS;AAAA,EAC1E,IAAI,EAAE,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],"sourcesContent":["import { forwardRef, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, MouseEvent, ReactNode } from \"react\";\nimport { X } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { horizontalStep } from \"../lib/direction\";\nimport { FIELD_INVALID } from \"./ui\";\nimport { DEFAULT_COMMON_LABELS, useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\n\n/**\n * A chip: a compact pill carrying one value.\n *\n * Three jobs, deliberately one component. A chip can be inert (a tag on a row), a link\n * (a jump to a section), or a toggle (a filter that is on or off) — and the difference is\n * which prop you pass, not which component you pick. Keeping them together is what stops\n * an app growing three near-identical pills that drift apart; it is the shape this kit\n * already uses for `Button`, which is a link when it is given an href.\n *\n * A chip is not a `Button`. It is smaller, it is rounded to a pill, and it reads as a\n * VALUE rather than as an action — which matters because a row of eight buttons says\n * \"choose one of eight things to do\" and a row of eight chips says \"here are eight\n * things\". Using `Button` for both is the mistake this exists to prevent.\n */\n\nexport type ChipTone =\n | \"neutral\"\n | \"brand\"\n | \"danger\"\n | \"warning\"\n | \"success\"\n | \"info\"\n | \"income\"\n | \"expense\";\n/** `lg` is the 44px touch target (`min-h-11`) a phone surface wants; `md` is ~28px. */\nexport type ChipSize = \"sm\" | \"md\" | \"lg\";\n\nconst TONE: Record<ChipTone, { idle: string; selected: string }> = {\n neutral: {\n idle: \"border-[var(--border)] bg-[var(--bg-surface-2)] text-[var(--text-secondary)]\",\n selected: \"border-[var(--border-strong)] bg-[var(--bg-active)] text-[var(--text-primary)]\",\n },\n brand: {\n idle: \"border-[var(--border)] bg-[var(--brand-bg)] text-[var(--brand-muted)]\",\n selected: \"border-[var(--brand)] bg-[var(--brand)] text-[var(--brand-contrast)]\",\n },\n danger: {\n idle: \"border-[var(--danger-border)] bg-[var(--danger-bg)] text-[var(--danger)]\",\n selected: \"border-[var(--danger)] bg-[var(--danger)] text-[var(--danger-contrast)]\",\n },\n warning: {\n idle: \"border-[var(--warning-border)] bg-[var(--warning-bg)] text-[var(--warning)]\",\n selected: \"border-[var(--warning)] bg-[var(--warning-bg)] text-[var(--warning)]\",\n },\n success: {\n idle: \"border-[var(--success-border)] bg-[var(--success-bg)] text-[var(--success)]\",\n selected: \"border-[var(--success)] bg-[var(--success-bg)] text-[var(--success)]\",\n },\n info: {\n idle: \"border-[var(--info-border)] bg-[var(--info-bg)] text-[var(--info)]\",\n selected: \"border-[var(--info)] bg-[var(--info-bg)] text-[var(--info)]\",\n },\n // The money pair (Keksdose's direction toggle). Only the TEXT and the BORDER carry\n // the tint, on the neutral chip's own surfaces: the money tokens are chosen for text\n // contrast, and a filled amber pill beside an amber figure reads as one smear.\n // `border-current` takes its hue from the text, so the two cannot drift apart.\n income: {\n idle: \"border-current/40 bg-[var(--bg-surface-2)] text-[var(--money-income)]\",\n selected: \"border-current bg-[var(--bg-active)] text-[var(--money-income)]\",\n },\n expense: {\n idle: \"border-current/40 bg-[var(--bg-surface-2)] text-[var(--money-expense)]\",\n selected: \"border-current bg-[var(--bg-active)] text-[var(--money-expense)]\",\n },\n};\n\n/**\n * `body` is the whole pill when the chip is ONE element. When a link or a button also has\n * a dismiss control, the pill is a wrapper holding two siblings (see the note on\n * {@link Chip}): `split` is then the interactive part's own padding — the full start\n * inset, a short end one before the ×; `tail` is the wrapper's end inset after the ×.\n */\nconst SIZE: Record<\n ChipSize,\n { body: string; split: string; tail: string; icon: string; remove: string }\n> = {\n sm: {\n body: \"gap-1 px-2 py-0.5 text-xs\",\n split: \"gap-1 ps-2 pe-1 py-0.5 text-xs\",\n tail: \"pe-1.5\",\n icon: \"size-3\",\n remove: \"size-3\",\n },\n md: {\n body: \"gap-1.5 px-2.5 py-1 text-sm\",\n split: \"gap-1.5 ps-2.5 pe-1.5 py-1 text-sm\",\n tail: \"pe-2\",\n icon: \"size-3.5\",\n remove: \"size-3.5\",\n },\n lg: {\n body: \"min-h-11 gap-2 px-4 py-2 text-sm\",\n split: \"min-h-11 gap-2 ps-4 pe-2 py-2 text-sm\",\n tail: \"min-h-11 pe-3.5\",\n icon: \"size-4\",\n remove: \"size-4\",\n },\n};\n\nconst CHIP_PILL = \"inline-flex max-w-full items-center rounded-full border transition-colors\";\n// `focus-visible`, not `focus`: a chip commonly receives focus programmatically (the\n// ChipInput moves focus onto one after a removal) and a ring that appears on a\n// pointer click reads as a stuck selection.\nconst CHIP_RING =\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--bg-surface)]\";\nconst CHIP_BASE = `${CHIP_PILL} ${CHIP_RING}`;\n\ninterface ChipBaseProps {\n children: ReactNode;\n tone?: ChipTone;\n size?: ChipSize;\n icon?: LucideIcon;\n /**\n * Marks the chip as the current one — `aria-current` on a link, `aria-pressed` on a\n * toggle.\n *\n * On an ON/OFF toggle, keep the LABEL the same in both states and let `selected`\n * carry the state. A label that flips with it (\"Skip this month\" / \"Ask again this\n * month\") is announced together with \"pressed\", and then says the opposite of what\n * it does.\n *\n * A control that switches between two NAMED states (outflow ⇄ inflow) is not a\n * toggle but an ACTION button: leave `selected` out, let the visible label and the\n * tone follow the state (\"− Outflow\" / \"+ Inflow\"), and name the action in\n * `aria-label` (\"Direction: outflow — tap for inflow\"). Without `selected` the chip\n * reports no pressed state at all. A fixed label there contradicts the figure beside\n * it — \"+ Outflow\" in green next to an inflow (keksdose #417).\n */\n selected?: boolean;\n /** Renders a dismiss affordance. Works alongside `href`/`onClick` — see the note below. */\n onRemove?: () => void;\n /** Accessible name for the dismiss button. Default: `common.remove` from the\n * {@link UiKitProvider}, else \"Remove\". */\n removeLabel?: string;\n disabled?: boolean;\n className?: string;\n /**\n * Roving focus, for a container that manages a row of chips (see {@link ChipInput}).\n * A chip with no `href`/`onClick` is inert and unfocusable by default; give it a\n * `tabIndex` and a `role` and it becomes the thing arrow keys move between.\n */\n tabIndex?: number;\n role?: string;\n onKeyDown?: (e: KeyboardEvent<HTMLElement>) => void;\n onFocus?: () => void;\n /** Accessible name, when the visible text is not the whole story. */\n \"aria-label\"?: string;\n /** Any other ARIA attribute — `aria-describedby`, `aria-expanded`, `aria-controls`,\n * `aria-haspopup` — reaches the chip's interactive element. */\n [key: `aria-${string}`]: string | boolean | number | undefined;\n /** A test id, a `data-tour` anchor, or any other data attribute. */\n [key: `data-${string}`]: unknown;\n id?: string;\n /** A native tooltip. For anything a user must read, prefer the kit's `Tooltip`. */\n title?: string;\n}\n\n/**\n * A chip is a link OR a button, never both — so the types say so. Before 0.7.0 both were\n * accepted and `onClick` was silently dropped whenever `href` was set; a link that must\n * also run code wants a router `Link`-style `onClick` on the anchor, which is a different\n * component's job.\n */\nexport type ChipProps = ChipBaseProps &\n (\n | {\n /** Renders the chip as a link. Mutually exclusive with `onClick`. */\n href?: string;\n onClick?: never;\n }\n | {\n href?: never;\n /** Renders the chip as a toggle button. Mutually exclusive with `href`. Receives\n * the click, so a chip inside a clickable row can `stopPropagation()`. */\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\n }\n );\n\n/**\n * Note on `onRemove` with `href`/`onClick`: a button cannot be nested inside a button or\n * a link, so when both are present the chip renders a wrapper holding TWO siblings — the\n * interactive body and the dismiss control. The WRAPPER is the visual pill (border, tone,\n * `className`) and the two sit inside it, so the × reads as part of the chip; the body's\n * focus ring is drawn on the body alone, and `ref`, `id` and the ARIA props still reach\n * the body — the interactive element.\n */\nexport const Chip = forwardRef<HTMLElement, ChipProps>(function Chip(\n {\n children,\n tone = \"neutral\",\n size = \"md\",\n icon: Icon,\n selected,\n href,\n onClick,\n onRemove,\n removeLabel,\n disabled = false,\n className,\n tabIndex,\n role,\n onKeyDown,\n onFocus,\n ...rest\n },\n ref,\n) {\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS, { remove: removeLabel });\n const s = SIZE[size];\n const palette = TONE[tone];\n const interactive = !!href || !!onClick;\n const surface = cn(\n selected ? palette.selected : palette.idle,\n disabled && \"cursor-default opacity-50\",\n );\n const look = cn(\n CHIP_BASE,\n s.body,\n surface,\n interactive && !disabled && \"cursor-pointer hover:brightness-[0.97] dark:hover:brightness-110\",\n className,\n );\n\n const body = (\n <>\n {Icon && <Icon className={cn(s.icon, \"shrink-0\")} aria-hidden />}\n <span className=\"min-w-0 truncate\">{children}</span>\n </>\n );\n\n const remove = onRemove ? (\n <button\n type=\"button\"\n // The name carries WHAT is being removed, not just \"Remove\" — a screen-reader user\n // tabbing a row of eight dismiss buttons otherwise hears the same word eight times\n // with no way to tell which one they are on.\n // Composed through `common.fieldValue` because the punctuation between the two\n // halves is the language's, not ours. A chip whose content is not plain text\n // has no value to name, and gets the bare verb rather than a dangling colon.\n aria-label={\n typeof children === \"string\" && children\n ? common.fieldValue(common.remove, children)\n : common.remove\n }\n onClick={(e) => {\n // The chip may itself be a link; removing it must not also follow it.\n e.preventDefault();\n e.stopPropagation();\n onRemove();\n }}\n disabled={disabled}\n className={cn(\n // Logical margins: the × sits at the END of the pill, which is the left in RTL.\n \"-me-0.5 ms-0.5 shrink-0 rounded-full p-0.5 transition-colors\",\n \"hover:bg-[var(--bg-active)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]\",\n disabled && \"pointer-events-none\",\n )}\n >\n <X className={s.remove} aria-hidden />\n </button>\n ) : null;\n\n // ── The combined shape: one pill, two interactive siblings inside it.\n const pill = (inner: ReactNode) => (\n <span className={cn(CHIP_PILL, s.tail, surface, className)}>\n {inner}\n {remove}\n </span>\n );\n // The body inside a pill: no border or surface of its own (the pill has them), a\n // hover wash in the text's own hue so it works on every tone.\n const inner = cn(\n \"inline-flex min-w-0 items-center self-stretch rounded-full transition-colors\",\n CHIP_RING,\n s.split,\n !disabled && \"cursor-pointer hover:bg-current/10\",\n disabled && \"cursor-default\",\n );\n\n // ── The three shapes.\n if (href && !disabled) {\n const link = (\n <a\n ref={ref as React.Ref<HTMLAnchorElement>}\n href={href}\n aria-current={selected ? \"true\" : undefined}\n className={remove ? inner : look}\n {...rest}\n >\n {body}\n </a>\n );\n return remove ? pill(link) : link;\n }\n\n if (onClick) {\n const button = (\n <button\n ref={ref as React.Ref<HTMLButtonElement>}\n type=\"button\"\n onClick={onClick}\n disabled={disabled}\n // Only when `selected` is PASSED: a chip with `onClick` and no `selected` is an\n // action button (it does something), not a toggle (it is on or off), and\n // announcing it \"not pressed\" would claim a state it does not have.\n aria-pressed={selected}\n className={remove ? inner : look}\n {...rest}\n >\n {body}\n </button>\n );\n return remove ? pill(button) : button;\n }\n\n return (\n <span\n ref={ref as React.Ref<HTMLSpanElement>}\n className={look}\n tabIndex={tabIndex}\n role={role}\n onKeyDown={onKeyDown}\n onFocus={onFocus}\n {...rest}\n >\n {body}\n {remove}\n </span>\n );\n});\n\n/* ── ChipInput ────────────────────────────────────────────────────────────── */\n\nexport interface ChipInputLabels {\n /** Announced after a value is added. Receives the value. */\n added: (value: string) => string;\n /** Announced after a value is removed. Receives the value. */\n removed: (value: string) => string;\n /** Accessible name for each chip's dismiss button. */\n remove: string;\n /** Shown when `max` is reached. Receives the limit. */\n atLimit: (max: number) => string;\n /** Shown when a duplicate is rejected. Receives the value. */\n duplicate: (value: string) => string;\n}\n\nexport const DEFAULT_CHIP_INPUT_LABELS: ChipInputLabels = {\n added: (v) => `${v} added`,\n removed: (v) => `${v} removed`,\n remove: \"Remove\",\n atLimit: (max) => `Limit of ${max} reached`,\n duplicate: (v) => `${v} is already in the list`,\n};\n\nexport function resolveChipInputLabels(labels?: Partial<ChipInputLabels>): ChipInputLabels {\n return labels ? { ...DEFAULT_CHIP_INPUT_LABELS, ...labels } : DEFAULT_CHIP_INPUT_LABELS;\n}\n\n/**\n * `onChange` is the field's own — the whole LIST, not a DOM event — so the wrapper\n * div's `onChange` is omitted rather than shadowed. `placeholder` is likewise this\n * component's, forwarded to the inner `<input>`; the div has none of its own.\n */\nexport interface ChipInputProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\" | \"placeholder\" | \"children\"> {\n value: string[];\n onChange: (next: string[]) => void;\n placeholder?: string;\n /** Visible label, rendered above the field. Without one, name the field with\n * `aria-label`. */\n label?: string;\n /**\n * @deprecated Pass `aria-label` instead — the DOM spelling the rest of this kit\n * now uses. Still honoured, and still second to `aria-label` when both are given.\n */\n ariaLabel?: string;\n /** Reject or rewrite a value on commit. Return a string to reject WITH that message. */\n validate?: (raw: string) => string | null;\n /** Characters that commit the current text, besides Enter. Default: comma. */\n separators?: string[];\n allowDuplicates?: boolean;\n max?: number;\n tone?: ChipTone;\n size?: ChipSize;\n disabled?: boolean;\n invalid?: boolean;\n /** Error text. Wires `aria-describedby` and implies `invalid`. */\n error?: ReactNode;\n labels?: Partial<ChipInputLabels>;\n className?: string;\n}\n\n/**\n * A field whose value is a LIST, entered as chips.\n *\n * The keyboard model is the whole component; the pills are the easy part. Per the WAI\n * pattern for a \"tag\" input:\n *\n * Enter, or any separator commit the typed text\n * Backspace on empty text move focus to the last chip (does NOT delete it)\n * ← → while on a chip move between chips, in reading order (mirrored in RTL)\n * Backspace / Delete remove the focused chip, focus its neighbour\n * Escape clear what is typed but keep the committed chips\n * paste splits on the separators, so a pasted CSV becomes chips\n *\n * The Backspace-on-empty behaviour is the one worth arguing about. Deleting immediately\n * is more common and is a trap: it is a destructive action with no feedback on a key\n * people hit by reflex, and the value it destroys may have taken a while to type. Moving\n * focus first makes the second Backspace a deliberate one, and it is what lets a\n * keyboard user reach a chip at all.\n */\nexport function ChipInput({\n value,\n onChange,\n placeholder,\n label,\n ariaLabel,\n validate,\n separators = [\",\"],\n allowDuplicates = false,\n max,\n tone = \"neutral\",\n size = \"md\",\n disabled = false,\n invalid = false,\n error,\n labels,\n className,\n \"aria-label\": ariaLabelAttr,\n ...rest\n}: ChipInputProps) {\n // `labels` over the provider's `chipInput` over English — the same order\n // `resolveChipInputLabels` gives outside a provider.\n const text = useKitLabels(\"chipInput\", DEFAULT_CHIP_INPUT_LABELS, labels);\n // A batch of pasted values is announced as one list, joined the way the language\n // joins a list in a sentence (\"a, b and c added\") — hence the long conjunction,\n // where a trigger's summary would use the narrow one.\n const locale = useKitLocale();\n const [draft, setDraft] = useState(\"\");\n const [message, setMessage] = useState(\"\");\n // The last refusal, shown under the field until the next edit. The live region alone\n // told only a screen-reader user why Enter did nothing; everyone else saw the text\n // simply stay put.\n const [rejected, setRejected] = useState<string | null>(null);\n const [focusedChip, setFocusedChip] = useState<number | null>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const chipRefs = useRef<Array<HTMLElement | null>>([]);\n const id = useId();\n const listId = `${id}-list`;\n const errorId = `${id}-error`;\n const rejectedId = `${id}-rejected`;\n const isInvalid = invalid || !!error;\n const describedBy = [error ? errorId : null, rejected ? rejectedId : null]\n .filter(Boolean)\n .join(\" \");\n\n const focusChip = (index: number | null) => {\n setFocusedChip(index);\n if (index === null) inputRef.current?.focus();\n else chipRefs.current[index]?.focus();\n };\n\n /**\n * Try to add every candidate, as ONE change.\n *\n * Batched rather than looped for a reason that bites immediately: `commit` closes over\n * `value`, so calling it once per pasted item makes every call compute its result from\n * the list as it was BEFORE the paste, and each `onChange` overwrites the last. A\n * pasted \"one,two,three\" left only \"three\". Accumulating locally and emitting once is\n * also the correct behaviour for an undo stack — a paste is one action.\n */\n const commitMany = (raws: string[]): { added: string[]; rejection: string | null } => {\n const next = [...value];\n const added: string[] = [];\n let rejection: string | null = null;\n\n for (const raw of raws) {\n const candidate = raw.trim();\n if (!candidate) continue;\n if (max !== undefined && next.length >= max) {\n rejection ??= text.atLimit(max);\n break;\n }\n if (!allowDuplicates && next.includes(candidate)) {\n rejection ??= text.duplicate(candidate);\n continue;\n }\n const invalidReason = validate?.(candidate);\n if (invalidReason) {\n rejection ??= invalidReason;\n continue;\n }\n next.push(candidate);\n added.push(candidate);\n }\n\n if (added.length) onChange(next);\n // A rejection is the more useful thing to say: \"three added\" is obvious from the\n // chips appearing, whereas \"already in the list\" is the only sign of what did not.\n const addedList = new Intl.ListFormat(locale, { type: \"conjunction\", style: \"long\" });\n setMessage(rejection ?? (added.length ? text.added(addedList.format(added)) : \"\"));\n setRejected(rejection);\n return { added, rejection };\n };\n\n const commit = (raw: string): boolean => commitMany([raw]).added.length > 0;\n\n const removeAt = (index: number) => {\n const removed = value[index];\n onChange(value.filter((_, i) => i !== index));\n setMessage(text.removed(removed));\n setRejected(null);\n // Focus the neighbour that takes its place, or the input when the list empties —\n // dropping focus to <body> here is how a keyboard user loses the field entirely.\n const next = index >= value.length - 1 ? null : index;\n requestAnimationFrame(() => focusChip(value.length - 1 === 0 ? null : next));\n };\n\n const onInputKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"Enter\") {\n // Only when there is something to commit: an empty Enter belongs to the form.\n if (draft.trim()) {\n e.preventDefault();\n if (commit(draft)) setDraft(\"\");\n }\n return;\n }\n if (separators.includes(e.key)) {\n e.preventDefault();\n if (commit(draft)) setDraft(\"\");\n return;\n }\n if (e.key === \"Escape\" && draft) {\n e.preventDefault();\n setDraft(\"\");\n return;\n }\n if (e.key === \"Backspace\" && !draft && value.length) {\n e.preventDefault();\n focusChip(value.length - 1);\n }\n };\n\n const onChipKeyDown = (e: KeyboardEvent<HTMLElement>, index: number) => {\n if (e.key === \"Backspace\" || e.key === \"Delete\") {\n e.preventDefault();\n removeAt(index);\n return;\n }\n // ←/→ follow the reading direction, not DOM order: in RTL the previous chip is to\n // the RIGHT, and ArrowLeft moves on towards the input.\n const step = horizontalStep(e.key, e.currentTarget);\n if (step === -1 && index > 0) {\n e.preventDefault();\n focusChip(index - 1);\n return;\n }\n if (step === 1) {\n e.preventDefault();\n focusChip(index === value.length - 1 ? null : index + 1);\n return;\n }\n if (e.key === \"Escape\") {\n e.preventDefault();\n focusChip(null);\n }\n };\n\n return (\n // The rest lands on the OUTER box — the thing a `data-tour` step or a test id\n // wants to point at — while the accessible name below goes on the `<input>`,\n // because that is what a screen-reader user actually lands in. Spreading the two\n // to the same element would have named a decorative wrapper and left the field\n // anonymous.\n <div {...rest} className={cn(\"space-y-1\", className)}>\n {label && (\n <label htmlFor={`${id}-input`} className=\"block text-sm text-[var(--text-secondary)]\">\n {label}\n </label>\n )}\n <div\n // `relative` so the live region below can be `sr-only` without escaping to the\n // initial containing block and inflating the document height.\n className={cn(\n \"relative flex flex-wrap items-center gap-1.5 rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-2 py-1.5 shadow-sm\",\n \"focus-within:border-[var(--brand)] focus-within:ring-1 focus-within:ring-[var(--brand)]\",\n disabled && \"cursor-default bg-[var(--bg-surface-2)]\",\n isInvalid && FIELD_INVALID,\n )}\n onClick={() => !disabled && inputRef.current?.focus()}\n >\n {/* `display: contents` on the wrappers so the chips participate in the field's\n own flex wrap rather than forming a nested row. The list semantics are\n restored with explicit roles, because `contents` removes the ul/li boxes from\n the accessibility tree in several engines. */}\n {/* eslint-disable-next-line jsx-a11y/no-redundant-roles -- NOT redundant here: the\n `contents` display below removes the ul and li boxes from the box tree, and\n several engines drop the list semantics with them. The explicit role is what\n puts \"list, 3 items\" back. */}\n <ul id={listId} role=\"list\" className=\"contents\">\n {value.map((v, i) => (\n <li key={`${v}-${i}`} role=\"presentation\" className=\"contents\">\n <Chip\n ref={(el: HTMLElement | null) => {\n chipRefs.current[i] = el;\n }}\n tone={tone}\n size={size}\n disabled={disabled}\n removeLabel={text.remove}\n onRemove={disabled ? undefined : () => removeAt(i)}\n // A ROVING tabIndex: only the focused chip is tabbable, so Tab leaves\n // the field instead of walking through every value in it — the reason a\n // list of twenty tags is otherwise a twenty-stop detour for a keyboard.\n tabIndex={focusedChip === i ? 0 : -1}\n role=\"listitem\"\n aria-label={v}\n onKeyDown={(e) => onChipKeyDown(e, i)}\n onFocus={() => setFocusedChip(i)}\n data-chip-index={i}\n >\n {v}\n </Chip>\n </li>\n ))}\n </ul>\n <input\n id={`${id}-input`}\n ref={inputRef}\n value={draft}\n onChange={(e) => {\n setDraft(e.target.value);\n setMessage(\"\");\n setRejected(null);\n }}\n onKeyDown={onInputKeyDown}\n onBlur={() => {\n // Commit on blur: a value typed and then clicked away from is a value the\n // user meant to add, and losing it silently is the commonest complaint\n // about this pattern.\n if (draft.trim() && commit(draft)) setDraft(\"\");\n }}\n onPaste={(e) => {\n const pasted = e.clipboardData.getData(\"text\");\n const pattern = new RegExp(`[${separators.map((s) => `\\\\${s}`).join(\"\")}\\n\\r]`);\n if (!pattern.test(pasted)) return;\n e.preventDefault();\n if (commitMany(pasted.split(pattern)).added.length) setDraft(\"\");\n }}\n placeholder={value.length ? undefined : placeholder}\n disabled={disabled}\n // A visible `label` is already wired through `htmlFor`, so adding a name\n // here would give the field two. Failing that, the DOM spelling wins and\n // the deprecated `ariaLabel` is the fallback.\n aria-label={label ? undefined : (ariaLabelAttr ?? ariaLabel)}\n aria-describedby={describedBy || undefined}\n aria-invalid={isInvalid || !!rejected || undefined}\n className=\"min-w-[6rem] flex-1 bg-transparent py-0.5 text-sm text-[var(--text-primary)] outline-none placeholder:text-[var(--text-placeholder)] disabled:cursor-default\"\n />\n {/* Additions, removals and rejections move no focus, so nothing would announce\n them. `sr-only-fixed` rather than `sr-only`: this sits inside a consumer's\n markup and must not extend the document height. */}\n <span role=\"status\" aria-live=\"polite\" aria-atomic className=\"sr-only-fixed\">\n {message}\n </span>\n </div>\n {error && (\n <p id={errorId} className=\"text-xs text-[var(--danger)]\">\n {error}\n </p>\n )}\n {rejected && (\n <p id={rejectedId} className=\"text-xs text-[var(--danger)]\" data-chip-input-rejected=\"\">\n {rejected}\n </p>\n )}\n </div>\n );\n}\n"],"mappings":";AAyOI,mBACW,KADX;AAzOJ,SAAS,YAAY,OAAO,QAAQ,gBAAgB;AAEpD,SAAS,SAAS;AAElB,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB,cAAc,oBAAoB;AA6BlE,MAAM,OAA6D;AAAA,EACjE,SAAS;AAAA,IACP,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AAAA,EACA,OAAO;AA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,6 +46,14 @@ interface ChoiceCardProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "t
|
|
|
46
46
|
onCheckedChange?: (checked: boolean) => void;
|
|
47
47
|
/** Classes for the `<input>`. `className` styles the card. */
|
|
48
48
|
inputClassName?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Must be ticked to submit. Reaches the `<input>` as the native `required` (a
|
|
51
|
+
* `<form>` refuses to submit without it, a screen reader announces "required"),
|
|
52
|
+
* and draws the kit's `aria-hidden` star after the title — {@link Checkbox}'s
|
|
53
|
+
* contract, down to writing the title WITHOUT a literal "*". Inside a
|
|
54
|
+
* {@link ChoiceCardGroup} the star goes on the legend instead, once.
|
|
55
|
+
*/
|
|
56
|
+
required?: boolean;
|
|
49
57
|
}
|
|
50
58
|
declare const ChoiceCard: react.ForwardRefExoticComponent<ChoiceCardProps & react.RefAttributes<HTMLInputElement>>;
|
|
51
59
|
interface ChoiceCardOption<T extends string> {
|
|
@@ -71,7 +79,16 @@ interface ChoiceCardGroupBaseProps<T extends string> {
|
|
|
71
79
|
/** What is wrong with the answer as a whole. Rendered under the cards and attached
|
|
72
80
|
* to the fieldset. */
|
|
73
81
|
error?: ReactNode;
|
|
74
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* An answer is needed. Draws the required star after the `legend` (none without
|
|
84
|
+
* one — the name then comes from `aria-label`, which has nowhere to draw it), and
|
|
85
|
+
* reaches the inputs as the native `required`:
|
|
86
|
+
* - radios: every radio of the set, which is how HTML marks a radio group — the
|
|
87
|
+
* group is satisfied by any one of them, and each announces "required";
|
|
88
|
+
* - checkboxes: every box while NONE is ticked, dropped from all of them once one
|
|
89
|
+
* is — "at least one", which checkboxes cannot say natively. A form then refuses
|
|
90
|
+
* to submit an empty set, and nothing is left demanding a second box.
|
|
91
|
+
*/
|
|
75
92
|
required?: boolean;
|
|
76
93
|
}
|
|
77
94
|
/** One of the set: radios. `value` is `null` while nothing is chosen. */
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef, useCallback, useEffect, useId, useRef } from "react";
|
|
3
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useRef } from "react";
|
|
4
4
|
import { Check, Minus } from "lucide-react";
|
|
5
5
|
import { cn } from "../lib/cn.js";
|
|
6
6
|
import { assignRef, hasMessage, mergeDescribedBy } from "./choice-parts.js";
|
|
7
|
+
const InGroupContext = createContext(false);
|
|
8
|
+
function RequiredMark() {
|
|
9
|
+
return /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "ms-0.5 text-[var(--danger)]", children: "*" });
|
|
10
|
+
}
|
|
7
11
|
const CARD = "flex cursor-pointer items-start gap-3 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-3 shadow-sm transition-colors hover:border-[var(--border-strong)] hover:bg-[var(--bg-hover)] has-[:checked]:border-[var(--brand)] has-[:checked]:bg-[var(--brand-bg)] has-[:checked]:ring-1 has-[:checked]:ring-[var(--brand)] has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[var(--brand)] has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-60";
|
|
8
12
|
const CARD_DISABLED = "hover:border-[var(--border)] hover:bg-[var(--bg-surface)]";
|
|
9
13
|
const CARD_INVALID = "border-[var(--danger-border)] ring-1 ring-[var(--danger-border)] has-[:checked]:border-[var(--danger-border)] has-[:checked]:ring-[var(--danger-border)]";
|
|
@@ -24,8 +28,10 @@ const ChoiceCard = forwardRef(function ChoiceCard2({
|
|
|
24
28
|
inputClassName,
|
|
25
29
|
id,
|
|
26
30
|
disabled,
|
|
31
|
+
required,
|
|
27
32
|
...rest
|
|
28
33
|
}, ref) {
|
|
34
|
+
const inGroup = useContext(InGroupContext);
|
|
29
35
|
const generated = useId();
|
|
30
36
|
const inputId = id ?? generated;
|
|
31
37
|
const titleId = `${inputId}-title`;
|
|
@@ -59,6 +65,7 @@ const ChoiceCard = forwardRef(function ChoiceCard2({
|
|
|
59
65
|
ref: setRef,
|
|
60
66
|
id: inputId,
|
|
61
67
|
disabled,
|
|
68
|
+
required,
|
|
62
69
|
...rest,
|
|
63
70
|
type,
|
|
64
71
|
"aria-labelledby": rest["aria-labelledby"] ?? titleId,
|
|
@@ -98,12 +105,15 @@ const ChoiceCard = forwardRef(function ChoiceCard2({
|
|
|
98
105
|
] }),
|
|
99
106
|
Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, className: "mt-0.5 size-4 shrink-0 text-[var(--text-secondary)]" }),
|
|
100
107
|
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
101
|
-
/* @__PURE__ */
|
|
108
|
+
/* @__PURE__ */ jsxs(
|
|
102
109
|
"span",
|
|
103
110
|
{
|
|
104
111
|
id: titleId,
|
|
105
112
|
className: "block select-none text-sm font-medium leading-5 text-[var(--text-primary)]",
|
|
106
|
-
children:
|
|
113
|
+
children: [
|
|
114
|
+
title,
|
|
115
|
+
required && !inGroup && /* @__PURE__ */ jsx(RequiredMark, {})
|
|
116
|
+
]
|
|
107
117
|
}
|
|
108
118
|
),
|
|
109
119
|
showDescription && /* @__PURE__ */ jsx("span", { id: descriptionId, className: "mt-0.5 block text-xs text-[var(--text-muted)]", children: description }),
|
|
@@ -131,7 +141,7 @@ function ChoiceCardGroup(props) {
|
|
|
131
141
|
props.onChange(v);
|
|
132
142
|
}
|
|
133
143
|
};
|
|
134
|
-
return /* @__PURE__ */ jsxs(
|
|
144
|
+
return /* @__PURE__ */ jsx(InGroupContext.Provider, { value: true, children: /* @__PURE__ */ jsxs(
|
|
135
145
|
"fieldset",
|
|
136
146
|
{
|
|
137
147
|
"aria-label": props["aria-label"],
|
|
@@ -139,8 +149,11 @@ function ChoiceCardGroup(props) {
|
|
|
139
149
|
disabled,
|
|
140
150
|
className: "min-w-0",
|
|
141
151
|
children: [
|
|
142
|
-
legend !== void 0 && /* @__PURE__ */
|
|
143
|
-
|
|
152
|
+
legend !== void 0 && /* @__PURE__ */ jsxs("legend", { className: "mb-2 text-sm font-medium text-[var(--text-primary)]", children: [
|
|
153
|
+
legend,
|
|
154
|
+
required && /* @__PURE__ */ jsx(RequiredMark, {})
|
|
155
|
+
] }),
|
|
156
|
+
/* @__PURE__ */ jsx("div", { className: cn("grid gap-2 sm:grid-cols-2", className), children: options.map((o) => /* @__PURE__ */ jsx(
|
|
144
157
|
ChoiceCard,
|
|
145
158
|
{
|
|
146
159
|
type: props.multiple ? "checkbox" : "radio",
|
|
@@ -151,7 +164,7 @@ function ChoiceCardGroup(props) {
|
|
|
151
164
|
icon: o.icon,
|
|
152
165
|
disabled: o.disabled,
|
|
153
166
|
invalid: showError,
|
|
154
|
-
required: !props.multiple
|
|
167
|
+
required: required && (!props.multiple || props.value.length === 0) ? true : void 0,
|
|
155
168
|
checked: isChecked(o.value),
|
|
156
169
|
onCheckedChange: (on) => toggle(o.value, on),
|
|
157
170
|
className: cardClassName
|
|
@@ -161,7 +174,7 @@ function ChoiceCardGroup(props) {
|
|
|
161
174
|
showError && /* @__PURE__ */ jsx("p", { id: errorId, className: "mt-1 text-[11px] leading-tight text-[var(--danger)]", children: error })
|
|
162
175
|
]
|
|
163
176
|
}
|
|
164
|
-
);
|
|
177
|
+
) });
|
|
165
178
|
}
|
|
166
179
|
export {
|
|
167
180
|
ChoiceCard,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/choice-card.tsx"],"sourcesContent":["import { forwardRef, useCallback, useEffect, useId, useRef } from \"react\";\nimport type { ChangeEvent, ComponentType, InputHTMLAttributes, ReactNode } from \"react\";\nimport { Check, Minus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { assignRef, hasMessage, mergeDescribedBy } from \"./choice-parts\";\n\n/**\n * A checkbox or a radio, presented as a bordered card: a title, a line of description,\n * an optional icon — and the whole card is the hit area.\n *\n * Kastlan built this twice by hand: the \"manage roles\" dialog wraps a `Checkbox` in a\n * bordered `<label>` per role, and the lease wizard's \"set up recurring rent\" option is\n * a `Checkbox` with `className=\"rounded-md border p-3\"`. Neither had a focus ring on\n * the card or a checked look beyond the 16px box, and the role picker's border stayed\n * grey whether the role was on or off.\n *\n * Still a native `<input>` underneath, for the reasons {@link Checkbox} gives: it\n * submits with its form, answers to `required`, and a radio set sharing a `name` gets\n * the browser's own arrow-key behaviour — which already flips in a right-to-left page.\n * The card is a `<label>` wrapped round it, so a click anywhere on the card lands on\n * the input; the input is NAMED by the title alone and DESCRIBED by the description,\n * so a screen reader does not read the whole card as its name.\n *\n * Checked is said three ways, none of them colour alone: the box's tick (or the\n * radio's dot), a heavier border, and the brand-tinted surface.\n */\n\nexport type ChoiceCardType = \"checkbox\" | \"radio\";\n\nexport interface ChoiceCardProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"type\" | \"title\"> {\n /** \"checkbox\" (default) for an on/off option or one of several; \"radio\" for one of\n * a set — give every card of the set the same `name`, or use {@link ChoiceCardGroup}. */\n type?: ChoiceCardType;\n /** The option's name — the input's accessible name. */\n title: ReactNode;\n /** A line or two under the title. Attached with `aria-describedby`. */\n description?: ReactNode;\n /** A Lucide icon (or any component taking a `className`), shown at the card's start. */\n icon?: ComponentType<{ className?: string; \"aria-hidden\"?: boolean }>;\n /** Checkbox only: \"some but not all\". See {@link CheckboxProps.indeterminate}. */\n indeterminate?: boolean;\n /** Paints the card and sets `aria-invalid` together. */\n invalid?: boolean;\n /** What is wrong, in the caller's words. Rendered in the card and attached with\n * `aria-describedby`; implies `invalid`. */\n error?: ReactNode;\n /** The checked state as a boolean. Fires alongside `onChange`, never instead of it. */\n onCheckedChange?: (checked: boolean) => void;\n /** Classes for the `<input>`. `className` styles the card. */\n inputClassName?: string;\n}\n\n// The card. `has-[:checked]` and `has-[:focus-visible]` read the INPUT's state, so an\n// uncontrolled card (`defaultChecked`, a plain form) looks right with no React state.\nconst CARD =\n \"flex cursor-pointer items-start gap-3 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-3 shadow-sm transition-colors \" +\n \"hover:border-[var(--border-strong)] hover:bg-[var(--bg-hover)] \" +\n \"has-[:checked]:border-[var(--brand)] has-[:checked]:bg-[var(--brand-bg)] has-[:checked]:ring-1 has-[:checked]:ring-[var(--brand)] \" +\n // The focus mark is the CARD's, not the 16px box's: the card is what was clicked and\n // what the eye is on. An OUTLINE rather than a ring, because the checked state already\n // spends the ring — two `ring-*` widths on one element are decided by stylesheet\n // order, and the loser would be the focus mark. Offset, so the two never merge.\n \"has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[var(--brand)] \" +\n // Read from the input too, so a card disabled by its `<fieldset>` fades as well.\n \"has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-60\";\n\n// No hover offer on a card that cannot be changed.\nconst CARD_DISABLED = \"hover:border-[var(--border)] hover:bg-[var(--bg-surface)]\";\n\nconst CARD_INVALID =\n \"border-[var(--danger-border)] ring-1 ring-[var(--danger-border)] has-[:checked]:border-[var(--danger-border)] has-[:checked]:ring-[var(--danger-border)]\";\n\nconst BOX =\n \"peer size-4 shrink-0 appearance-none border border-[var(--border-strong)] bg-[var(--bg-surface)] transition-colors \" +\n \"checked:border-[var(--brand)] focus:outline-none disabled:cursor-not-allowed\";\nconst CHECKBOX = \"rounded-[4px] checked:bg-[var(--brand)]\";\n// A radio's dot is its BORDER: a 5px brand border round a surface-coloured 4px\n// centre. No glyph to lay over it, and it scales with the box.\nconst RADIO = \"rounded-full checked:border-[5px]\";\n\nexport const ChoiceCard = forwardRef<HTMLInputElement, ChoiceCardProps>(function ChoiceCard(\n {\n type = \"checkbox\",\n title,\n description,\n icon: Icon,\n indeterminate = false,\n invalid,\n error,\n onCheckedChange,\n onChange,\n className,\n inputClassName,\n id,\n disabled,\n ...rest\n },\n ref,\n) {\n const generated = useId();\n const inputId = id ?? generated;\n const titleId = `${inputId}-title`;\n const descriptionId = `${inputId}-description`;\n const errorId = `${inputId}-error`;\n const showDescription = hasMessage(description);\n const showError = hasMessage(error);\n const isInvalid = Boolean(invalid) || showError;\n const mixed = type === \"checkbox\" && indeterminate;\n\n const local = useRef<HTMLInputElement | null>(null);\n const setRef = useCallback(\n (node: HTMLInputElement | null) => {\n local.current = node;\n assignRef(ref, node);\n },\n [ref],\n );\n // After every render, as Checkbox does: a click clears the DOM property.\n useEffect(() => {\n if (local.current) local.current.indeterminate = mixed;\n });\n\n return (\n <label\n htmlFor={inputId}\n className={cn(CARD, disabled && CARD_DISABLED, isInvalid && CARD_INVALID, className)}\n >\n {/* A 20px cell, so the box centres on the title's first line (text-sm). */}\n <span className=\"relative flex h-5 shrink-0 items-center\">\n <input\n ref={setRef}\n id={inputId}\n disabled={disabled}\n {...rest}\n type={type}\n aria-labelledby={rest[\"aria-labelledby\"] ?? titleId}\n aria-invalid={isInvalid || rest[\"aria-invalid\"] || undefined}\n aria-describedby={mergeDescribedBy(\n rest[\"aria-describedby\"],\n showDescription && descriptionId,\n showError && errorId,\n )}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n onCheckedChange?.(e.target.checked);\n }}\n className={cn(\n BOX,\n type === \"radio\" ? RADIO : CHECKBOX,\n mixed && \"border-[var(--brand)] bg-[var(--brand)]\",\n inputClassName,\n )}\n />\n {type === \"checkbox\" &&\n (mixed ? (\n <Minus\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none absolute inset-0 m-auto size-3 text-[var(--brand-contrast)]\"\n />\n ) : (\n <Check\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none invisible absolute inset-0 m-auto size-3 text-[var(--brand-contrast)] peer-checked:visible\"\n />\n ))}\n </span>\n {Icon && <Icon aria-hidden className=\"mt-0.5 size-4 shrink-0 text-[var(--text-secondary)]\" />}\n <span className=\"min-w-0 flex-1\">\n <span\n id={titleId}\n // `select-none`: a double-click to toggle twice would otherwise select the words.\n className=\"block select-none text-sm font-medium leading-5 text-[var(--text-primary)]\"\n >\n {title}\n </span>\n {showDescription && (\n <span id={descriptionId} className=\"mt-0.5 block text-xs text-[var(--text-muted)]\">\n {description}\n </span>\n )}\n {showError && (\n <span id={errorId} className=\"mt-1 block text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </span>\n )}\n </span>\n </label>\n );\n});\nChoiceCard.displayName = \"ChoiceCard\";\n\n/* ── ChoiceCardGroup ─────────────────────────────────────────────────────── */\n\nexport interface ChoiceCardOption<T extends string> {\n value: T;\n title: ReactNode;\n description?: ReactNode;\n icon?: ChoiceCardProps[\"icon\"];\n disabled?: boolean;\n}\n\ninterface ChoiceCardGroupBaseProps<T extends string> {\n options: ChoiceCardOption<T>[];\n /** The question the cards answer. Rendered as the fieldset's `<legend>`, which is\n * what names the group. Without one, pass `aria-label`. */\n legend?: ReactNode;\n \"aria-label\"?: string;\n /** Shared by every input — what a plain form submits under. Generated if omitted. */\n name?: string;\n /** Classes for the card grid. Default: one column, two from `sm` up. */\n className?: string;\n /** Classes for every card. */\n cardClassName?: string;\n disabled?: boolean;\n /** What is wrong with the answer as a whole. Rendered under the cards and attached\n * to the fieldset. */\n error?: ReactNode;\n /** Radio mode only: marks the first input `required`, which is how a radio set is. */\n required?: boolean;\n}\n\n/** One of the set: radios. `value` is `null` while nothing is chosen. */\nexport interface ChoiceCardSingleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple?: false;\n value: T | null;\n onChange: (value: T) => void;\n}\n\n/** Any of the set: checkboxes. */\nexport interface ChoiceCardMultipleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple: true;\n value: T[];\n onChange: (value: T[]) => void;\n}\n\nexport type ChoiceCardGroupProps<T extends string> =\n | ChoiceCardSingleProps<T>\n | ChoiceCardMultipleProps<T>;\n\n/**\n * A set of {@link ChoiceCard}s answering one question, in a `<fieldset>`.\n *\n * `multiple` picks the input: radios (one of the set, the browser's arrow keys\n * between them) or checkboxes (any of the set, Tab between them). The value is kept\n * in the order of `options`, not the order the boxes were ticked, so a list saved\n * from it does not depend on the order someone clicked in.\n */\nexport function ChoiceCardGroup<T extends string>(props: ChoiceCardGroupProps<T>) {\n const { options, legend, name, className, cardClassName, disabled, error, required } = props;\n const generated = useId();\n const groupName = name ?? generated;\n const errorId = `${generated}-error`;\n const showError = hasMessage(error);\n\n const isChecked = (v: T) => (props.multiple ? props.value.includes(v) : props.value === v);\n const toggle = (v: T, on: boolean) => {\n if (props.multiple) {\n const next = new Set(props.value);\n if (on) next.add(v);\n else next.delete(v);\n props.onChange(options.map((o) => o.value).filter((x) => next.has(x)));\n } else if (on) {\n props.onChange(v);\n }\n };\n\n return (\n <fieldset\n aria-label={props[\"aria-label\"]}\n aria-describedby={showError ? errorId : undefined}\n disabled={disabled}\n className=\"min-w-0\"\n >\n {legend !== undefined && (\n <legend className=\"mb-2 text-sm font-medium text-[var(--text-primary)]\">{legend}</legend>\n )}\n <div className={cn(\"grid gap-2 sm:grid-cols-2\", className)}>\n {options.map((o, i) => (\n <ChoiceCard\n key={o.value}\n type={props.multiple ? \"checkbox\" : \"radio\"}\n name={groupName}\n value={o.value}\n title={o.title}\n description={o.description}\n icon={o.icon}\n disabled={o.disabled}\n invalid={showError}\n required={!props.multiple && required && i === 0 ? true : undefined}\n checked={isChecked(o.value)}\n onCheckedChange={(on) => toggle(o.value, on)}\n className={cardClassName}\n />\n ))}\n </div>\n {showError && (\n <p id={errorId} className=\"mt-1 text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </p>\n )}\n </fieldset>\n );\n}\n"],"mappings":";AAgIM,SACE,KADF;AAhIN,SAAS,YAAY,aAAa,WAAW,OAAO,cAAc;AAElE,SAAS,OAAO,aAAa;AAC7B,SAAS,UAAU;AACnB,SAAS,WAAW,YAAY,wBAAwB;AAkDxD,MAAM,OACJ;AAYF,MAAM,gBAAgB;AAEtB,MAAM,eACJ;AAEF,MAAM,MACJ;AAEF,MAAM,WAAW;AAGjB,MAAM,QAAQ;AAEP,MAAM,aAAa,WAA8C,SAASA,YAC/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AAE,KAAK,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC;AAAA,IACvE,WAAW,IAAI;AACb,YAAM,SAAS,CAAC;AAAA,IAClB;AAAA,EACF;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAY,MAAM,YAAY;AAAA,MAC9B,oBAAkB,YAAY,UAAU;AAAA,MACxC;AAAA,MACA,WAAU;AAAA,MAET;AAAA,mBAAW,UACV,oBAAC,YAAO,WAAU,uDAAuD,kBAAO;AAAA,QAElF,oBAAC,SAAI,WAAW,GAAG,6BAA6B,SAAS,GACtD,kBAAQ,IAAI,CAAC,GAAG,MACf;AAAA,UAAC;AAAA;AAAA,YAEC,MAAM,MAAM,WAAW,aAAa;AAAA,YACpC,MAAM;AAAA,YACN,OAAO,EAAE;AAAA,YACT,OAAO,EAAE;AAAA,YACT,aAAa,EAAE;AAAA,YACf,MAAM,EAAE;AAAA,YACR,UAAU,EAAE;AAAA,YACZ,SAAS;AAAA,YACT,UAAU,CAAC,MAAM,YAAY,YAAY,MAAM,IAAI,OAAO;AAAA,YAC1D,SAAS,UAAU,EAAE,KAAK;AAAA,YAC1B,iBAAiB,CAAC,OAAO,OAAO,EAAE,OAAO,EAAE;AAAA,YAC3C,WAAW;AAAA;AAAA,UAZN,EAAE;AAAA,QAaT,CACD,GACH;AAAA,QACC,aACC,oBAAC,OAAE,IAAI,SAAS,WAAU,uDACvB,iBACH;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":["ChoiceCard"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/choice-card.tsx"],"sourcesContent":["import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useRef } from \"react\";\nimport type { ChangeEvent, ComponentType, InputHTMLAttributes, ReactNode } from \"react\";\nimport { Check, Minus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { assignRef, hasMessage, mergeDescribedBy } from \"./choice-parts\";\n\n/**\n * A checkbox or a radio, presented as a bordered card: a title, a line of description,\n * an optional icon — and the whole card is the hit area.\n *\n * Kastlan built this twice by hand: the \"manage roles\" dialog wraps a `Checkbox` in a\n * bordered `<label>` per role, and the lease wizard's \"set up recurring rent\" option is\n * a `Checkbox` with `className=\"rounded-md border p-3\"`. Neither had a focus ring on\n * the card or a checked look beyond the 16px box, and the role picker's border stayed\n * grey whether the role was on or off.\n *\n * Still a native `<input>` underneath, for the reasons {@link Checkbox} gives: it\n * submits with its form, answers to `required`, and a radio set sharing a `name` gets\n * the browser's own arrow-key behaviour — which already flips in a right-to-left page.\n * The card is a `<label>` wrapped round it, so a click anywhere on the card lands on\n * the input; the input is NAMED by the title alone and DESCRIBED by the description,\n * so a screen reader does not read the whole card as its name.\n *\n * Checked is said three ways, none of them colour alone: the box's tick (or the\n * radio's dot), a heavier border, and the brand-tinted surface.\n */\n\nexport type ChoiceCardType = \"checkbox\" | \"radio\";\n\nexport interface ChoiceCardProps extends Omit<InputHTMLAttributes<HTMLInputElement>, \"type\" | \"title\"> {\n /** \"checkbox\" (default) for an on/off option or one of several; \"radio\" for one of\n * a set — give every card of the set the same `name`, or use {@link ChoiceCardGroup}. */\n type?: ChoiceCardType;\n /** The option's name — the input's accessible name. */\n title: ReactNode;\n /** A line or two under the title. Attached with `aria-describedby`. */\n description?: ReactNode;\n /** A Lucide icon (or any component taking a `className`), shown at the card's start. */\n icon?: ComponentType<{ className?: string; \"aria-hidden\"?: boolean }>;\n /** Checkbox only: \"some but not all\". See {@link CheckboxProps.indeterminate}. */\n indeterminate?: boolean;\n /** Paints the card and sets `aria-invalid` together. */\n invalid?: boolean;\n /** What is wrong, in the caller's words. Rendered in the card and attached with\n * `aria-describedby`; implies `invalid`. */\n error?: ReactNode;\n /** The checked state as a boolean. Fires alongside `onChange`, never instead of it. */\n onCheckedChange?: (checked: boolean) => void;\n /** Classes for the `<input>`. `className` styles the card. */\n inputClassName?: string;\n /**\n * Must be ticked to submit. Reaches the `<input>` as the native `required` (a\n * `<form>` refuses to submit without it, a screen reader announces \"required\"),\n * and draws the kit's `aria-hidden` star after the title — {@link Checkbox}'s\n * contract, down to writing the title WITHOUT a literal \"*\". Inside a\n * {@link ChoiceCardGroup} the star goes on the legend instead, once.\n */\n required?: boolean;\n}\n\n/** Set by {@link ChoiceCardGroup}: its legend carries the one required mark, so the\n * cards inside it draw none of their own. Private — not a prop a caller could set\n * by accident on a lone card. */\nconst InGroupContext = createContext(false);\n\n/** The kit's required mark — {@link Label}'s: `aria-hidden`, because the word is\n * announced from the control and a star read out in the name is only noise. */\nfunction RequiredMark() {\n return (\n <span aria-hidden className=\"ms-0.5 text-[var(--danger)]\">\n *\n </span>\n );\n}\n\n// The card. `has-[:checked]` and `has-[:focus-visible]` read the INPUT's state, so an\n// uncontrolled card (`defaultChecked`, a plain form) looks right with no React state.\nconst CARD =\n \"flex cursor-pointer items-start gap-3 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] p-3 shadow-sm transition-colors \" +\n \"hover:border-[var(--border-strong)] hover:bg-[var(--bg-hover)] \" +\n \"has-[:checked]:border-[var(--brand)] has-[:checked]:bg-[var(--brand-bg)] has-[:checked]:ring-1 has-[:checked]:ring-[var(--brand)] \" +\n // The focus mark is the CARD's, not the 16px box's: the card is what was clicked and\n // what the eye is on. An OUTLINE rather than a ring, because the checked state already\n // spends the ring — two `ring-*` widths on one element are decided by stylesheet\n // order, and the loser would be the focus mark. Offset, so the two never merge.\n \"has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-[var(--brand)] \" +\n // Read from the input too, so a card disabled by its `<fieldset>` fades as well.\n \"has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-60\";\n\n// No hover offer on a card that cannot be changed.\nconst CARD_DISABLED = \"hover:border-[var(--border)] hover:bg-[var(--bg-surface)]\";\n\nconst CARD_INVALID =\n \"border-[var(--danger-border)] ring-1 ring-[var(--danger-border)] has-[:checked]:border-[var(--danger-border)] has-[:checked]:ring-[var(--danger-border)]\";\n\nconst BOX =\n \"peer size-4 shrink-0 appearance-none border border-[var(--border-strong)] bg-[var(--bg-surface)] transition-colors \" +\n \"checked:border-[var(--brand)] focus:outline-none disabled:cursor-not-allowed\";\nconst CHECKBOX = \"rounded-[4px] checked:bg-[var(--brand)]\";\n// A radio's dot is its BORDER: a 5px brand border round a surface-coloured 4px\n// centre. No glyph to lay over it, and it scales with the box.\nconst RADIO = \"rounded-full checked:border-[5px]\";\n\nexport const ChoiceCard = forwardRef<HTMLInputElement, ChoiceCardProps>(function ChoiceCard(\n {\n type = \"checkbox\",\n title,\n description,\n icon: Icon,\n indeterminate = false,\n invalid,\n error,\n onCheckedChange,\n onChange,\n className,\n inputClassName,\n id,\n disabled,\n required,\n ...rest\n },\n ref,\n) {\n const inGroup = useContext(InGroupContext);\n const generated = useId();\n const inputId = id ?? generated;\n const titleId = `${inputId}-title`;\n const descriptionId = `${inputId}-description`;\n const errorId = `${inputId}-error`;\n const showDescription = hasMessage(description);\n const showError = hasMessage(error);\n const isInvalid = Boolean(invalid) || showError;\n const mixed = type === \"checkbox\" && indeterminate;\n\n const local = useRef<HTMLInputElement | null>(null);\n const setRef = useCallback(\n (node: HTMLInputElement | null) => {\n local.current = node;\n assignRef(ref, node);\n },\n [ref],\n );\n // After every render, as Checkbox does: a click clears the DOM property.\n useEffect(() => {\n if (local.current) local.current.indeterminate = mixed;\n });\n\n return (\n <label\n htmlFor={inputId}\n className={cn(CARD, disabled && CARD_DISABLED, isInvalid && CARD_INVALID, className)}\n >\n {/* A 20px cell, so the box centres on the title's first line (text-sm). */}\n <span className=\"relative flex h-5 shrink-0 items-center\">\n <input\n ref={setRef}\n id={inputId}\n disabled={disabled}\n required={required}\n {...rest}\n type={type}\n aria-labelledby={rest[\"aria-labelledby\"] ?? titleId}\n aria-invalid={isInvalid || rest[\"aria-invalid\"] || undefined}\n aria-describedby={mergeDescribedBy(\n rest[\"aria-describedby\"],\n showDescription && descriptionId,\n showError && errorId,\n )}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n onCheckedChange?.(e.target.checked);\n }}\n className={cn(\n BOX,\n type === \"radio\" ? RADIO : CHECKBOX,\n mixed && \"border-[var(--brand)] bg-[var(--brand)]\",\n inputClassName,\n )}\n />\n {type === \"checkbox\" &&\n (mixed ? (\n <Minus\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none absolute inset-0 m-auto size-3 text-[var(--brand-contrast)]\"\n />\n ) : (\n <Check\n aria-hidden\n strokeWidth={3}\n className=\"pointer-events-none invisible absolute inset-0 m-auto size-3 text-[var(--brand-contrast)] peer-checked:visible\"\n />\n ))}\n </span>\n {Icon && <Icon aria-hidden className=\"mt-0.5 size-4 shrink-0 text-[var(--text-secondary)]\" />}\n <span className=\"min-w-0 flex-1\">\n <span\n id={titleId}\n // `select-none`: a double-click to toggle twice would otherwise select the words.\n className=\"block select-none text-sm font-medium leading-5 text-[var(--text-primary)]\"\n >\n {title}\n {required && !inGroup && <RequiredMark />}\n </span>\n {showDescription && (\n <span id={descriptionId} className=\"mt-0.5 block text-xs text-[var(--text-muted)]\">\n {description}\n </span>\n )}\n {showError && (\n <span id={errorId} className=\"mt-1 block text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </span>\n )}\n </span>\n </label>\n );\n});\nChoiceCard.displayName = \"ChoiceCard\";\n\n/* ── ChoiceCardGroup ─────────────────────────────────────────────────────── */\n\nexport interface ChoiceCardOption<T extends string> {\n value: T;\n title: ReactNode;\n description?: ReactNode;\n icon?: ChoiceCardProps[\"icon\"];\n disabled?: boolean;\n}\n\ninterface ChoiceCardGroupBaseProps<T extends string> {\n options: ChoiceCardOption<T>[];\n /** The question the cards answer. Rendered as the fieldset's `<legend>`, which is\n * what names the group. Without one, pass `aria-label`. */\n legend?: ReactNode;\n \"aria-label\"?: string;\n /** Shared by every input — what a plain form submits under. Generated if omitted. */\n name?: string;\n /** Classes for the card grid. Default: one column, two from `sm` up. */\n className?: string;\n /** Classes for every card. */\n cardClassName?: string;\n disabled?: boolean;\n /** What is wrong with the answer as a whole. Rendered under the cards and attached\n * to the fieldset. */\n error?: ReactNode;\n /**\n * An answer is needed. Draws the required star after the `legend` (none without\n * one — the name then comes from `aria-label`, which has nowhere to draw it), and\n * reaches the inputs as the native `required`:\n * - radios: every radio of the set, which is how HTML marks a radio group — the\n * group is satisfied by any one of them, and each announces \"required\";\n * - checkboxes: every box while NONE is ticked, dropped from all of them once one\n * is — \"at least one\", which checkboxes cannot say natively. A form then refuses\n * to submit an empty set, and nothing is left demanding a second box.\n */\n required?: boolean;\n}\n\n/** One of the set: radios. `value` is `null` while nothing is chosen. */\nexport interface ChoiceCardSingleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple?: false;\n value: T | null;\n onChange: (value: T) => void;\n}\n\n/** Any of the set: checkboxes. */\nexport interface ChoiceCardMultipleProps<T extends string> extends ChoiceCardGroupBaseProps<T> {\n multiple: true;\n value: T[];\n onChange: (value: T[]) => void;\n}\n\nexport type ChoiceCardGroupProps<T extends string> =\n | ChoiceCardSingleProps<T>\n | ChoiceCardMultipleProps<T>;\n\n/**\n * A set of {@link ChoiceCard}s answering one question, in a `<fieldset>`.\n *\n * `multiple` picks the input: radios (one of the set, the browser's arrow keys\n * between them) or checkboxes (any of the set, Tab between them). The value is kept\n * in the order of `options`, not the order the boxes were ticked, so a list saved\n * from it does not depend on the order someone clicked in.\n */\nexport function ChoiceCardGroup<T extends string>(props: ChoiceCardGroupProps<T>) {\n const { options, legend, name, className, cardClassName, disabled, error, required } = props;\n const generated = useId();\n const groupName = name ?? generated;\n const errorId = `${generated}-error`;\n const showError = hasMessage(error);\n\n const isChecked = (v: T) => (props.multiple ? props.value.includes(v) : props.value === v);\n const toggle = (v: T, on: boolean) => {\n if (props.multiple) {\n const next = new Set(props.value);\n if (on) next.add(v);\n else next.delete(v);\n props.onChange(options.map((o) => o.value).filter((x) => next.has(x)));\n } else if (on) {\n props.onChange(v);\n }\n };\n\n return (\n <InGroupContext.Provider value={true}>\n <fieldset\n aria-label={props[\"aria-label\"]}\n aria-describedby={showError ? errorId : undefined}\n disabled={disabled}\n className=\"min-w-0\"\n >\n {legend !== undefined && (\n <legend className=\"mb-2 text-sm font-medium text-[var(--text-primary)]\">\n {legend}\n {required && <RequiredMark />}\n </legend>\n )}\n <div className={cn(\"grid gap-2 sm:grid-cols-2\", className)}>\n {options.map((o) => (\n <ChoiceCard\n key={o.value}\n type={props.multiple ? \"checkbox\" : \"radio\"}\n name={groupName}\n value={o.value}\n title={o.title}\n description={o.description}\n icon={o.icon}\n disabled={o.disabled}\n invalid={showError}\n required={required && (!props.multiple || props.value.length === 0) ? true : undefined}\n checked={isChecked(o.value)}\n onCheckedChange={(on) => toggle(o.value, on)}\n className={cardClassName}\n />\n ))}\n </div>\n {showError && (\n <p id={errorId} className=\"mt-1 text-[11px] leading-tight text-[var(--danger)]\">\n {error}\n </p>\n )}\n </fieldset>\n </InGroupContext.Provider>\n );\n}\n"],"mappings":";AAqEI,cAoFE,YApFF;AArEJ,SAAS,eAAe,YAAY,aAAa,YAAY,WAAW,OAAO,cAAc;AAE7F,SAAS,OAAO,aAAa;AAC7B,SAAS,UAAU;AACnB,SAAS,WAAW,YAAY,wBAAwB;AA2DxD,MAAM,iBAAiB,cAAc,KAAK;AAI1C,SAAS,eAAe;AACtB,SACE,oBAAC,UAAK,eAAW,MAAC,WAAU,+BAA8B,eAE1D;AAEJ;AAIA,MAAM,OACJ;AAYF,MAAM,gBAAgB;AAEtB,MAAM,eACJ;AAEF,MAAM,MACJ;AAEF,MAAM,WAAW;AAGjB,MAAM,QAAQ;AAEP,MAAM,aAAa,WAA8C,SAASA,YAC/E;AAAA,EACE,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM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AC;AAAA,IAClB;AAAA,EACF;AAEA,SACE,oBAAC,eAAe,UAAf,EAAwB,OAAO,MAC9B;AAAA,IAAC;AAAA;AAAA,MACC,cAAY,MAAM,YAAY;AAAA,MAC9B,oBAAkB,YAAY,UAAU;AAAA,MACxC;AAAA,MACA,WAAU;AAAA,MAET;AAAA,mBAAW,UACV,qBAAC,YAAO,WAAU,uDACf;AAAA;AAAA,UACA,YAAY,oBAAC,gBAAa;AAAA,WAC7B;AAAA,QAEF,oBAAC,SAAI,WAAW,GAAG,6BAA6B,SAAS,GACtD,kBAAQ,IAAI,CAAC,MACZ;AAAA,UAAC;AAAA;AAAA,YAEC,MAAM,MAAM,WAAW,aAAa;AAAA,YACpC,MAAM;AAAA,YACN,OAAO,EAAE;AAAA,YACT,OAAO,EAAE;AAAA,YACT,aAAa,EAAE;AAAA,YACf,MAAM,EAAE;AAAA,YACR,UAAU,EAAE;AAAA,YACZ,SAAS;AAAA,YACT,UAAU,aAAa,CAAC,MAAM,YAAY,MAAM,MAAM,WAAW,KAAK,OAAO;AAAA,YAC7E,SAAS,UAAU,EAAE,KAAK;AAAA,YAC1B,iBAAiB,CAAC,OAAO,OAAO,EAAE,OAAO,EAAE;AAAA,YAC3C,WAAW;AAAA;AAAA,UAZN,EAAE;AAAA,QAaT,CACD,GACH;AAAA,QACC,aACC,oBAAC,OAAE,IAAI,SAAS,WAAU,uDACvB,iBACH;AAAA;AAAA;AAAA,EAEJ,GACF;AAEJ;","names":["ChoiceCard"]}
|
|
@@ -3,6 +3,20 @@ import { ReactNode, RefObject, Dispatch, SetStateAction, ComponentPropsWithoutRe
|
|
|
3
3
|
import { AnchorRect } from '../hooks/use-anchored-rect.js';
|
|
4
4
|
import { AnchoredPanel } from '../hooks/use-anchored-panel.js';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* What an entity picker hands `onChange` when it is cleared — `clearValue` on
|
|
8
|
+
* {@link EntityCombobox} and {@link InlineEntityCombobox}. `null` by default.
|
|
9
|
+
*
|
|
10
|
+
* A closed set rather than any value, on purpose: every member is something no
|
|
11
|
+
* option can be (an option's value is a `string | number`, and `""` is never a real
|
|
12
|
+
* id), so the picker can also READ it back — a field whose `value` is the clear
|
|
13
|
+
* value shows as empty, with no clear button, exactly as `null` does. An arbitrary
|
|
14
|
+
* sentinel could collide with an id and would make that read ambiguous.
|
|
15
|
+
*
|
|
16
|
+
* No `undefined`: a prop set to `undefined` is a prop not passed, so it would read as
|
|
17
|
+
* the default and emit `null` — the one outcome the caller had asked not to get.
|
|
18
|
+
*/
|
|
19
|
+
type ComboClearValue = null | "";
|
|
6
20
|
interface ComboOption<V extends string | number> {
|
|
7
21
|
value: V;
|
|
8
22
|
label: string;
|
|
@@ -16,7 +30,52 @@ interface ComboOption<V extends string | number> {
|
|
|
16
30
|
* Searchable like `sublabel`.
|
|
17
31
|
*/
|
|
18
32
|
group?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Shown but not takeable: rendered dimmed with `aria-disabled`, passed over by the
|
|
35
|
+
* arrow keys, and a click or Enter on it does nothing. For a row whose existence is
|
|
36
|
+
* the information — a write-locked result, an account that is closed — where
|
|
37
|
+
* leaving it out would read as "there is no such thing". Say WHY in `sublabel`: a
|
|
38
|
+
* hover tooltip is the one explanation a phone cannot show.
|
|
39
|
+
*
|
|
40
|
+
* Honoured by {@link Autocomplete}, {@link InlineEntityCombobox} and the panel
|
|
41
|
+
* pickers ({@link EntityCombobox}, {@link MultiEntityCombobox}); on those an already
|
|
42
|
+
* chosen disabled option stays chosen — the row only refuses to be toggled.
|
|
43
|
+
*/
|
|
44
|
+
disabled?: boolean;
|
|
19
45
|
}
|
|
46
|
+
/** A row the user may take — present and not {@link ComboOption.disabled}. */
|
|
47
|
+
declare const isOptionEnabled: (o: {
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
} | undefined) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The next takeable row from `from`, stepping `dir` — what the arrow keys use so a
|
|
52
|
+
* disabled row is passed over, as the APG allows. Stays on `from` at the end of the
|
|
53
|
+
* list (the family's arrows clamp rather than wrap) and answers `-1` when `from` is
|
|
54
|
+
* not a row and there is nothing to step to.
|
|
55
|
+
*/
|
|
56
|
+
declare function stepEnabled(rows: readonly {
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
}[], from: number, dir: 1 | -1): number;
|
|
59
|
+
/** `i` when that row is takeable, else the nearest takeable one after it, else
|
|
60
|
+
* before it, else `-1`. For a highlight that starts on a fixed index (the panel
|
|
61
|
+
* pickers open on row 0) and must never rest on a disabled row. */
|
|
62
|
+
declare function settleEnabled(rows: readonly {
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
}[], i: number): number;
|
|
65
|
+
/** Classes a disabled row adds over its normal ones — dimmed, no hover, the
|
|
66
|
+
* kit's soft-disabled look (`DangerConfirm`, `SignaturePad`). */
|
|
67
|
+
declare const DISABLED_ROW_CLASS = "cursor-not-allowed opacity-50 hover:bg-transparent";
|
|
68
|
+
/**
|
|
69
|
+
* The family's floating label, as a real `<label for>` (lenkbank): the input is then
|
|
70
|
+
* named the way {@link Input}'s is, so `getByLabelText` and any helper that walks
|
|
71
|
+
* `<label htmlFor>` finds it. Same placement and type as {@link FieldLabel}, which
|
|
72
|
+
* stays a `<span>` for the TRIGGER pickers — a `<button>` is labelable, but those
|
|
73
|
+
* compose their own "label: value" name. `pointer-events-none` (from the class)
|
|
74
|
+
* keeps a press on it landing on the field under it, as before.
|
|
75
|
+
*/
|
|
76
|
+
declare function ComboboxFieldLabel({ htmlFor, className, children, ...rest }: ComponentPropsWithoutRef<"label"> & {
|
|
77
|
+
htmlFor: string;
|
|
78
|
+
}): react.JSX.Element;
|
|
20
79
|
/**
|
|
21
80
|
* Where a combobox's rows come from, and how a query narrows them. Shared by the
|
|
22
81
|
* trigger pickers ({@link useComboboxCore}) and the inline {@link Autocomplete}, so
|
|
@@ -161,7 +220,7 @@ interface ComboboxPanelProps<V extends string | number> extends ComponentPropsWi
|
|
|
161
220
|
}
|
|
162
221
|
/**
|
|
163
222
|
* The portalled dropdown (search header + result rows + optional create row)
|
|
164
|
-
* shared by the single- and multi-value comboboxes.
|
|
223
|
+
* shared by the single- and multi-value comboboxes. Start-aligned to the trigger
|
|
165
224
|
* and sized to its width; `multi` swaps the trailing check for a leading
|
|
166
225
|
* checkbox. `onChoose` decides whether to close (single) or stay open (multi).
|
|
167
226
|
*
|
|
@@ -187,4 +246,4 @@ interface ComboboxPanelProps<V extends string | number> extends ComponentPropsWi
|
|
|
187
246
|
*/
|
|
188
247
|
declare function ComboboxPanel<V extends string | number>({ core, listboxId, searchPlaceholder, emptyLabel, multi, isSelected, onChoose, showCreate, onCreate, createContent, sheetTitle, closeLabel, loadErrorLabel, className, style, ...rest }: ComboboxPanelProps<V>): react.JSX.Element | null;
|
|
189
248
|
|
|
190
|
-
export { type ComboOption, type ComboboxCore, type ComboboxCoreOptions, ComboboxPanel, type ComboboxPanelProps, type OptionSource, type OptionSourceOptions, SUGGESTION_LIST_CLASS, suggestionRowClass, useActiveOptionScroll, useComboboxCore, useComboboxFieldError, useOptionSource };
|
|
249
|
+
export { type ComboClearValue, type ComboOption, type ComboboxCore, type ComboboxCoreOptions, ComboboxFieldLabel, ComboboxPanel, type ComboboxPanelProps, DISABLED_ROW_CLASS, type OptionSource, type OptionSourceOptions, SUGGESTION_LIST_CLASS, isOptionEnabled, settleEnabled, stepEnabled, suggestionRowClass, useActiveOptionScroll, useComboboxCore, useComboboxFieldError, useOptionSource };
|