@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,135 @@
|
|
|
1
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import { CircleAlert, CircleCheck, Info, TriangleAlert, X } from 'lucide-react';
|
|
3
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import { Button } from './button';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* A notice is a hairline card like any other. Its tone sits in the icon's well, the badge's two
|
|
9
|
+
* colours from one ramp (a 500 wash at 20%, the glyph at 600, or 700 for the pale green and amber and
|
|
10
|
+
* for the theme's accent, which may be pale, so it keeps 3:1 on the wash), so the state reads at a glance
|
|
11
|
+
* while the box stays quiet: a coloured box would make every notice the loudest thing on the page.
|
|
12
|
+
*/
|
|
13
|
+
export const alertVariants = cva(
|
|
14
|
+
[
|
|
15
|
+
'@container/alert flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2.5 rounded-item border border-neutral-200 bg-neutral-50 px-4 py-3 text-xs',
|
|
16
|
+
// It settles in from just above as it appears, rather than landing all at once.
|
|
17
|
+
'transition-[opacity,translate] duration-200 ease-out-strong starting:-translate-y-1 starting:opacity-0 motion-reduce:starting:translate-y-0',
|
|
18
|
+
],
|
|
19
|
+
{
|
|
20
|
+
variants: {
|
|
21
|
+
tone: {
|
|
22
|
+
neutral:
|
|
23
|
+
'[&>[data-slot=alert-icon]]:bg-neutral-950/5 [&>[data-slot=alert-icon]]:text-neutral-600',
|
|
24
|
+
primary:
|
|
25
|
+
'[&>[data-slot=alert-icon]]:bg-primary-500/20 [&>[data-slot=alert-icon]]:text-primary-700',
|
|
26
|
+
success:
|
|
27
|
+
'[&>[data-slot=alert-icon]]:bg-success-500/20 [&>[data-slot=alert-icon]]:text-success-700',
|
|
28
|
+
warning:
|
|
29
|
+
'[&>[data-slot=alert-icon]]:bg-warning-500/20 [&>[data-slot=alert-icon]]:text-warning-700',
|
|
30
|
+
error: '[&>[data-slot=alert-icon]]:bg-error-500/20 [&>[data-slot=alert-icon]]:text-error-600',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: { tone: 'neutral' },
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const toneIcons = {
|
|
38
|
+
neutral: Info,
|
|
39
|
+
primary: Info,
|
|
40
|
+
success: CircleCheck,
|
|
41
|
+
warning: TriangleAlert,
|
|
42
|
+
error: CircleAlert,
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
export type AlertProps = Omit<ComponentProps<'div'>, 'title'> &
|
|
46
|
+
VariantProps<typeof alertVariants> & {
|
|
47
|
+
/** What happened or what to know, in a line. */
|
|
48
|
+
title: ReactNode;
|
|
49
|
+
/** Replaces the tone's icon; `false` leaves it out. */
|
|
50
|
+
icon?: ReactNode | false;
|
|
51
|
+
/** Buttons at the end of the row: the fix ("Update card") rather than a link to read about it. */
|
|
52
|
+
action?: ReactNode;
|
|
53
|
+
/** Shows a ghost × that calls this. */
|
|
54
|
+
onDismiss?: () => void;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* An inline notice on a page or in a form: info, success, warning or error. The title says it,
|
|
59
|
+
* the children explain it in a sentence, and the action fixes it. An error is announced at once;
|
|
60
|
+
* the other tones wait their turn.
|
|
61
|
+
*/
|
|
62
|
+
export const Alert = ({
|
|
63
|
+
tone,
|
|
64
|
+
title,
|
|
65
|
+
icon,
|
|
66
|
+
action,
|
|
67
|
+
onDismiss,
|
|
68
|
+
className,
|
|
69
|
+
children,
|
|
70
|
+
...props
|
|
71
|
+
}: AlertProps) => {
|
|
72
|
+
const Icon = toneIcons[tone ?? 'neutral'];
|
|
73
|
+
// A title alone is one line, so the alert slims to it: a 24px well and less space above and below.
|
|
74
|
+
const slim = !children;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div
|
|
78
|
+
className={cn(alertVariants({ tone }), slim && 'py-2', className)}
|
|
79
|
+
data-slot="alert"
|
|
80
|
+
data-tone={tone ?? 'neutral'}
|
|
81
|
+
role={tone === 'error' ? 'alert' : 'status'}
|
|
82
|
+
{...props}
|
|
83
|
+
>
|
|
84
|
+
{icon !== false && (
|
|
85
|
+
// A 32px well, the size of an icon tile, so the tone shows before the words are read.
|
|
86
|
+
// 24px beside a title alone.
|
|
87
|
+
<span
|
|
88
|
+
aria-hidden
|
|
89
|
+
className={cn(
|
|
90
|
+
'flex shrink-0 items-center justify-center rounded-chip [&_svg:not([class*=size-])]:size-4',
|
|
91
|
+
slim ? 'size-6' : 'size-8',
|
|
92
|
+
)}
|
|
93
|
+
data-slot="alert-icon"
|
|
94
|
+
>
|
|
95
|
+
{icon ?? <Icon strokeWidth={2} />}
|
|
96
|
+
</span>
|
|
97
|
+
)}
|
|
98
|
+
<div className="flex min-w-0 flex-1 flex-col gap-0.5" data-slot="alert-text">
|
|
99
|
+
<p className="font-medium text-neutral-950">{title}</p>
|
|
100
|
+
{children && <div className="text-neutral-600">{children}</div>}
|
|
101
|
+
</div>
|
|
102
|
+
{onDismiss && (
|
|
103
|
+
// Before the action in the source, so a wrapped action leaves the × at the top right. Pulled
|
|
104
|
+
// out by its own inset, so its glyph sits as far from the edge as the icon well.
|
|
105
|
+
<Button
|
|
106
|
+
aria-label="Dismiss"
|
|
107
|
+
className="order-2 -my-1 -me-1.5 self-start"
|
|
108
|
+
data-slot="alert-dismiss"
|
|
109
|
+
onClick={onDismiss}
|
|
110
|
+
size="icon-sm"
|
|
111
|
+
variant="ghost"
|
|
112
|
+
>
|
|
113
|
+
<X strokeWidth={2} />
|
|
114
|
+
</Button>
|
|
115
|
+
)}
|
|
116
|
+
{action && (
|
|
117
|
+
// Beside the words while the alert has 384px inside; narrower, it takes a line of its own
|
|
118
|
+
// under them, in line with the title, rather than squeezing them: indented by the
|
|
119
|
+
// well's fixed pixels and the gap-x-3, which moves with the spacing unit.
|
|
120
|
+
<div
|
|
121
|
+
className={cn(
|
|
122
|
+
'@max-sm/alert:order-3 order-1 flex shrink-0 @max-sm/alert:basis-full items-center gap-2',
|
|
123
|
+
icon !== false &&
|
|
124
|
+
(slim
|
|
125
|
+
? '@max-sm/alert:ps-[calc(24px+var(--spacing)*3)]'
|
|
126
|
+
: '@max-sm/alert:ps-[calc(32px+var(--spacing)*3)]'),
|
|
127
|
+
)}
|
|
128
|
+
data-slot="alert-action"
|
|
129
|
+
>
|
|
130
|
+
{action}
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import { focusRing, touchTarget } from './button';
|
|
6
|
+
import { CopyButton, type CopyButtonProps } from './copy-button';
|
|
7
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip';
|
|
8
|
+
|
|
9
|
+
export type AssistantAnswerProps = Omit<ComponentProps<'article'>, 'title'> & {
|
|
10
|
+
/**
|
|
11
|
+
* Above the answer, what the assistant did to reach it: `Thinking` while it works, then
|
|
12
|
+
* `AssistantAnswerStep`s for what it did ("12 sources used"), one to a line.
|
|
13
|
+
*/
|
|
14
|
+
work?: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Under the answer, once it is written: `AssistantAnswerCopy` and `AssistantAnswerAction`s (copy,
|
|
17
|
+
* try again, good, bad). Held back while `pending`, as there is nothing whole yet to act on.
|
|
18
|
+
*/
|
|
19
|
+
actions?: ReactNode;
|
|
20
|
+
/** The answer is still being worked out or written: it is busy, and its actions wait. */
|
|
21
|
+
pending?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An assistant's answer to a question: not a message but the page's own content, open in the
|
|
26
|
+
* column with no card, avatar or time, so it can hold what the product shows elsewhere (stat cards,
|
|
27
|
+
* a chart, a table) at the column's full width. From the top: what it did, the answer as blocks 16
|
|
28
|
+
* apart, then what can be done with it. The question before it is one's own `ChatMessage`.
|
|
29
|
+
*/
|
|
30
|
+
export const AssistantAnswer = ({
|
|
31
|
+
work,
|
|
32
|
+
actions,
|
|
33
|
+
pending = false,
|
|
34
|
+
className,
|
|
35
|
+
children,
|
|
36
|
+
...props
|
|
37
|
+
}: AssistantAnswerProps) => {
|
|
38
|
+
const hasBody = children != null && children !== false && children !== '';
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<article
|
|
42
|
+
aria-busy={pending || undefined}
|
|
43
|
+
className={cn('flex min-w-0 flex-col gap-4 text-neutral-950 text-xs', className)}
|
|
44
|
+
data-pending={pending || undefined}
|
|
45
|
+
data-slot="assistant-answer"
|
|
46
|
+
{...props}
|
|
47
|
+
>
|
|
48
|
+
{work != null && (
|
|
49
|
+
<div
|
|
50
|
+
className="flex min-w-0 flex-col items-start gap-2"
|
|
51
|
+
data-slot="assistant-answer-work"
|
|
52
|
+
>
|
|
53
|
+
{work}
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
{hasBody && (
|
|
57
|
+
<div
|
|
58
|
+
className={cn(
|
|
59
|
+
'wrap-break-word flex min-w-0 flex-col gap-4',
|
|
60
|
+
// Lists written in the answer keep their markers inside the column's text edge.
|
|
61
|
+
'[&_li+li]:mt-1 [&_li]:pl-1 [&_ol]:list-decimal [&_ol]:pl-5 [&_strong]:font-medium [&_ul]:list-disc [&_ul]:pl-5',
|
|
62
|
+
)}
|
|
63
|
+
data-slot="assistant-answer-body"
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
{actions != null && !pending && (
|
|
69
|
+
// 8 under the answer, the first icon on the text's edge rather than its square.
|
|
70
|
+
<div
|
|
71
|
+
className="-mt-2 -ml-1.5 flex items-center gap-0.5"
|
|
72
|
+
data-slot="assistant-answer-actions"
|
|
73
|
+
>
|
|
74
|
+
{actions}
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</article>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type AssistantAnswerStepProps = Omit<ComponentProps<'button'>, 'type'> & {
|
|
82
|
+
/** A 16 icon before the words, in `neutral-500`. */
|
|
83
|
+
icon?: ReactNode;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* One thing the assistant did, in its `work`: a 16 icon and the words, 13 `neutral-600`. With an
|
|
88
|
+
* `onClick` it opens what it names (the sources it read) and darkens on hover; without one it is a
|
|
89
|
+
* plain line.
|
|
90
|
+
*/
|
|
91
|
+
export const AssistantAnswerStep = ({
|
|
92
|
+
icon,
|
|
93
|
+
onClick,
|
|
94
|
+
className,
|
|
95
|
+
children,
|
|
96
|
+
...props
|
|
97
|
+
}: AssistantAnswerStepProps) => {
|
|
98
|
+
const classes = cn(
|
|
99
|
+
'inline-flex min-w-0 max-w-full items-center gap-2 rounded-chip text-neutral-600 text-xs [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-neutral-500',
|
|
100
|
+
className,
|
|
101
|
+
);
|
|
102
|
+
const content = (
|
|
103
|
+
<>
|
|
104
|
+
{icon}
|
|
105
|
+
<span className="min-w-0 truncate">{children}</span>
|
|
106
|
+
</>
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
return onClick ? (
|
|
110
|
+
<button
|
|
111
|
+
{...props}
|
|
112
|
+
className={cn(
|
|
113
|
+
classes,
|
|
114
|
+
'cursor-pointer transition-colors duration-150 ease-out-strong hover:text-neutral-950 [&_svg]:transition-colors hover:[&_svg]:text-neutral-950',
|
|
115
|
+
focusRing,
|
|
116
|
+
)}
|
|
117
|
+
data-slot="assistant-answer-step"
|
|
118
|
+
onClick={onClick}
|
|
119
|
+
type="button"
|
|
120
|
+
>
|
|
121
|
+
{content}
|
|
122
|
+
</button>
|
|
123
|
+
) : (
|
|
124
|
+
<p className={classes} data-slot="assistant-answer-step">
|
|
125
|
+
{content}
|
|
126
|
+
</p>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type AssistantAnswerActionProps = Omit<ComponentProps<'button'>, 'type' | 'children'> & {
|
|
131
|
+
/** Its name and tooltip: "Try again", "Good answer". */
|
|
132
|
+
label: string;
|
|
133
|
+
/** The 14 icon. */
|
|
134
|
+
icon: ReactNode;
|
|
135
|
+
/** For a toggle (good, bad): on, it stays dark and says so. */
|
|
136
|
+
pressed?: boolean;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* One action under an answer: a 24 square ghost button with a 14 icon and its name in a tooltip,
|
|
141
|
+
* the size of `AssistantAnswerCopy` so the two sit in one row. A pressed toggle stays `neutral-950`.
|
|
142
|
+
*/
|
|
143
|
+
export const AssistantAnswerAction = ({
|
|
144
|
+
label,
|
|
145
|
+
icon,
|
|
146
|
+
pressed,
|
|
147
|
+
className,
|
|
148
|
+
...props
|
|
149
|
+
}: AssistantAnswerActionProps) => (
|
|
150
|
+
<Tooltip>
|
|
151
|
+
<TooltipTrigger
|
|
152
|
+
render={
|
|
153
|
+
<button
|
|
154
|
+
{...props}
|
|
155
|
+
aria-label={label}
|
|
156
|
+
aria-pressed={pressed}
|
|
157
|
+
className={cn(
|
|
158
|
+
'inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-chip text-neutral-600 transition-[background-color,color] duration-150 ease-out-strong hover:bg-neutral-950/5 hover:text-neutral-950 aria-pressed:text-neutral-950 [&_svg]:size-3.5',
|
|
159
|
+
touchTarget,
|
|
160
|
+
focusRing,
|
|
161
|
+
className,
|
|
162
|
+
)}
|
|
163
|
+
data-slot="assistant-answer-action"
|
|
164
|
+
type="button"
|
|
165
|
+
/>
|
|
166
|
+
}
|
|
167
|
+
>
|
|
168
|
+
{icon}
|
|
169
|
+
</TooltipTrigger>
|
|
170
|
+
<TooltipContent>{label}</TooltipContent>
|
|
171
|
+
</Tooltip>
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
export type AssistantAnswerCopyProps = CopyButtonProps;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The first action under an answer: copies `text` (the answer's words) and, for 1.5s, crossfades
|
|
178
|
+
* to a tick and says "Copied"; named "Copy answer".
|
|
179
|
+
*/
|
|
180
|
+
export const AssistantAnswerCopy = ({
|
|
181
|
+
label = 'Copy answer',
|
|
182
|
+
...props
|
|
183
|
+
}: AssistantAnswerCopyProps) => (
|
|
184
|
+
<CopyButton data-slot="assistant-answer-copy" label={label} {...props} />
|
|
185
|
+
);
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
import { ArrowUp, Plus, Square } from 'lucide-react';
|
|
5
|
+
import {
|
|
6
|
+
type ComponentProps,
|
|
7
|
+
type KeyboardEvent,
|
|
8
|
+
type MouseEvent,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
type Ref,
|
|
11
|
+
type RefCallback,
|
|
12
|
+
useCallback,
|
|
13
|
+
useLayoutEffect,
|
|
14
|
+
useRef,
|
|
15
|
+
useState,
|
|
16
|
+
} from 'react';
|
|
17
|
+
import { cn } from '../lib/cn';
|
|
18
|
+
import { Button } from './button';
|
|
19
|
+
import { AttachContext, assignRef, focusTextOnPress, hasContent } from './chat-shared';
|
|
20
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from './dropdown-menu';
|
|
21
|
+
|
|
22
|
+
export const assistantPromptVariants = cva(
|
|
23
|
+
[
|
|
24
|
+
'flex min-w-0 cursor-text flex-col border border-neutral-200 bg-neutral-50 transition-[border-color] duration-150',
|
|
25
|
+
'has-[textarea:focus-visible]:outline-2 has-[textarea:focus-visible]:outline-focus has-[textarea:focus-visible]:outline-solid has-[textarea:focus-visible]:outline-offset-2',
|
|
26
|
+
],
|
|
27
|
+
{
|
|
28
|
+
variants: {
|
|
29
|
+
size: {
|
|
30
|
+
// The corner nests round the buttons': theirs plus the padding, so it follows the
|
|
31
|
+
// theme's corners, and squares off with them at corner scale 0. The empty page's
|
|
32
|
+
// prompt: room for a long question before it scrolls.
|
|
33
|
+
lg: 'gap-0.5 rounded-[min(calc(var(--radius-chip)+var(--spacing)*2),calc(var(--radius-chip)*100))] p-2',
|
|
34
|
+
// Docked at the foot of a conversation.
|
|
35
|
+
md: 'gap-0.5 rounded-[min(calc(var(--radius-chip)+var(--spacing)*1.5),calc(var(--radius-chip)*100))] p-1.5',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
defaultVariants: {
|
|
39
|
+
size: 'lg',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const inputSizes = {
|
|
45
|
+
// Two lines and a bit at 14 before the foot: with the 8 padding, the 2 gap, the 28 foot and the
|
|
46
|
+
// hairlines the box is 104.
|
|
47
|
+
lg: 'min-h-14 max-h-60 px-2 pt-2 text-sm',
|
|
48
|
+
// One line at 13 in 28: the box is 72 with the foot.
|
|
49
|
+
md: 'min-h-7 max-h-40 px-2 pt-1.5 text-xs',
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
// Both sizes write at 16px on a touch screen: anything smaller and iOS zooms the page in on focus.
|
|
53
|
+
const touchText = 'pointer-coarse:text-base';
|
|
54
|
+
|
|
55
|
+
export type AssistantPromptProps = Omit<ComponentProps<'form'>, 'onSubmit' | 'children'> &
|
|
56
|
+
VariantProps<typeof assistantPromptVariants> & {
|
|
57
|
+
/** Controlled draft. */
|
|
58
|
+
value?: string;
|
|
59
|
+
defaultValue?: string;
|
|
60
|
+
onValueChange?: (value: string) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Called with the trimmed question on Enter or the send button. The draft clears afterwards
|
|
63
|
+
* unless this returns `false`.
|
|
64
|
+
*/
|
|
65
|
+
onSend?: (text: string) => unknown;
|
|
66
|
+
/** A reply is being written: the send button becomes Stop, and Enter waits. */
|
|
67
|
+
streaming?: boolean;
|
|
68
|
+
/** Called by Stop while `streaming`. */
|
|
69
|
+
onStop?: () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Draws a quiet attach button before send, which opens the file picker and calls this with
|
|
72
|
+
* the files chosen; show them in `attachments`. The same prop, meaning the same, as on
|
|
73
|
+
* `MessageComposer`. Leave it, `onAdd` and `attach` out for no attach button.
|
|
74
|
+
*/
|
|
75
|
+
onAttach?: (files: File[]) => void;
|
|
76
|
+
/** The picker's file types, as the input's `accept`: "image/*,.pdf". */
|
|
77
|
+
accept?: string;
|
|
78
|
+
/** Draws the attach button and calls this instead of opening the picker. */
|
|
79
|
+
onAdd?: () => void;
|
|
80
|
+
/**
|
|
81
|
+
* Makes the attach button open a menu above it of what can go with a question:
|
|
82
|
+
* `DropdownMenuItem`s with a 16 icon, and `MessageComposerAttachItem` for files (needs `onAttach`).
|
|
83
|
+
*/
|
|
84
|
+
attachMenu?: ReactNode;
|
|
85
|
+
/** Replaces the attach button entirely, as `attach` does on `MessageComposer`. */
|
|
86
|
+
attach?: ReactNode;
|
|
87
|
+
/**
|
|
88
|
+
* What waits to go with the question: a `ChatAttachments` row, each with `onRemove`. It sits
|
|
89
|
+
* inside the box, above the text. With something waiting, the question can be sent empty.
|
|
90
|
+
*/
|
|
91
|
+
attachments?: ReactNode;
|
|
92
|
+
/** At the left of the foot: a model or mode menu, a scope chip. */
|
|
93
|
+
start?: ReactNode;
|
|
94
|
+
placeholder?: string;
|
|
95
|
+
disabled?: boolean;
|
|
96
|
+
autoFocus?: boolean;
|
|
97
|
+
/** Accessible name of the text box. */
|
|
98
|
+
label?: string;
|
|
99
|
+
/** Accessible names of the attach, send and stop buttons. */
|
|
100
|
+
attachLabel?: string;
|
|
101
|
+
sendLabel?: string;
|
|
102
|
+
stopLabel?: string;
|
|
103
|
+
name?: string;
|
|
104
|
+
maxLength?: number;
|
|
105
|
+
textareaRef?: Ref<HTMLTextAreaElement>;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Where a question to an assistant is written: a text box over a foot with an optional menu at the
|
|
110
|
+
* left and attach and send at the right. `lg` is the empty page's prompt, `md` the one docked under
|
|
111
|
+
* a conversation. Enter sends, Shift+Enter starts a new line; while a reply streams, send becomes
|
|
112
|
+
* Stop. Clicking anywhere on the box that is not a button puts the caret in the text.
|
|
113
|
+
*/
|
|
114
|
+
export const AssistantPrompt = ({
|
|
115
|
+
size,
|
|
116
|
+
value: valueProp,
|
|
117
|
+
defaultValue = '',
|
|
118
|
+
onValueChange,
|
|
119
|
+
onSend,
|
|
120
|
+
streaming = false,
|
|
121
|
+
onStop,
|
|
122
|
+
onAttach,
|
|
123
|
+
accept,
|
|
124
|
+
onAdd,
|
|
125
|
+
attachMenu,
|
|
126
|
+
attach,
|
|
127
|
+
attachments,
|
|
128
|
+
start,
|
|
129
|
+
placeholder = 'Ask anything…',
|
|
130
|
+
disabled = false,
|
|
131
|
+
autoFocus,
|
|
132
|
+
label = 'Question',
|
|
133
|
+
attachLabel = 'Attach',
|
|
134
|
+
sendLabel = 'Send',
|
|
135
|
+
stopLabel = 'Stop',
|
|
136
|
+
name,
|
|
137
|
+
maxLength,
|
|
138
|
+
textareaRef,
|
|
139
|
+
className,
|
|
140
|
+
onMouseDown,
|
|
141
|
+
...props
|
|
142
|
+
}: AssistantPromptProps) => {
|
|
143
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
144
|
+
const controlled = valueProp !== undefined;
|
|
145
|
+
const value = controlled ? valueProp : uncontrolled;
|
|
146
|
+
const attached = hasContent(attachments);
|
|
147
|
+
const canSend = !disabled && !streaming && (value.trim().length > 0 || attached);
|
|
148
|
+
const nodeRef = useRef<HTMLTextAreaElement | null>(null);
|
|
149
|
+
const fileRef = useRef<HTMLInputElement | null>(null);
|
|
150
|
+
const menuCloseReason = useRef<string | null>(null);
|
|
151
|
+
const resolved = size ?? 'lg';
|
|
152
|
+
|
|
153
|
+
const setValue = (next: string) => {
|
|
154
|
+
if (!controlled) setUncontrolled(next);
|
|
155
|
+
onValueChange?.(next);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const setRef = useCallback<RefCallback<HTMLTextAreaElement>>(
|
|
159
|
+
node => {
|
|
160
|
+
nodeRef.current = node;
|
|
161
|
+
assignRef(textareaRef, node);
|
|
162
|
+
},
|
|
163
|
+
[textareaRef],
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// Grow with the draft up to max-h, then scroll; field-sizing is not in every browser yet.
|
|
167
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the height follows the value and the size.
|
|
168
|
+
useLayoutEffect(() => {
|
|
169
|
+
const node = nodeRef.current;
|
|
170
|
+
|
|
171
|
+
if (!node) return;
|
|
172
|
+
node.style.height = 'auto';
|
|
173
|
+
node.style.height = `${node.scrollHeight}px`;
|
|
174
|
+
}, [value, resolved]);
|
|
175
|
+
|
|
176
|
+
const send = () => {
|
|
177
|
+
if (!canSend) return;
|
|
178
|
+
if (onSend?.(value.trim()) !== false) setValue('');
|
|
179
|
+
nodeRef.current?.focus();
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
183
|
+
// Enter during IME composition picks a candidate; it must not send half a word.
|
|
184
|
+
if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing) return;
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
send();
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// The box reads as one field: a press on its padding or its foot lands in the text.
|
|
190
|
+
const focusText = (event: MouseEvent<HTMLFormElement>) => {
|
|
191
|
+
onMouseDown?.(event);
|
|
192
|
+
focusTextOnPress(event, nodeRef.current, disabled);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const openFiles = onAttach ? () => fileRef.current?.click() : null;
|
|
196
|
+
const onAttachPress = onAdd ?? openFiles ?? undefined;
|
|
197
|
+
|
|
198
|
+
const attachButton = (
|
|
199
|
+
<Button
|
|
200
|
+
aria-label={attachLabel}
|
|
201
|
+
data-slot="assistant-prompt-attach"
|
|
202
|
+
disabled={disabled}
|
|
203
|
+
onClick={attachMenu ? undefined : onAttachPress}
|
|
204
|
+
size="icon-sm"
|
|
205
|
+
variant="ghost"
|
|
206
|
+
>
|
|
207
|
+
<Plus aria-hidden strokeWidth={2} />
|
|
208
|
+
</Button>
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const attachment =
|
|
212
|
+
attach ??
|
|
213
|
+
(attachMenu ? (
|
|
214
|
+
<DropdownMenu
|
|
215
|
+
onOpenChange={(open, details) => {
|
|
216
|
+
if (!open) menuCloseReason.current = details.reason;
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
<DropdownMenuTrigger disabled={disabled} render={attachButton} />
|
|
220
|
+
{/* Opens upward from the "+"; picking goes back to the text, Escape leaves focus on the "+". */}
|
|
221
|
+
<DropdownMenuContent
|
|
222
|
+
align="end"
|
|
223
|
+
className="min-w-menu-wide"
|
|
224
|
+
finalFocus={() =>
|
|
225
|
+
menuCloseReason.current === 'item-press' ? nodeRef.current : true
|
|
226
|
+
}
|
|
227
|
+
side="top"
|
|
228
|
+
sideOffset={8}
|
|
229
|
+
>
|
|
230
|
+
{attachMenu}
|
|
231
|
+
</DropdownMenuContent>
|
|
232
|
+
</DropdownMenu>
|
|
233
|
+
) : (
|
|
234
|
+
onAttachPress && attachButton
|
|
235
|
+
));
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<AttachContext.Provider value={{ openFiles }}>
|
|
239
|
+
<form
|
|
240
|
+
className={cn(
|
|
241
|
+
assistantPromptVariants({ size }),
|
|
242
|
+
// The buttons dim themselves when disabled; dimming the frame too would halve them again.
|
|
243
|
+
disabled
|
|
244
|
+
? 'cursor-not-allowed'
|
|
245
|
+
: 'hover:border-neutral-300 has-[textarea:focus]:border-neutral-300',
|
|
246
|
+
className,
|
|
247
|
+
)}
|
|
248
|
+
data-disabled={disabled || undefined}
|
|
249
|
+
data-size={resolved}
|
|
250
|
+
data-slot="assistant-prompt"
|
|
251
|
+
data-streaming={streaming || undefined}
|
|
252
|
+
onMouseDown={focusText}
|
|
253
|
+
onSubmit={event => {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
send();
|
|
256
|
+
}}
|
|
257
|
+
{...props}
|
|
258
|
+
>
|
|
259
|
+
{onAttach && (
|
|
260
|
+
<input
|
|
261
|
+
accept={accept}
|
|
262
|
+
className="hidden"
|
|
263
|
+
data-slot="assistant-prompt-file"
|
|
264
|
+
disabled={disabled}
|
|
265
|
+
multiple
|
|
266
|
+
onChange={event => {
|
|
267
|
+
const files = Array.from(event.currentTarget.files ?? []);
|
|
268
|
+
// Cleared, so choosing the same file again after removing it still reports.
|
|
269
|
+
event.currentTarget.value = '';
|
|
270
|
+
if (files.length > 0) onAttach(files);
|
|
271
|
+
nodeRef.current?.focus();
|
|
272
|
+
}}
|
|
273
|
+
ref={fileRef}
|
|
274
|
+
tabIndex={-1}
|
|
275
|
+
type="file"
|
|
276
|
+
/>
|
|
277
|
+
)}
|
|
278
|
+
{attached && (
|
|
279
|
+
// What waits to go, inside the box above the text, so the question and its files read as one.
|
|
280
|
+
<div className="min-w-0 px-1 pt-1" data-slot="assistant-prompt-attachments">
|
|
281
|
+
{attachments}
|
|
282
|
+
</div>
|
|
283
|
+
)}
|
|
284
|
+
<textarea
|
|
285
|
+
aria-label={label}
|
|
286
|
+
// biome-ignore lint/a11y/noAutofocus: an empty assistant page has one thing to do, and asks for it.
|
|
287
|
+
autoFocus={autoFocus}
|
|
288
|
+
className={cn(
|
|
289
|
+
'block min-w-0 resize-none overflow-y-auto bg-transparent text-neutral-900 outline-none placeholder:text-neutral-600',
|
|
290
|
+
'disabled:cursor-not-allowed disabled:text-neutral-400 disabled:placeholder:text-neutral-300',
|
|
291
|
+
inputSizes[resolved],
|
|
292
|
+
touchText,
|
|
293
|
+
)}
|
|
294
|
+
data-slot="assistant-prompt-input"
|
|
295
|
+
disabled={disabled}
|
|
296
|
+
maxLength={maxLength}
|
|
297
|
+
name={name}
|
|
298
|
+
onChange={event => setValue(event.target.value)}
|
|
299
|
+
onKeyDown={onKeyDown}
|
|
300
|
+
placeholder={placeholder}
|
|
301
|
+
ref={setRef}
|
|
302
|
+
rows={1}
|
|
303
|
+
value={value}
|
|
304
|
+
/>
|
|
305
|
+
<div className="flex min-w-0 items-center gap-1" data-slot="assistant-prompt-foot">
|
|
306
|
+
{start != null && (
|
|
307
|
+
<div
|
|
308
|
+
className="flex min-w-0 items-center gap-1"
|
|
309
|
+
data-slot="assistant-prompt-start"
|
|
310
|
+
>
|
|
311
|
+
{start}
|
|
312
|
+
</div>
|
|
313
|
+
)}
|
|
314
|
+
<div className="ml-auto flex shrink-0 items-center gap-1">
|
|
315
|
+
{attachment}
|
|
316
|
+
{streaming ? (
|
|
317
|
+
<Button
|
|
318
|
+
aria-label={stopLabel}
|
|
319
|
+
data-slot="assistant-prompt-stop"
|
|
320
|
+
// Stop gives way to send, so the press would leave focus on nothing: it returns to the text.
|
|
321
|
+
onClick={() => {
|
|
322
|
+
onStop?.();
|
|
323
|
+
nodeRef.current?.focus();
|
|
324
|
+
}}
|
|
325
|
+
size="icon-sm"
|
|
326
|
+
type="button"
|
|
327
|
+
variant="primary"
|
|
328
|
+
>
|
|
329
|
+
<Square
|
|
330
|
+
aria-hidden
|
|
331
|
+
className="size-2.5 fill-current"
|
|
332
|
+
strokeWidth={0}
|
|
333
|
+
/>
|
|
334
|
+
</Button>
|
|
335
|
+
) : (
|
|
336
|
+
<Button
|
|
337
|
+
aria-label={sendLabel}
|
|
338
|
+
data-slot="assistant-prompt-send"
|
|
339
|
+
disabled={!canSend}
|
|
340
|
+
size="icon-sm"
|
|
341
|
+
type="submit"
|
|
342
|
+
variant="primary"
|
|
343
|
+
>
|
|
344
|
+
<ArrowUp aria-hidden strokeWidth={2} />
|
|
345
|
+
</Button>
|
|
346
|
+
)}
|
|
347
|
+
</div>
|
|
348
|
+
</div>
|
|
349
|
+
</form>
|
|
350
|
+
</AttachContext.Provider>
|
|
351
|
+
);
|
|
352
|
+
};
|