@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,308 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Toast as ToastPrimitive } from '@base-ui/react/toast';
|
|
4
|
+
import { ArrowRight, CircleAlert, CircleCheck, Info, TriangleAlert, Undo2, X } from 'lucide-react';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
import { cn } from '../lib/cn';
|
|
7
|
+
import { focusRing } from './button';
|
|
8
|
+
import { Theme, ThemeScope, usePortalContainer, useTheme } from './theme';
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip';
|
|
10
|
+
|
|
11
|
+
export type ToastProviderProps = {
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
/** How long a toast stays, in ms; 0 keeps it until it is closed. */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** How many show at once; older ones leave first. */
|
|
16
|
+
limit?: number;
|
|
17
|
+
/** Where the toasts are portalled; the body by default. */
|
|
18
|
+
container?: HTMLElement | null;
|
|
19
|
+
/** Classes for the stack; lift it with `bottom-*` where a bottom bar sits below. */
|
|
20
|
+
viewportClassName?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* A layer above dialogs, menus and tooltips (z-50): a toast raised while a dialog is open reports on
|
|
25
|
+
* what the dialog did, so it stands over the scrim rather than under it.
|
|
26
|
+
*/
|
|
27
|
+
const TOAST_LAYER = 'z-60';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Holds the toasts for everything inside it and draws them in the bottom right corner, across the
|
|
31
|
+
* foot on a phone. They pile up, the newest in front and the older ones peeking
|
|
32
|
+
* over it; pointing at the pile fans it out. Raise one from anywhere below it with
|
|
33
|
+
* `useToast().add({ title, description, type, actionProps })`; a `data.tab` makes it a folder card.
|
|
34
|
+
*/
|
|
35
|
+
export const ToastProvider = ({
|
|
36
|
+
children,
|
|
37
|
+
timeout = 5000,
|
|
38
|
+
limit = 3,
|
|
39
|
+
container,
|
|
40
|
+
viewportClassName,
|
|
41
|
+
}: ToastProviderProps) => (
|
|
42
|
+
<ToastPrimitive.Provider limit={limit} timeout={timeout}>
|
|
43
|
+
{children}
|
|
44
|
+
<ToastPrimitive.Portal container={usePortalContainer(container)}>
|
|
45
|
+
<ThemeScope>
|
|
46
|
+
<ToastPrimitive.Viewport
|
|
47
|
+
className={cn(
|
|
48
|
+
// The toasts stand on its foot, so it needs a width but no height.
|
|
49
|
+
'fixed right-6 bottom-6 w-toast outline-none max-sm:inset-x-4 max-sm:bottom-4 max-sm:w-auto',
|
|
50
|
+
TOAST_LAYER,
|
|
51
|
+
viewportClassName,
|
|
52
|
+
)}
|
|
53
|
+
data-slot="toast-viewport"
|
|
54
|
+
>
|
|
55
|
+
<ToastList />
|
|
56
|
+
</ToastPrimitive.Viewport>
|
|
57
|
+
</ThemeScope>
|
|
58
|
+
</ToastPrimitive.Portal>
|
|
59
|
+
</ToastPrimitive.Provider>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
/** The toast manager: `add`, `close`, `update` and `promise`, and the toasts showing now. */
|
|
63
|
+
export const useToast = ToastPrimitive.useToastManager;
|
|
64
|
+
|
|
65
|
+
// The tones and glyphs of an Alert, so a toast of a type reads as an alert of that tone would.
|
|
66
|
+
const typeIcons: Record<string, ReactNode> = {
|
|
67
|
+
primary: <Info strokeWidth={2} />,
|
|
68
|
+
success: <CircleCheck strokeWidth={2} />,
|
|
69
|
+
warning: <TriangleAlert strokeWidth={2} />,
|
|
70
|
+
error: <CircleAlert strokeWidth={2} />,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// The well takes the badge's wash, its 500 at 20%, under the glyph at 700: a glyph needs 3:1 on
|
|
74
|
+
// it, which 700 reaches in every tone, where the badge's words need 4.5:1 and take 800.
|
|
75
|
+
const wellTones: Record<string, string> = {
|
|
76
|
+
primary: 'bg-primary-500/20 text-primary-700',
|
|
77
|
+
success: 'bg-success-500/20 text-success-700',
|
|
78
|
+
warning: 'bg-warning-500/20 text-warning-700',
|
|
79
|
+
error: 'bg-error-500/20 text-error-700',
|
|
80
|
+
neutral: 'bg-neutral-500/20 text-neutral-700',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Per-toast options, passed as `data` to `add`. */
|
|
84
|
+
export type ToastData = {
|
|
85
|
+
/**
|
|
86
|
+
* A tab on top, like a folder's, saying what is going on ("Report archived", "Export in
|
|
87
|
+
* progress"); the action moves into it beside the words.
|
|
88
|
+
*/
|
|
89
|
+
tab?: string;
|
|
90
|
+
/** A 16px icon, or a 36px picture of the thing, for the well, where a `type` has none of its own. */
|
|
91
|
+
icon?: ReactNode;
|
|
92
|
+
/** The action's icon; an undo arrow for an `undo` action, an arrow for anything else. Its label names it. */
|
|
93
|
+
actionIcon?: ReactNode;
|
|
94
|
+
/**
|
|
95
|
+
* The action takes back what the toast reports, so it draws the undo arrow whatever its label
|
|
96
|
+
* says ("Restore", "Ongedaan maken"). Left out, an action labelled "Undo" still counts as one.
|
|
97
|
+
*/
|
|
98
|
+
undo?: boolean;
|
|
99
|
+
};
|
|
100
|
+
/*
|
|
101
|
+
* The pile, from the variables Base UI sets on each toast. Collapsed, a toast behind the front one
|
|
102
|
+
* takes its height, shrinks a tenth per place and rises 8px a place, so the older ones peek over
|
|
103
|
+
* the front. Fanned out, each stands at its own offset with a 12px gap, and the gap is bridged so
|
|
104
|
+
* the pointer can cross it without the pile closing.
|
|
105
|
+
*/
|
|
106
|
+
const pileClass = [
|
|
107
|
+
'[--gap:12px] [--peek:8px] [--scale:calc(max(0,1-(var(--toast-index)*0.1)))] [--shrink:calc(1-var(--scale))]',
|
|
108
|
+
'[--height:var(--toast-frontmost-height,var(--toast-height))]',
|
|
109
|
+
'[--offset-y:calc(var(--toast-offset-y)*-1-var(--toast-index)*var(--gap)+var(--toast-swipe-movement-y))]',
|
|
110
|
+
'group/toast absolute right-0 bottom-0 z-[calc(100-var(--toast-index))] flex w-full origin-bottom flex-col items-end',
|
|
111
|
+
// Behind, it is cut to the front one's height; its top, a tab or a card's edge, is what shows.
|
|
112
|
+
'h-(--height) overflow-hidden data-expanded:h-(--toast-height) data-expanded:overflow-visible',
|
|
113
|
+
'[transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-var(--toast-index)*var(--peek)-var(--shrink)*var(--height)))_scale(var(--scale))]',
|
|
114
|
+
'data-expanded:[transform:translateX(var(--toast-swipe-movement-x))_translateY(var(--offset-y))]',
|
|
115
|
+
"after:absolute after:top-full after:left-0 after:h-[calc(var(--gap)+1px)] after:w-full after:content-['']",
|
|
116
|
+
// It rises in from below and leaves the way it is swiped, or back down.
|
|
117
|
+
'data-starting-style:[transform:translateY(24px)] data-starting-style:opacity-0',
|
|
118
|
+
'data-ending-style:opacity-0 [&[data-ending-style]:not([data-swipe-direction])]:[transform:translateY(24px)]',
|
|
119
|
+
'data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+100%))]',
|
|
120
|
+
'data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+100%))]',
|
|
121
|
+
// Past the limit, the oldest fades out of the back of the pile.
|
|
122
|
+
'data-limited:opacity-0',
|
|
123
|
+
'[transition:transform_400ms_var(--ease-out-strong),opacity_400ms,height_150ms] motion-reduce:transition-none',
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
// What a toast says shows only at the front of the pile or once it fans out; behind, just its shape.
|
|
127
|
+
const faceClass =
|
|
128
|
+
'opacity-[calc(1-min(var(--toast-index),1))] transition-opacity duration-200 group-data-expanded/toast:opacity-100';
|
|
129
|
+
|
|
130
|
+
// The surface, a hairline round it, in the mode opposite the page's (see ToastList).
|
|
131
|
+
const surfaceClass = 'border border-neutral-200 bg-neutral-50 text-neutral-950 text-xs';
|
|
132
|
+
|
|
133
|
+
// A 36px square on the card: the ×, and the action when there is no tab to hold it.
|
|
134
|
+
const squareClass = cn(
|
|
135
|
+
'inline-flex size-option shrink-0 cursor-pointer items-center justify-center rounded-item text-neutral-600 transition-[background-color,color] duration-150 hover:bg-neutral-950/5 hover:text-neutral-950 [&_svg]:size-4',
|
|
136
|
+
focusRing,
|
|
137
|
+
faceClass,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// Past these, a title or description wraps in the 360px card.
|
|
141
|
+
const LONG_TITLE = 32;
|
|
142
|
+
const LONG_DESCRIPTION = 44;
|
|
143
|
+
|
|
144
|
+
type ListedToast = ToastPrimitive.Root.ToastObject<ToastData>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The action as an icon, named in a tooltip, since Base UI's own action always shows its label.
|
|
148
|
+
* In a tab it sits in the line of text and only darkens and lightens, as a word would; on the
|
|
149
|
+
* card it is a 36px square beside the ×.
|
|
150
|
+
*/
|
|
151
|
+
const ToastActionIcon = ({ toast, inTab }: { toast: ListedToast; inTab: boolean }) => {
|
|
152
|
+
const { children: label, ...actionProps } = toast.actionProps ?? {};
|
|
153
|
+
if (!label) return null;
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<Tooltip>
|
|
157
|
+
<TooltipTrigger
|
|
158
|
+
render={
|
|
159
|
+
<button
|
|
160
|
+
{...actionProps}
|
|
161
|
+
aria-label={typeof label === 'string' ? label : undefined}
|
|
162
|
+
className={
|
|
163
|
+
inTab
|
|
164
|
+
? cn(
|
|
165
|
+
'-my-0.5 inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-chip text-neutral-950 transition-colors duration-150 hover:text-neutral-600 [&_svg]:size-3.5',
|
|
166
|
+
focusRing,
|
|
167
|
+
faceClass,
|
|
168
|
+
)
|
|
169
|
+
: squareClass
|
|
170
|
+
}
|
|
171
|
+
data-slot="toast-action"
|
|
172
|
+
type="button"
|
|
173
|
+
>
|
|
174
|
+
{toast.data?.actionIcon ??
|
|
175
|
+
((toast.data?.undo ?? label === 'Undo') ? (
|
|
176
|
+
<Undo2 strokeWidth={2} />
|
|
177
|
+
) : (
|
|
178
|
+
<ArrowRight strokeWidth={2} />
|
|
179
|
+
))}
|
|
180
|
+
</button>
|
|
181
|
+
}
|
|
182
|
+
/>
|
|
183
|
+
<TooltipContent positionerClassName={TOAST_LAYER}>{label}</TooltipContent>
|
|
184
|
+
</Tooltip>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* One toast: a card with the thing (`title`, two lines at most), a line about it (`description`,
|
|
190
|
+
* three at most) and its icon in a badge-toned well, then the action and the ×. A `data.tab` sets
|
|
191
|
+
* a tab on top saying what is going on, and the action moves into it. It is drawn in the mode
|
|
192
|
+
* opposite the page's, so it stands out in either and keeps the theme's own colours.
|
|
193
|
+
*/
|
|
194
|
+
const ToastList = () => {
|
|
195
|
+
const { toasts } = useToast<ToastData>();
|
|
196
|
+
const { mode } = useTheme();
|
|
197
|
+
|
|
198
|
+
return toasts.map(toast => {
|
|
199
|
+
const icon = toast.data?.icon ?? (toast.type ? typeIcons[toast.type] : undefined);
|
|
200
|
+
const tab = toast.data?.tab;
|
|
201
|
+
// Text that wraps reads as a paragraph, so the title stands a little further off it.
|
|
202
|
+
const wordy =
|
|
203
|
+
(typeof toast.title === 'string' && toast.title.length > LONG_TITLE) ||
|
|
204
|
+
(typeof toast.description === 'string' && toast.description.length > LONG_DESCRIPTION);
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<ToastPrimitive.Root
|
|
208
|
+
className={cn(pileClass)}
|
|
209
|
+
data-slot="toast"
|
|
210
|
+
key={toast.id}
|
|
211
|
+
swipeDirection={['down', 'right']}
|
|
212
|
+
toast={toast}
|
|
213
|
+
>
|
|
214
|
+
<Theme
|
|
215
|
+
className="flex h-full w-full flex-col items-start"
|
|
216
|
+
mode={mode === 'dark' ? 'light' : 'dark'}
|
|
217
|
+
>
|
|
218
|
+
{tab && (
|
|
219
|
+
<span
|
|
220
|
+
className={cn(
|
|
221
|
+
surfaceClass,
|
|
222
|
+
'relative z-10 -mb-px flex max-w-3/4 items-center gap-2 rounded-t-item border-b-0 px-4 pt-2.5 pb-1 text-neutral-600',
|
|
223
|
+
)}
|
|
224
|
+
data-slot="toast-tab"
|
|
225
|
+
>
|
|
226
|
+
<span className={cn('truncate', faceClass)}>{tab}</span>
|
|
227
|
+
<ToastActionIcon inTab toast={toast} />
|
|
228
|
+
{/*
|
|
229
|
+
* The foot curves into the card, the hairline running along it. It is
|
|
230
|
+
* sized from the tab's corner (12px at the default 10px), so it squares
|
|
231
|
+
* off with the theme's corners and keeps a 1px line at any size.
|
|
232
|
+
*/}
|
|
233
|
+
<svg
|
|
234
|
+
aria-hidden="true"
|
|
235
|
+
className="absolute bottom-0 left-[calc(100%+1px)] size-[calc(var(--radius-item)*1.2)] overflow-visible"
|
|
236
|
+
viewBox="0 0 12 12"
|
|
237
|
+
>
|
|
238
|
+
<path
|
|
239
|
+
className="fill-neutral-50"
|
|
240
|
+
d="M-0.5 -0.5A12 12 0 0 0 11.5 11.5V12H-1Z"
|
|
241
|
+
/>
|
|
242
|
+
<path
|
|
243
|
+
className="fill-none stroke-neutral-200"
|
|
244
|
+
d="M-0.5 -0.5A12 12 0 0 0 11.5 11.5"
|
|
245
|
+
vectorEffect="non-scaling-stroke"
|
|
246
|
+
/>
|
|
247
|
+
</svg>
|
|
248
|
+
</span>
|
|
249
|
+
)}
|
|
250
|
+
<div
|
|
251
|
+
className={cn(
|
|
252
|
+
// Top-aligned, so a name or line that wraps grows the card down and the well and × stay put.
|
|
253
|
+
'flex w-full min-w-0 flex-1 items-start gap-1.5 rounded-card p-2',
|
|
254
|
+
tab && 'rounded-tl-none',
|
|
255
|
+
!icon && 'pl-4',
|
|
256
|
+
surfaceClass,
|
|
257
|
+
)}
|
|
258
|
+
data-slot="toast-card"
|
|
259
|
+
>
|
|
260
|
+
{icon && (
|
|
261
|
+
<span
|
|
262
|
+
className={cn(
|
|
263
|
+
'flex size-option shrink-0 items-center justify-center overflow-hidden rounded-item [&_svg:not([class*=size-])]:size-4',
|
|
264
|
+
wellTones[toast.type ?? 'neutral'] ?? wellTones.neutral,
|
|
265
|
+
faceClass,
|
|
266
|
+
)}
|
|
267
|
+
data-slot="toast-icon"
|
|
268
|
+
>
|
|
269
|
+
{icon}
|
|
270
|
+
</span>
|
|
271
|
+
)}
|
|
272
|
+
<span
|
|
273
|
+
className={cn(
|
|
274
|
+
// Two lines beside the 36px well; more text grows it.
|
|
275
|
+
'flex min-h-option min-w-0 flex-1 flex-col justify-center py-0.5 pr-1',
|
|
276
|
+
wordy ? 'gap-1.5' : 'gap-0.5',
|
|
277
|
+
icon && 'ml-2.5',
|
|
278
|
+
faceClass,
|
|
279
|
+
)}
|
|
280
|
+
>
|
|
281
|
+
<ToastPrimitive.Title
|
|
282
|
+
className="line-clamp-2 font-medium text-sm"
|
|
283
|
+
data-slot="toast-title"
|
|
284
|
+
render={<span />}
|
|
285
|
+
/>
|
|
286
|
+
<ToastPrimitive.Description
|
|
287
|
+
className="line-clamp-3 text-neutral-600"
|
|
288
|
+
data-slot="toast-description"
|
|
289
|
+
render={<span />}
|
|
290
|
+
/>
|
|
291
|
+
</span>
|
|
292
|
+
{/* The action and the × side by side, their squares touching, so they read as one pair. */}
|
|
293
|
+
<span className="flex shrink-0">
|
|
294
|
+
{!tab && <ToastActionIcon inTab={false} toast={toast} />}
|
|
295
|
+
<ToastPrimitive.Close
|
|
296
|
+
aria-label="Dismiss"
|
|
297
|
+
className={squareClass}
|
|
298
|
+
data-slot="toast-close"
|
|
299
|
+
>
|
|
300
|
+
<X strokeWidth={2} />
|
|
301
|
+
</ToastPrimitive.Close>
|
|
302
|
+
</span>
|
|
303
|
+
</div>
|
|
304
|
+
</Theme>
|
|
305
|
+
</ToastPrimitive.Root>
|
|
306
|
+
);
|
|
307
|
+
});
|
|
308
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Toolbar as ToolbarPrimitive } from '@base-ui/react/toolbar';
|
|
4
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
5
|
+
import { Sparkles } from 'lucide-react';
|
|
6
|
+
import { type ComponentProps, createContext, type ReactNode, useContext } from 'react';
|
|
7
|
+
import { cn } from '../lib/cn';
|
|
8
|
+
import { useOverflowScroll } from '../lib/overflow-scroll';
|
|
9
|
+
import { focusRing } from './button';
|
|
10
|
+
|
|
11
|
+
const toolbarVariants = cva(
|
|
12
|
+
'flex w-fit max-w-full items-stretch border border-neutral-200 bg-neutral-50 shadow-float',
|
|
13
|
+
{
|
|
14
|
+
variants: {
|
|
15
|
+
variant: {
|
|
16
|
+
inline: 'h-control overflow-hidden rounded-control',
|
|
17
|
+
// The field row's 38px: items stretch to the 30px left inside a 3px inset and the hairline. It
|
|
18
|
+
// keeps the inline bar's corner, not the dock's pill, so both variants follow the theme's corners.
|
|
19
|
+
// The inset is fixed px, not the spacing unit, so the items' corner calc below stays true.
|
|
20
|
+
floating:
|
|
21
|
+
'h-control-lg rounded-control p-[3px] [--spacing-icon:var(--spacing-icon-lg)]',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
defaultVariants: { variant: 'inline' },
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* The items sit in a row inside the bar, so a bar wider than its room scrolls sideways under its
|
|
30
|
+
* own border and shadow rather than clipping its last actions: the scrollbar hidden, the edge with
|
|
31
|
+
* more faded. A bar that fits is left exactly as it was, since the row only scrolls once it
|
|
32
|
+
* overflows.
|
|
33
|
+
*/
|
|
34
|
+
const toolbarRowVariants = cva('flex min-w-0 items-stretch', {
|
|
35
|
+
variants: {
|
|
36
|
+
variant: {
|
|
37
|
+
inline: '',
|
|
38
|
+
// Scrolling, the row reaches out over the inset and the hairline, so a focus ring keeps its room.
|
|
39
|
+
floating: 'gap-0.5 data-overflows:-m-[4px] data-overflows:p-[4px]',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
defaultVariants: { variant: 'inline' },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const toolbarButtonVariants = cva(
|
|
46
|
+
[
|
|
47
|
+
'inline-flex cursor-pointer select-none items-center whitespace-nowrap font-medium text-neutral-600 text-xs transition-[background-color,color] duration-150',
|
|
48
|
+
'hover:text-neutral-950',
|
|
49
|
+
// Base UI keeps a disabled toolbar button focusable, so it sets data-disabled rather than the disabled attribute.
|
|
50
|
+
'data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg:not([class*=size-])]:size-icon [&_svg]:shrink-0',
|
|
51
|
+
// In a compact shell a button with an icon keeps only the icon, a square on the bar's height;
|
|
52
|
+
// its label stays in the tree at no size, so a screen reader still says it. A button
|
|
53
|
+
// without an icon keeps its label, since it has nothing else to show.
|
|
54
|
+
'@max-shell-compact/shell:has-[>svg]:gap-0 @max-shell-compact/shell:has-[>svg]:px-2 @max-shell-compact/shell:has-[>svg]:text-[0px]',
|
|
55
|
+
focusRing,
|
|
56
|
+
],
|
|
57
|
+
{
|
|
58
|
+
variants: {
|
|
59
|
+
variant: {
|
|
60
|
+
// The bar clips overflow, so the ring has to sit inside the button. The divider runs the full
|
|
61
|
+
// height, but the hover sits 2px inside it, the same shape as the chip.
|
|
62
|
+
inline: [
|
|
63
|
+
'relative isolate gap-2 border-neutral-200 not-last:border-r px-3 focus-visible:-outline-offset-2',
|
|
64
|
+
'before:absolute before:inset-[2px] before:-z-10 before:rounded-[calc(var(--radius-control)-3px)] before:transition-colors before:duration-150 hover:before:bg-neutral-950/5',
|
|
65
|
+
],
|
|
66
|
+
// The bar's radius minus its 3px inset and 1px border, so the curves stay concentric.
|
|
67
|
+
floating:
|
|
68
|
+
'gap-2 rounded-[calc(var(--radius-control)-4px)] px-3 hover:bg-neutral-950/5',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
defaultVariants: { variant: 'inline' },
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
type ToolbarVariant = NonNullable<VariantProps<typeof toolbarVariants>['variant']>;
|
|
76
|
+
|
|
77
|
+
const ToolbarVariantContext = createContext<ToolbarVariant>('inline');
|
|
78
|
+
|
|
79
|
+
// Base UI also accepts a className function of state; Continuum merges strings with cn(), so it takes a string.
|
|
80
|
+
export type ToolbarProps = Omit<ComponentProps<typeof ToolbarPrimitive.Root>, 'className'> &
|
|
81
|
+
VariantProps<typeof toolbarVariants> & { className?: string };
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* `inline` is an AI toolbar over a table cell or a selection: flush segments
|
|
85
|
+
* split by hairlines. `floating` is a bottom action bar: padded, with rounded
|
|
86
|
+
* items and no dividers, at the dock's height with the inline bar's corners.
|
|
87
|
+
*/
|
|
88
|
+
export const Toolbar = ({ variant, className, children, ...props }: ToolbarProps) => {
|
|
89
|
+
const { ref, edges, style } = useOverflowScroll<HTMLDivElement>();
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<ToolbarVariantContext.Provider value={variant ?? 'inline'}>
|
|
93
|
+
<ToolbarPrimitive.Root
|
|
94
|
+
className={cn(toolbarVariants({ variant }), className)}
|
|
95
|
+
data-slot="toolbar"
|
|
96
|
+
data-variant={variant ?? 'inline'}
|
|
97
|
+
{...props}
|
|
98
|
+
>
|
|
99
|
+
<div
|
|
100
|
+
className={cn(
|
|
101
|
+
toolbarRowVariants({ variant }),
|
|
102
|
+
edges.overflows && 'scrollbar-none overflow-x-auto',
|
|
103
|
+
)}
|
|
104
|
+
data-overflows={edges.overflows || undefined}
|
|
105
|
+
data-slot="toolbar-row"
|
|
106
|
+
ref={ref}
|
|
107
|
+
style={edges.overflows ? style : undefined}
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
</div>
|
|
111
|
+
</ToolbarPrimitive.Root>
|
|
112
|
+
</ToolbarVariantContext.Provider>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const ToolbarButton = ({
|
|
117
|
+
className,
|
|
118
|
+
...props
|
|
119
|
+
}: Omit<ComponentProps<typeof ToolbarPrimitive.Button>, 'className'> & { className?: string }) => {
|
|
120
|
+
const variant = useContext(ToolbarVariantContext);
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<ToolbarPrimitive.Button
|
|
124
|
+
className={cn(toolbarButtonVariants({ variant }), className)}
|
|
125
|
+
data-slot="toolbar-button"
|
|
126
|
+
type="button"
|
|
127
|
+
{...props}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
type ToolbarChipProps = ComponentProps<'span'> & {
|
|
133
|
+
/** Replaces the default sparkles icon. */
|
|
134
|
+
icon?: ReactNode;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const toolbarChipVariants = cva(
|
|
138
|
+
'inline-flex select-none items-center gap-1.5 whitespace-nowrap bg-primary-500/20 font-medium text-primary-800 text-xxs [&_svg:not([class*=size-])]:size-4 [&_svg]:shrink-0',
|
|
139
|
+
{
|
|
140
|
+
variants: {
|
|
141
|
+
variant: {
|
|
142
|
+
// Inset 2px inside a 1px border, so the bar's radius minus 3px keeps it concentric.
|
|
143
|
+
inline: 'm-[2px] rounded-[calc(var(--radius-control)-3px)] px-2',
|
|
144
|
+
// The bar's own 3px inset already holds it, so it takes the buttons' size and corner.
|
|
145
|
+
floating: 'rounded-[calc(var(--radius-control)-4px)] px-2.5',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
defaultVariants: { variant: 'inline' },
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
/** The lead chip ("AI suggestions") at the start of the toolbar, coloured like a primary badge. */
|
|
153
|
+
export const ToolbarChip = ({ icon, className, children, ...props }: ToolbarChipProps) => {
|
|
154
|
+
const variant = useContext(ToolbarVariantContext);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<span
|
|
158
|
+
className={cn(toolbarChipVariants({ variant }), className)}
|
|
159
|
+
data-slot="toolbar-chip"
|
|
160
|
+
{...props}
|
|
161
|
+
>
|
|
162
|
+
{icon ?? <Sparkles strokeWidth={2} />}
|
|
163
|
+
{children}
|
|
164
|
+
</span>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Tooltip as TooltipPrimitive } from '@base-ui/react/tooltip';
|
|
4
|
+
import { type ComponentProps, createContext, useContext } from 'react';
|
|
5
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
6
|
+
import { ThemeScope, usePortalContainer } from './theme';
|
|
7
|
+
|
|
8
|
+
// Whether a TooltipProvider sits above, so a tooltip inside it joins that provider's group.
|
|
9
|
+
const InProviderContext = createContext(false);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Groups the tooltips inside it: once one has shown, the next one pointed at opens at once, so
|
|
13
|
+
* moving along a rail or a toolbar reads each label without waiting again.
|
|
14
|
+
*/
|
|
15
|
+
export const TooltipProvider = ({
|
|
16
|
+
delay = 300,
|
|
17
|
+
children,
|
|
18
|
+
...props
|
|
19
|
+
}: ComponentProps<typeof TooltipPrimitive.Provider>) => (
|
|
20
|
+
<TooltipPrimitive.Provider data-slot="tooltip-provider" delay={delay} {...props}>
|
|
21
|
+
<InProviderContext.Provider value>{children}</InProviderContext.Provider>
|
|
22
|
+
</TooltipPrimitive.Provider>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Brings its own provider when there is none higher up, so a lone tooltip works; inside a
|
|
27
|
+
* TooltipProvider it joins that one, since a provider of its own would cut it out of the group.
|
|
28
|
+
*/
|
|
29
|
+
export const Tooltip = (props: ComponentProps<typeof TooltipPrimitive.Root>) => {
|
|
30
|
+
const root = <TooltipPrimitive.Root data-slot="tooltip" {...props} />;
|
|
31
|
+
return useContext(InProviderContext) ? root : <TooltipProvider>{root}</TooltipProvider>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const TooltipTrigger = (props: ComponentProps<typeof TooltipPrimitive.Trigger>) => (
|
|
35
|
+
<TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
type TooltipContentProps = WithClassName<ComponentProps<typeof TooltipPrimitive.Popup>> &
|
|
39
|
+
Pick<
|
|
40
|
+
ComponentProps<typeof TooltipPrimitive.Positioner>,
|
|
41
|
+
'align' | 'alignOffset' | 'side' | 'sideOffset'
|
|
42
|
+
> & {
|
|
43
|
+
/** Where the chip is portalled; the body by default. */
|
|
44
|
+
container?: ComponentProps<typeof TooltipPrimitive.Portal>['container'];
|
|
45
|
+
/** Classes for the positioner, such as a higher layer for a tooltip on something above dialogs. */
|
|
46
|
+
positionerClassName?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Dark label chip for icon-only controls, such as the analytics rail. */
|
|
50
|
+
export const TooltipContent = ({
|
|
51
|
+
className,
|
|
52
|
+
side = 'top',
|
|
53
|
+
sideOffset = 6,
|
|
54
|
+
align = 'center',
|
|
55
|
+
alignOffset = 0,
|
|
56
|
+
container,
|
|
57
|
+
positionerClassName,
|
|
58
|
+
...props
|
|
59
|
+
}: TooltipContentProps) => (
|
|
60
|
+
<TooltipPrimitive.Portal container={usePortalContainer(container)}>
|
|
61
|
+
<ThemeScope>
|
|
62
|
+
<TooltipPrimitive.Positioner
|
|
63
|
+
align={align}
|
|
64
|
+
alignOffset={alignOffset}
|
|
65
|
+
className={cn('z-50', positionerClassName)}
|
|
66
|
+
data-slot="tooltip-positioner"
|
|
67
|
+
side={side}
|
|
68
|
+
sideOffset={sideOffset}
|
|
69
|
+
>
|
|
70
|
+
<TooltipPrimitive.Popup
|
|
71
|
+
className={cn(
|
|
72
|
+
'max-w-tooltip origin-(--transform-origin) select-none text-balance rounded-chip bg-neutral-950 px-2 py-1 font-medium text-neutral-50 text-xxs',
|
|
73
|
+
// Base UI keeps the popup mounted while it fades out; data-instant marks a hop between
|
|
74
|
+
// grouped tooltips, which should swap without fading.
|
|
75
|
+
'transition-opacity duration-200 ease-out-strong data-ending-style:opacity-0 data-starting-style:opacity-0 data-instant:transition-none motion-reduce:transition-none',
|
|
76
|
+
className,
|
|
77
|
+
)}
|
|
78
|
+
data-slot="tooltip-content"
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
</TooltipPrimitive.Positioner>
|
|
82
|
+
</ThemeScope>
|
|
83
|
+
</TooltipPrimitive.Portal>
|
|
84
|
+
);
|