@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,199 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ArrowUp, Paperclip, Plus } from 'lucide-react';
|
|
4
|
+
import { useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
import { Button } from './button.js';
|
|
7
|
+
import { AttachContext, assignRef, focusTextOnPress, hasContent, SuggestionsContext, } from './chat-shared.js';
|
|
8
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from './dropdown-menu.js';
|
|
9
|
+
let warnedNoPicker = false;
|
|
10
|
+
/**
|
|
11
|
+
* The "Add attachments" row of an `attachMenu`, in `MessageComposer` or `AssistantPrompt`: a paperclip and
|
|
12
|
+
* the label, opening that part's own file picker, so the files arrive through `onAttach` as they do
|
|
13
|
+
* without a menu. It needs `onAttach` on the part round it.
|
|
14
|
+
*/
|
|
15
|
+
export const MessageComposerAttachItem = ({ children = 'Add attachments', onClick, ...props }) => {
|
|
16
|
+
const picker = useContext(AttachContext);
|
|
17
|
+
return (_jsxs(DropdownMenuItem, { "data-slot": "message-composer-attach-item", onClick: event => {
|
|
18
|
+
onClick?.(event);
|
|
19
|
+
if (picker?.openFiles)
|
|
20
|
+
picker.openFiles();
|
|
21
|
+
else if (!warnedNoPicker) {
|
|
22
|
+
warnedNoPicker = true;
|
|
23
|
+
console.warn('MessageComposerAttachItem: pass `onAttach` to the MessageComposer or AssistantPrompt round it, or this row opens no file picker.');
|
|
24
|
+
}
|
|
25
|
+
}, ...props, children: [_jsx(Paperclip, { "aria-hidden": true, strokeWidth: 2 }), children] }));
|
|
26
|
+
};
|
|
27
|
+
const optionSelector = '[role=option]:not([aria-disabled=true])';
|
|
28
|
+
/**
|
|
29
|
+
* Where the current user writes: an attach button filled in the action colour, a text box that
|
|
30
|
+
* grows with the draft and a quiet send arrow that wakes once there is something to send. Enter
|
|
31
|
+
* sends; Shift+Enter starts a new line. Above the box, from the top: who else is typing, then what
|
|
32
|
+
* waits to go with the message; suggestions for a reference being typed float just over the box.
|
|
33
|
+
*/
|
|
34
|
+
export const MessageComposer = ({ value: valueProp, defaultValue = '', onValueChange, onSend, onAttach, accept, onAdd, attachMenu, attach: attachSlot, start, attachments, typing, suggestions, onSuggestionsClose, placeholder = 'Write a message', disabled = false, label = 'Message', attachLabel, addLabel, sendLabel = 'Send', name, maxLength, textareaRef, className, ...props }) => {
|
|
35
|
+
const attachName = attachLabel ?? addLabel ?? 'Attach';
|
|
36
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
37
|
+
const controlled = valueProp !== undefined;
|
|
38
|
+
const value = controlled ? valueProp : uncontrolled;
|
|
39
|
+
const attached = hasContent(attachments);
|
|
40
|
+
const canSend = !disabled && (value.trim().length > 0 || attached);
|
|
41
|
+
const suggesting = !disabled && hasContent(suggestions);
|
|
42
|
+
const nodeRef = useRef(null);
|
|
43
|
+
const fileRef = useRef(null);
|
|
44
|
+
const listRef = useRef(null);
|
|
45
|
+
const listId = useId();
|
|
46
|
+
const menuCloseReason = useRef(null);
|
|
47
|
+
const [activeId, setActiveId] = useState(null);
|
|
48
|
+
const setValue = (next) => {
|
|
49
|
+
if (!controlled)
|
|
50
|
+
setUncontrolled(next);
|
|
51
|
+
onValueChange?.(next);
|
|
52
|
+
};
|
|
53
|
+
const setRef = useCallback(node => {
|
|
54
|
+
nodeRef.current = node;
|
|
55
|
+
assignRef(textareaRef, node);
|
|
56
|
+
}, [textareaRef]);
|
|
57
|
+
// Grow with the draft up to max-h, then scroll; field-sizing is not in every browser yet.
|
|
58
|
+
const fit = useCallback(() => {
|
|
59
|
+
const node = nodeRef.current;
|
|
60
|
+
if (!node)
|
|
61
|
+
return;
|
|
62
|
+
node.style.height = 'auto';
|
|
63
|
+
node.style.height = `${node.scrollHeight}px`;
|
|
64
|
+
}, []);
|
|
65
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the height follows the value.
|
|
66
|
+
useLayoutEffect(fit, [fit, value]);
|
|
67
|
+
// The same draft wraps onto more or fewer lines as the box's width changes (a window resized,
|
|
68
|
+
// a panel opened beside it) and once the font has loaded, so the height is fitted again then.
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const node = nodeRef.current;
|
|
71
|
+
if (!node)
|
|
72
|
+
return;
|
|
73
|
+
let width = node.clientWidth;
|
|
74
|
+
const observer = new ResizeObserver(() => {
|
|
75
|
+
if (node.clientWidth === width)
|
|
76
|
+
return;
|
|
77
|
+
width = node.clientWidth;
|
|
78
|
+
fit();
|
|
79
|
+
});
|
|
80
|
+
observer.observe(node);
|
|
81
|
+
void document.fonts?.ready.then(fit);
|
|
82
|
+
return () => observer.disconnect();
|
|
83
|
+
}, [fit]);
|
|
84
|
+
const options = () => Array.from(listRef.current?.querySelectorAll(optionSelector) ?? []);
|
|
85
|
+
// The first row is active as the suggestions open, and again whenever the active one leaves the list.
|
|
86
|
+
useLayoutEffect(() => {
|
|
87
|
+
if (!suggesting) {
|
|
88
|
+
if (activeId !== null)
|
|
89
|
+
setActiveId(null);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const rows = Array.from(listRef.current?.querySelectorAll(optionSelector) ?? []);
|
|
93
|
+
if (!rows.some(row => row.id === activeId))
|
|
94
|
+
setActiveId(rows[0]?.id ?? null);
|
|
95
|
+
});
|
|
96
|
+
// The active row is kept in view as the arrows move past the list's edge.
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!activeId)
|
|
99
|
+
return;
|
|
100
|
+
listRef.current
|
|
101
|
+
?.querySelector(`[id="${CSS.escape(activeId)}"]`)
|
|
102
|
+
?.scrollIntoView({ block: 'nearest' });
|
|
103
|
+
}, [activeId]);
|
|
104
|
+
const send = () => {
|
|
105
|
+
if (!canSend)
|
|
106
|
+
return;
|
|
107
|
+
if (onSend?.(value.trim()) !== false)
|
|
108
|
+
setValue('');
|
|
109
|
+
nodeRef.current?.focus();
|
|
110
|
+
};
|
|
111
|
+
const onKeyDown = (event) => {
|
|
112
|
+
// Enter during IME composition picks a candidate; it must not send half a word.
|
|
113
|
+
if (event.nativeEvent.isComposing)
|
|
114
|
+
return;
|
|
115
|
+
if (suggesting) {
|
|
116
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
const rows = options();
|
|
119
|
+
if (rows.length === 0)
|
|
120
|
+
return;
|
|
121
|
+
const at = rows.findIndex(row => row.id === activeId);
|
|
122
|
+
const step = event.key === 'ArrowDown' ? 1 : -1;
|
|
123
|
+
const next = at === -1
|
|
124
|
+
? step === 1
|
|
125
|
+
? 0
|
|
126
|
+
: rows.length - 1
|
|
127
|
+
: (at + step + rows.length) % rows.length;
|
|
128
|
+
setActiveId(rows[next]?.id ?? null);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if ((event.key === 'Enter' || event.key === 'Tab') && !event.shiftKey) {
|
|
132
|
+
const row = options().find(option => option.id === activeId);
|
|
133
|
+
if (row) {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
row.click();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (event.key === 'Escape') {
|
|
140
|
+
// Only the suggestions close: a sheet or dialog round the composer stays open.
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
event.stopPropagation();
|
|
143
|
+
onSuggestionsClose?.();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (event.key !== 'Enter' || event.shiftKey)
|
|
148
|
+
return;
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
send();
|
|
151
|
+
};
|
|
152
|
+
const openFiles = onAttach ? () => fileRef.current?.click() : null;
|
|
153
|
+
const attach = onAdd ?? openFiles ?? undefined;
|
|
154
|
+
const addButton = (_jsx(Button, { "aria-label": attachName,
|
|
155
|
+
// The composer's one filled control: the send beside it stays a quiet arrow.
|
|
156
|
+
className: "size-cell rounded-item", "data-slot": "message-composer-add", disabled: disabled, onClick: attachMenu ? undefined : attach,
|
|
157
|
+
// No size variant: the cell square (32) and its corner are its own, not the 34 control row.
|
|
158
|
+
size: null, variant: "primary", children: _jsx(Plus, { "aria-hidden": true, strokeWidth: 2 }) }));
|
|
159
|
+
const leading = attachSlot ??
|
|
160
|
+
start ??
|
|
161
|
+
(attachMenu ? (_jsxs(DropdownMenu, { onOpenChange: (open, details) => {
|
|
162
|
+
if (!open)
|
|
163
|
+
menuCloseReason.current = details.reason;
|
|
164
|
+
}, children: [_jsx(DropdownMenuTrigger, { disabled: disabled, render: addButton }), _jsx(DropdownMenuContent, { align: "start", className: "min-w-menu-wide", finalFocus: () => menuCloseReason.current === 'item-press' ? nodeRef.current : true, side: "top", sideOffset: 8, children: attachMenu })] })) : (attach && addButton));
|
|
165
|
+
return (_jsx(AttachContext.Provider, { value: { openFiles }, children: _jsxs("form", { className: cn('flex min-w-0 flex-col', className), "data-disabled": disabled || undefined, "data-slot": "message-composer", onSubmit: event => {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
send();
|
|
168
|
+
}, ...props, children: [typing !== undefined && (
|
|
169
|
+
// Held at its 24 row (6 above it, 8 clear of what follows) while nobody types, so the box never moves.
|
|
170
|
+
_jsx("div", { className: "box-content flex h-6 min-w-0 items-center pt-1.5 pb-2", "data-slot": "message-composer-typing", children: typing })), onAttach && (_jsx("input", { accept: accept, className: "hidden", "data-slot": "message-composer-file", disabled: disabled, multiple: true, onChange: event => {
|
|
171
|
+
const files = Array.from(event.currentTarget.files ?? []);
|
|
172
|
+
// Cleared, so choosing the same file again after removing it still reports.
|
|
173
|
+
event.currentTarget.value = '';
|
|
174
|
+
if (files.length > 0)
|
|
175
|
+
onAttach(files);
|
|
176
|
+
nodeRef.current?.focus();
|
|
177
|
+
}, ref: fileRef, tabIndex: -1, type: "file" })), attached && (
|
|
178
|
+
// What waits to go, outside the box and 8 above it, so the box keeps its one-line look.
|
|
179
|
+
_jsx("div", { className: "min-w-0 pb-2", "data-slot": "message-composer-attachments", children: attachments })), _jsxs("div", { className: "relative min-w-0", "data-slot": "message-composer-field", children: [suggesting && (
|
|
180
|
+
// Over whatever is above the box, 8 clear of it and its full width.
|
|
181
|
+
_jsx("div", { className: "absolute inset-x-0 bottom-full z-10 pb-2", "data-slot": "message-composer-suggestions", ref: listRef, children: _jsx(SuggestionsContext.Provider, { value: { listId, activeId, setActiveId }, children: suggestions }) })), _jsxs("div", { className: cn(
|
|
182
|
+
// 48 high at one line (control-xl): a cell row in 8 of room, the hairline inside
|
|
183
|
+
// it. The corner is the attach button's and 4 more, not the padding's full 8, so
|
|
184
|
+
// box and button read as one shape; it squares off with them at corner scale 0.
|
|
185
|
+
'flex min-h-control-xl cursor-text items-end gap-3 rounded-[min(calc(var(--radius-item)+4px),calc(var(--radius-item)*100))] border border-neutral-100 bg-neutral-50 py-[calc(--spacing(2)-1px)] pr-[calc(--spacing(2.5)-1px)] pl-[calc(--spacing(2)-1px)] shadow-composer transition-[border-color] duration-150', 'has-[textarea:focus-visible]:outline-2 has-[textarea:focus-visible]:outline-focus has-[textarea:focus-visible]:outline-solid has-[textarea:focus-visible]:outline-offset-2',
|
|
186
|
+
// The buttons dim themselves when disabled; dimming the frame too would halve them again.
|
|
187
|
+
disabled
|
|
188
|
+
? 'cursor-not-allowed'
|
|
189
|
+
: 'hover:border-neutral-200 has-[textarea:focus]:border-neutral-200'), "data-slot": "message-composer-box", onMouseDown: event => focusTextOnPress(event, nodeRef.current, disabled), children: [leading, _jsx("textarea", { "aria-activedescendant": (suggesting && activeId) || undefined, "aria-controls": suggesting ? listId : undefined, "aria-label": label, className: cn(
|
|
190
|
+
// One line is the cell row of the buttons beside it: text-xs's line and the rest either side.
|
|
191
|
+
'block max-h-40 min-h-cell min-w-0 flex-1 resize-none overflow-y-auto bg-transparent py-[calc((var(--spacing-cell)-var(--text-xs--line-height))/2)] text-neutral-900 text-xs outline-none placeholder:text-neutral-600',
|
|
192
|
+
// 16px on a touch screen, or iOS zooms the page in on focus; one line still fills the cell row.
|
|
193
|
+
'pointer-coarse:py-[calc((var(--spacing-cell)-var(--text-base--line-height))/2)] pointer-coarse:text-base', 'disabled:cursor-not-allowed disabled:text-neutral-400 disabled:placeholder:text-neutral-300', !leading && 'pl-2'), "data-slot": "message-composer-input", disabled: disabled, maxLength: maxLength, name: name, onBlur: () => {
|
|
194
|
+
if (suggesting)
|
|
195
|
+
onSuggestionsClose?.();
|
|
196
|
+
}, onChange: event => setValue(event.target.value), onKeyDown: onKeyDown, placeholder: placeholder, ref: setRef, rows: 1, value: value }), _jsx(Button, { "aria-label": sendLabel,
|
|
197
|
+
// Quiet: an arrow in the text's grey that darkens on hover, dimmed until there is something to send.
|
|
198
|
+
className: "size-cell rounded-item [&_svg]:size-5", "data-slot": "message-composer-send", disabled: !canSend, size: null, type: "submit", variant: "ghost", children: _jsx(ArrowUp, { "aria-hidden": true, strokeWidth: 2 }) })] })] })] }) }));
|
|
199
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
2
|
+
import { type ComponentProps } from 'react';
|
|
3
|
+
export type NavRailProps = ComponentProps<'nav'> & {
|
|
4
|
+
/** Open with each item's label beside its icon; closed it is icons, named in tooltips. */
|
|
5
|
+
expanded?: boolean;
|
|
6
|
+
defaultExpanded?: boolean;
|
|
7
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The app's main navigation as a floating island at the page's edge: 52px of icons, or 208px with
|
|
11
|
+
* each item's label once expanded (a `NavRailToggle` opens and closes it). The current item sits on
|
|
12
|
+
* one action pill that slides from the old item to the new one, and the icons keep their place
|
|
13
|
+
* as the rail widens, so only the labels arrive.
|
|
14
|
+
*/
|
|
15
|
+
export declare const NavRail: ({ expanded: expandedProp, defaultExpanded, onExpandedChange, className, style, children, ...props }: NavRailProps) => import("react").JSX.Element;
|
|
16
|
+
export declare const NavRailSeparator: ({ className, ...props }: ComponentProps<"hr">) => import("react").JSX.Element;
|
|
17
|
+
type RailItemProps = useRender.ComponentProps<'button'> & {
|
|
18
|
+
/** Beside the icon when the rail is open, in a tooltip when it is closed, and the accessible name. */
|
|
19
|
+
label: string;
|
|
20
|
+
/** The current section; also set by passing aria-current="page" yourself. */
|
|
21
|
+
active?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** One section: its 16px icon as children. Pass `render={<a href="…" />}` to make it a link. */
|
|
24
|
+
export declare const NavRailItem: ({ label, active, render, ref, className, children, type, ...props }: RailItemProps) => import("react").JSX.Element;
|
|
25
|
+
/** Opens and closes the rail; usually its first row. */
|
|
26
|
+
export declare const NavRailToggle: ({ className, onClick, collapseLabel, expandLabel, ...props }: ComponentProps<"button"> & {
|
|
27
|
+
/** Its names for screen readers and the tooltip while the rail is open and while it is closed. */
|
|
28
|
+
collapseLabel?: string;
|
|
29
|
+
expandLabel?: string;
|
|
30
|
+
}) => import("react").JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
4
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
5
|
+
import { PanelLeft } from 'lucide-react';
|
|
6
|
+
import { createContext, useContext, useLayoutEffect, useRef, useState, } from 'react';
|
|
7
|
+
import { cn } from '../lib/cn.js';
|
|
8
|
+
import { focusRing } from './button.js';
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip.js';
|
|
10
|
+
const NavRailContext = createContext({ expanded: false, setExpanded: () => { } });
|
|
11
|
+
/**
|
|
12
|
+
* The app's main navigation as a floating island at the page's edge: 52px of icons, or 208px with
|
|
13
|
+
* each item's label once expanded (a `NavRailToggle` opens and closes it). The current item sits on
|
|
14
|
+
* one action pill that slides from the old item to the new one, and the icons keep their place
|
|
15
|
+
* as the rail widens, so only the labels arrive.
|
|
16
|
+
*/
|
|
17
|
+
export const NavRail = ({ expanded: expandedProp, defaultExpanded = false, onExpandedChange, className, style, children, ...props }) => {
|
|
18
|
+
const [expandedState, setExpandedState] = useState(defaultExpanded);
|
|
19
|
+
const expanded = expandedProp ?? expandedState;
|
|
20
|
+
const setExpanded = (value) => {
|
|
21
|
+
setExpandedState(value);
|
|
22
|
+
onExpandedChange?.(value);
|
|
23
|
+
};
|
|
24
|
+
const ref = useRef(null);
|
|
25
|
+
const [pill, setPill] = useState();
|
|
26
|
+
// Measured before paint after every render, so the pill finds the current item however it was
|
|
27
|
+
// set; it lands on the first one in place and slides from then on.
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
const item = ref.current?.querySelector('[data-slot=rail-item][aria-current=page]');
|
|
30
|
+
setPill(previous => {
|
|
31
|
+
if (!item)
|
|
32
|
+
return undefined;
|
|
33
|
+
const next = { top: item.offsetTop, height: item.offsetHeight };
|
|
34
|
+
if (previous && previous.top === next.top && previous.height === next.height)
|
|
35
|
+
return previous;
|
|
36
|
+
return { ...next, moved: previous !== undefined };
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return (_jsx(NavRailContext.Provider, { value: { expanded, setExpanded }, children: _jsxs("nav", { className: cn('group/rail relative isolate flex shrink-0 flex-col gap-0.5 overflow-hidden rounded-dock border border-neutral-200 bg-neutral-50 p-[8px]', 'transition-[width] duration-300 ease-out-strong motion-reduce:transition-none', expanded ? 'w-rail-open' : 'w-rail', className), "data-expanded": expanded || undefined, "data-slot": "rail", ref: ref, style: style, ...props, children: [pill && (_jsx("span", { "aria-hidden": true, className: cn('absolute inset-x-[8px] top-0 -z-10 rounded-item bg-action shadow-action [background-image:var(--action-gradient)]', pill.moved &&
|
|
40
|
+
'transition-[translate,height] duration-200 ease-out-strong motion-reduce:transition-none'), "data-slot": "rail-pill", style: { translate: `0 ${pill.top}px`, height: pill.height } })), children] }) }));
|
|
41
|
+
};
|
|
42
|
+
export const NavRailSeparator = ({ className, ...props }) => (_jsx("hr", { className: cn('my-1.5 h-px w-full shrink-0 border-0 bg-neutral-200', className), "data-slot": "rail-separator", ...props }));
|
|
43
|
+
/*
|
|
44
|
+
* A control-tall row the rail's inner width: closed, the icon sits centred in it, and open it stays
|
|
45
|
+
* put. The rail is a fixed 52px box, so its insets are fixed pixels too, not the spacing unit: 8px
|
|
46
|
+
* round the rows and (52 − 2 border − 16 inset − 16 icon) / 2 = 9px either side of the icon.
|
|
47
|
+
*/
|
|
48
|
+
const railRowClass = 'flex h-control w-full shrink-0 cursor-pointer items-center gap-2.5 overflow-hidden rounded-item px-[calc((var(--spacing-control)-16px)/2)] text-neutral-600 transition-[background-color,color] duration-150 hover:bg-neutral-950/5 hover:text-neutral-800 [&_svg:not([class*=size-])]:size-4 [&_svg]:shrink-0';
|
|
49
|
+
// The label beside the icon: there while open, faded out and clipped while closed.
|
|
50
|
+
const NavRailLabel = ({ children }) => (_jsx("span", { className: "min-w-0 truncate font-medium text-xs opacity-0 transition-opacity duration-200 group-data-expanded/rail:opacity-100", "data-slot": "rail-label", children: children }));
|
|
51
|
+
/** One section: its 16px icon as children. Pass `render={<a href="…" />}` to make it a link. */
|
|
52
|
+
export const NavRailItem = ({ label, active, render, ref, className, children, type = 'button', ...props }) => {
|
|
53
|
+
const { expanded } = useContext(NavRailContext);
|
|
54
|
+
// The item is built first and handed to the trigger, so the tooltip wires
|
|
55
|
+
// itself onto the button or link rather than wrapping it in another one.
|
|
56
|
+
const item = useRender({
|
|
57
|
+
defaultTagName: 'button',
|
|
58
|
+
render,
|
|
59
|
+
ref,
|
|
60
|
+
// State keys become data attributes, so this sets data-slot="rail-item".
|
|
61
|
+
state: { slot: 'rail-item' },
|
|
62
|
+
props: mergeProps({
|
|
63
|
+
'aria-current': active ? 'page' : undefined,
|
|
64
|
+
'aria-label': label,
|
|
65
|
+
className: cn(railRowClass,
|
|
66
|
+
// The pill under it is the current look; the item only takes the pill's text colour.
|
|
67
|
+
'aria-[current=page]:text-on-action aria-[current=page]:hover:bg-transparent aria-[current=page]:hover:text-on-action', focusRing, className),
|
|
68
|
+
children: (_jsxs(_Fragment, { children: [_jsx("span", { className: "flex w-4 shrink-0 justify-center", "data-slot": "rail-icon", children: children }), _jsx(NavRailLabel, { children: label })] })),
|
|
69
|
+
type: render ? undefined : type,
|
|
70
|
+
}, props),
|
|
71
|
+
});
|
|
72
|
+
return (
|
|
73
|
+
// Open, the label is on the row already, so the tooltip stands down.
|
|
74
|
+
_jsxs(Tooltip, { disabled: expanded, children: [_jsx(TooltipTrigger, { render: item }), _jsx(TooltipContent, { side: "right", children: label })] }));
|
|
75
|
+
};
|
|
76
|
+
/** Opens and closes the rail; usually its first row. */
|
|
77
|
+
export const NavRailToggle = ({ className, onClick, collapseLabel = 'Collapse navigation', expandLabel = 'Expand navigation', ...props }) => {
|
|
78
|
+
const { expanded, setExpanded } = useContext(NavRailContext);
|
|
79
|
+
// Named for what it holds, the app's navigation, since "rail" is the library's word, not the reader's.
|
|
80
|
+
const label = expanded ? collapseLabel : expandLabel;
|
|
81
|
+
return (_jsxs(Tooltip, { disabled: expanded, children: [_jsx(TooltipTrigger, { render: _jsxs("button", { "aria-expanded": expanded, "aria-label": label, className: cn(railRowClass, focusRing, className), "data-slot": "rail-toggle", onClick: event => {
|
|
82
|
+
onClick?.(event);
|
|
83
|
+
setExpanded(!expanded);
|
|
84
|
+
}, type: "button", ...props, children: [_jsx(PanelLeft, { "aria-hidden": true, strokeWidth: 2 }), _jsx(NavRailLabel, { children: "Collapse" })] }) }), _jsx(TooltipContent, { side: "right", children: label })] }));
|
|
85
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
declare const noticeTones: {
|
|
3
|
+
readonly neutral: "[&_svg]:text-neutral-500";
|
|
4
|
+
readonly primary: "[&_svg]:text-primary-700";
|
|
5
|
+
readonly success: "[&_svg]:text-success-700";
|
|
6
|
+
readonly warning: "[&_svg]:text-warning-700";
|
|
7
|
+
readonly error: "[&_svg]:text-error-600";
|
|
8
|
+
};
|
|
9
|
+
export type NoticeTone = keyof typeof noticeTones;
|
|
10
|
+
export type NoticeProps = Omit<ComponentProps<'output'>, 'children'> & {
|
|
11
|
+
/** What just happened, in a word or two: "Saved", "Link copied". Nothing hides the notice. */
|
|
12
|
+
message?: ReactNode;
|
|
13
|
+
/** Leads the message; a tick by default. Pass a `<Spinner size="sm" />` while it is still working. */
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
/** Colours the icon. Success for the default tick, neutral for an icon of your own, as a spinner. */
|
|
16
|
+
tone?: NoticeTone;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The quiet toast: for small actions that need no undo, a tab slides out from under a bar's
|
|
20
|
+
* hairline, centred, and the hairline runs round it. Place it in a positioned bar with a bottom
|
|
21
|
+
* border (the header bar, a sheet's or a panel's header); it is drawn in the bar's own surface and
|
|
22
|
+
* border, so it reads as the bar saying something, not as something laid over the page. Bigger
|
|
23
|
+
* news, or anything with an undo, is a toast at the foot instead.
|
|
24
|
+
*/
|
|
25
|
+
export declare const Notice: ({ message, icon, tone, className, ...props }: NoticeProps) => import("react").JSX.Element;
|
|
26
|
+
export type NoticeOptions = {
|
|
27
|
+
icon?: ReactNode;
|
|
28
|
+
tone?: NoticeTone;
|
|
29
|
+
/** How long it shows, in ms; 0 keeps it until the next one or `clear`. */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* State for a `Notice`: `show("Saved")` raises it and it leaves by itself after a moment.
|
|
34
|
+
* Spread `notice` on the notice: `<HeaderBarNotice {...notice} />`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const useNotice: (defaultTimeout?: number) => {
|
|
37
|
+
notice: {
|
|
38
|
+
message?: ReactNode;
|
|
39
|
+
icon?: ReactNode;
|
|
40
|
+
tone?: NoticeTone;
|
|
41
|
+
};
|
|
42
|
+
show: (message: ReactNode, { icon, tone, timeout }?: NoticeOptions) => void;
|
|
43
|
+
clear: () => void;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Check } from 'lucide-react';
|
|
4
|
+
import { useCallback, useEffect, useRef, useState, } from 'react';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
/*
|
|
7
|
+
* Only the icon carries the tone, at the step an alert's takes (700, 600 for the error red, so it
|
|
8
|
+
* reaches 3:1): the tab stays the bar's surface, and the colour is the accent that says how it went.
|
|
9
|
+
*/
|
|
10
|
+
const noticeTones = {
|
|
11
|
+
neutral: '[&_svg]:text-neutral-500',
|
|
12
|
+
primary: '[&_svg]:text-primary-700',
|
|
13
|
+
success: '[&_svg]:text-success-700',
|
|
14
|
+
warning: '[&_svg]:text-warning-700',
|
|
15
|
+
error: '[&_svg]:text-error-600',
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The quiet toast: for small actions that need no undo, a tab slides out from under a bar's
|
|
19
|
+
* hairline, centred, and the hairline runs round it. Place it in a positioned bar with a bottom
|
|
20
|
+
* border (the header bar, a sheet's or a panel's header); it is drawn in the bar's own surface and
|
|
21
|
+
* border, so it reads as the bar saying something, not as something laid over the page. Bigger
|
|
22
|
+
* news, or anything with an undo, is a toast at the foot instead.
|
|
23
|
+
*/
|
|
24
|
+
export const Notice = ({ message, icon, tone, className, ...props }) => {
|
|
25
|
+
// The last message stays while the tab slides away, so it does not empty as it leaves.
|
|
26
|
+
const [shown, setShown] = useState();
|
|
27
|
+
const open = message !== undefined && message !== null && message !== false;
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (open)
|
|
30
|
+
setShown({ message, icon, tone: tone ?? (icon ? 'neutral' : 'success') });
|
|
31
|
+
}, [open, message, icon, tone]);
|
|
32
|
+
return (
|
|
33
|
+
// The clip starts on the bar's hairline (just past its padding box), so the tab comes out of
|
|
34
|
+
// that edge rather than out of nowhere, and covers the hairline where it hangs.
|
|
35
|
+
_jsx("output", { "aria-live": "polite", className: cn(
|
|
36
|
+
// Padded by the fillets' size, so the clip keeps them. The fillet follows the tab's
|
|
37
|
+
// corner (8px at the default 10px), so a square theme squares it too.
|
|
38
|
+
'pointer-events-none absolute top-full left-1/2 z-20 -translate-x-1/2 overflow-hidden px-(--fillet) pb-px [--fillet:calc(var(--radius-item)*0.8)]', className), "data-slot": "notice", ...props, children: _jsx("div", { className: cn('pointer-events-auto relative flex h-cell items-center gap-1.5 whitespace-nowrap rounded-b-item border border-neutral-200 border-t-0 bg-neutral-50 px-3 text-neutral-700 text-xs',
|
|
39
|
+
/*
|
|
40
|
+
* Where the bar's hairline turns down into the tab, it bends round a curve the
|
|
41
|
+
* fillet's size instead of a corner: a square either side, filled with the bar's
|
|
42
|
+
* surface outside a quarter circle and drawn with its border on the curve,
|
|
43
|
+
* transparent inside. At a 0 corner the squares are 0 and the turn is square.
|
|
44
|
+
*/
|
|
45
|
+
"before:absolute before:top-0 before:left-[calc(var(--fillet)*-1)] before:size-(--fillet) before:content-[''] before:[background:radial-gradient(circle_at_0_100%,transparent_calc(var(--fillet)_-_1.25px),var(--color-neutral-200)_calc(var(--fillet)_-_0.75px),var(--color-neutral-200)_calc(var(--fillet)_-_0.25px),var(--color-neutral-50)_calc(var(--fillet)_+_0.25px))]", "after:absolute after:top-0 after:right-[calc(var(--fillet)*-1)] after:size-(--fillet) after:content-[''] after:[background:radial-gradient(circle_at_100%_100%,transparent_calc(var(--fillet)_-_1.25px),var(--color-neutral-200)_calc(var(--fillet)_-_0.75px),var(--color-neutral-200)_calc(var(--fillet)_-_0.25px),var(--color-neutral-50)_calc(var(--fillet)_+_0.25px))]", '[&_svg:not([class*=size-])]:size-3.5 [&_svg]:shrink-0', noticeTones[shown?.tone ?? 'neutral'], 'transition-[translate,opacity] duration-200 ease-out-strong motion-reduce:translate-y-0 motion-reduce:transition-opacity', open ? 'translate-y-0 opacity-100' : '-translate-y-full opacity-0'), "data-open": open || undefined, "data-slot": "notice-tab", children: shown && (_jsxs(_Fragment, { children: [shown.icon ?? _jsx(Check, { strokeWidth: 2 }), shown.message] })) }) }));
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* State for a `Notice`: `show("Saved")` raises it and it leaves by itself after a moment.
|
|
49
|
+
* Spread `notice` on the notice: `<HeaderBarNotice {...notice} />`.
|
|
50
|
+
*/
|
|
51
|
+
export const useNotice = (defaultTimeout = 1800) => {
|
|
52
|
+
const [notice, setNotice] = useState({});
|
|
53
|
+
const timer = useRef(undefined);
|
|
54
|
+
const clear = useCallback(() => {
|
|
55
|
+
window.clearTimeout(timer.current);
|
|
56
|
+
setNotice(current => ({ ...current, message: undefined }));
|
|
57
|
+
}, []);
|
|
58
|
+
const show = useCallback((message, { icon, tone, timeout = defaultTimeout } = {}) => {
|
|
59
|
+
window.clearTimeout(timer.current);
|
|
60
|
+
setNotice({ message, icon, tone });
|
|
61
|
+
if (timeout > 0)
|
|
62
|
+
timer.current = window.setTimeout(clear, timeout);
|
|
63
|
+
}, [clear, defaultTimeout]);
|
|
64
|
+
useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
65
|
+
return { notice, show, clear };
|
|
66
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type OptimisticAction = {
|
|
2
|
+
/** Shows the change at once, as though it were done. */
|
|
3
|
+
apply: () => void;
|
|
4
|
+
/** Puts the thing back exactly as it was, in its place in the list. */
|
|
5
|
+
revert: () => void;
|
|
6
|
+
/** Sends the change. It runs as the change shows; if it rejects, the change is reverted and an error toast says so. */
|
|
7
|
+
commit?: () => unknown;
|
|
8
|
+
/** Sends the reverse, when Undo is pressed. */
|
|
9
|
+
undo?: () => unknown;
|
|
10
|
+
/** The toast's title: the thing it happened to ("Northwind Q3 review"). */
|
|
11
|
+
title: string;
|
|
12
|
+
/** What happened to it ("Moved to Archive"). */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** An optional tab over the toast ("Report archived"). */
|
|
15
|
+
tab?: string;
|
|
16
|
+
/** The error toast's words when the commit fails. */
|
|
17
|
+
failed?: {
|
|
18
|
+
title: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* An optimistic update with Undo, on the toast: the change shows at once, a toast says what happened
|
|
24
|
+
* with Undo for its 5s, and the request goes as the change shows. Undo reverts it and sends the
|
|
25
|
+
* reverse; a request that fails reverts it and says so in an `error` toast. For a reversible action
|
|
26
|
+
* that almost always succeeds (archive, move, mark as read, delete to a bin). Needs a ToastProvider.
|
|
27
|
+
*/
|
|
28
|
+
export declare const useOptimisticUndo: () => ({ apply, revert, commit, undo, title, description, tab, failed }: OptimisticAction) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useToast } from './toast.js';
|
|
4
|
+
/**
|
|
5
|
+
* An optimistic update with Undo, on the toast: the change shows at once, a toast says what happened
|
|
6
|
+
* with Undo for its 5s, and the request goes as the change shows. Undo reverts it and sends the
|
|
7
|
+
* reverse; a request that fails reverts it and says so in an `error` toast. For a reversible action
|
|
8
|
+
* that almost always succeeds (archive, move, mark as read, delete to a bin). Needs a ToastProvider.
|
|
9
|
+
*/
|
|
10
|
+
export const useOptimisticUndo = () => {
|
|
11
|
+
const toast = useToast();
|
|
12
|
+
return useCallback(({ apply, revert, commit, undo, title, description, tab, failed }) => {
|
|
13
|
+
let undone = false;
|
|
14
|
+
apply();
|
|
15
|
+
const id = toast.add({
|
|
16
|
+
title,
|
|
17
|
+
description,
|
|
18
|
+
data: { tab, undo: true },
|
|
19
|
+
actionProps: {
|
|
20
|
+
children: 'Undo',
|
|
21
|
+
onClick: () => {
|
|
22
|
+
undone = true;
|
|
23
|
+
revert();
|
|
24
|
+
undo?.();
|
|
25
|
+
toast.close(id);
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
Promise.resolve()
|
|
30
|
+
.then(commit)
|
|
31
|
+
.catch(() => {
|
|
32
|
+
if (undone)
|
|
33
|
+
return;
|
|
34
|
+
toast.close(id);
|
|
35
|
+
revert();
|
|
36
|
+
toast.add({
|
|
37
|
+
title: failed?.title ?? title,
|
|
38
|
+
description: failed?.description ?? 'It didn’t go through, so nothing changed',
|
|
39
|
+
type: 'error',
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}, [toast]);
|
|
43
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
export type OptionRowProps = Omit<ComponentProps<'label'>, 'title'> & {
|
|
3
|
+
icon?: ReactNode;
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
/** The control the row toggles: a <Checkbox /> or <RadioGroupItem />. */
|
|
7
|
+
control?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The report generator's selectable row: 48px with an icon tile, 44px for the
|
|
11
|
+
* plain radio rows. Being a <label>, a click anywhere on it toggles the control
|
|
12
|
+
* in the trailing slot.
|
|
13
|
+
*/
|
|
14
|
+
export declare const OptionRow: ({ icon, label, description, control, className, ...props }: OptionRowProps) => import("react").JSX.Element;
|
|
15
|
+
export declare const OptionList: ({ className, ...props }: ComponentProps<"div">) => import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '../lib/cn.js';
|
|
3
|
+
import { IconTile } from './icon-tile.js';
|
|
4
|
+
/**
|
|
5
|
+
* The report generator's selectable row: 48px with an icon tile, 44px for the
|
|
6
|
+
* plain radio rows. Being a <label>, a click anywhere on it toggles the control
|
|
7
|
+
* in the trailing slot.
|
|
8
|
+
*/
|
|
9
|
+
export const OptionRow = ({ icon, label, description, control, className, ...props }) => (
|
|
10
|
+
// biome-ignore lint/a11y/noLabelWithoutControl: the control arrives through the `control` slot
|
|
11
|
+
_jsxs("label", { className: cn('flex cursor-pointer items-center justify-between gap-3 rounded-item border border-neutral-200 py-2 pr-3 pl-2 transition-[border-color] duration-150',
|
|
12
|
+
// The control inside carries the disabled state: its hidden input, or Base UI's data attribute.
|
|
13
|
+
'not-has-disabled:not-has-data-disabled:hover:border-neutral-300', 'has-data-disabled:cursor-not-allowed has-disabled:cursor-not-allowed has-data-disabled:opacity-50 has-disabled:opacity-50', !icon && 'p-3', className), "data-slot": "option-row", ...props, children: [_jsxs("span", { className: "flex min-w-0 items-center gap-3", children: [icon && _jsx(IconTile, { children: icon }), _jsxs("span", { className: "flex min-w-0 flex-col", children: [_jsx("span", { className: "font-normal text-neutral-950 text-sm", children: label }), description && (_jsx("span", { className: "font-normal text-neutral-600 text-xs", children: description }))] })] }), control] }));
|
|
14
|
+
export const OptionList = ({ className, ...props }) => (_jsx("div", { className: cn('flex flex-col gap-2', className), "data-slot": "option-list", ...props }));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
export declare const pageContentVariants: (props?: ({
|
|
4
|
+
width?: "inset" | "default" | "dense" | "full" | "narrow" | "wide" | null | undefined;
|
|
5
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
|
+
export type PageContentProps = ComponentProps<'div'> & VariantProps<typeof pageContentVariants>;
|
|
7
|
+
/**
|
|
8
|
+
* The centred column a page's content sits in. Its width follows how dense the
|
|
9
|
+
* content is, not the screen: a page never runs to the panel's edges.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PageContent: ({ width, className, ...props }: PageContentProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cva } from 'class-variance-authority';
|
|
3
|
+
import { cn } from '../lib/cn.js';
|
|
4
|
+
export const pageContentVariants = cva(
|
|
5
|
+
// Content-box, so the cap is the content's width and the side padding sits outside it. A page
|
|
6
|
+
// starts clear of the header bar: 64px at every width. In a compact shell (a phone) the screen
|
|
7
|
+
// can't spare that: 16px a side and 40px down.
|
|
8
|
+
'mx-auto box-content min-w-0 px-4 pt-16 sm:px-6 @max-shell-compact/shell:px-4 @max-shell-compact/shell:pt-10', {
|
|
9
|
+
variants: {
|
|
10
|
+
width: {
|
|
11
|
+
/** 640: one object made or edited, its fields stacked (a new post, a new customer), and settings. */
|
|
12
|
+
narrow: 'max-w-content-narrow',
|
|
13
|
+
/** 896: overviews, details, documents. */
|
|
14
|
+
default: 'max-w-content',
|
|
15
|
+
/** 1080: content that needs the width, like a list with several columns. */
|
|
16
|
+
wide: 'max-w-content-wide',
|
|
17
|
+
/** 1280: a very dense table. */
|
|
18
|
+
dense: 'max-w-content-dense',
|
|
19
|
+
/** Lots of information, several dense tables: the panel less 64px a side, 128px on the largest screens. */
|
|
20
|
+
inset: 'lg:px-16 2xl:px-content-inset',
|
|
21
|
+
/** Only when asked for: the panel's whole width, edge to edge. */
|
|
22
|
+
full: 'px-0 sm:px-0 @max-shell-compact/shell:px-0',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: { width: 'default' },
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The centred column a page's content sits in. Its width follows how dense the
|
|
29
|
+
* content is, not the screen: a page never runs to the panel's edges.
|
|
30
|
+
*/
|
|
31
|
+
export const PageContent = ({ width, className, ...props }) => (_jsx("div", { className: cn(pageContentVariants({ width }), className), "data-slot": "page-content", "data-width": width ?? 'default', ...props }));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
export type PaginationButtonProps = ComponentProps<'button'> & {
|
|
3
|
+
/** Marks the current page (aria-current="page"). */
|
|
4
|
+
current?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/** A square page button on the control row's 34px; the current page only darkens its label. */
|
|
7
|
+
export declare const PaginationButton: ({ current, className, type, ...props }: PaginationButtonProps) => import("react").JSX.Element;
|
|
8
|
+
export declare const PaginationPrevious: ({ "aria-label": label, ...props }: ComponentProps<"button">) => import("react").JSX.Element;
|
|
9
|
+
export declare const PaginationNext: ({ "aria-label": label, ...props }: ComponentProps<"button">) => import("react").JSX.Element;
|
|
10
|
+
type PageItem = number | 'start-ellipsis' | 'end-ellipsis';
|
|
11
|
+
/**
|
|
12
|
+
* Always the same number of slots (first, last, the current page with its
|
|
13
|
+
* siblings, and an ellipsis on either side), so the row never changes width.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getPageItems: (page: number, pageCount: number, siblings?: number) => PageItem[];
|
|
16
|
+
export type PaginationProps = Omit<ComponentProps<'nav'>, 'children' | 'results'> & {
|
|
17
|
+
/** Current page, starting at 1. */
|
|
18
|
+
page: number;
|
|
19
|
+
pageCount: number;
|
|
20
|
+
onPageChange: (page: number) => void;
|
|
21
|
+
/** Pages shown either side of the current one. */
|
|
22
|
+
siblings?: number;
|
|
23
|
+
/** Left slot, e.g. "Results: 1 - 10 of 96". */
|
|
24
|
+
results?: ReactNode;
|
|
25
|
+
/** Right slot, e.g. a rows-per-page select. */
|
|
26
|
+
end?: ReactNode;
|
|
27
|
+
/** The previous button's accessible name; "Previous page" by default. */
|
|
28
|
+
previousLabel?: string;
|
|
29
|
+
/** The next button's accessible name; "Next page" by default. */
|
|
30
|
+
nextLabel?: string;
|
|
31
|
+
};
|
|
32
|
+
/** The library's pagination bar: results on the left, pages centred, an optional right slot. */
|
|
33
|
+
export declare const Pagination: ({ page, pageCount, onPageChange, siblings, results, end, previousLabel, nextLabel, className, "aria-label": label, ...props }: PaginationProps) => import("react").JSX.Element;
|
|
34
|
+
export {};
|