@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,283 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { CircleAlert, CircleCheck, FileText, Upload, X } from 'lucide-react';
|
|
4
|
+
import {
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
type DragEvent,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
useId,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { cn } from '../lib/cn';
|
|
13
|
+
import { Button } from './button';
|
|
14
|
+
import { useFieldControl } from './field';
|
|
15
|
+
import { IconTile } from './icon-tile';
|
|
16
|
+
import { Progress } from './progress';
|
|
17
|
+
import { Truncate } from './truncate';
|
|
18
|
+
|
|
19
|
+
/** "2.4 MB", "860 KB", "312 B": one decimal only where it still says something. */
|
|
20
|
+
export const formatFileSize = (bytes: number) => {
|
|
21
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
22
|
+
const units = ['KB', 'MB', 'GB'];
|
|
23
|
+
let value = bytes / 1024;
|
|
24
|
+
let unit = 0;
|
|
25
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
26
|
+
value /= 1024;
|
|
27
|
+
unit += 1;
|
|
28
|
+
}
|
|
29
|
+
return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type DropZoneProps = Omit<ComponentProps<'div'>, 'title' | 'onDrop'> & {
|
|
33
|
+
/** What goes here, in a line: "Drop CSV files here". */
|
|
34
|
+
title?: ReactNode;
|
|
35
|
+
/** What is accepted and how much: "CSV or XLSX, up to 10 MB each". */
|
|
36
|
+
description?: ReactNode;
|
|
37
|
+
/** The secondary button that opens the file picker. */
|
|
38
|
+
action?: ReactNode;
|
|
39
|
+
icon?: ReactNode;
|
|
40
|
+
/** Passed to the file input, and checked again on drop, where the browser does not. */
|
|
41
|
+
accept?: string;
|
|
42
|
+
multiple?: boolean;
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/** Receives the picked or dropped files that match `accept`. */
|
|
45
|
+
onFiles?: (files: File[]) => void;
|
|
46
|
+
/** The name the hidden file input submits under in a form. */
|
|
47
|
+
name?: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** Whether a file matches an `accept` list of extensions and MIME types (`image/*` included). */
|
|
51
|
+
const accepts = (file: File, accept?: string) => {
|
|
52
|
+
if (!accept) return true;
|
|
53
|
+
const name = file.name.toLowerCase();
|
|
54
|
+
const type = file.type.toLowerCase();
|
|
55
|
+
return accept
|
|
56
|
+
.split(',')
|
|
57
|
+
.map(rule => rule.trim().toLowerCase())
|
|
58
|
+
.some(rule =>
|
|
59
|
+
rule.startsWith('.')
|
|
60
|
+
? name.endsWith(rule)
|
|
61
|
+
: rule.endsWith('/*')
|
|
62
|
+
? type.startsWith(rule.slice(0, -1))
|
|
63
|
+
: type === rule,
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The empty-state panel made a drop target: a dashed, left-aligned well with one line on what goes
|
|
69
|
+
* here and a secondary button that opens the picker. Dragging files over it darkens the dash and
|
|
70
|
+
* lays the 3% wash over it.
|
|
71
|
+
*/
|
|
72
|
+
export const DropZone = ({
|
|
73
|
+
title = 'Drop files here',
|
|
74
|
+
description,
|
|
75
|
+
action = 'Choose files',
|
|
76
|
+
icon = <Upload strokeWidth={2} />,
|
|
77
|
+
accept,
|
|
78
|
+
multiple = true,
|
|
79
|
+
disabled: disabledProp,
|
|
80
|
+
onFiles,
|
|
81
|
+
name,
|
|
82
|
+
id: idProp,
|
|
83
|
+
className,
|
|
84
|
+
'aria-invalid': ariaInvalid,
|
|
85
|
+
...props
|
|
86
|
+
}: DropZoneProps) => {
|
|
87
|
+
const input = useRef<HTMLInputElement>(null);
|
|
88
|
+
const [dragging, setDragging] = useState(false);
|
|
89
|
+
// dragenter and dragleave fire for every child crossed, so the zone counts them to know it is left.
|
|
90
|
+
const depth = useRef(0);
|
|
91
|
+
const generatedId = useId();
|
|
92
|
+
const { invalid, disabled, ...control } = useFieldControl({
|
|
93
|
+
id: idProp,
|
|
94
|
+
disabled: disabledProp,
|
|
95
|
+
'aria-invalid': ariaInvalid,
|
|
96
|
+
});
|
|
97
|
+
const inputId = control.id ?? generatedId;
|
|
98
|
+
const descriptionId = description ? `${inputId}-description` : undefined;
|
|
99
|
+
const describedBy =
|
|
100
|
+
[descriptionId, control['aria-describedby']].filter(Boolean).join(' ') || undefined;
|
|
101
|
+
|
|
102
|
+
const take = (list: FileList | null) => {
|
|
103
|
+
if (!list) return;
|
|
104
|
+
const files = Array.from(list).filter(file => accepts(file, accept));
|
|
105
|
+
if (files.length > 0) onFiles?.(multiple ? files : files.slice(0, 1));
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const onDragEnter = (event: DragEvent<HTMLDivElement>) => {
|
|
109
|
+
if (disabled || !event.dataTransfer.types.includes('Files')) return;
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
depth.current += 1;
|
|
112
|
+
setDragging(true);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const onDragLeave = () => {
|
|
116
|
+
depth.current = Math.max(0, depth.current - 1);
|
|
117
|
+
if (depth.current === 0) setDragging(false);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const onDrop = (event: DragEvent<HTMLDivElement>) => {
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
depth.current = 0;
|
|
123
|
+
setDragging(false);
|
|
124
|
+
if (!disabled) take(event.dataTransfer.files);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div
|
|
129
|
+
className={cn(
|
|
130
|
+
'flex flex-wrap items-center gap-x-3 gap-y-4 rounded-item border border-dashed p-4 transition-[background-color,border-color] duration-150 motion-reduce:transition-none',
|
|
131
|
+
invalid ? 'border-error-500' : 'border-neutral-300',
|
|
132
|
+
'data-dragging:border-neutral-500 data-dragging:bg-neutral-950/3',
|
|
133
|
+
'data-disabled:opacity-50',
|
|
134
|
+
className,
|
|
135
|
+
)}
|
|
136
|
+
data-disabled={disabled || undefined}
|
|
137
|
+
data-dragging={dragging || undefined}
|
|
138
|
+
data-invalid={invalid || undefined}
|
|
139
|
+
data-slot="drop-zone"
|
|
140
|
+
onDragEnter={onDragEnter}
|
|
141
|
+
onDragLeave={onDragLeave}
|
|
142
|
+
// Without preventing dragover the browser opens the file instead of dropping it here.
|
|
143
|
+
onDragOver={event => {
|
|
144
|
+
if (!disabled) event.preventDefault();
|
|
145
|
+
}}
|
|
146
|
+
onDrop={onDrop}
|
|
147
|
+
{...props}
|
|
148
|
+
>
|
|
149
|
+
<IconTile tone={invalid ? 'error' : 'neutral'}>{icon}</IconTile>
|
|
150
|
+
<div
|
|
151
|
+
className="flex min-w-0 flex-1 basis-48 flex-col gap-0.5"
|
|
152
|
+
data-slot="drop-zone-text"
|
|
153
|
+
>
|
|
154
|
+
<p className="font-medium text-neutral-950 text-xs">{title}</p>
|
|
155
|
+
{description && (
|
|
156
|
+
<p
|
|
157
|
+
className={cn('text-xs', invalid ? 'text-error-600' : 'text-neutral-600')}
|
|
158
|
+
data-slot="drop-zone-description"
|
|
159
|
+
id={descriptionId}
|
|
160
|
+
>
|
|
161
|
+
{description}
|
|
162
|
+
</p>
|
|
163
|
+
)}
|
|
164
|
+
</div>
|
|
165
|
+
<Button
|
|
166
|
+
aria-describedby={describedBy}
|
|
167
|
+
disabled={disabled}
|
|
168
|
+
onClick={() => input.current?.click()}
|
|
169
|
+
variant="secondary"
|
|
170
|
+
>
|
|
171
|
+
{action}
|
|
172
|
+
</Button>
|
|
173
|
+
<input
|
|
174
|
+
accept={accept}
|
|
175
|
+
aria-invalid={invalid || undefined}
|
|
176
|
+
className="hidden"
|
|
177
|
+
data-slot="drop-zone-input"
|
|
178
|
+
disabled={disabled}
|
|
179
|
+
id={inputId}
|
|
180
|
+
multiple={multiple}
|
|
181
|
+
name={name}
|
|
182
|
+
onChange={event => {
|
|
183
|
+
take(event.target.files);
|
|
184
|
+
// Cleared, so picking the same file again after removing it still reports it.
|
|
185
|
+
event.target.value = '';
|
|
186
|
+
}}
|
|
187
|
+
ref={input}
|
|
188
|
+
tabIndex={-1}
|
|
189
|
+
type="file"
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/** The files taken by a drop zone, under it; spaced, not ruled. */
|
|
196
|
+
export const DropZoneFiles = ({ className, ...props }: ComponentProps<'ul'>) => (
|
|
197
|
+
<ul className={cn('flex flex-col gap-4', className)} data-slot="drop-zone-files" {...props} />
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
export type DropZoneFileProps = Omit<ComponentProps<'li'>, 'onError'> & {
|
|
201
|
+
name: string;
|
|
202
|
+
/** Bytes, formatted for you, or text as it should read. */
|
|
203
|
+
size?: number | string;
|
|
204
|
+
/** Upload progress 0–100 while `status` is uploading. */
|
|
205
|
+
progress?: number;
|
|
206
|
+
status?: 'uploading' | 'done' | 'error';
|
|
207
|
+
/** Why it failed, in place of the size. */
|
|
208
|
+
error?: ReactNode;
|
|
209
|
+
onRemove?: () => void;
|
|
210
|
+
/**
|
|
211
|
+
* Where a long name cuts: in the `middle` by default, so the extension and the end that tells
|
|
212
|
+
* one file from the next stay (`invoice-2026-…-0142.pdf`); `end` for names read from the start.
|
|
213
|
+
*/
|
|
214
|
+
truncate?: 'end' | 'middle';
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** One file: its tile, name and size, a bar while it uploads, and a ghost × to cancel or remove it. */
|
|
218
|
+
export const DropZoneFile = ({
|
|
219
|
+
name,
|
|
220
|
+
size,
|
|
221
|
+
progress = 0,
|
|
222
|
+
status = 'done',
|
|
223
|
+
error,
|
|
224
|
+
onRemove,
|
|
225
|
+
truncate = 'middle',
|
|
226
|
+
className,
|
|
227
|
+
...props
|
|
228
|
+
}: DropZoneFileProps) => {
|
|
229
|
+
const meta =
|
|
230
|
+
status === 'error' ? error : typeof size === 'number' ? formatFileSize(size) : size;
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<li
|
|
234
|
+
className={cn('flex items-center gap-3', className)}
|
|
235
|
+
data-slot="drop-zone-file"
|
|
236
|
+
data-status={status}
|
|
237
|
+
{...props}
|
|
238
|
+
>
|
|
239
|
+
<IconTile
|
|
240
|
+
tone={status === 'done' ? 'success' : status === 'error' ? 'error' : 'neutral'}
|
|
241
|
+
variant={status === 'uploading' ? 'filled' : 'outline'}
|
|
242
|
+
>
|
|
243
|
+
{status === 'done' ? (
|
|
244
|
+
<CircleCheck strokeWidth={2} />
|
|
245
|
+
) : status === 'error' ? (
|
|
246
|
+
<CircleAlert strokeWidth={2} />
|
|
247
|
+
) : (
|
|
248
|
+
<FileText strokeWidth={2} />
|
|
249
|
+
)}
|
|
250
|
+
</IconTile>
|
|
251
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1.5">
|
|
252
|
+
<div className="flex items-baseline justify-between gap-3 text-xs">
|
|
253
|
+
<Truncate at={truncate} className="font-medium text-neutral-950">
|
|
254
|
+
{name}
|
|
255
|
+
</Truncate>
|
|
256
|
+
{meta && (
|
|
257
|
+
<span
|
|
258
|
+
className={cn(
|
|
259
|
+
'shrink-0 tabular-nums',
|
|
260
|
+
status === 'error' ? 'text-error-600' : 'text-neutral-600',
|
|
261
|
+
)}
|
|
262
|
+
>
|
|
263
|
+
{meta}
|
|
264
|
+
</span>
|
|
265
|
+
)}
|
|
266
|
+
</div>
|
|
267
|
+
{status === 'uploading' && (
|
|
268
|
+
<Progress aria-label={`${name} upload`} value={progress} />
|
|
269
|
+
)}
|
|
270
|
+
</div>
|
|
271
|
+
{onRemove && (
|
|
272
|
+
<Button
|
|
273
|
+
aria-label={`${status === 'uploading' ? 'Cancel' : 'Remove'} ${name}`}
|
|
274
|
+
onClick={onRemove}
|
|
275
|
+
size="icon-sm"
|
|
276
|
+
variant="ghost"
|
|
277
|
+
>
|
|
278
|
+
<X strokeWidth={2} />
|
|
279
|
+
</Button>
|
|
280
|
+
)}
|
|
281
|
+
</li>
|
|
282
|
+
);
|
|
283
|
+
};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Menu as MenuPrimitive } from '@base-ui/react/menu';
|
|
4
|
+
import type { VariantProps } from 'class-variance-authority';
|
|
5
|
+
import { Check, ChevronRight, Search } from 'lucide-react';
|
|
6
|
+
import {
|
|
7
|
+
type ComponentProps,
|
|
8
|
+
createContext,
|
|
9
|
+
type KeyboardEvent,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
useContext,
|
|
12
|
+
useEffect,
|
|
13
|
+
useRef,
|
|
14
|
+
} from 'react';
|
|
15
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
16
|
+
import { MenuItem, menuItemVariants } from './menu-item';
|
|
17
|
+
import { ThemeScope, usePortalContainer } from './theme';
|
|
18
|
+
|
|
19
|
+
const contentClass = [
|
|
20
|
+
'flex max-h-(--available-height) min-w-menu flex-col gap-1 overflow-y-auto rounded-card border border-neutral-200 bg-neutral-50 p-1 shadow-float outline-none',
|
|
21
|
+
// Base UI keeps the popup mounted while it closes, so the same scale and fade play on the way out.
|
|
22
|
+
'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',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Base UI's GroupLabel throws outside a Group, while a label at the top of a menu is common.
|
|
27
|
+
* The groups below flag their subtree so the label can link itself to a group only when it has one.
|
|
28
|
+
*/
|
|
29
|
+
const InGroupContext = createContext(false);
|
|
30
|
+
|
|
31
|
+
type PositionProps = Pick<
|
|
32
|
+
MenuPrimitive.Positioner.Props,
|
|
33
|
+
'side' | 'sideOffset' | 'align' | 'alignOffset' | 'collisionPadding'
|
|
34
|
+
>;
|
|
35
|
+
|
|
36
|
+
/** Row-action and account menus (report editor ellipsis, invoice table rows). */
|
|
37
|
+
export const DropdownMenu = (props: MenuPrimitive.Root.Props) => (
|
|
38
|
+
<MenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const DropdownMenuTrigger = (props: MenuPrimitive.Trigger.Props) => (
|
|
42
|
+
<MenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export const DropdownMenuGroup = (props: MenuPrimitive.Group.Props) => (
|
|
46
|
+
<InGroupContext.Provider value>
|
|
47
|
+
<MenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
|
48
|
+
</InGroupContext.Provider>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const DropdownMenuSub = (props: MenuPrimitive.SubmenuRoot.Props) => (
|
|
52
|
+
<MenuPrimitive.SubmenuRoot data-slot="dropdown-menu-sub" {...props} />
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const DropdownMenuRadioGroup = (props: MenuPrimitive.RadioGroup.Props) => (
|
|
56
|
+
<InGroupContext.Provider value>
|
|
57
|
+
<MenuPrimitive.RadioGroup data-slot="dropdown-menu-radio-group" {...props} />
|
|
58
|
+
</InGroupContext.Provider>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export type DropdownMenuContentProps = WithClassName<MenuPrimitive.Popup.Props> &
|
|
62
|
+
PositionProps & {
|
|
63
|
+
/** Where the menu is portalled; the body by default. */
|
|
64
|
+
container?: MenuPrimitive.Portal.Props['container'];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const DropdownMenuContent = ({
|
|
68
|
+
className,
|
|
69
|
+
side,
|
|
70
|
+
sideOffset = 4,
|
|
71
|
+
align,
|
|
72
|
+
alignOffset,
|
|
73
|
+
collisionPadding,
|
|
74
|
+
container,
|
|
75
|
+
...props
|
|
76
|
+
}: DropdownMenuContentProps) => (
|
|
77
|
+
<MenuPrimitive.Portal container={usePortalContainer(container)}>
|
|
78
|
+
<ThemeScope>
|
|
79
|
+
<MenuPrimitive.Positioner
|
|
80
|
+
align={align}
|
|
81
|
+
alignOffset={alignOffset}
|
|
82
|
+
className="z-50 outline-none"
|
|
83
|
+
collisionPadding={collisionPadding}
|
|
84
|
+
data-slot="dropdown-menu-positioner"
|
|
85
|
+
side={side}
|
|
86
|
+
sideOffset={sideOffset}
|
|
87
|
+
>
|
|
88
|
+
<MenuPrimitive.Popup
|
|
89
|
+
className={cn(contentClass, className)}
|
|
90
|
+
data-slot="dropdown-menu-content"
|
|
91
|
+
{...props}
|
|
92
|
+
/>
|
|
93
|
+
</MenuPrimitive.Positioner>
|
|
94
|
+
</ThemeScope>
|
|
95
|
+
</MenuPrimitive.Portal>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
export const DropdownMenuSubContent = ({
|
|
99
|
+
className,
|
|
100
|
+
side,
|
|
101
|
+
sideOffset,
|
|
102
|
+
align,
|
|
103
|
+
alignOffset,
|
|
104
|
+
collisionPadding,
|
|
105
|
+
container,
|
|
106
|
+
...props
|
|
107
|
+
}: DropdownMenuContentProps) => (
|
|
108
|
+
<MenuPrimitive.Portal container={usePortalContainer(container)}>
|
|
109
|
+
<ThemeScope>
|
|
110
|
+
<MenuPrimitive.Positioner
|
|
111
|
+
align={align}
|
|
112
|
+
alignOffset={alignOffset}
|
|
113
|
+
className="z-50 outline-none"
|
|
114
|
+
collisionPadding={collisionPadding}
|
|
115
|
+
data-slot="dropdown-menu-sub-positioner"
|
|
116
|
+
side={side}
|
|
117
|
+
sideOffset={sideOffset}
|
|
118
|
+
>
|
|
119
|
+
<MenuPrimitive.Popup
|
|
120
|
+
className={cn(contentClass, className)}
|
|
121
|
+
data-slot="dropdown-menu-sub-content"
|
|
122
|
+
{...props}
|
|
123
|
+
/>
|
|
124
|
+
</MenuPrimitive.Positioner>
|
|
125
|
+
</ThemeScope>
|
|
126
|
+
</MenuPrimitive.Portal>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
export type DropdownMenuItemProps = WithClassName<MenuPrimitive.Item.Props> &
|
|
130
|
+
VariantProps<typeof menuItemVariants>;
|
|
131
|
+
|
|
132
|
+
export const DropdownMenuItem = ({ variant, className, ...props }: DropdownMenuItemProps) => (
|
|
133
|
+
<MenuPrimitive.Item
|
|
134
|
+
className={cn(menuItemVariants({ variant }), className)}
|
|
135
|
+
data-slot="dropdown-menu-item"
|
|
136
|
+
data-variant={variant ?? 'default'}
|
|
137
|
+
{...props}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
export const DropdownMenuCheckboxItem = ({
|
|
142
|
+
icon,
|
|
143
|
+
className,
|
|
144
|
+
children,
|
|
145
|
+
...props
|
|
146
|
+
}: WithClassName<MenuPrimitive.CheckboxItem.Props> & {
|
|
147
|
+
/** A 16px icon before the name, in the row's leading slot like a plain item's. */
|
|
148
|
+
icon?: ReactNode;
|
|
149
|
+
}) => (
|
|
150
|
+
<MenuItem
|
|
151
|
+
className={className}
|
|
152
|
+
data-slot="dropdown-menu-checkbox-item"
|
|
153
|
+
leading={icon}
|
|
154
|
+
render={<MenuPrimitive.CheckboxItem {...props} />}
|
|
155
|
+
trailing={
|
|
156
|
+
<MenuPrimitive.CheckboxItemIndicator className="flex">
|
|
157
|
+
<Check strokeWidth={2} />
|
|
158
|
+
</MenuPrimitive.CheckboxItemIndicator>
|
|
159
|
+
}
|
|
160
|
+
>
|
|
161
|
+
{children}
|
|
162
|
+
</MenuItem>
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
export const DropdownMenuRadioItem = ({
|
|
166
|
+
icon,
|
|
167
|
+
className,
|
|
168
|
+
children,
|
|
169
|
+
...props
|
|
170
|
+
}: WithClassName<MenuPrimitive.RadioItem.Props> & {
|
|
171
|
+
/** A 16px icon before the name, in the row's leading slot like a plain item's. */
|
|
172
|
+
icon?: ReactNode;
|
|
173
|
+
}) => (
|
|
174
|
+
// Checked takes the same selected wash as a select's picked option.
|
|
175
|
+
<MenuItem
|
|
176
|
+
className={cn('data-checked:bg-selected data-checked:text-neutral-950', className)}
|
|
177
|
+
data-slot="dropdown-menu-radio-item"
|
|
178
|
+
leading={icon}
|
|
179
|
+
render={<MenuPrimitive.RadioItem {...props} />}
|
|
180
|
+
trailing={
|
|
181
|
+
<MenuPrimitive.RadioItemIndicator className="flex">
|
|
182
|
+
<Check strokeWidth={2} />
|
|
183
|
+
</MenuPrimitive.RadioItemIndicator>
|
|
184
|
+
}
|
|
185
|
+
>
|
|
186
|
+
{children}
|
|
187
|
+
</MenuItem>
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
export const DropdownMenuSubTrigger = ({
|
|
191
|
+
icon,
|
|
192
|
+
className,
|
|
193
|
+
children,
|
|
194
|
+
...props
|
|
195
|
+
}: WithClassName<MenuPrimitive.SubmenuTrigger.Props> & {
|
|
196
|
+
/** A 16px icon before the name, in the row's leading slot; in the children it would sit over the name. */
|
|
197
|
+
icon?: ReactNode;
|
|
198
|
+
}) => (
|
|
199
|
+
<MenuItem
|
|
200
|
+
className={cn('data-popup-open:bg-selected data-popup-open:text-neutral-800', className)}
|
|
201
|
+
data-slot="dropdown-menu-sub-trigger"
|
|
202
|
+
leading={icon}
|
|
203
|
+
render={<MenuPrimitive.SubmenuTrigger {...props} />}
|
|
204
|
+
trailing={<ChevronRight strokeWidth={2} />}
|
|
205
|
+
>
|
|
206
|
+
{children}
|
|
207
|
+
</MenuItem>
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const labelClass = 'px-3 pt-1.5 pb-1 font-medium text-neutral-600 text-xxs';
|
|
211
|
+
|
|
212
|
+
export const DropdownMenuLabel = ({ className, ...props }: ComponentProps<'div'>) => {
|
|
213
|
+
const inGroup = useContext(InGroupContext);
|
|
214
|
+
|
|
215
|
+
// Outside a group the label only titles the menu, so a plain element is enough.
|
|
216
|
+
const Label = inGroup ? MenuPrimitive.GroupLabel : 'div';
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<Label className={cn(labelClass, className)} data-slot="dropdown-menu-label" {...props} />
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const DropdownMenuSeparator = ({
|
|
224
|
+
className,
|
|
225
|
+
...props
|
|
226
|
+
}: WithClassName<MenuPrimitive.Separator.Props>) => (
|
|
227
|
+
<MenuPrimitive.Separator
|
|
228
|
+
className={cn('-mx-1 h-px bg-neutral-200', className)}
|
|
229
|
+
data-slot="dropdown-menu-separator"
|
|
230
|
+
{...props}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
export const DropdownMenuShortcut = ({ className, ...props }: ComponentProps<'span'>) => (
|
|
235
|
+
<span
|
|
236
|
+
className={cn('ml-auto pl-3 font-medium text-neutral-600 text-xxs', className)}
|
|
237
|
+
data-slot="dropdown-menu-shortcut"
|
|
238
|
+
{...props}
|
|
239
|
+
/>
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
// The keys a search hands on to the menu: moving into the list, and leaving it.
|
|
243
|
+
const menuKeys = new Set(['ArrowDown', 'ArrowUp', 'Escape', 'Tab']);
|
|
244
|
+
|
|
245
|
+
export type DropdownMenuSearchProps = Omit<ComponentProps<'input'>, 'value' | 'onChange'> & {
|
|
246
|
+
value: string;
|
|
247
|
+
onValueChange: (value: string) => void;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* A search at the top of a menu, for one long enough to need it (assign to, move to, add label).
|
|
252
|
+
* No box: a 16px icon and the text, ruled off from the list full width, the icon in line with the
|
|
253
|
+
* rows' icons. It takes focus as the menu opens and keeps its typing from the menu's typeahead;
|
|
254
|
+
* the arrows still move into the list, and Enter runs the first item left. The menu filters its
|
|
255
|
+
* own items by `value`.
|
|
256
|
+
*/
|
|
257
|
+
export const DropdownMenuSearch = ({
|
|
258
|
+
value,
|
|
259
|
+
onValueChange,
|
|
260
|
+
placeholder = 'Search',
|
|
261
|
+
className,
|
|
262
|
+
onKeyDown,
|
|
263
|
+
...props
|
|
264
|
+
}: DropdownMenuSearchProps) => {
|
|
265
|
+
const ref = useRef<HTMLInputElement>(null);
|
|
266
|
+
|
|
267
|
+
// The menu focuses its popup as it opens; the search takes it over on the next frame.
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
const frame = requestAnimationFrame(() => ref.current?.focus());
|
|
270
|
+
return () => cancelAnimationFrame(frame);
|
|
271
|
+
}, []);
|
|
272
|
+
|
|
273
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
274
|
+
onKeyDown?.(event);
|
|
275
|
+
if (!menuKeys.has(event.key)) event.stopPropagation();
|
|
276
|
+
// Enter runs the first item left, as a command menu's search does; not while an IME is composing.
|
|
277
|
+
if (event.key === 'Enter' && !event.defaultPrevented && !event.nativeEvent.isComposing) {
|
|
278
|
+
const first = event.currentTarget
|
|
279
|
+
.closest('[data-slot=dropdown-menu-content],[data-slot=dropdown-menu-sub-content]')
|
|
280
|
+
?.querySelector<HTMLElement>(
|
|
281
|
+
'[role^=menuitem]:not([data-disabled]):not([aria-disabled=true])',
|
|
282
|
+
);
|
|
283
|
+
if (first) {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
first.click();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
className="-mx-1 -mt-1 flex h-row shrink-0 items-center gap-3 border-neutral-200 border-b px-4 text-neutral-500 [&_svg]:size-4 [&_svg]:shrink-0"
|
|
293
|
+
data-slot="dropdown-menu-search"
|
|
294
|
+
>
|
|
295
|
+
<Search aria-hidden strokeWidth={2} />
|
|
296
|
+
<input
|
|
297
|
+
autoComplete="off"
|
|
298
|
+
className={cn(
|
|
299
|
+
// 16px on a touch screen, or iOS zooms the page in when the search takes focus.
|
|
300
|
+
'h-full min-w-0 flex-1 bg-transparent pointer-coarse:text-base text-neutral-950 text-xs outline-none placeholder:text-neutral-600',
|
|
301
|
+
className,
|
|
302
|
+
)}
|
|
303
|
+
data-slot="dropdown-menu-search-input"
|
|
304
|
+
onChange={event => onValueChange(event.target.value)}
|
|
305
|
+
onKeyDown={handleKeyDown}
|
|
306
|
+
placeholder={placeholder}
|
|
307
|
+
ref={ref}
|
|
308
|
+
spellCheck={false}
|
|
309
|
+
value={value}
|
|
310
|
+
{...props}
|
|
311
|
+
/>
|
|
312
|
+
</div>
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/** What a searched menu shows when nothing matches. */
|
|
317
|
+
export const DropdownMenuEmpty = ({ className, ...props }: ComponentProps<'div'>) => (
|
|
318
|
+
<div
|
|
319
|
+
className={cn('px-3 py-2.5 text-neutral-600 text-xs', className)}
|
|
320
|
+
data-slot="dropdown-menu-empty"
|
|
321
|
+
{...props}
|
|
322
|
+
/>
|
|
323
|
+
);
|