@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,191 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Tabs as TabsPrimitive } from '@base-ui/react/tabs';
|
|
4
|
+
import {
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
createContext,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useEffect,
|
|
10
|
+
useRef,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
13
|
+
import { OverflowChevron, useOverflowScroll } from '../lib/overflow-scroll';
|
|
14
|
+
import { focusRing } from './button';
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* Tabs switch between panels: the facets of one object (Summary · Findings · Sources), each with
|
|
18
|
+
* content of its own. To pick a value that reshapes the same content (List · Grid, 7d · 30d), use a
|
|
19
|
+
* SegmentedControl instead.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export type TabsVariant = 'pill' | 'line';
|
|
23
|
+
|
|
24
|
+
// A context, not a parent selector, so a pill list nested in a line list keeps its own look.
|
|
25
|
+
const TabsVariantContext = createContext<TabsVariant>('line');
|
|
26
|
+
|
|
27
|
+
export const Tabs = ({
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}: WithClassName<ComponentProps<typeof TabsPrimitive.Root>>) => (
|
|
31
|
+
<TabsPrimitive.Root
|
|
32
|
+
className={cn('flex flex-col gap-4', className)}
|
|
33
|
+
data-slot="tabs"
|
|
34
|
+
{...props}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export type TabsListProps = WithClassName<ComponentProps<typeof TabsPrimitive.List>> & {
|
|
39
|
+
/**
|
|
40
|
+
* `line` (the default) sets the tabs on a hairline and underlines the active one, for the tabs of a
|
|
41
|
+
* page, section or panel under its title. `pill` fills the active tab, for a tight spot in a card or dialog.
|
|
42
|
+
*/
|
|
43
|
+
variant?: TabsVariant;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* More tabs than fit scroll sideways, as the dock's items do: a chevron either side, the edge with
|
|
48
|
+
* more faded, and the active tab kept in view. A list that fits is left exactly as it was: it only
|
|
49
|
+
* becomes a scroller once it overflows, so a focus ring on its first or last tab is never clipped.
|
|
50
|
+
*/
|
|
51
|
+
export const TabsList = ({
|
|
52
|
+
activateOnFocus = true,
|
|
53
|
+
variant = 'line',
|
|
54
|
+
className,
|
|
55
|
+
...props
|
|
56
|
+
}: TabsListProps) => {
|
|
57
|
+
const { ref, edges, step, reveal, style } = useOverflowScroll<HTMLDivElement>();
|
|
58
|
+
const list = useRef<HTMLDivElement | null>(null);
|
|
59
|
+
const shown = useRef<{ tab: string | null; overflows?: boolean; reveal?: typeof reveal }>({
|
|
60
|
+
tab: null,
|
|
61
|
+
});
|
|
62
|
+
const setList = useCallback(
|
|
63
|
+
(node: HTMLDivElement | null) => {
|
|
64
|
+
list.current = node;
|
|
65
|
+
ref(node);
|
|
66
|
+
},
|
|
67
|
+
[ref],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// Brought into view only when the active tab changes, as the top nav does, so a re-render never
|
|
71
|
+
// scrolls the row back while someone is looking along it. The list holds no value, so the
|
|
72
|
+
// active tab is known by its place; `reveal` is new once the row has mounted, and the row
|
|
73
|
+
// starting to scroll counts too, since only then can the tab be out of view.
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const tabs = Array.from(list.current?.children ?? []);
|
|
76
|
+
const index = tabs.findIndex(tab => tab.matches('[data-active]'));
|
|
77
|
+
const tab = index < 0 ? null : `${index}:${tabs[index]?.textContent ?? ''}`;
|
|
78
|
+
const { overflows } = edges;
|
|
79
|
+
const last = shown.current;
|
|
80
|
+
if (tab === last.tab && reveal === last.reveal && overflows === last.overflows) return;
|
|
81
|
+
shown.current = { tab, overflows, reveal };
|
|
82
|
+
if (tab && overflows) reveal('[data-active]');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<TabsVariantContext.Provider value={variant}>
|
|
87
|
+
<div
|
|
88
|
+
className={cn(
|
|
89
|
+
'relative flex min-w-0 items-center',
|
|
90
|
+
// The hairline belongs to the frame, not the scroller, so it runs the full width
|
|
91
|
+
// under the chevrons and never fades with the row. The active tab's underline
|
|
92
|
+
// paints over its last pixel, as it hung over the list's border before.
|
|
93
|
+
variant === 'line' &&
|
|
94
|
+
"before:absolute before:inset-x-0 before:bottom-0 before:h-px before:bg-neutral-200 before:content-['']",
|
|
95
|
+
)}
|
|
96
|
+
data-slot="tabs-list-frame"
|
|
97
|
+
>
|
|
98
|
+
{edges.overflows && (
|
|
99
|
+
<OverflowChevron
|
|
100
|
+
className={chevron}
|
|
101
|
+
direction={-1}
|
|
102
|
+
disabled={!edges.start}
|
|
103
|
+
onStep={step}
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
106
|
+
<TabsPrimitive.List
|
|
107
|
+
// Arrow keys select as they move, as they did before: a tab here only swaps a panel, so
|
|
108
|
+
// there is nothing costly to guard behind Enter.
|
|
109
|
+
activateOnFocus={activateOnFocus}
|
|
110
|
+
className={cn(
|
|
111
|
+
'flex min-w-0 flex-1 items-center',
|
|
112
|
+
variant === 'pill' && 'gap-0.5',
|
|
113
|
+
// Scrolling, the row clips 4px over and under its tabs, so a focus ring keeps its room.
|
|
114
|
+
edges.overflows && 'scrollbar-none -my-1 overflow-x-auto py-1',
|
|
115
|
+
className,
|
|
116
|
+
)}
|
|
117
|
+
data-slot="tabs-list"
|
|
118
|
+
data-variant={variant}
|
|
119
|
+
ref={setList}
|
|
120
|
+
style={edges.overflows ? style : undefined}
|
|
121
|
+
{...props}
|
|
122
|
+
/>
|
|
123
|
+
{edges.overflows && (
|
|
124
|
+
<OverflowChevron
|
|
125
|
+
className={chevron}
|
|
126
|
+
direction={1}
|
|
127
|
+
disabled={!edges.end}
|
|
128
|
+
onStep={step}
|
|
129
|
+
/>
|
|
130
|
+
)}
|
|
131
|
+
</div>
|
|
132
|
+
</TabsVariantContext.Provider>
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// A pill tab's 34px and corner, for both looks.
|
|
137
|
+
const chevron = 'size-control rounded-control';
|
|
138
|
+
|
|
139
|
+
const triggerVariants: Record<TabsVariant, string> = {
|
|
140
|
+
// The control row's height and corner, so a pill tab sits level with the buttons and fields beside it.
|
|
141
|
+
pill: 'h-control rounded-control px-3 text-neutral-600 hover:bg-neutral-950/5 hover:text-neutral-950 data-active:bg-tint data-active:text-tint-fg',
|
|
142
|
+
// Set edge to edge, so the underline spans the tab, and 44px tall, so the label has room above the line.
|
|
143
|
+
// Its last pixel is the frame's hairline, so the 2px underline sits on the line, not above it.
|
|
144
|
+
line: "relative h-tab rounded-chip px-3 text-neutral-600 after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:bg-neutral-950 after:opacity-0 after:transition-opacity after:duration-150 after:content-[''] hover:text-neutral-950 data-active:text-neutral-950 data-active:after:opacity-100",
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* One tab. Holds, in this order: an optional leading icon, the label, then an optional trailing
|
|
149
|
+
* piece (a `TabsCount`, a `Kbd`, a `StatusDot` or an icon). Badges and chips stay out: at 22–25px
|
|
150
|
+
* they fill a 29px tab and read as a button inside a button.
|
|
151
|
+
*/
|
|
152
|
+
export const TabsTrigger = ({
|
|
153
|
+
className,
|
|
154
|
+
...props
|
|
155
|
+
}: WithClassName<ComponentProps<typeof TabsPrimitive.Tab>>) => {
|
|
156
|
+
const variant = useContext(TabsVariantContext);
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<TabsPrimitive.Tab
|
|
160
|
+
className={cn(
|
|
161
|
+
'inline-flex cursor-pointer select-none items-center justify-center gap-2 whitespace-nowrap font-medium text-xs transition-[background-color,color] duration-150',
|
|
162
|
+
triggerVariants[variant],
|
|
163
|
+
// Base UI marks a disabled tab with data-disabled, which also covers a rendered non-button.
|
|
164
|
+
'data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg:not([class*=size-])]:size-icon [&_svg]:shrink-0',
|
|
165
|
+
focusRing,
|
|
166
|
+
className,
|
|
167
|
+
)}
|
|
168
|
+
data-slot="tabs-trigger"
|
|
169
|
+
{...props}
|
|
170
|
+
/>
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** The number after a tab's label ("Findings 12"). Takes the tab's colour, so it follows the active state. */
|
|
175
|
+
export const TabsCount = ({ className, ...props }: ComponentProps<'span'>) => (
|
|
176
|
+
<span
|
|
177
|
+
className={cn(
|
|
178
|
+
'inline-flex h-4 min-w-4 items-center justify-center rounded-pill bg-current/10 px-1 font-medium text-xxs tabular-nums',
|
|
179
|
+
className,
|
|
180
|
+
)}
|
|
181
|
+
data-slot="tabs-count"
|
|
182
|
+
{...props}
|
|
183
|
+
/>
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
export const TabsContent = ({
|
|
187
|
+
className,
|
|
188
|
+
...props
|
|
189
|
+
}: WithClassName<ComponentProps<typeof TabsPrimitive.Panel>>) => (
|
|
190
|
+
<TabsPrimitive.Panel className={cn(focusRing, className)} data-slot="tabs-content" {...props} />
|
|
191
|
+
);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import { focusRing } from './button';
|
|
6
|
+
import { useFieldControl } from './field';
|
|
7
|
+
import { inputTextClass } from './input';
|
|
8
|
+
|
|
9
|
+
/** A multi-line Input (medium size): same border states, grows downwards only. */
|
|
10
|
+
export const Textarea = ({
|
|
11
|
+
className,
|
|
12
|
+
id,
|
|
13
|
+
disabled,
|
|
14
|
+
'aria-describedby': describedBy,
|
|
15
|
+
'aria-invalid': ariaInvalid,
|
|
16
|
+
...props
|
|
17
|
+
}: ComponentProps<'textarea'>) => {
|
|
18
|
+
const { invalid, ...control } = useFieldControl({
|
|
19
|
+
id,
|
|
20
|
+
disabled,
|
|
21
|
+
'aria-describedby': describedBy,
|
|
22
|
+
'aria-invalid': ariaInvalid,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<textarea
|
|
27
|
+
className={cn(
|
|
28
|
+
'block min-h-24 w-full resize-y rounded-control border bg-control px-3 py-2.5 shadow-control transition-[border-color,background-color] duration-150',
|
|
29
|
+
inputTextClass,
|
|
30
|
+
'disabled:opacity-50',
|
|
31
|
+
focusRing,
|
|
32
|
+
invalid
|
|
33
|
+
? 'border-error-500'
|
|
34
|
+
: control.disabled
|
|
35
|
+
? 'border-neutral-200'
|
|
36
|
+
: 'border-neutral-200 hover:border-neutral-300 hover:bg-control-hover hover:placeholder:text-neutral-700 focus:border-neutral-300',
|
|
37
|
+
className,
|
|
38
|
+
)}
|
|
39
|
+
data-slot="textarea"
|
|
40
|
+
{...control}
|
|
41
|
+
{...props}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
4
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
5
|
+
import { LucideProvider } from 'lucide-react';
|
|
6
|
+
import { type CSSProperties, createContext, type ReactNode, useContext, useMemo } from 'react';
|
|
7
|
+
import { cn } from '../lib/cn';
|
|
8
|
+
|
|
9
|
+
export type ThemeMode = 'light' | 'dark';
|
|
10
|
+
|
|
11
|
+
type ThemeValue = {
|
|
12
|
+
/** The id of a custom theme (its `.continuum[data-theme=…]` block); none for the default. */
|
|
13
|
+
theme?: string;
|
|
14
|
+
mode: ThemeMode;
|
|
15
|
+
/** Corner scale: every radius token times this; 1 is the theme as drawn. */
|
|
16
|
+
radius: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ThemeContext = createContext<ThemeValue>({ mode: 'light', radius: 1 });
|
|
20
|
+
|
|
21
|
+
/** The scale as a style, left off at 1 so the theme's own values apply untouched. */
|
|
22
|
+
const radiusStyle = (radius: number, style?: CSSProperties) =>
|
|
23
|
+
radius === 1 ? style : ({ ...style, '--continuum-radius-scale': radius } as CSSProperties);
|
|
24
|
+
|
|
25
|
+
export const useTheme = () => useContext(ThemeContext);
|
|
26
|
+
|
|
27
|
+
type ThemeProps = useRender.ComponentProps<'div'> & Partial<ThemeValue>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Opens a themed scope. Everything the system styles has to sit inside one,
|
|
31
|
+
* because the tokens and the built stylesheet only apply under `.continuum`.
|
|
32
|
+
* `theme` names a custom theme written by the theme builder or `createThemeCss`;
|
|
33
|
+
* without one the default tokens apply. Pass `render={<body />}` or any element
|
|
34
|
+
* to make it the scope itself.
|
|
35
|
+
*/
|
|
36
|
+
export const Theme = ({
|
|
37
|
+
theme,
|
|
38
|
+
mode,
|
|
39
|
+
radius,
|
|
40
|
+
render,
|
|
41
|
+
ref,
|
|
42
|
+
className,
|
|
43
|
+
style,
|
|
44
|
+
...props
|
|
45
|
+
}: ThemeProps) => {
|
|
46
|
+
const parent = useTheme();
|
|
47
|
+
const value = useMemo(
|
|
48
|
+
() => ({
|
|
49
|
+
theme: theme ?? parent.theme,
|
|
50
|
+
mode: mode ?? parent.mode,
|
|
51
|
+
radius: radius ?? parent.radius,
|
|
52
|
+
}),
|
|
53
|
+
[theme, mode, radius, parent.theme, parent.mode, parent.radius],
|
|
54
|
+
);
|
|
55
|
+
const element = useRender({
|
|
56
|
+
defaultTagName: 'div',
|
|
57
|
+
render,
|
|
58
|
+
ref,
|
|
59
|
+
props: mergeProps<'div'>(
|
|
60
|
+
{
|
|
61
|
+
className: cn('continuum', className),
|
|
62
|
+
style: radiusStyle(value.radius, style),
|
|
63
|
+
// Plain attributes rather than state, so a missing theme sets no attribute at all.
|
|
64
|
+
...({ 'data-theme': value.theme, 'data-mode': value.mode } as object),
|
|
65
|
+
},
|
|
66
|
+
props,
|
|
67
|
+
),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<ThemeContext.Provider value={value}>
|
|
72
|
+
{/* Every lucide icon inside is 16 at stroke 2, the system's icon, unless it sets its own size. */}
|
|
73
|
+
<LucideProvider size={16} strokeWidth={2}>
|
|
74
|
+
{element}
|
|
75
|
+
</LucideProvider>
|
|
76
|
+
</ThemeContext.Provider>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const PortalContext = createContext<HTMLElement | null>(null);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Where the overlays inside it open: menus, popovers, tooltips, dialogs, sheets and toasts portal
|
|
84
|
+
* into `container` instead of the body. The container has to hold fixed descendants (a transform,
|
|
85
|
+
* `contain: paint` or `container-type: size`) and be sized to the screen it stands for, so a scrim,
|
|
86
|
+
* a sheet and a menu's collisions keep to it, as a preview of a phone's screen needs. An overlay's
|
|
87
|
+
* own `container` prop still wins.
|
|
88
|
+
*/
|
|
89
|
+
export const PortalContainer = ({
|
|
90
|
+
container,
|
|
91
|
+
children,
|
|
92
|
+
}: {
|
|
93
|
+
container: HTMLElement | null;
|
|
94
|
+
children: ReactNode;
|
|
95
|
+
}) => <PortalContext.Provider value={container}>{children}</PortalContext.Provider>;
|
|
96
|
+
|
|
97
|
+
/** The container an overlay portals into: its own if given, else the nearest PortalContainer's, else the body. */
|
|
98
|
+
export const usePortalContainer = <T = HTMLElement>(container?: T | null) => {
|
|
99
|
+
const fallback = useContext(PortalContext);
|
|
100
|
+
return container ?? fallback ?? undefined;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Re-opens the current theme inside a portal. Base UI renders menus, tooltips
|
|
105
|
+
* and dialogs at the end of the body, outside the scope that styles them.
|
|
106
|
+
*/
|
|
107
|
+
export const ThemeScope = ({ children }: { children: ReactNode }) => {
|
|
108
|
+
const { theme, mode, radius } = useTheme();
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div
|
|
112
|
+
className="continuum contents"
|
|
113
|
+
data-mode={mode}
|
|
114
|
+
data-theme={theme}
|
|
115
|
+
style={radiusStyle(radius)}
|
|
116
|
+
>
|
|
117
|
+
{children}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
import { Check } from 'lucide-react';
|
|
5
|
+
import { type ComponentProps, type ReactNode, useEffect, useState } from 'react';
|
|
6
|
+
import { cn } from '../lib/cn';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* What shows while an assistant thinks or works, in three sizes of wait. All of it moves by opacity
|
|
10
|
+
* and translate alone, so it stays smooth while the page is busy streaming, and every loop slows
|
|
11
|
+
* under reduced motion rather than stop: a still mark would read as stuck, not as thinking.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const thinkingMarkVariants = cva('inline-grid shrink-0 grid-cols-3', {
|
|
15
|
+
variants: {
|
|
16
|
+
size: {
|
|
17
|
+
// Nine 2 squares 1 apart (8 across), beside 11px type.
|
|
18
|
+
sm: 'gap-px *:size-0.5',
|
|
19
|
+
// Nine 3 squares 1 apart (11 across), beside 13px type.
|
|
20
|
+
md: 'gap-px *:size-[3px]',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: { size: 'md' },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Each square's diagonal, 0 at the top left to 4 at the bottom right: the wave reaches them in turn.
|
|
27
|
+
const squares = Array.from({ length: 9 }, (_, index) => (index % 3) + Math.floor(index / 3));
|
|
28
|
+
|
|
29
|
+
export type ThinkingMarkProps = Omit<ComponentProps<'span'>, 'children'> &
|
|
30
|
+
VariantProps<typeof thinkingMarkVariants>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Nine small squares in the text colour, in a 3 by 3 grid, with a wave rolling across them from the
|
|
34
|
+
* top left corner to the bottom right: each swells to full and back as it passes (1.4s a wave, 2.8s
|
|
35
|
+
* under reduced motion). Decorative; whatever holds it says what is happening.
|
|
36
|
+
*/
|
|
37
|
+
export const ThinkingMark = ({ size, className, ...props }: ThinkingMarkProps) => (
|
|
38
|
+
<span
|
|
39
|
+
aria-hidden
|
|
40
|
+
className={cn(
|
|
41
|
+
// The wave's length is set once here and each diagonal starts an eighth of it later.
|
|
42
|
+
'[--think:1.4s] motion-reduce:[--think:2.8s]',
|
|
43
|
+
thinkingMarkVariants({ size }),
|
|
44
|
+
className,
|
|
45
|
+
)}
|
|
46
|
+
data-slot="thinking-mark"
|
|
47
|
+
{...props}
|
|
48
|
+
>
|
|
49
|
+
{squares.map((diagonal, index) => (
|
|
50
|
+
<span
|
|
51
|
+
className="animate-think rounded-[0.5px] bg-current [animation-duration:var(--think)]"
|
|
52
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: the squares are positions.
|
|
53
|
+
key={index}
|
|
54
|
+
// Negative, so the wave is already rolling on the first frame instead of starting dark.
|
|
55
|
+
style={{ animationDelay: `calc(var(--think) * ${diagonal / 8 - 1})` }}
|
|
56
|
+
/>
|
|
57
|
+
))}
|
|
58
|
+
</span>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export type ThinkingTextProps = ComponentProps<'span'>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Words that are being worked on: a band of light crosses them, letter by letter, every 2s, from the
|
|
65
|
+
* line's own grey to full ink and back, so the words themselves say the work is going on. Still, in
|
|
66
|
+
* `neutral-600`, under reduced motion.
|
|
67
|
+
*/
|
|
68
|
+
export const ThinkingText = ({ className, ...props }: ThinkingTextProps) => (
|
|
69
|
+
<span
|
|
70
|
+
className={cn(
|
|
71
|
+
'animate-glint bg-[linear-gradient(90deg,var(--color-neutral-600)_40%,var(--color-neutral-950)_50%,var(--color-neutral-600)_60%)] bg-size-[200%_100%] bg-clip-text text-transparent',
|
|
72
|
+
'motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-neutral-600',
|
|
73
|
+
className,
|
|
74
|
+
)}
|
|
75
|
+
data-slot="thinking-text"
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
export type ThinkingProps = ComponentProps<'output'> &
|
|
81
|
+
VariantProps<typeof thinkingMarkVariants> & {
|
|
82
|
+
/** What it is doing, in a few words; "Thinking" when left out. Announced when it changes. */
|
|
83
|
+
children?: ReactNode;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The mark and a few words beside it, in a line ("Thinking", "Searching the docs"): for a short wait
|
|
88
|
+
* with something already on screen to sit beside. A status: its words are read once, and again when
|
|
89
|
+
* they change.
|
|
90
|
+
*/
|
|
91
|
+
export const Thinking = ({ size, children = 'Thinking', className, ...props }: ThinkingProps) => (
|
|
92
|
+
<output
|
|
93
|
+
aria-atomic
|
|
94
|
+
className={cn(
|
|
95
|
+
'inline-flex min-w-0 items-center text-neutral-600',
|
|
96
|
+
size === 'sm' ? 'gap-1.5 text-xxs' : 'gap-2 text-xs',
|
|
97
|
+
className,
|
|
98
|
+
)}
|
|
99
|
+
data-slot="thinking"
|
|
100
|
+
{...props}
|
|
101
|
+
>
|
|
102
|
+
<ThinkingMark className="text-neutral-950" size={size} />
|
|
103
|
+
<ThinkingText className="min-w-0 truncate">{children}</ThinkingText>
|
|
104
|
+
</output>
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
export type ThinkingCaretProps = Omit<ComponentProps<'span'>, 'children'> & {
|
|
108
|
+
/** Read once when the words start coming; `false` for a message that says it is busy itself. */
|
|
109
|
+
label?: string | false;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* One square at the end of words still coming in, swelling and fading (1.2s each way, 2.4s under
|
|
114
|
+
* reduced motion). It goes after the last word and moves on with the text; take it away when the
|
|
115
|
+
* last word is in.
|
|
116
|
+
*/
|
|
117
|
+
export const ThinkingCaret = ({ label = 'Writing', className, ...props }: ThinkingCaretProps) => (
|
|
118
|
+
<span className="contents" data-slot="thinking-caret-root">
|
|
119
|
+
<span
|
|
120
|
+
aria-hidden
|
|
121
|
+
className={cn(
|
|
122
|
+
// A 6 square on the baseline, 4 after the last letter: a block, so it never reads as a
|
|
123
|
+
// text caret the reader could type at.
|
|
124
|
+
'ml-1 inline-block size-1.5 animate-breathe rounded-[1px] bg-current align-baseline text-neutral-950 motion-reduce:[animation-duration:2.4s]',
|
|
125
|
+
className,
|
|
126
|
+
)}
|
|
127
|
+
data-slot="thinking-caret"
|
|
128
|
+
{...props}
|
|
129
|
+
/>
|
|
130
|
+
{label !== false && <output className="sr-only">{label}</output>}
|
|
131
|
+
</span>
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
/** "42s", "3m 05s", "1h 12m": how long a run has been going, short enough to sit beside its title. */
|
|
135
|
+
export const formatThinkingElapsed = (ms: number) => {
|
|
136
|
+
const total = Math.max(0, Math.floor(ms / 1000));
|
|
137
|
+
const h = Math.floor(total / 3600);
|
|
138
|
+
const m = Math.floor((total % 3600) / 60);
|
|
139
|
+
const s = total % 60;
|
|
140
|
+
if (h > 0) return `${h}h ${String(m).padStart(2, '0')}m`;
|
|
141
|
+
if (m > 0) return `${m}m ${String(s).padStart(2, '0')}s`;
|
|
142
|
+
return `${s}s`;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// The time since `from`, every second; nothing until it has mounted, so a server render matches.
|
|
146
|
+
const useElapsed = (from: number | Date | undefined) => {
|
|
147
|
+
const start = from instanceof Date ? from.getTime() : from;
|
|
148
|
+
const [now, setNow] = useState<number | null>(null);
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (start == null) return;
|
|
152
|
+
setNow(Date.now());
|
|
153
|
+
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
|
154
|
+
return () => window.clearInterval(timer);
|
|
155
|
+
}, [start]);
|
|
156
|
+
|
|
157
|
+
return start == null || now == null ? null : now - start;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type ThinkingStep = {
|
|
161
|
+
label: ReactNode;
|
|
162
|
+
/** Done, being worked on now, or still to come. */
|
|
163
|
+
state: 'done' | 'active' | 'waiting';
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export type ThinkingRunProps = Omit<ComponentProps<'div'>, 'title'> & {
|
|
167
|
+
/**
|
|
168
|
+
* The run's steps, when it knows them: listed under the title, the finished ones with a check, the
|
|
169
|
+
* one it is on with the mark and its words lit, the ones to come faint. Takes the place of the
|
|
170
|
+
* step line.
|
|
171
|
+
*/
|
|
172
|
+
steps?: ThinkingStep[];
|
|
173
|
+
/** What the run is doing as a whole: "Reconciling March invoices". */
|
|
174
|
+
title: ReactNode;
|
|
175
|
+
/** The step it is on now, in a line: "Reading invoices.csv". Announced as it changes. */
|
|
176
|
+
children?: ReactNode;
|
|
177
|
+
/** When the run began; the time since counts up beside the title, every second. */
|
|
178
|
+
startedAt?: number | Date;
|
|
179
|
+
/** At the end of the row, usually a secondary "Stop" button. */
|
|
180
|
+
action?: ReactNode;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* A run that takes a while (tens of seconds to minutes): a card with the mark, what the run is doing
|
|
185
|
+
* and the step it is on, how long it has been going, and a way to stop it; a light runs along its
|
|
186
|
+
* bottom edge, so it reads as working even while the step stays the same.
|
|
187
|
+
*/
|
|
188
|
+
export const ThinkingRun = ({
|
|
189
|
+
title,
|
|
190
|
+
children,
|
|
191
|
+
steps,
|
|
192
|
+
startedAt,
|
|
193
|
+
action,
|
|
194
|
+
className,
|
|
195
|
+
...props
|
|
196
|
+
}: ThinkingRunProps) => {
|
|
197
|
+
const elapsed = useElapsed(startedAt);
|
|
198
|
+
const active = steps?.find(step => step.state === 'active');
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<div
|
|
202
|
+
aria-busy
|
|
203
|
+
className={cn(
|
|
204
|
+
'relative flex min-w-0 flex-col gap-3 rounded-card border border-neutral-200 bg-neutral-50 py-3 pr-3 pl-4',
|
|
205
|
+
className,
|
|
206
|
+
)}
|
|
207
|
+
data-slot="thinking-run"
|
|
208
|
+
{...props}
|
|
209
|
+
>
|
|
210
|
+
<div className="flex min-w-0 items-center gap-3">
|
|
211
|
+
<div className="flex min-w-0 flex-1 gap-3">
|
|
212
|
+
<span className="flex h-lh w-[11px] shrink-0 items-center text-neutral-950 text-xs">
|
|
213
|
+
<ThinkingMark />
|
|
214
|
+
</span>
|
|
215
|
+
{/* Only the words are live: the clock beside them would be read every second. */}
|
|
216
|
+
<output aria-atomic className="flex min-w-0 flex-col text-xs">
|
|
217
|
+
<span className="truncate font-medium text-neutral-950">{title}</span>
|
|
218
|
+
{steps === undefined && children != null && children !== false && (
|
|
219
|
+
<ThinkingText className="truncate" data-slot="thinking-run-step">
|
|
220
|
+
{children}
|
|
221
|
+
</ThinkingText>
|
|
222
|
+
)}
|
|
223
|
+
{active && <span className="sr-only">{active.label}</span>}
|
|
224
|
+
</output>
|
|
225
|
+
</div>
|
|
226
|
+
{elapsed != null && (
|
|
227
|
+
<span
|
|
228
|
+
className="shrink-0 text-neutral-600 text-xxs tabular-nums"
|
|
229
|
+
data-slot="thinking-run-elapsed"
|
|
230
|
+
>
|
|
231
|
+
{formatThinkingElapsed(elapsed)}
|
|
232
|
+
</span>
|
|
233
|
+
)}
|
|
234
|
+
{action}
|
|
235
|
+
</div>
|
|
236
|
+
{steps && (
|
|
237
|
+
// The steps, under the title and on its text edge: the mark's 11 slot, then 12.
|
|
238
|
+
<ol
|
|
239
|
+
aria-hidden
|
|
240
|
+
className="flex flex-col gap-2 pl-[23px] text-xs"
|
|
241
|
+
data-slot="thinking-run-steps"
|
|
242
|
+
>
|
|
243
|
+
{steps.map((step, index) => (
|
|
244
|
+
<li
|
|
245
|
+
className="flex min-w-0 items-center gap-3"
|
|
246
|
+
data-state={step.state}
|
|
247
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: steps are in order.
|
|
248
|
+
key={index}
|
|
249
|
+
>
|
|
250
|
+
<span className="flex w-[11px] shrink-0 justify-center">
|
|
251
|
+
{step.state === 'done' && (
|
|
252
|
+
<Check className="size-3 text-neutral-500" strokeWidth={2.5} />
|
|
253
|
+
)}
|
|
254
|
+
{step.state === 'active' && (
|
|
255
|
+
<ThinkingMark className="text-neutral-950" size="sm" />
|
|
256
|
+
)}
|
|
257
|
+
{step.state === 'waiting' && (
|
|
258
|
+
<span className="size-1 rounded-[1px] bg-neutral-300" />
|
|
259
|
+
)}
|
|
260
|
+
</span>
|
|
261
|
+
{step.state === 'active' ? (
|
|
262
|
+
<ThinkingText className="truncate">{step.label}</ThinkingText>
|
|
263
|
+
) : (
|
|
264
|
+
<span
|
|
265
|
+
className={cn(
|
|
266
|
+
'truncate',
|
|
267
|
+
step.state === 'done'
|
|
268
|
+
? 'text-neutral-600'
|
|
269
|
+
: 'text-neutral-400',
|
|
270
|
+
)}
|
|
271
|
+
>
|
|
272
|
+
{step.label}
|
|
273
|
+
</span>
|
|
274
|
+
)}
|
|
275
|
+
</li>
|
|
276
|
+
))}
|
|
277
|
+
</ol>
|
|
278
|
+
)}
|
|
279
|
+
{/*
|
|
280
|
+
* The light on the bottom hairline: a segment a quarter of the width, soft at both ends,
|
|
281
|
+
* crossing in 2.4s and resting off the edges between passes. Its own clip, a pixel out over
|
|
282
|
+
* the border and on the card's corners, so it runs on the hairline itself and fades round
|
|
283
|
+
* the bend. Under reduced motion it stops crossing and the whole hairline swells instead.
|
|
284
|
+
*/}
|
|
285
|
+
<span
|
|
286
|
+
aria-hidden
|
|
287
|
+
className="pointer-events-none absolute -inset-px overflow-hidden rounded-[inherit]"
|
|
288
|
+
>
|
|
289
|
+
<span className="absolute inset-x-0 bottom-0 h-px">
|
|
290
|
+
<span className="absolute inset-y-0 left-0 w-1/4 animate-sweep bg-linear-to-r from-transparent via-neutral-950 to-transparent motion-reduce:w-full motion-reduce:animate-breathe motion-reduce:via-neutral-400 motion-reduce:[animation-duration:2.4s]" />
|
|
291
|
+
</span>
|
|
292
|
+
</span>
|
|
293
|
+
</div>
|
|
294
|
+
);
|
|
295
|
+
};
|