@contui/ui 0.0.0-stage → 0.1.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/LICENSE +30 -0
- package/README.md +150 -2
- package/cli/contui.mjs +250 -0
- package/dist/charts/area-chart.d.ts +8 -0
- package/dist/charts/area-chart.js +9 -0
- package/dist/charts/bar-chart.d.ts +9 -0
- package/dist/charts/bar-chart.js +10 -0
- package/dist/charts/bubble-chart.d.ts +60 -0
- package/dist/charts/bubble-chart.js +392 -0
- package/dist/charts/bullet-chart.d.ts +53 -0
- package/dist/charts/bullet-chart.js +123 -0
- package/dist/charts/candlestick-chart.d.ts +77 -0
- package/dist/charts/candlestick-chart.js +558 -0
- package/dist/charts/cartesian.d.ts +121 -0
- package/dist/charts/cartesian.js +625 -0
- package/dist/charts/chart-card.d.ts +80 -0
- package/dist/charts/chart-card.js +114 -0
- package/dist/charts/donut-chart.d.ts +40 -0
- package/dist/charts/donut-chart.js +88 -0
- package/dist/charts/funnel-chart.d.ts +16 -0
- package/dist/charts/funnel-chart.js +164 -0
- package/dist/charts/horizontal-bar-chart.d.ts +67 -0
- package/dist/charts/horizontal-bar-chart.js +481 -0
- package/dist/charts/index.d.ts +21 -0
- package/dist/charts/index.js +32 -0
- package/dist/charts/legend.d.ts +23 -0
- package/dist/charts/legend.js +22 -0
- package/dist/charts/lib/candlestick-window.d.ts +15 -0
- package/dist/charts/lib/candlestick-window.js +23 -0
- package/dist/charts/lib/color.d.ts +39 -0
- package/dist/charts/lib/color.js +83 -0
- package/dist/charts/lib/format.d.ts +11 -0
- package/dist/charts/lib/format.js +33 -0
- package/dist/charts/lib/frame.d.ts +6 -0
- package/dist/charts/lib/frame.js +6 -0
- package/dist/charts/lib/layout.d.ts +11 -0
- package/dist/charts/lib/layout.js +71 -0
- package/dist/charts/lib/path.d.ts +35 -0
- package/dist/charts/lib/path.js +203 -0
- package/dist/charts/lib/scale.d.ts +41 -0
- package/dist/charts/lib/scale.js +80 -0
- package/dist/charts/lib/use-active.d.ts +18 -0
- package/dist/charts/lib/use-active.js +71 -0
- package/dist/charts/lib/use-size.d.ts +9 -0
- package/dist/charts/lib/use-size.js +40 -0
- package/dist/charts/line-chart.d.ts +7 -0
- package/dist/charts/line-chart.js +8 -0
- package/dist/charts/radar-chart.d.ts +27 -0
- package/dist/charts/radar-chart.js +165 -0
- package/dist/charts/rose-chart.d.ts +35 -0
- package/dist/charts/rose-chart.js +242 -0
- package/dist/charts/sparkline.d.ts +35 -0
- package/dist/charts/sparkline.js +110 -0
- package/dist/charts/tooltip.d.ts +35 -0
- package/dist/charts/tooltip.js +22 -0
- package/dist/charts/treemap.d.ts +28 -0
- package/dist/charts/treemap.js +103 -0
- package/dist/charts/uptime-strip.d.ts +40 -0
- package/dist/charts/uptime-strip.js +178 -0
- package/dist/components/accordion.d.ts +31 -0
- package/dist/components/accordion.js +34 -0
- package/dist/components/activity-item.d.ts +12 -0
- package/dist/components/activity-item.js +6 -0
- package/dist/components/alert.d.ts +21 -0
- package/dist/components/alert.js +58 -0
- package/dist/components/assistant-answer.d.ts +52 -0
- package/dist/components/assistant-answer.js +40 -0
- package/dist/components/assistant-prompt.d.ts +63 -0
- package/dist/components/assistant-prompt.js +122 -0
- package/dist/components/avatar.d.ts +28 -0
- package/dist/components/avatar.js +75 -0
- package/dist/components/badge.d.ts +16 -0
- package/dist/components/badge.js +33 -0
- package/dist/components/bar-list.d.ts +65 -0
- package/dist/components/bar-list.js +119 -0
- package/dist/components/block-slider.d.ts +43 -0
- package/dist/components/block-slider.js +63 -0
- package/dist/components/branch-graph.d.ts +87 -0
- package/dist/components/branch-graph.js +231 -0
- package/dist/components/breadcrumb.d.ts +41 -0
- package/dist/components/breadcrumb.js +53 -0
- package/dist/components/button.d.ts +23 -0
- package/dist/components/button.js +108 -0
- package/dist/components/calendar.d.ts +5 -0
- package/dist/components/calendar.js +90 -0
- package/dist/components/card.d.ts +65 -0
- package/dist/components/card.js +104 -0
- package/dist/components/chat-attachment.d.ts +47 -0
- package/dist/components/chat-attachment.js +63 -0
- package/dist/components/chat-event.d.ts +7 -0
- package/dist/components/chat-event.js +7 -0
- package/dist/components/chat-message.d.ts +59 -0
- package/dist/components/chat-message.js +91 -0
- package/dist/components/chat-reference.d.ts +20 -0
- package/dist/components/chat-reference.js +41 -0
- package/dist/components/chat-shared.d.ts +21 -0
- package/dist/components/chat-shared.js +23 -0
- package/dist/components/chat-suggestions.d.ts +59 -0
- package/dist/components/chat-suggestions.js +88 -0
- package/dist/components/chat-thread.d.ts +39 -0
- package/dist/components/chat-thread.js +172 -0
- package/dist/components/chat-typing.d.ts +35 -0
- package/dist/components/chat-typing.js +66 -0
- package/dist/components/checkbox.d.ts +18 -0
- package/dist/components/checkbox.js +33 -0
- package/dist/components/checklist.d.ts +26 -0
- package/dist/components/checklist.js +18 -0
- package/dist/components/chip.d.ts +29 -0
- package/dist/components/chip.js +61 -0
- package/dist/components/code-input.d.ts +40 -0
- package/dist/components/code-input.js +285 -0
- package/dist/components/color-picker.d.ts +38 -0
- package/dist/components/color-picker.js +855 -0
- package/dist/components/combobox.d.ts +75 -0
- package/dist/components/combobox.js +112 -0
- package/dist/components/command-menu.d.ts +58 -0
- package/dist/components/command-menu.js +166 -0
- package/dist/components/copy-button.d.ts +16 -0
- package/dist/components/copy-button.js +31 -0
- package/dist/components/data-grid.d.ts +50 -0
- package/dist/components/data-grid.js +599 -0
- package/dist/components/date-picker.d.ts +109 -0
- package/dist/components/date-picker.js +268 -0
- package/dist/components/description-list.d.ts +12 -0
- package/dist/components/description-list.js +10 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +140 -0
- package/dist/components/dock.d.ts +45 -0
- package/dist/components/dock.js +79 -0
- package/dist/components/drop-zone.d.ts +46 -0
- package/dist/components/drop-zone.js +101 -0
- package/dist/components/dropdown-menu.d.ts +50 -0
- package/dist/components/dropdown-menu.js +78 -0
- package/dist/components/editable-cell.d.ts +34 -0
- package/dist/components/editable-cell.js +89 -0
- package/dist/components/empty-state.d.ts +17 -0
- package/dist/components/empty-state.js +9 -0
- package/dist/components/field.d.ts +43 -0
- package/dist/components/field.js +75 -0
- package/dist/components/filter-condition.d.ts +188 -0
- package/dist/components/filter-condition.js +113 -0
- package/dist/components/filter-menu.d.ts +57 -0
- package/dist/components/filter-menu.js +46 -0
- package/dist/components/header-bar.d.ts +84 -0
- package/dist/components/header-bar.js +94 -0
- package/dist/components/hold-button.d.ts +15 -0
- package/dist/components/hold-button.js +88 -0
- package/dist/components/icon-tile.d.ts +12 -0
- package/dist/components/icon-tile.js +29 -0
- package/dist/components/info-tip.d.ts +13 -0
- package/dist/components/info-tip.js +26 -0
- package/dist/components/input.d.ts +17 -0
- package/dist/components/input.js +83 -0
- package/dist/components/kbd.d.ts +6 -0
- package/dist/components/kbd.js +7 -0
- package/dist/components/menu-item.d.ts +56 -0
- package/dist/components/menu-item.js +94 -0
- package/dist/components/message-composer.d.ts +75 -0
- package/dist/components/message-composer.js +199 -0
- package/dist/components/nav-rail.d.ts +31 -0
- package/dist/components/nav-rail.js +85 -0
- package/dist/components/notice.d.ts +45 -0
- package/dist/components/notice.js +66 -0
- package/dist/components/optimistic-undo.d.ts +28 -0
- package/dist/components/optimistic-undo.js +43 -0
- package/dist/components/option-row.d.ts +15 -0
- package/dist/components/option-row.js +14 -0
- package/dist/components/page-content.d.ts +11 -0
- package/dist/components/page-content.js +31 -0
- package/dist/components/pagination.d.ts +34 -0
- package/dist/components/pagination.js +41 -0
- package/dist/components/popover.d.ts +27 -0
- package/dist/components/popover.js +25 -0
- package/dist/components/progress.d.ts +33 -0
- package/dist/components/progress.js +75 -0
- package/dist/components/radio-group.d.ts +7 -0
- package/dist/components/radio-group.js +33 -0
- package/dist/components/readonly-field.d.ts +33 -0
- package/dist/components/readonly-field.js +80 -0
- package/dist/components/segmented-control.d.ts +21 -0
- package/dist/components/segmented-control.js +108 -0
- package/dist/components/select.d.ts +42 -0
- package/dist/components/select.js +86 -0
- package/dist/components/separator.d.ts +10 -0
- package/dist/components/separator.js +7 -0
- package/dist/components/setting-row.d.ts +53 -0
- package/dist/components/setting-row.js +93 -0
- package/dist/components/sidebar-switcher.d.ts +47 -0
- package/dist/components/sidebar-switcher.js +20 -0
- package/dist/components/sidebar.d.ts +220 -0
- package/dist/components/sidebar.js +327 -0
- package/dist/components/skeleton.d.ts +18 -0
- package/dist/components/skeleton.js +23 -0
- package/dist/components/slider.d.ts +15 -0
- package/dist/components/slider.js +28 -0
- package/dist/components/spinner.d.ts +14 -0
- package/dist/components/spinner.js +19 -0
- package/dist/components/status-dot.d.ts +24 -0
- package/dist/components/status-dot.js +35 -0
- package/dist/components/stepper.d.ts +60 -0
- package/dist/components/stepper.js +197 -0
- package/dist/components/switch.d.ts +9 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table-cell.d.ts +38 -0
- package/dist/components/table-cell.js +107 -0
- package/dist/components/table-context.d.ts +48 -0
- package/dist/components/table-context.js +69 -0
- package/dist/components/table-head.d.ts +42 -0
- package/dist/components/table-head.js +188 -0
- package/dist/components/table-tree.d.ts +96 -0
- package/dist/components/table-tree.js +137 -0
- package/dist/components/table.d.ts +78 -0
- package/dist/components/table.js +119 -0
- package/dist/components/tabs.d.ts +27 -0
- package/dist/components/tabs.js +79 -0
- package/dist/components/textarea.d.ts +3 -0
- package/dist/components/textarea.js +20 -0
- package/dist/components/theme.d.ts +41 -0
- package/dist/components/theme.js +60 -0
- package/dist/components/thinking.d.ts +68 -0
- package/dist/components/thinking.js +94 -0
- package/dist/components/toast.d.ts +39 -0
- package/dist/components/toast.js +110 -0
- package/dist/components/toolbar.d.ts +25 -0
- package/dist/components/toolbar.js +92 -0
- package/dist/components/tooltip.d.ts +23 -0
- package/dist/components/tooltip.js +27 -0
- package/dist/components/top-nav.d.ts +129 -0
- package/dist/components/top-nav.js +211 -0
- package/dist/components/truncate.d.ts +29 -0
- package/dist/components/truncate.js +138 -0
- package/dist/deprecated.d.ts +43 -0
- package/dist/deprecated.js +47 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +93 -0
- package/dist/lib/cn.d.ts +5 -0
- package/dist/lib/cn.js +14 -0
- package/dist/lib/color.d.ts +136 -0
- package/dist/lib/color.js +307 -0
- package/dist/lib/contrast.d.ts +53 -0
- package/dist/lib/contrast.js +169 -0
- package/dist/lib/create-theme.d.ts +240 -0
- package/dist/lib/create-theme.js +461 -0
- package/dist/lib/harmony.d.ts +102 -0
- package/dist/lib/harmony.js +426 -0
- package/dist/lib/import-theme.d.ts +22 -0
- package/dist/lib/import-theme.js +221 -0
- package/dist/lib/overflow-scroll.d.ts +25 -0
- package/dist/lib/overflow-scroll.js +66 -0
- package/dist/lib/radio-toggle-render.d.ts +3 -0
- package/dist/lib/radio-toggle-render.js +9 -0
- package/dist/lib/reorder.d.ts +38 -0
- package/dist/lib/reorder.js +193 -0
- package/dist/lib/spacing.d.ts +101 -0
- package/dist/lib/spacing.js +118 -0
- package/dist/lib/tailwind-palette.d.ts +5 -0
- package/dist/lib/tailwind-palette.js +351 -0
- package/dist/lib/truncate.d.ts +18 -0
- package/dist/lib/truncate.js +69 -0
- package/dist/lib/use-single-value.d.ts +5 -0
- package/dist/lib/use-single-value.js +17 -0
- package/dist/styles.css +7988 -0
- package/mcp/server.mjs +87590 -0
- package/package.json +58 -5
- package/skills/continuum-fix-padding/SKILL.md +69 -0
- package/skills/continuum-fix-padding/scripts/compute.ts +155 -0
- package/skills/continuum-fix-padding/scripts/spacing.ts +189 -0
- package/skills/continuum-taste/SKILL.md +186 -0
- package/skills/continuum-taste/assets/tokens.css +647 -0
- package/skills/continuum-taste/references/charts.md +375 -0
- package/skills/continuum-taste/references/components.md +1369 -0
- package/skills/continuum-taste/references/foundations.md +539 -0
- package/skills/continuum-taste/references/media/canvas.md +75 -0
- package/skills/continuum-taste/references/media/css.md +61 -0
- package/skills/continuum-taste/references/media/react.md +161 -0
- package/skills/continuum-taste/references/method.md +87 -0
- package/skills/continuum-taste/references/pages.md +391 -0
- package/skills/continuum-taste/references/patterns.md +77 -0
- package/skills/continuum-taste/references/screens/agent.tsx +450 -0
- package/skills/continuum-taste/references/screens/analytics-overview.tsx +377 -0
- package/skills/continuum-taste/references/screens/checkout-funnel.tsx +193 -0
- package/skills/continuum-taste/references/screens/customer.tsx +475 -0
- package/skills/continuum-taste/references/screens/customers.tsx +608 -0
- package/skills/continuum-taste/references/screens/index.tsx +72 -0
- package/skills/continuum-taste/references/screens/invoice-editor.tsx +558 -0
- package/skills/continuum-taste/references/screens/new-customer.tsx +205 -0
- package/skills/continuum-taste/references/screens/overview.tsx +196 -0
- package/skills/continuum-taste/references/screens/report-generator.tsx +329 -0
- package/skills/continuum-taste/references/screens/risk-report.tsx +577 -0
- package/skills/continuum-taste/references/screens/sequence-editor.tsx +455 -0
- package/skills/continuum-taste/references/screens/settings.tsx +288 -0
- package/skills/continuum-taste/references/screens/shared.tsx +204 -0
- package/skills/continuum-taste/references/screens/sign-in.tsx +104 -0
- package/skills/continuum-taste/references/screens/workspace.tsx +596 -0
- package/skills/continuum-taste/references/theming.md +95 -0
- package/src/charts/area-chart.tsx +17 -0
- package/src/charts/bar-chart.tsx +15 -0
- package/src/charts/bubble-chart.tsx +913 -0
- package/src/charts/bullet-chart.tsx +419 -0
- package/src/charts/candlestick-chart.tsx +1242 -0
- package/src/charts/cartesian.tsx +1437 -0
- package/src/charts/chart-card.tsx +394 -0
- package/src/charts/donut-chart.tsx +299 -0
- package/src/charts/funnel-chart.tsx +373 -0
- package/src/charts/horizontal-bar-chart.tsx +991 -0
- package/src/charts/index.ts +76 -0
- package/src/charts/legend.tsx +59 -0
- package/src/charts/lib/candlestick-window.ts +42 -0
- package/src/charts/lib/color.ts +110 -0
- package/src/charts/lib/format.ts +42 -0
- package/src/charts/lib/frame.ts +6 -0
- package/src/charts/lib/layout.ts +78 -0
- package/src/charts/lib/path.ts +225 -0
- package/src/charts/lib/scale.ts +91 -0
- package/src/charts/lib/use-active.ts +87 -0
- package/src/charts/lib/use-size.ts +45 -0
- package/src/charts/line-chart.tsx +16 -0
- package/src/charts/radar-chart.tsx +485 -0
- package/src/charts/rose-chart.tsx +553 -0
- package/src/charts/sparkline.tsx +293 -0
- package/src/charts/tooltip.tsx +105 -0
- package/src/charts/treemap.tsx +271 -0
- package/src/charts/uptime-strip.tsx +469 -0
- package/src/components/accordion.tsx +136 -0
- package/src/components/activity-item.tsx +43 -0
- package/src/components/alert.tsx +135 -0
- package/src/components/assistant-answer.tsx +185 -0
- package/src/components/assistant-prompt.tsx +352 -0
- package/src/components/avatar.tsx +157 -0
- package/src/components/badge.tsx +55 -0
- package/src/components/bar-list.tsx +350 -0
- package/src/components/block-slider.tsx +189 -0
- package/src/components/branch-graph.tsx +580 -0
- package/src/components/breadcrumb.tsx +173 -0
- package/src/components/button.tsx +157 -0
- package/src/components/calendar.tsx +154 -0
- package/src/components/card.tsx +296 -0
- package/src/components/chat-attachment.tsx +255 -0
- package/src/components/chat-event.tsx +34 -0
- package/src/components/chat-message.tsx +332 -0
- package/src/components/chat-reference.tsx +100 -0
- package/src/components/chat-shared.ts +41 -0
- package/src/components/chat-suggestions.tsx +188 -0
- package/src/components/chat-thread.tsx +348 -0
- package/src/components/chat-typing.tsx +155 -0
- package/src/components/checkbox.tsx +83 -0
- package/src/components/checklist.tsx +146 -0
- package/src/components/chip.tsx +152 -0
- package/src/components/code-input.tsx +406 -0
- package/src/components/color-picker.tsx +1385 -0
- package/src/components/combobox.tsx +420 -0
- package/src/components/command-menu.tsx +405 -0
- package/src/components/copy-button.tsx +87 -0
- package/src/components/data-grid.tsx +965 -0
- package/src/components/date-picker.tsx +652 -0
- package/src/components/description-list.tsx +39 -0
- package/src/components/dialog.tsx +367 -0
- package/src/components/dock.tsx +192 -0
- package/src/components/drop-zone.tsx +283 -0
- package/src/components/dropdown-menu.tsx +323 -0
- package/src/components/editable-cell.tsx +219 -0
- package/src/components/empty-state.tsx +50 -0
- package/src/components/field.tsx +148 -0
- package/src/components/filter-condition.tsx +463 -0
- package/src/components/filter-menu.tsx +196 -0
- package/src/components/header-bar.tsx +220 -0
- package/src/components/hold-button.tsx +146 -0
- package/src/components/icon-tile.tsx +43 -0
- package/src/components/info-tip.tsx +87 -0
- package/src/components/input.tsx +136 -0
- package/src/components/kbd.tsx +17 -0
- package/src/components/menu-item.tsx +216 -0
- package/src/components/message-composer.tsx +458 -0
- package/src/components/nav-rail.tsx +235 -0
- package/src/components/notice.tsx +133 -0
- package/src/components/optimistic-undo.ts +68 -0
- package/src/components/option-row.tsx +54 -0
- package/src/components/page-content.tsx +44 -0
- package/src/components/pagination.tsx +182 -0
- package/src/components/popover.tsx +113 -0
- package/src/components/progress.tsx +222 -0
- package/src/components/radio-group.tsx +80 -0
- package/src/components/readonly-field.tsx +251 -0
- package/src/components/segmented-control.tsx +205 -0
- package/src/components/select.tsx +259 -0
- package/src/components/separator.tsx +30 -0
- package/src/components/setting-row.tsx +277 -0
- package/src/components/sidebar-switcher.tsx +134 -0
- package/src/components/sidebar.tsx +804 -0
- package/src/components/skeleton.tsx +57 -0
- package/src/components/slider.tsx +106 -0
- package/src/components/spinner.tsx +43 -0
- package/src/components/status-dot.tsx +100 -0
- package/src/components/stepper.tsx +459 -0
- package/src/components/switch.tsx +54 -0
- package/src/components/table-cell.tsx +239 -0
- package/src/components/table-context.ts +135 -0
- package/src/components/table-head.tsx +393 -0
- package/src/components/table-tree.tsx +357 -0
- package/src/components/table.tsx +295 -0
- package/src/components/tabs.tsx +191 -0
- package/src/components/textarea.tsx +44 -0
- package/src/components/theme.tsx +120 -0
- package/src/components/thinking.tsx +295 -0
- package/src/components/toast.tsx +308 -0
- package/src/components/toolbar.tsx +166 -0
- package/src/components/tooltip.tsx +84 -0
- package/src/components/top-nav.tsx +660 -0
- package/src/components/truncate.tsx +234 -0
- package/src/deprecated.ts +61 -0
- package/src/index.ts +184 -0
- package/src/lib/cn.ts +22 -0
- package/src/lib/color.ts +469 -0
- package/src/lib/contrast.ts +220 -0
- package/src/lib/create-theme.ts +659 -0
- package/src/lib/harmony.ts +609 -0
- package/src/lib/import-theme.ts +272 -0
- package/src/lib/overflow-scroll.tsx +108 -0
- package/src/lib/radio-toggle-render.tsx +15 -0
- package/src/lib/reorder.ts +222 -0
- package/src/lib/spacing.ts +189 -0
- package/src/lib/tailwind-palette.ts +355 -0
- package/src/lib/truncate.ts +79 -0
- package/src/lib/use-single-value.ts +23 -0
- package/src/styles/continuum.css +3 -0
- package/src/styles/theme.css +524 -0
- package/src/styles/tokens.css +647 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Combobox as ComboboxPrimitive } from '@base-ui/react/combobox';
|
|
2
|
+
import type { VariantProps } from 'class-variance-authority';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import { type WithClassName } from '../lib/cn.js';
|
|
5
|
+
import { inputVariants } from './input.js';
|
|
6
|
+
export declare const Combobox: <Value, Multiple extends boolean | undefined = false, Item = Value>({ disabled, ...props }: ComboboxPrimitive.Root.Props<Value, Multiple, Item>) => import("react").JSX.Element;
|
|
7
|
+
/** Filters items by their label, with the locale's collation; pass its `contains` to `filter`. */
|
|
8
|
+
export declare const useComboboxFilter: typeof ComboboxPrimitive.useFilter;
|
|
9
|
+
/** Renders the selected value; in multiple mode, a function of the values that maps them to chips. */
|
|
10
|
+
export declare const ComboboxValue: (props: ComboboxPrimitive.Value.Props) => import("react").JSX.Element;
|
|
11
|
+
export type ComboboxInputProps = Omit<ComboboxPrimitive.Input.Props, 'size' | 'className'> & Omit<VariantProps<typeof inputVariants>, 'invalid' | 'disabled'> & {
|
|
12
|
+
leadingIcon?: ReactNode;
|
|
13
|
+
/** The chevron that opens the list without typing. */
|
|
14
|
+
showTrigger?: boolean;
|
|
15
|
+
/** A clear button, shown in place of the chevron once there is a value. */
|
|
16
|
+
showClear?: boolean;
|
|
17
|
+
/** The clear button's accessible name; "Clear" by default. */
|
|
18
|
+
clearLabel?: string;
|
|
19
|
+
/** The chevron's accessible name; "Show options" by default. */
|
|
20
|
+
triggerLabel?: string;
|
|
21
|
+
/** Classes for the bordered box. */
|
|
22
|
+
className?: string;
|
|
23
|
+
/** Classes for the native input. */
|
|
24
|
+
inputClassName?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Looks exactly like Input: the group carries the border and the focus ring, the native input is
|
|
28
|
+
* borderless. The group is also what the list anchors to, so the panel lines up with the box rather
|
|
29
|
+
* than with the text.
|
|
30
|
+
*/
|
|
31
|
+
export declare const ComboboxInput: ({ size, leadingIcon, showTrigger, showClear, clearLabel, triggerLabel, className, inputClassName, id, disabled, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, ...props }: ComboboxInputProps) => import("react").JSX.Element;
|
|
32
|
+
export type ComboboxChipsProps = Omit<ComboboxPrimitive.Chips.Props, 'className'> & Omit<VariantProps<typeof inputVariants>, 'invalid' | 'disabled'> & {
|
|
33
|
+
className?: string;
|
|
34
|
+
invalid?: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The box for multiple selection: chips and a ComboboxChipsInput wrap inside it and the box grows a
|
|
38
|
+
* row at a time. It renders as the input group too, so the list anchors to the whole box.
|
|
39
|
+
*/
|
|
40
|
+
export declare const ComboboxChips: ({ size, invalid: invalidProp, className, ...props }: ComboboxChipsProps) => import("react").JSX.Element;
|
|
41
|
+
/** The borderless input after the chips; it takes the rest of the row and wraps when narrow. */
|
|
42
|
+
export declare const ComboboxChipsInput: ({ className, id, disabled, "aria-describedby": describedBy, "aria-invalid": ariaInvalid, ...props }: Omit<ComboboxPrimitive.Input.Props, "className"> & {
|
|
43
|
+
className?: string;
|
|
44
|
+
}) => import("react").JSX.Element;
|
|
45
|
+
export type ComboboxChipProps = Omit<ComboboxPrimitive.Chip.Props, 'className'> & {
|
|
46
|
+
className?: string;
|
|
47
|
+
/** Leading 12px icon. */
|
|
48
|
+
icon?: ReactNode;
|
|
49
|
+
/** Hide the remove button, e.g. for a value that can't be dropped. */
|
|
50
|
+
showRemove?: boolean;
|
|
51
|
+
/** Accessible name of the remove button; defaults to "Remove <label>" for text labels. */
|
|
52
|
+
removeLabel?: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A selected value, drawn as a soft Chip: a 25px pill on neutral-100 with a 12px remove icon.
|
|
56
|
+
* Backspace and the arrow keys move between chips, so a chip shows the focus ring when it has focus.
|
|
57
|
+
*/
|
|
58
|
+
export declare const ComboboxChip: ({ icon, showRemove, removeLabel, className, children, ...props }: ComboboxChipProps) => import("react").JSX.Element;
|
|
59
|
+
export type ComboboxContentProps = WithClassName<ComboboxPrimitive.Popup.Props> & Pick<ComboboxPrimitive.Positioner.Props, 'side' | 'sideOffset' | 'align' | 'alignOffset' | 'anchor' | 'collisionPadding'> & {
|
|
60
|
+
/** Where the list is portalled; the body by default. */
|
|
61
|
+
container?: ComboboxPrimitive.Portal.Props['container'];
|
|
62
|
+
};
|
|
63
|
+
/** The panel, drawn exactly as SelectContent: a raised list on the surface, as wide as the box. */
|
|
64
|
+
export declare const ComboboxContent: ({ className, side, sideOffset, align, alignOffset, anchor, collisionPadding, container, ...props }: ComboboxContentProps) => import("react").JSX.Element;
|
|
65
|
+
/** Scrolls the items; with no matches it collapses so only the empty message shows. */
|
|
66
|
+
export declare const ComboboxList: ({ className, ...props }: WithClassName<ComboboxPrimitive.List.Props>) => import("react").JSX.Element;
|
|
67
|
+
/** An option: a `MenuItem` row, as in a select, with a check on the picked one. */
|
|
68
|
+
export declare const ComboboxItem: ({ className, children, ...props }: WithClassName<ComboboxPrimitive.Item.Props>) => import("react").JSX.Element;
|
|
69
|
+
export declare const ComboboxEmpty: ({ className, children, ...props }: WithClassName<ComboboxPrimitive.Empty.Props>) => import("react").JSX.Element;
|
|
70
|
+
/** Groups keep the list's 4px rhythm between their rows. */
|
|
71
|
+
export declare const ComboboxGroup: ({ className, ...props }: WithClassName<ComboboxPrimitive.Group.Props>) => import("react").JSX.Element;
|
|
72
|
+
export declare const ComboboxGroupLabel: ({ className, ...props }: WithClassName<ComboboxPrimitive.GroupLabel.Props>) => import("react").JSX.Element;
|
|
73
|
+
/** Renders a group's filtered items when the list is built from grouped `items`. */
|
|
74
|
+
export declare const ComboboxCollection: (props: ComboboxPrimitive.Collection.Props) => import("react").JSX.Element;
|
|
75
|
+
export declare const ComboboxSeparator: ({ className, ...props }: WithClassName<ComboboxPrimitive.Separator.Props>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Combobox as ComboboxPrimitive } from '@base-ui/react/combobox';
|
|
4
|
+
import { Check, ChevronDown, X } from 'lucide-react';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
import { focusRing } from './button.js';
|
|
7
|
+
import { chipClass, chipRemoveClass } from './chip.js';
|
|
8
|
+
import { useField, useFieldControl } from './field.js';
|
|
9
|
+
import { inputTextClass, inputVariants } from './input.js';
|
|
10
|
+
import { MenuItem } from './menu-item.js';
|
|
11
|
+
import { ThemeScope, usePortalContainer } from './theme.js';
|
|
12
|
+
/*
|
|
13
|
+
* A text input that filters a list, built from the same parts as Input (the box) and Select (the
|
|
14
|
+
* panel), so the two read as one family. Root renders no element; it is wrapped only so a disabled
|
|
15
|
+
* Field reaches it, since its disabled state is what keeps the clear button, the chevron and each
|
|
16
|
+
* chip's × out of reach. The wrapper keeps Root's generic value types.
|
|
17
|
+
*/
|
|
18
|
+
export const Combobox = ({ disabled, ...props }) => {
|
|
19
|
+
const field = useField();
|
|
20
|
+
return (_jsx(ComboboxPrimitive.Root, { disabled: disabled ?? field?.disabled, ...props }));
|
|
21
|
+
};
|
|
22
|
+
/** Filters items by their label, with the locale's collation; pass its `contains` to `filter`. */
|
|
23
|
+
export const useComboboxFilter = ComboboxPrimitive.useFilter;
|
|
24
|
+
/** Renders the selected value; in multiple mode, a function of the values that maps them to chips. */
|
|
25
|
+
export const ComboboxValue = (props) => (_jsx(ComboboxPrimitive.Value, { ...props }));
|
|
26
|
+
/** Ghost icon button inside the box: no border or fill of its own, so it reads as part of the input. */
|
|
27
|
+
const inlineButtonClass = [
|
|
28
|
+
'-mr-1 inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-item text-neutral-600 transition-colors duration-150 hover:text-neutral-950',
|
|
29
|
+
'disabled:pointer-events-none',
|
|
30
|
+
focusRing,
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Looks exactly like Input: the group carries the border and the focus ring, the native input is
|
|
34
|
+
* borderless. The group is also what the list anchors to, so the panel lines up with the box rather
|
|
35
|
+
* than with the text.
|
|
36
|
+
*/
|
|
37
|
+
export const ComboboxInput = ({ size, leadingIcon, showTrigger = true, showClear = false, clearLabel = 'Clear', triggerLabel = 'Show options', className, inputClassName, id, disabled, 'aria-describedby': describedBy, 'aria-invalid': ariaInvalid, ...props }) => {
|
|
38
|
+
const { invalid, ...control } = useFieldControl({
|
|
39
|
+
id,
|
|
40
|
+
disabled,
|
|
41
|
+
'aria-describedby': describedBy,
|
|
42
|
+
'aria-invalid': ariaInvalid,
|
|
43
|
+
});
|
|
44
|
+
return (_jsxs(ComboboxPrimitive.InputGroup, { className: state => cn(inputVariants({
|
|
45
|
+
size,
|
|
46
|
+
invalid,
|
|
47
|
+
disabled: Boolean(control.disabled) || state.disabled,
|
|
48
|
+
}), className), "data-invalid": invalid || undefined, "data-slot": "combobox-input", children: [leadingIcon, _jsx(ComboboxPrimitive.Input, { className: state => cn('h-full min-w-0 flex-1 bg-transparent outline-none', inputTextClass, !invalid &&
|
|
49
|
+
!state.disabled &&
|
|
50
|
+
'group-hover/input:placeholder:text-neutral-700', inputClassName), "data-slot": "combobox-input-control", ...control, ...props }), showClear && (_jsx(ComboboxPrimitive.Clear, { "aria-label": clearLabel, className: cn(inlineButtonClass), "data-slot": "combobox-clear", children: _jsx(X, { "aria-hidden": true, strokeWidth: 2 }) })), showTrigger && (_jsx(ComboboxPrimitive.Trigger, { "aria-label": triggerLabel,
|
|
51
|
+
// Clear only mounts with a value; one trailing control at a time keeps the box calm.
|
|
52
|
+
className: cn(inlineButtonClass, 'group-has-data-[slot=combobox-clear]/input:hidden'), "data-slot": "combobox-trigger", children: _jsx(ChevronDown, { "aria-hidden": true, strokeWidth: 2 }) }))] }));
|
|
53
|
+
};
|
|
54
|
+
/*
|
|
55
|
+
* Chips sit in a box of the input's own height: (38 − 2 − 25) / 2 leaves 5.5px around a 25px chip
|
|
56
|
+
* at md, 3.5px at sm. The md inset is worked out from the heights, since the chip follows the small
|
|
57
|
+
* control and not the large one at every item size. The left inset matches it once a chip is there,
|
|
58
|
+
* so the chip's pill nests in the box's corner rather than floating at the text inset.
|
|
59
|
+
*/
|
|
60
|
+
const chipsSizeClass = {
|
|
61
|
+
sm: 'h-auto min-h-control py-[3.5px] has-data-[slot=combobox-chip]:pl-[3.5px]',
|
|
62
|
+
md: [
|
|
63
|
+
'h-auto min-h-control-lg py-[calc((var(--spacing-control-lg)_-_2px_-_var(--spacing-chip))/2)]',
|
|
64
|
+
'has-data-[slot=combobox-chip]:pl-[calc((var(--spacing-control-lg)_-_2px_-_var(--spacing-chip))/2)]',
|
|
65
|
+
].join(' '),
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The box for multiple selection: chips and a ComboboxChipsInput wrap inside it and the box grows a
|
|
69
|
+
* row at a time. It renders as the input group too, so the list anchors to the whole box.
|
|
70
|
+
*/
|
|
71
|
+
export const ComboboxChips = ({ size, invalid: invalidProp, className, ...props }) => {
|
|
72
|
+
const { invalid } = useFieldControl({ 'aria-invalid': invalidProp });
|
|
73
|
+
return (_jsx(ComboboxPrimitive.Chips, { className: cn(inputVariants({ size, invalid }), 'flex-wrap gap-1.5', chipsSizeClass[size ?? 'md'],
|
|
74
|
+
// The disabled state lives on the root, so the box reads it from its input.
|
|
75
|
+
'has-[input:disabled]:cursor-not-allowed has-[input:disabled]:border-neutral-200 has-[input:disabled]:opacity-50', className), "data-invalid": invalid || undefined, "data-slot": "combobox-chips", render: _jsx(ComboboxPrimitive.InputGroup, {}), ...props }));
|
|
76
|
+
};
|
|
77
|
+
/** The borderless input after the chips; it takes the rest of the row and wraps when narrow. */
|
|
78
|
+
export const ComboboxChipsInput = ({ className, id, disabled, 'aria-describedby': describedBy, 'aria-invalid': ariaInvalid, ...props }) => {
|
|
79
|
+
const { invalid, ...control } = useFieldControl({
|
|
80
|
+
id,
|
|
81
|
+
disabled,
|
|
82
|
+
'aria-describedby': describedBy,
|
|
83
|
+
'aria-invalid': ariaInvalid,
|
|
84
|
+
});
|
|
85
|
+
return (_jsx(ComboboxPrimitive.Input, { className: cn('h-chip min-w-16 flex-1 bg-transparent outline-none', inputTextClass, !invalid && 'not-disabled:group-hover/input:placeholder:text-neutral-700', className), "data-slot": "combobox-chips-input", ...control, ...props }));
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* A selected value, drawn as a soft Chip: a 25px pill on neutral-100 with a 12px remove icon.
|
|
89
|
+
* Backspace and the arrow keys move between chips, so a chip shows the focus ring when it has focus.
|
|
90
|
+
*/
|
|
91
|
+
export const ComboboxChip = ({ icon, showRemove = true, removeLabel, className, children, ...props }) => (_jsxs(ComboboxPrimitive.Chip
|
|
92
|
+
// A disabled chip is only ever in a disabled box, which already dims it.
|
|
93
|
+
, {
|
|
94
|
+
// A disabled chip is only ever in a disabled box, which already dims it.
|
|
95
|
+
className: cn(chipClass, 'min-w-0', focusRing, className), "data-slot": "combobox-chip", ...props, children: [_jsxs("span", { className: "inline-flex min-w-0 items-center gap-1.5", children: [icon, _jsx("span", { className: "min-w-0 truncate", children: children })] }), showRemove && (_jsx(ComboboxPrimitive.ChipRemove, { "aria-label": removeLabel ?? (typeof children === 'string' ? `Remove ${children}` : 'Remove'), className: chipRemoveClass, "data-slot": "combobox-chip-remove", children: _jsx(X, { "aria-hidden": true, className: "size-3", strokeWidth: 2 }) }))] }));
|
|
96
|
+
/** The panel, drawn exactly as SelectContent: a raised list on the surface, as wide as the box. */
|
|
97
|
+
export const ComboboxContent = ({ className, side = 'bottom', sideOffset = 4, align = 'start', alignOffset = 0, anchor, collisionPadding, container, ...props }) => (_jsx(ComboboxPrimitive.Portal, { container: usePortalContainer(container), children: _jsx(ThemeScope, { children: _jsx(ComboboxPrimitive.Positioner, { align: align, alignOffset: alignOffset, anchor: anchor, className: "z-50 outline-none", collisionPadding: collisionPadding, "data-slot": "combobox-positioner", side: side, sideOffset: sideOffset, children: _jsx(ComboboxPrimitive.Popup, { className: cn('relative flex max-h-(--available-height) min-w-(--anchor-width) max-w-(--available-width) flex-col overflow-hidden rounded-card border border-neutral-200 bg-neutral-50 shadow-float outline-none', 'origin-(--transform-origin) transition-[opacity,scale] duration-200 ease-out-strong data-ending-style:scale-95 data-starting-style:scale-95 data-ending-style:opacity-0 data-starting-style:opacity-0 motion-reduce:transition-none', className), "data-slot": "combobox-content", ...props }) }) }) }));
|
|
98
|
+
/** Scrolls the items; with no matches it collapses so only the empty message shows. */
|
|
99
|
+
export const ComboboxList = ({ className, ...props }) => (_jsx(ComboboxPrimitive.List, { className: cn('flex min-h-0 scroll-py-1 flex-col gap-1 overflow-y-auto overscroll-contain p-1 outline-none data-empty:p-0', className), "data-slot": "combobox-list", ...props }));
|
|
100
|
+
/** An option: a `MenuItem` row, as in a select, with a check on the picked one. */
|
|
101
|
+
export const ComboboxItem = ({ className, children, ...props }) => (_jsx(MenuItem, { className: className, "data-slot": "combobox-item", render: _jsx(ComboboxPrimitive.Item, { ...props }), trailing: _jsx(ComboboxPrimitive.ItemIndicator, { className: "flex", children: _jsx(Check, { strokeWidth: 2 }) }), children: children }));
|
|
102
|
+
/*
|
|
103
|
+
* Base UI keeps the element mounted (it is a live region that announces "No results") and only
|
|
104
|
+
* drops its children when there are matches, so the row is sized with not-empty: rather than hidden.
|
|
105
|
+
*/
|
|
106
|
+
export const ComboboxEmpty = ({ className, children = 'No results', ...props }) => (_jsx(ComboboxPrimitive.Empty, { className: cn('not-empty:m-1 not-empty:flex not-empty:h-option not-empty:items-center not-empty:px-2 font-normal text-neutral-600 text-xs', className), "data-slot": "combobox-empty", ...props, children: children }));
|
|
107
|
+
/** Groups keep the list's 4px rhythm between their rows. */
|
|
108
|
+
export const ComboboxGroup = ({ className, ...props }) => (_jsx(ComboboxPrimitive.Group, { className: cn('flex flex-col gap-1', className), "data-slot": "combobox-group", ...props }));
|
|
109
|
+
export const ComboboxGroupLabel = ({ className, ...props }) => (_jsx(ComboboxPrimitive.GroupLabel, { className: cn('px-3 pt-1.5 pb-1 font-medium text-neutral-600 text-xxs', className), "data-slot": "combobox-group-label", ...props }));
|
|
110
|
+
/** Renders a group's filtered items when the list is built from grouped `items`. */
|
|
111
|
+
export const ComboboxCollection = (props) => (_jsx(ComboboxPrimitive.Collection, { ...props }));
|
|
112
|
+
export const ComboboxSeparator = ({ className, ...props }) => (_jsx(ComboboxPrimitive.Separator, { className: cn('-mx-1 h-px bg-neutral-200', className), "data-slot": "combobox-separator", ...props }));
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Dialog as DialogPrimitive } from '@base-ui/react/dialog';
|
|
2
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
3
|
+
import { type DialogContentProps } from './dialog.js';
|
|
4
|
+
/** Whether every word typed appears in the label or one of its keywords. */
|
|
5
|
+
export declare const matchesCommand: (query: string, ...fields: (string | undefined)[]) => boolean;
|
|
6
|
+
/** Opens a command menu with ⌘K or Ctrl+K from anywhere on the page. */
|
|
7
|
+
export declare const useCommandMenuShortcut: (onOpen: () => void, key?: string) => void;
|
|
8
|
+
export type CommandMenuProps = Omit<DialogPrimitive.Root.Props, 'children'> & {
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
/** The search, controlled; it is cleared each time the menu opens otherwise. */
|
|
11
|
+
query?: string;
|
|
12
|
+
onQueryChange?: (query: string) => void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Search and run anything from the keyboard: a dialog pinned near the top with a borderless search,
|
|
16
|
+
* commands in groups below it, arrows to move and Enter to run. Items hide themselves when they do
|
|
17
|
+
* not match what is typed, and a group with nothing left hides with them.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CommandMenu: ({ query: queryProp, onQueryChange, open, onOpenChange, children, ...props }: CommandMenuProps) => import("react").JSX.Element;
|
|
20
|
+
/** The panel: 560px, pinned at a sixth of the screen from the top, so it does not jump as results change. */
|
|
21
|
+
export declare const CommandMenuContent: ({ className, "aria-label": label, ...props }: DialogContentProps) => import("react").JSX.Element;
|
|
22
|
+
export type CommandMenuInputProps = Omit<ComponentProps<'input'>, 'value' | 'onChange'> & {
|
|
23
|
+
/** Trailing in the search row, such as an Esc key. */
|
|
24
|
+
trailing?: ReactNode;
|
|
25
|
+
/** The close button's name for screen readers. */
|
|
26
|
+
closeLabel?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The search: no box, a 16px icon, the text at 14px, ruled off from the list full width. On a touch
|
|
30
|
+
* screen, with no Esc key to press, it ends in the dialog header's close button.
|
|
31
|
+
*/
|
|
32
|
+
export declare const CommandMenuInput: ({ trailing, closeLabel, className, placeholder, onKeyDown, ...props }: CommandMenuInputProps) => import("react").JSX.Element;
|
|
33
|
+
/** The commands, scrolling under the search once there are more than fit. */
|
|
34
|
+
export declare const CommandMenuList: ({ className, children, ...props }: ComponentProps<"div">) => import("react").JSX.Element;
|
|
35
|
+
export type CommandMenuGroupProps = Omit<ComponentProps<'div'>, 'title'> & {
|
|
36
|
+
label: ReactNode;
|
|
37
|
+
};
|
|
38
|
+
/** A labelled run of commands; it hides once none of them match. */
|
|
39
|
+
export declare const CommandMenuGroup: ({ label, className, children, ...props }: CommandMenuGroupProps) => import("react").JSX.Element;
|
|
40
|
+
export type CommandMenuItemProps = Omit<ComponentProps<'div'>, 'onSelect'> & {
|
|
41
|
+
/** What the item is matched by, along with `keywords`. */
|
|
42
|
+
value: string;
|
|
43
|
+
/** Other words it answers to: "invoice" for "Billing". */
|
|
44
|
+
keywords?: string[];
|
|
45
|
+
/** Leading 16px icon. */
|
|
46
|
+
icon?: ReactNode;
|
|
47
|
+
/** Trailing, quiet: a Kbd shortcut or where the item lives. */
|
|
48
|
+
hint?: ReactNode;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/** Runs the command, from a click or Enter. */
|
|
51
|
+
onSelect?: () => void;
|
|
52
|
+
};
|
|
53
|
+
/** One command: a 36px row, highlighted with the 5% wash as the arrows reach it. */
|
|
54
|
+
export declare const CommandMenuItem: ({ value, keywords, icon, hint, disabled, onSelect, className, children, ...props }: CommandMenuItemProps) => import("react").JSX.Element | null;
|
|
55
|
+
/** Shown in place of the list once nothing matches what is typed. */
|
|
56
|
+
export declare const CommandMenuEmpty: ({ className, children, ...props }: ComponentProps<"p">) => import("react").JSX.Element;
|
|
57
|
+
/** Keys to drive the list, under it and ruled off full width. */
|
|
58
|
+
export declare const CommandMenuFooter: ({ className, ...props }: ComponentProps<"div">) => import("react").JSX.Element;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Dialog as DialogPrimitive } from '@base-ui/react/dialog';
|
|
4
|
+
import { Search, X } from 'lucide-react';
|
|
5
|
+
import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
6
|
+
import { cn } from '../lib/cn.js';
|
|
7
|
+
import { Button } from './button.js';
|
|
8
|
+
import { Dialog, DialogContent } from './dialog.js';
|
|
9
|
+
import { MenuItem } from './menu-item.js';
|
|
10
|
+
const CommandMenuContext = createContext(null);
|
|
11
|
+
const useCommandMenu = () => {
|
|
12
|
+
const context = useContext(CommandMenuContext);
|
|
13
|
+
if (!context)
|
|
14
|
+
throw new Error('Command menu parts must be inside <CommandMenu>.');
|
|
15
|
+
return context;
|
|
16
|
+
};
|
|
17
|
+
/** Whether every word typed appears in the label or one of its keywords. */
|
|
18
|
+
export const matchesCommand = (query, ...fields) => {
|
|
19
|
+
const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
20
|
+
const haystack = fields.filter(Boolean).join(' ').toLowerCase();
|
|
21
|
+
return words.every(word => haystack.includes(word));
|
|
22
|
+
};
|
|
23
|
+
/** Opens a command menu with ⌘K or Ctrl+K from anywhere on the page. */
|
|
24
|
+
export const useCommandMenuShortcut = (onOpen, key = 'k') => {
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const listener = (event) => {
|
|
27
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === key) {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
onOpen();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
window.addEventListener('keydown', listener);
|
|
33
|
+
return () => window.removeEventListener('keydown', listener);
|
|
34
|
+
}, [onOpen, key]);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Search and run anything from the keyboard: a dialog pinned near the top with a borderless search,
|
|
38
|
+
* commands in groups below it, arrows to move and Enter to run. Items hide themselves when they do
|
|
39
|
+
* not match what is typed, and a group with nothing left hides with them.
|
|
40
|
+
*/
|
|
41
|
+
export const CommandMenu = ({ query: queryProp, onQueryChange, open, onOpenChange, children, ...props }) => {
|
|
42
|
+
const [ownQuery, setOwnQuery] = useState('');
|
|
43
|
+
const query = queryProp ?? ownQuery;
|
|
44
|
+
const [active, setActive] = useState();
|
|
45
|
+
const listId = useId();
|
|
46
|
+
const listRef = useRef(null);
|
|
47
|
+
const setQuery = useCallback((next) => {
|
|
48
|
+
setOwnQuery(next);
|
|
49
|
+
onQueryChange?.(next);
|
|
50
|
+
}, [onQueryChange]);
|
|
51
|
+
// Opened through `open` (a shortcut, a button elsewhere), it never hears onOpenChange, so the
|
|
52
|
+
// search is cleared here as well.
|
|
53
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs as the menu opens, not as the query changes
|
|
54
|
+
useLayoutEffect(() => {
|
|
55
|
+
if (open && queryProp === undefined)
|
|
56
|
+
setOwnQuery('');
|
|
57
|
+
}, [open]);
|
|
58
|
+
return (_jsx(Dialog, { onOpenChange: (next, details) => {
|
|
59
|
+
if (next && queryProp === undefined)
|
|
60
|
+
setOwnQuery('');
|
|
61
|
+
onOpenChange?.(next, details);
|
|
62
|
+
}, open: open, ...props, children: _jsx(CommandMenuContext.Provider, { value: { query, setQuery, active, setActive, listId, listRef }, children: children }) }));
|
|
63
|
+
};
|
|
64
|
+
/** The panel: 560px, pinned at a sixth of the screen from the top, so it does not jump as results change. */
|
|
65
|
+
export const CommandMenuContent = ({ className, 'aria-label': label = 'Command menu', ...props }) => (_jsx(DialogContent, { "aria-label": label, className: cn('mt-[16cqh] mb-auto w-[min(var(--spacing-command),calc(100%-32px))]', className), "data-slot": "command-menu-content", ...props }));
|
|
66
|
+
/** The items showing now, in order, read from the list itself. */
|
|
67
|
+
const visibleItems = (list) => Array.from(list?.querySelectorAll('[data-slot="command-menu-item"]:not([data-disabled])') ?? []);
|
|
68
|
+
/**
|
|
69
|
+
* The search: no box, a 16px icon, the text at 14px, ruled off from the list full width. On a touch
|
|
70
|
+
* screen, with no Esc key to press, it ends in the dialog header's close button.
|
|
71
|
+
*/
|
|
72
|
+
export const CommandMenuInput = ({ trailing, closeLabel = 'Close', className, placeholder = 'Search or run a command', onKeyDown, ...props }) => {
|
|
73
|
+
const { query, setQuery, active, setActive, listId, listRef } = useCommandMenu();
|
|
74
|
+
const move = (by) => {
|
|
75
|
+
const items = visibleItems(listRef.current);
|
|
76
|
+
if (items.length === 0)
|
|
77
|
+
return;
|
|
78
|
+
const index = items.findIndex(item => item.id === active);
|
|
79
|
+
const next = items[(index + by + items.length) % items.length];
|
|
80
|
+
setActive(next?.id);
|
|
81
|
+
};
|
|
82
|
+
const handleKeyDown = (event) => {
|
|
83
|
+
onKeyDown?.(event);
|
|
84
|
+
if (event.defaultPrevented)
|
|
85
|
+
return;
|
|
86
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
move(event.key === 'ArrowDown' ? 1 : -1);
|
|
89
|
+
}
|
|
90
|
+
else if (event.key === 'Home' || event.key === 'End') {
|
|
91
|
+
const items = visibleItems(listRef.current);
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
setActive((event.key === 'Home' ? items[0] : items.at(-1))?.id);
|
|
94
|
+
}
|
|
95
|
+
else if (event.key === 'Enter' && active) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
document.getElementById(active)?.click();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return (_jsxs("div", { className: "flex h-bar shrink-0 items-center gap-2.5 border-neutral-200 border-b px-4 text-neutral-500 [&_svg:not([class*=size-])]:size-4 [&_svg]:shrink-0", "data-slot": "command-menu-search", children: [_jsx(Search, { "aria-hidden": true, strokeWidth: 2 }), _jsx("input", { "aria-activedescendant": active, "aria-autocomplete": "list", "aria-controls": listId, "aria-expanded": true, autoComplete: "off", className: cn(
|
|
101
|
+
// 16px on a touch screen, or iOS zooms the page in when the search takes focus.
|
|
102
|
+
'h-full min-w-0 flex-1 bg-transparent pointer-coarse:text-base text-neutral-950 text-sm outline-none placeholder:text-neutral-600', className), "data-slot": "command-menu-input", onChange: event => setQuery(event.target.value), onKeyDown: handleKeyDown, placeholder: placeholder, role: "combobox", spellCheck: false, value: query, ...props }), trailing, _jsx(DialogPrimitive.Close, { "aria-label": closeLabel, render: _jsx(Button, { className: "-mr-1.25 pointer-fine:hidden size-[calc(var(--spacing-bar)-22px)] rounded-control", size: "icon-sm", variant: "secondary" }), children: _jsx(X, { className: "size-3.5", strokeWidth: 2 }) })] }));
|
|
103
|
+
};
|
|
104
|
+
/** The commands, scrolling under the search once there are more than fit. */
|
|
105
|
+
export const CommandMenuList = ({ className, children, ...props }) => {
|
|
106
|
+
const { query, active, setActive, listId, listRef } = useCommandMenu();
|
|
107
|
+
// After every change to what shows, keep an item highlighted: the same one if it is still there.
|
|
108
|
+
useLayoutEffect(() => {
|
|
109
|
+
const items = visibleItems(listRef.current);
|
|
110
|
+
if (!items.some(item => item.id === active))
|
|
111
|
+
setActive(items[0]?.id);
|
|
112
|
+
});
|
|
113
|
+
// Typing starts again from the top of the list.
|
|
114
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs on each new query on purpose
|
|
115
|
+
useLayoutEffect(() => {
|
|
116
|
+
setActive(visibleItems(listRef.current)[0]?.id);
|
|
117
|
+
listRef.current?.scrollTo({ top: 0 });
|
|
118
|
+
}, [query]);
|
|
119
|
+
// The highlighted item kept in view by scrolling the list alone: scrollIntoView would scroll every
|
|
120
|
+
// ancestor too, the page included, so a menu shown open on a page pulled the page to itself.
|
|
121
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs on each new active item; the list is read from its ref
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const list = listRef.current;
|
|
124
|
+
const item = active ? document.getElementById(active) : null;
|
|
125
|
+
if (!list || !item)
|
|
126
|
+
return;
|
|
127
|
+
const bounds = list.getBoundingClientRect();
|
|
128
|
+
const box = item.getBoundingClientRect();
|
|
129
|
+
if (box.top < bounds.top)
|
|
130
|
+
list.scrollTop -= bounds.top - box.top;
|
|
131
|
+
else if (box.bottom > bounds.bottom)
|
|
132
|
+
list.scrollTop += box.bottom - bounds.bottom;
|
|
133
|
+
}, [active]);
|
|
134
|
+
return (_jsx("div", { className: cn('group/command-list flex max-h-[min(360px,50cqh)] flex-col gap-1 overflow-y-auto p-1.5', className), "data-slot": "command-menu-list", id: listId, ref: listRef, role: "listbox", ...props, children: children }));
|
|
135
|
+
};
|
|
136
|
+
/** A labelled run of commands; it hides once none of them match. */
|
|
137
|
+
export const CommandMenuGroup = ({ label, className, children, ...props }) => {
|
|
138
|
+
const labelId = useId();
|
|
139
|
+
return (
|
|
140
|
+
// biome-ignore lint/a11y/useSemanticElements: a group of options in a listbox, which a fieldset is not
|
|
141
|
+
_jsxs("div", { "aria-labelledby": labelId, className: cn('flex not-has-data-[slot=command-menu-item]:hidden flex-col', className), "data-slot": "command-menu-group", role: "group", ...props, children: [_jsx("div", { className: "px-2.5 pt-2 pb-1 font-medium text-neutral-600 text-xxs", "data-slot": "command-menu-label", id: labelId, children: label }), children] }));
|
|
142
|
+
};
|
|
143
|
+
/** One command: a 36px row, highlighted with the 5% wash as the arrows reach it. */
|
|
144
|
+
export const CommandMenuItem = ({ value, keywords, icon, hint, disabled = false, onSelect, className, children, ...props }) => {
|
|
145
|
+
const { query, active, setActive } = useCommandMenu();
|
|
146
|
+
const id = useId();
|
|
147
|
+
if (!matchesCommand(query, value, ...(keywords ?? [])))
|
|
148
|
+
return null;
|
|
149
|
+
const highlighted = active === id;
|
|
150
|
+
return (
|
|
151
|
+
// Never focused itself: the search keeps focus and points at the highlighted option.
|
|
152
|
+
_jsx(MenuItem, { "aria-disabled": disabled || undefined, "aria-selected": highlighted,
|
|
153
|
+
// A size up from a popup row and set on the search row's lines: its icon 16px in
|
|
154
|
+
// from the panel edge (6px of list plus 10px of row) and 10px from the label.
|
|
155
|
+
className: cn('gap-2.5 rounded-item px-2.5', className), "data-disabled": disabled || undefined, "data-highlighted": highlighted || undefined, "data-slot": "command-menu-item", id: id, onClick: disabled ? undefined : onSelect, onPointerMove: () => {
|
|
156
|
+
if (!disabled && !highlighted)
|
|
157
|
+
setActive(id);
|
|
158
|
+
}, role: "option", tabIndex: -1, leading: icon, trailing: hint, ...props, children: children ?? value }));
|
|
159
|
+
};
|
|
160
|
+
/** Shown in place of the list once nothing matches what is typed. */
|
|
161
|
+
export const CommandMenuEmpty = ({ className, children, ...props }) => {
|
|
162
|
+
const { query } = useCommandMenu();
|
|
163
|
+
return (_jsx("p", { className: cn('hidden px-2.5 py-3 text-neutral-600 text-xs group-not-has-[[data-slot=command-menu-item]]/command-list:block', className), "data-slot": "command-menu-empty", ...props, children: children ?? `Nothing matches “${query.trim()}”.` }));
|
|
164
|
+
};
|
|
165
|
+
/** Keys to drive the list, under it and ruled off full width. */
|
|
166
|
+
export const CommandMenuFooter = ({ className, ...props }) => (_jsx("div", { className: cn('flex pointer-coarse:hidden h-row shrink-0 items-center gap-4 overflow-hidden whitespace-nowrap border-neutral-200 border-t px-4 text-neutral-600 text-xxs', className), "data-slot": "command-menu-footer", ...props }));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
|
+
export type CopyButtonProps = Omit<ComponentProps<'button'>, 'onCopy' | 'children'> & {
|
|
3
|
+
/** The text put on the clipboard. */
|
|
4
|
+
text: string;
|
|
5
|
+
/** Its name and tooltip; "Copy" by default. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** What it says once it has copied. */
|
|
8
|
+
copiedLabel?: string;
|
|
9
|
+
onCopy?: (text: string) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A 24 square ghost button with a 14 copy icon, for a value that sits in a line of text (a table
|
|
13
|
+
* cell): small enough to sit inside a 17 line without growing it. Once copied, the icon crossfades
|
|
14
|
+
* to a tick for 1.5s and the change is announced; the tooltip says what it does.
|
|
15
|
+
*/
|
|
16
|
+
export declare const CopyButton: ({ text, label, copiedLabel, onCopy, className, "aria-label": name, ...props }: CopyButtonProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { Check, Copy } from 'lucide-react';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
import { focusRing, touchTarget } from './button.js';
|
|
7
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip.js';
|
|
8
|
+
/**
|
|
9
|
+
* A 24 square ghost button with a 14 copy icon, for a value that sits in a line of text (a table
|
|
10
|
+
* cell): small enough to sit inside a 17 line without growing it. Once copied, the icon crossfades
|
|
11
|
+
* to a tick for 1.5s and the change is announced; the tooltip says what it does.
|
|
12
|
+
*/
|
|
13
|
+
export const CopyButton = ({ text, label = 'Copy', copiedLabel = 'Copied', onCopy, className, 'aria-label': name, ...props }) => {
|
|
14
|
+
const [copied, setCopied] = useState(false);
|
|
15
|
+
const timer = useRef(undefined);
|
|
16
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
17
|
+
const copy = async () => {
|
|
18
|
+
try {
|
|
19
|
+
await navigator.clipboard.writeText(text);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// No clipboard (an insecure origin or a denied permission): leave the state alone rather than lie.
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
onCopy?.(text);
|
|
26
|
+
setCopied(true);
|
|
27
|
+
clearTimeout(timer.current);
|
|
28
|
+
timer.current = setTimeout(() => setCopied(false), 1500);
|
|
29
|
+
};
|
|
30
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx("button", { ...props, "aria-label": copied ? copiedLabel : (name ?? label), className: cn('inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-chip text-neutral-600 transition-[background-color,color,opacity] duration-150 ease-out-strong hover:bg-neutral-950/5 hover:text-neutral-950', 'data-copied:text-neutral-950', touchTarget, focusRing, className), "data-copied": copied || undefined, "data-slot": "copy-button", onClick: copy, type: "button" }), children: _jsxs("span", { className: "grid place-items-center *:col-start-1 *:row-start-1 *:size-3.5 *:transition-[opacity,scale] *:duration-150 *:ease-out-strong motion-reduce:*:scale-100", children: [_jsx(Copy, { className: cn(copied && 'scale-[0.8] opacity-0'), strokeWidth: 2 }), _jsx(Check, { className: cn(!copied && 'scale-[0.8] opacity-0'), strokeWidth: 2 })] }) }), _jsx(TooltipContent, { children: copied ? copiedLabel : label })] }), _jsx("span", { "aria-live": "polite", className: "sr-only", children: copied ? copiedLabel : '' })] }));
|
|
31
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
export type DataGridColumn = {
|
|
3
|
+
/** The column's name; a letter (A, B, …) when left out. */
|
|
4
|
+
label?: string;
|
|
5
|
+
/** Its width in px, 112 by default; the reader resizes it from the head's right edge. */
|
|
6
|
+
width?: number;
|
|
7
|
+
/** Left by default; a cell that holds a number goes right on its own. */
|
|
8
|
+
align?: 'left' | 'right';
|
|
9
|
+
};
|
|
10
|
+
/** A block of cells, by row and column index, both ends included. */
|
|
11
|
+
export type DataGridRange = {
|
|
12
|
+
top: number;
|
|
13
|
+
left: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
right: number;
|
|
16
|
+
};
|
|
17
|
+
type Cell = {
|
|
18
|
+
row: number;
|
|
19
|
+
col: number;
|
|
20
|
+
};
|
|
21
|
+
export type DataGridProps = Omit<ComponentProps<'div'>, 'children' | 'onChange'> & {
|
|
22
|
+
/** The grid's name, for a screen reader. */
|
|
23
|
+
label: string;
|
|
24
|
+
/** The values, a row at a time. */
|
|
25
|
+
values: string[][];
|
|
26
|
+
/** Makes the grid editable: called with the whole grid after each edit, paste, fill or undo. */
|
|
27
|
+
onValuesChange?: (values: string[][]) => void;
|
|
28
|
+
/** The columns; left out, as many lettered columns as the widest row has values. */
|
|
29
|
+
columns?: DataGridColumn[];
|
|
30
|
+
/** Called as the selection changes, with its range and the cell it started from. */
|
|
31
|
+
/**
|
|
32
|
+
* Called as the selection changes, with the block being made, the cell it started from, and
|
|
33
|
+
* every selected block (those added with Ctrl or ⌘ first, this one last).
|
|
34
|
+
*/
|
|
35
|
+
onSelectionChange?: (range: DataGridRange, active: Cell, ranges: DataGridRange[]) => void;
|
|
36
|
+
/** Inside the frame under the grid, ruled off: a sum of the selection, a count. */
|
|
37
|
+
footer?: ReactNode;
|
|
38
|
+
/**
|
|
39
|
+
* Inside the frame over the column heads, ruled off: what works on this grid (a scenario, a
|
|
40
|
+
* view, where it stands), as a `TableToolbar` on a table. It stays put while the grid scrolls.
|
|
41
|
+
*/
|
|
42
|
+
toolbar?: ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* The last rows are the sheet's summary (a total, a target, a gap): set apart from the rows they
|
|
45
|
+
* sum by a firmer rule over the first, and written in 500, as a spreadsheet writes its totals.
|
|
46
|
+
*/
|
|
47
|
+
summaryRows?: number;
|
|
48
|
+
};
|
|
49
|
+
export declare const DataGrid: ({ label, values, onValuesChange, columns, onSelectionChange, footer, toolbar, summaryRows, className, ...props }: DataGridProps) => import("react").JSX.Element;
|
|
50
|
+
export {};
|