@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,348 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { ArrowDown } from 'lucide-react';
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
type ComponentProps,
|
|
7
|
+
cloneElement,
|
|
8
|
+
Fragment,
|
|
9
|
+
isValidElement,
|
|
10
|
+
type ReactElement,
|
|
11
|
+
type ReactNode,
|
|
12
|
+
type RefCallback,
|
|
13
|
+
useCallback,
|
|
14
|
+
useLayoutEffect,
|
|
15
|
+
useRef,
|
|
16
|
+
useState,
|
|
17
|
+
} from 'react';
|
|
18
|
+
import { cn } from '../lib/cn';
|
|
19
|
+
import { Button, focusRing } from './button';
|
|
20
|
+
import { assignRef } from './chat-shared';
|
|
21
|
+
import { Skeleton, SkeletonText } from './skeleton';
|
|
22
|
+
import { Spinner } from './spinner';
|
|
23
|
+
|
|
24
|
+
// Within this distance of the end the reader counts as following along, so a new message pulls them down.
|
|
25
|
+
const STICK_THRESHOLD = 48;
|
|
26
|
+
|
|
27
|
+
export type ChatThreadProps = ComponentProps<'div'> & {
|
|
28
|
+
/** Shown in place of the messages while the thread has none. */
|
|
29
|
+
empty?: ReactNode;
|
|
30
|
+
/** The first messages are loading: a skeleton of message rows stands in for them. */
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
/** Replaces the default `ChatThreadSkeleton` while `loading`. */
|
|
33
|
+
skeleton?: ReactNode;
|
|
34
|
+
/** Earlier messages are loading: a quiet spinner row heads the thread. */
|
|
35
|
+
loadingEarlier?: boolean;
|
|
36
|
+
loadingEarlierLabel?: ReactNode;
|
|
37
|
+
/** Called once each time the reader scrolls to within 48px of the top: fetch earlier messages. */
|
|
38
|
+
onReachStart?: () => void;
|
|
39
|
+
/** The jump button's label for the messages that arrived while the reader was scrolled back. */
|
|
40
|
+
jumpLabel?: (count: number) => string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const defaultJumpLabel = (count: number) =>
|
|
44
|
+
count === 1 ? '1 new message' : `${count} new messages`;
|
|
45
|
+
|
|
46
|
+
type Keyed = ReactElement<Record<string, unknown>>;
|
|
47
|
+
|
|
48
|
+
const isMessage = (node: ReactNode): node is Keyed => isValidElement(node);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* One's own message, read from its props rather than its type, so a wrapper round `ChatMessage`
|
|
52
|
+
* counts too: `variant="own"` (forwarded to the message) or a `data-own` marker. A wrapper must also
|
|
53
|
+
* pass the `data-enter` the thread gives it on to the message, or a new one will not rise in.
|
|
54
|
+
*/
|
|
55
|
+
const isOwn = (node: Keyed) => {
|
|
56
|
+
const own = node.props['data-own'];
|
|
57
|
+
return node.props.variant === 'own' || (own != null && own !== false && own !== 'false');
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The scrolling column of a conversation. It opens at the latest message and follows new ones while
|
|
62
|
+
* the reader is at the end, but leaves them where they are once they have scrolled back to read,
|
|
63
|
+
* and counts what arrives meanwhile on a button that takes them back down. A message added after
|
|
64
|
+
* the thread has loaded rises in from the composer's side; the history it opened with stays still.
|
|
65
|
+
*/
|
|
66
|
+
export const ChatThread = ({
|
|
67
|
+
empty,
|
|
68
|
+
loading = false,
|
|
69
|
+
skeleton,
|
|
70
|
+
loadingEarlier = false,
|
|
71
|
+
loadingEarlierLabel,
|
|
72
|
+
onReachStart,
|
|
73
|
+
jumpLabel = defaultJumpLabel,
|
|
74
|
+
className,
|
|
75
|
+
children,
|
|
76
|
+
ref,
|
|
77
|
+
onScroll,
|
|
78
|
+
'aria-label': ariaLabel = 'Messages',
|
|
79
|
+
...props
|
|
80
|
+
}: ChatThreadProps) => {
|
|
81
|
+
const nodeRef = useRef<HTMLDivElement | null>(null);
|
|
82
|
+
const stuck = useRef(true);
|
|
83
|
+
const atStart = useRef(false);
|
|
84
|
+
const height = useRef(0);
|
|
85
|
+
// Whether the thread has shown its loaded messages once: only what comes after that enters.
|
|
86
|
+
const settled = useRef(false);
|
|
87
|
+
const committed = useRef<{ keys: readonly string[]; signature: string } | null>(null);
|
|
88
|
+
const entered = useRef(new Set<string>());
|
|
89
|
+
const [unread, setUnread] = useState(0);
|
|
90
|
+
|
|
91
|
+
const items = Children.toArray(children);
|
|
92
|
+
const messages = items.filter(isMessage);
|
|
93
|
+
const keys = messages.map(item => String(item.key));
|
|
94
|
+
const signature = keys.join('\u0000');
|
|
95
|
+
const count = items.length;
|
|
96
|
+
|
|
97
|
+
// What changed since the last commit: messages added after the first one kept are appended (they
|
|
98
|
+
// enter and count as unread), messages added before it are earlier history (the view holds still).
|
|
99
|
+
let appended: string[] = [];
|
|
100
|
+
let prepended = false;
|
|
101
|
+
const previous = committed.current;
|
|
102
|
+
|
|
103
|
+
if (previous && previous.signature !== signature && settled.current && !loading) {
|
|
104
|
+
const before = new Set(previous.keys);
|
|
105
|
+
const firstKept = keys.findIndex(key => before.has(key));
|
|
106
|
+
|
|
107
|
+
if (previous.keys.length === 0) appended = keys;
|
|
108
|
+
else if (firstKept !== -1) {
|
|
109
|
+
appended = keys.filter((key, i) => i > firstKept && !before.has(key));
|
|
110
|
+
prepended = firstKept > 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const sentOwn = messages.some(item => appended.includes(String(item.key)) && isOwn(item));
|
|
115
|
+
|
|
116
|
+
const setRef = useCallback<RefCallback<HTMLDivElement>>(
|
|
117
|
+
node => {
|
|
118
|
+
nodeRef.current = node;
|
|
119
|
+
assignRef(ref, node);
|
|
120
|
+
},
|
|
121
|
+
[ref],
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Layout effect, so the jump to the end lands before paint and the thread never flashes at the top.
|
|
125
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs when the messages change, which the signature stands for.
|
|
126
|
+
useLayoutEffect(() => {
|
|
127
|
+
const node = nodeRef.current;
|
|
128
|
+
|
|
129
|
+
if (!node) return;
|
|
130
|
+
|
|
131
|
+
// Strict mode runs this twice for one commit; the diff is applied once.
|
|
132
|
+
if (committed.current?.signature !== signature) {
|
|
133
|
+
// Earlier history went in above the reader: move by its height, so what they read stays put.
|
|
134
|
+
if (prepended && !stuck.current) {
|
|
135
|
+
node.scrollTop += node.scrollHeight - height.current;
|
|
136
|
+
}
|
|
137
|
+
// The reader's own message always takes them to the end, wherever they had scrolled.
|
|
138
|
+
if (sentOwn) stuck.current = true;
|
|
139
|
+
if (appended.length > 0 && !stuck.current) setUnread(n => n + appended.length);
|
|
140
|
+
for (const key of appended) entered.current.add(key);
|
|
141
|
+
committed.current = { keys, signature };
|
|
142
|
+
}
|
|
143
|
+
if (!loading) settled.current = true;
|
|
144
|
+
|
|
145
|
+
if (stuck.current) node.scrollTop = node.scrollHeight;
|
|
146
|
+
height.current = node.scrollHeight;
|
|
147
|
+
|
|
148
|
+
// A message can also grow in place (a streamed reply, an image that loads),
|
|
149
|
+
// which fires no scroll and changes no count, so the children are watched for size.
|
|
150
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
151
|
+
const observer = new ResizeObserver(() => {
|
|
152
|
+
if (stuck.current) node.scrollTop = node.scrollHeight;
|
|
153
|
+
height.current = node.scrollHeight;
|
|
154
|
+
});
|
|
155
|
+
for (const child of Array.from(node.children)) observer.observe(child);
|
|
156
|
+
return () => observer.disconnect();
|
|
157
|
+
}, [signature, loading, loadingEarlier]);
|
|
158
|
+
|
|
159
|
+
const jump = () => {
|
|
160
|
+
const node = nodeRef.current;
|
|
161
|
+
if (!node) return;
|
|
162
|
+
const still = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
163
|
+
node.scrollTo({ top: node.scrollHeight, behavior: still ? 'auto' : 'smooth' });
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const rendered = items.map(item =>
|
|
167
|
+
isMessage(item) &&
|
|
168
|
+
item.type !== Fragment &&
|
|
169
|
+
(appended.includes(String(item.key)) || entered.current.has(String(item.key)))
|
|
170
|
+
? cloneElement(item, { 'data-enter': '' })
|
|
171
|
+
: item,
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<div
|
|
176
|
+
aria-busy={loading || undefined}
|
|
177
|
+
aria-label={ariaLabel}
|
|
178
|
+
aria-live="polite"
|
|
179
|
+
aria-relevant="additions"
|
|
180
|
+
className={cn(
|
|
181
|
+
// Scroll anchoring is done by hand (see the effect), so the browser's own is off.
|
|
182
|
+
'flex min-h-0 flex-col gap-6 overflow-y-auto overscroll-contain p-4 [overflow-anchor:none]',
|
|
183
|
+
// What goes with a message hangs under it rather than a message's 24 apart: its
|
|
184
|
+
// attachments 4, a record linked under it 6. A system line keeps 16 either side, as its
|
|
185
|
+
// own 12 of padding already sets it apart.
|
|
186
|
+
'*:data-[slot=chat-event]:-my-2 *:data-[slot=chat-unread-divider]:-my-1 *:data-[slot=chat-attachments]:-mt-5 *:data-[slot=chat-reference]:-mt-4.5',
|
|
187
|
+
// A message added after load rises 8px into place as it fades in; reduced motion turns it off.
|
|
188
|
+
'*:data-enter:starting:translate-y-2 *:data-enter:starting:opacity-0 *:data-enter:transition-[opacity,translate,border-color] *:data-enter:duration-200 *:data-enter:ease-out-strong motion-reduce:*:data-enter:transition-none',
|
|
189
|
+
focusRing,
|
|
190
|
+
'focus-visible:-outline-offset-2',
|
|
191
|
+
className,
|
|
192
|
+
)}
|
|
193
|
+
data-empty={(!loading && count === 0) || undefined}
|
|
194
|
+
data-loading={loading || undefined}
|
|
195
|
+
data-slot="chat-thread"
|
|
196
|
+
onScroll={event => {
|
|
197
|
+
const node = event.currentTarget;
|
|
198
|
+
|
|
199
|
+
stuck.current =
|
|
200
|
+
node.scrollHeight - node.scrollTop - node.clientHeight < STICK_THRESHOLD;
|
|
201
|
+
if (stuck.current) setUnread(0);
|
|
202
|
+
|
|
203
|
+
const nearStart = node.scrollTop < STICK_THRESHOLD;
|
|
204
|
+
if (nearStart && !atStart.current && !loading && !loadingEarlier) {
|
|
205
|
+
onReachStart?.();
|
|
206
|
+
}
|
|
207
|
+
atStart.current = nearStart;
|
|
208
|
+
onScroll?.(event);
|
|
209
|
+
}}
|
|
210
|
+
ref={setRef}
|
|
211
|
+
role="log"
|
|
212
|
+
// biome-ignore lint/a11y/noNoninteractiveTabindex: a scrolling region has to take focus, or keyboard users cannot scroll it.
|
|
213
|
+
tabIndex={0}
|
|
214
|
+
{...props}
|
|
215
|
+
>
|
|
216
|
+
{loadingEarlier && !loading && (
|
|
217
|
+
<ChatLoadingEarlier>{loadingEarlierLabel}</ChatLoadingEarlier>
|
|
218
|
+
)}
|
|
219
|
+
{loading ? (
|
|
220
|
+
(skeleton ?? <ChatThreadSkeleton />)
|
|
221
|
+
) : count === 0 && empty != null ? (
|
|
222
|
+
<>
|
|
223
|
+
<div
|
|
224
|
+
className="m-auto max-w-measure-narrow text-balance text-center text-neutral-600 text-xs"
|
|
225
|
+
data-slot="chat-thread-empty"
|
|
226
|
+
>
|
|
227
|
+
{empty}
|
|
228
|
+
</div>
|
|
229
|
+
{rendered}
|
|
230
|
+
</>
|
|
231
|
+
) : (
|
|
232
|
+
rendered
|
|
233
|
+
)}
|
|
234
|
+
{unread > 0 && (
|
|
235
|
+
// Pinned to the foot of the view at no height, so it floats over the messages; the
|
|
236
|
+
// negative margin takes back the gap it would otherwise add after the last one. The
|
|
237
|
+
// messages are announced themselves, so the button and its count are kept out of the log.
|
|
238
|
+
<div
|
|
239
|
+
aria-live="off"
|
|
240
|
+
className="sticky bottom-0 -mt-6 h-0 shrink-0"
|
|
241
|
+
data-slot="chat-thread-jump"
|
|
242
|
+
>
|
|
243
|
+
<Button
|
|
244
|
+
className="absolute bottom-3 left-1/2 -translate-x-1/2 starting:translate-y-1 starting:opacity-0 shadow-float transition-[background-color,border-color,color,opacity,translate,scale] motion-reduce:starting:translate-y-0"
|
|
245
|
+
onClick={jump}
|
|
246
|
+
shape="pill"
|
|
247
|
+
variant="secondary"
|
|
248
|
+
>
|
|
249
|
+
<ArrowDown aria-hidden strokeWidth={2} />
|
|
250
|
+
{jumpLabel(unread)}
|
|
251
|
+
</Button>
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export type ChatThreadSkeletonProps = ComponentProps<'div'> & {
|
|
259
|
+
/** How many message rows; they alternate as a conversation does. */
|
|
260
|
+
rows?: number;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// Another person's message with a header and two lines, a short reply of one's own, then a longer one.
|
|
264
|
+
const skeletonRows = [
|
|
265
|
+
{ own: false, lines: 2 },
|
|
266
|
+
{ own: true, lines: 1 },
|
|
267
|
+
{ own: false, lines: 3 },
|
|
268
|
+
{ own: true, lines: 2 },
|
|
269
|
+
] as const;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The thread's first messages while they load: rows drawn as the messages are (the card with its
|
|
273
|
+
* avatar and name for others, the tint for one's own), sitting at the foot as the thread opens there.
|
|
274
|
+
*/
|
|
275
|
+
export const ChatThreadSkeleton = ({ rows = 3, className, ...props }: ChatThreadSkeletonProps) => (
|
|
276
|
+
<div
|
|
277
|
+
aria-hidden
|
|
278
|
+
className={cn('mt-auto flex flex-col gap-6', className)}
|
|
279
|
+
data-slot="chat-thread-skeleton"
|
|
280
|
+
{...props}
|
|
281
|
+
>
|
|
282
|
+
{Array.from({ length: rows }, (_, i) => {
|
|
283
|
+
const row = skeletonRows[i % skeletonRows.length] ?? skeletonRows[0];
|
|
284
|
+
|
|
285
|
+
return (
|
|
286
|
+
<div
|
|
287
|
+
className={cn(
|
|
288
|
+
// The message's own padding, so a row is as tall as the message that replaces it.
|
|
289
|
+
'flex flex-col gap-2 rounded-card py-4 pr-3 pl-4',
|
|
290
|
+
row.own
|
|
291
|
+
? 'ml-auto w-2/3 bg-tint'
|
|
292
|
+
: 'border border-neutral-200 bg-neutral-50',
|
|
293
|
+
)}
|
|
294
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: the rows never reorder
|
|
295
|
+
key={i}
|
|
296
|
+
>
|
|
297
|
+
{!row.own && (
|
|
298
|
+
<div className="flex items-center gap-2">
|
|
299
|
+
<Skeleton className="size-6 rounded-full" />
|
|
300
|
+
<Skeleton className="h-2.5 w-20 rounded-chip" />
|
|
301
|
+
</div>
|
|
302
|
+
)}
|
|
303
|
+
<SkeletonText className={row.own ? 'w-3/4' : undefined} lines={row.lines} />
|
|
304
|
+
</div>
|
|
305
|
+
);
|
|
306
|
+
})}
|
|
307
|
+
</div>
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
/** The quiet row at the head of the thread while earlier messages load. */
|
|
311
|
+
export const ChatLoadingEarlier = ({ className, children, ...props }: ComponentProps<'output'>) => (
|
|
312
|
+
// An <output> is a polite status region, so the row is announced once as it appears.
|
|
313
|
+
<output
|
|
314
|
+
className={cn(
|
|
315
|
+
'flex shrink-0 items-center justify-center gap-2 py-1 text-neutral-600 text-xs',
|
|
316
|
+
className,
|
|
317
|
+
)}
|
|
318
|
+
data-slot="chat-loading-earlier"
|
|
319
|
+
{...props}
|
|
320
|
+
>
|
|
321
|
+
<Spinner className="text-neutral-500" size="sm" />
|
|
322
|
+
{children ?? 'Loading earlier messages'}
|
|
323
|
+
</output>
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* A hairline across the thread with a label, above the first message the reader has not seen. The
|
|
328
|
+
* label is read as text where it stands, so the reader hears where the new messages begin.
|
|
329
|
+
*/
|
|
330
|
+
export const ChatUnreadDivider = ({
|
|
331
|
+
className,
|
|
332
|
+
children = 'New messages',
|
|
333
|
+
...props
|
|
334
|
+
}: ComponentProps<'div'>) => (
|
|
335
|
+
<div
|
|
336
|
+
className={cn(
|
|
337
|
+
// Quiet: a place in the thread, not news of its own; the messages under it are the news.
|
|
338
|
+
'flex shrink-0 items-center gap-3 text-neutral-600 text-xxs',
|
|
339
|
+
className,
|
|
340
|
+
)}
|
|
341
|
+
data-slot="chat-unread-divider"
|
|
342
|
+
{...props}
|
|
343
|
+
>
|
|
344
|
+
<span aria-hidden className="h-px flex-1 bg-neutral-200" />
|
|
345
|
+
<span className="shrink-0">{children}</span>
|
|
346
|
+
<span aria-hidden className="h-px flex-1 bg-neutral-200" />
|
|
347
|
+
</div>
|
|
348
|
+
);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ComponentProps, type ReactNode, useRef } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import { Avatar } from './avatar';
|
|
6
|
+
|
|
7
|
+
/** Three dots in the text's grey, pulsing one after another; still under reduced motion. */
|
|
8
|
+
export const ChatTypingDots = ({
|
|
9
|
+
className,
|
|
10
|
+
...props
|
|
11
|
+
}: Omit<ComponentProps<'span'>, 'children'>) => (
|
|
12
|
+
<span
|
|
13
|
+
aria-hidden
|
|
14
|
+
className={cn('inline-flex h-lh items-center gap-1 align-top text-neutral-600', className)}
|
|
15
|
+
data-slot="chat-typing-dots"
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
{[0, 160, 320].map(delay => (
|
|
19
|
+
<span
|
|
20
|
+
className="size-1.5 rounded-full bg-current motion-safe:animate-pulse motion-safe:[animation-duration:1.2s]"
|
|
21
|
+
key={delay}
|
|
22
|
+
style={{ animationDelay: `${delay}ms` }}
|
|
23
|
+
/>
|
|
24
|
+
))}
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export type ChatTypingLabelOptions = {
|
|
29
|
+
/** From this many people on, the line counts them instead of naming them; five by default. */
|
|
30
|
+
many?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Who is typing, in a line: "Maya is typing", "Maya and Liam are typing", "Maya, Liam and Noor are
|
|
35
|
+
* typing", "Maya, Liam and 2 others are typing", then "5 people are typing". Empty for nobody.
|
|
36
|
+
*/
|
|
37
|
+
export const chatTypingLabel = (
|
|
38
|
+
names: readonly string[],
|
|
39
|
+
{ many = 5 }: ChatTypingLabelOptions = {},
|
|
40
|
+
) => {
|
|
41
|
+
const [first, second, third] = names;
|
|
42
|
+
const n = names.length;
|
|
43
|
+
|
|
44
|
+
if (n === 0) return '';
|
|
45
|
+
if (n >= many) return `${n} people are typing`;
|
|
46
|
+
if (n === 1) return `${first} is typing`;
|
|
47
|
+
if (n === 2) return `${first} and ${second} are typing`;
|
|
48
|
+
if (n === 3) return `${first}, ${second} and ${third} are typing`;
|
|
49
|
+
return `${first}, ${second} and ${n - 2} others are typing`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const initialsOf = (name: string) =>
|
|
53
|
+
name
|
|
54
|
+
.split(/\s+/)
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.slice(0, 2)
|
|
57
|
+
.map(part => part.charAt(0).toUpperCase())
|
|
58
|
+
.join('');
|
|
59
|
+
|
|
60
|
+
export type ChatTypingProps = Omit<ComponentProps<'div'>, 'children'> & {
|
|
61
|
+
/** Who is typing now, in the order they started; empty, the row fades away. */
|
|
62
|
+
names: readonly string[];
|
|
63
|
+
/**
|
|
64
|
+
* Their avatars before the dots, 24px and round, up to three overlapping, in the same order:
|
|
65
|
+
* `true` draws their initials, or pass the avatars. Left out, the row is the dots alone.
|
|
66
|
+
*/
|
|
67
|
+
avatars?: readonly ReactNode[] | boolean;
|
|
68
|
+
/** Replaces the English line: a string, or a function of the names. */
|
|
69
|
+
text?: string | ((names: readonly string[]) => string);
|
|
70
|
+
/** @deprecated Use `text`; `label` means an accessible name elsewhere in the chat parts. */
|
|
71
|
+
label?: string | ((names: readonly string[]) => string);
|
|
72
|
+
/** Shows who is typing after the dots; `false` keeps the line for screen readers only. */
|
|
73
|
+
showLabel?: boolean;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Who is typing, in a row above the composer: their avatars, overlapping, who it is ("Maya is
|
|
78
|
+
* typing"), then three pulsing dots in a small pill. It belongs in the composer's `typing` slot,
|
|
79
|
+
* which keeps its height whether anyone types or not, so the composer never moves. Keep it rendered
|
|
80
|
+
* and pass the names: it fades in when someone starts and out when they stop. The line is announced
|
|
81
|
+
* once per change, never per dot.
|
|
82
|
+
*/
|
|
83
|
+
export const ChatTyping = ({
|
|
84
|
+
names,
|
|
85
|
+
avatars,
|
|
86
|
+
text: textProp,
|
|
87
|
+
label: legacyLabel,
|
|
88
|
+
showLabel = true,
|
|
89
|
+
className,
|
|
90
|
+
...props
|
|
91
|
+
}: ChatTypingProps) => {
|
|
92
|
+
const label = textProp ?? legacyLabel;
|
|
93
|
+
const active = names.length > 0;
|
|
94
|
+
// The last people seen typing stay on the line while it folds away, so it never empties mid-fade.
|
|
95
|
+
const kept = useRef(names);
|
|
96
|
+
if (active) kept.current = names;
|
|
97
|
+
const shown = kept.current;
|
|
98
|
+
|
|
99
|
+
const text =
|
|
100
|
+
typeof label === 'function'
|
|
101
|
+
? label(shown)
|
|
102
|
+
: typeof label === 'string'
|
|
103
|
+
? label
|
|
104
|
+
: chatTypingLabel(shown);
|
|
105
|
+
// Avatars passed in are kept the same way, so a stack built from the names does not vanish mid-fade.
|
|
106
|
+
const keptAvatars = useRef(avatars);
|
|
107
|
+
if (active) keptAvatars.current = avatars;
|
|
108
|
+
const given = keptAvatars.current;
|
|
109
|
+
const faces =
|
|
110
|
+
given === true
|
|
111
|
+
? shown.map(name => (
|
|
112
|
+
<Avatar fallback={initialsOf(name)} key={name} shape="round" size={24} />
|
|
113
|
+
))
|
|
114
|
+
: given || [];
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div
|
|
118
|
+
className={cn(
|
|
119
|
+
// It only fades and settles 4px: its slot keeps the height, so nothing around it moves.
|
|
120
|
+
'flex min-w-0 items-center transition-[opacity,translate] duration-200 ease-out-strong motion-reduce:transition-none',
|
|
121
|
+
active ? 'opacity-100' : 'pointer-events-none translate-y-1 opacity-0',
|
|
122
|
+
className,
|
|
123
|
+
)}
|
|
124
|
+
data-slot="chat-typing"
|
|
125
|
+
data-state={active ? 'open' : 'closed'}
|
|
126
|
+
{...props}
|
|
127
|
+
>
|
|
128
|
+
<div aria-hidden className="flex h-6 min-w-0 items-center gap-2">
|
|
129
|
+
{faces.length > 0 && (
|
|
130
|
+
// Up to three, each over the last by 10 and ringed in a 10% line, not the surface.
|
|
131
|
+
<div
|
|
132
|
+
className="flex shrink-0 items-center *:not-first:ml-[-10px] *:border-0 *:ring-1 *:ring-neutral-950/10"
|
|
133
|
+
data-slot="chat-typing-avatars"
|
|
134
|
+
>
|
|
135
|
+
{faces.slice(0, 3)}
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
{showLabel && (
|
|
139
|
+
<span className="min-w-0 truncate text-neutral-600 text-xs">{text}</span>
|
|
140
|
+
)}
|
|
141
|
+
<span
|
|
142
|
+
className="inline-flex h-6 shrink-0 items-center rounded-full border border-neutral-200 bg-neutral-50 px-2"
|
|
143
|
+
data-slot="chat-typing-bubble"
|
|
144
|
+
>
|
|
145
|
+
{/* Smaller than a pending message's 6 dots 4 apart: 4 dots 2 apart, to fit the 24 pill. */}
|
|
146
|
+
<ChatTypingDots className="h-auto gap-0.5 *:size-1" />
|
|
147
|
+
</span>
|
|
148
|
+
</div>
|
|
149
|
+
{/* Its own live region, holding only the words: they change when people do, not per dot. */}
|
|
150
|
+
<span aria-atomic aria-live="polite" className="sr-only">
|
|
151
|
+
{active ? text : ''}
|
|
152
|
+
</span>
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox';
|
|
4
|
+
import { Check, Minus } from 'lucide-react';
|
|
5
|
+
import type { ComponentProps } from 'react';
|
|
6
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
7
|
+
import { focusRing, touchTarget } from './button';
|
|
8
|
+
import { useFieldControl } from './field';
|
|
9
|
+
|
|
10
|
+
type CheckboxProps = Omit<
|
|
11
|
+
WithClassName<ComponentProps<typeof CheckboxPrimitive.Root>>,
|
|
12
|
+
'checked'
|
|
13
|
+
> & {
|
|
14
|
+
/**
|
|
15
|
+
* `'indeterminate'` is still accepted so call sites written for a tri-state
|
|
16
|
+
* checked keep working; it maps to Base UI's separate `indeterminate` prop.
|
|
17
|
+
*/
|
|
18
|
+
checked?: boolean | 'indeterminate';
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The library checkbox (20px like the radio, chip radius), used in table header/body cells,
|
|
23
|
+
* forms and the report-generator option rows. A menu row draws its own 16px
|
|
24
|
+
* `MenuItemIndicator`. Checked fills with the action colour but keeps its hairline, as
|
|
25
|
+
* drawn; it has no lit ring like the primary button.
|
|
26
|
+
*/
|
|
27
|
+
export const Checkbox = ({
|
|
28
|
+
className,
|
|
29
|
+
id,
|
|
30
|
+
disabled,
|
|
31
|
+
checked,
|
|
32
|
+
indeterminate,
|
|
33
|
+
'aria-describedby': describedBy,
|
|
34
|
+
'aria-invalid': ariaInvalid,
|
|
35
|
+
...props
|
|
36
|
+
}: CheckboxProps) => {
|
|
37
|
+
const { invalid, ...control } = useFieldControl({
|
|
38
|
+
id,
|
|
39
|
+
disabled,
|
|
40
|
+
'aria-describedby': describedBy,
|
|
41
|
+
'aria-invalid': ariaInvalid,
|
|
42
|
+
});
|
|
43
|
+
const mixed = indeterminate ?? checked === 'indeterminate';
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<CheckboxPrimitive.Root
|
|
47
|
+
// A mixed box reads as unticked underneath, so a click ticks it, as it did before.
|
|
48
|
+
checked={checked === 'indeterminate' ? false : checked}
|
|
49
|
+
className={cn(
|
|
50
|
+
'group/checkbox inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-chip border bg-transparent text-on-action shadow-control transition-[background-color,border-color] duration-150',
|
|
51
|
+
// A 44px square a finger can find round the 20px box, on a touch screen only.
|
|
52
|
+
touchTarget,
|
|
53
|
+
invalid
|
|
54
|
+
? 'border-error-500'
|
|
55
|
+
: 'border-neutral-300 not-data-disabled:hover:border-neutral-400',
|
|
56
|
+
'data-checked:bg-action data-indeterminate:bg-action',
|
|
57
|
+
'data-checked:[background-image:var(--action-gradient)] data-indeterminate:[background-image:var(--action-gradient)]',
|
|
58
|
+
// The root is a span, not a button, so the disabled state comes from its data attribute.
|
|
59
|
+
'data-disabled:cursor-not-allowed data-disabled:opacity-50',
|
|
60
|
+
focusRing,
|
|
61
|
+
className,
|
|
62
|
+
)}
|
|
63
|
+
data-slot="checkbox"
|
|
64
|
+
indeterminate={mixed}
|
|
65
|
+
{...control}
|
|
66
|
+
{...props}
|
|
67
|
+
>
|
|
68
|
+
<CheckboxPrimitive.Indicator
|
|
69
|
+
className="flex items-center justify-center"
|
|
70
|
+
data-slot="checkbox-indicator"
|
|
71
|
+
>
|
|
72
|
+
<Check
|
|
73
|
+
className="hidden size-3.5 group-data-checked/checkbox:block"
|
|
74
|
+
strokeWidth={2}
|
|
75
|
+
/>
|
|
76
|
+
<Minus
|
|
77
|
+
className="hidden size-3.5 group-data-indeterminate/checkbox:block"
|
|
78
|
+
strokeWidth={2}
|
|
79
|
+
/>
|
|
80
|
+
</CheckboxPrimitive.Indicator>
|
|
81
|
+
</CheckboxPrimitive.Root>
|
|
82
|
+
);
|
|
83
|
+
};
|