@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,251 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
import { Check, Copy } from 'lucide-react';
|
|
5
|
+
import { type ComponentProps, type ReactNode, useEffect, useId, useRef, useState } from 'react';
|
|
6
|
+
import { cn } from '../lib/cn';
|
|
7
|
+
import { Button } from './button';
|
|
8
|
+
import { StatusDot, type StatusDotTone } from './status-dot';
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip';
|
|
10
|
+
import { Truncate } from './truncate';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* The well is a read-only twin of Input: the same heights and radii, but filled with the 4% wash instead of
|
|
14
|
+
* bordered, so a fact never looks like something to type into.
|
|
15
|
+
*/
|
|
16
|
+
export const readonlyFieldWellVariants = cva(
|
|
17
|
+
'flex w-full min-w-0 items-center gap-2 bg-neutral-950/4 font-normal text-neutral-900 text-xs',
|
|
18
|
+
{
|
|
19
|
+
variants: {
|
|
20
|
+
size: {
|
|
21
|
+
sm: 'h-control rounded-control px-3',
|
|
22
|
+
md: 'h-control-lg rounded-control px-3',
|
|
23
|
+
},
|
|
24
|
+
copyable: {
|
|
25
|
+
// The copy button sits inset in the well, so the well's right padding becomes that inset.
|
|
26
|
+
true: '',
|
|
27
|
+
false: '',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
// The inset is the well's height less the 28px button, halved, so it matches the inset above
|
|
31
|
+
// and below at every size scale, and the button's corner calc below uses the same sum.
|
|
32
|
+
compoundVariants: [
|
|
33
|
+
{ size: 'sm', copyable: true, className: 'pr-[3px]' },
|
|
34
|
+
{
|
|
35
|
+
size: 'md',
|
|
36
|
+
copyable: true,
|
|
37
|
+
className: 'pr-[calc((var(--spacing-control-lg)-var(--spacing-control-sm))/2)]',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
defaultVariants: { size: 'md', copyable: false },
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
/* A bordered pill row for a single reading, such as a web vital: label left, status and value right. */
|
|
45
|
+
export const readonlyFieldVitalVariants = cva([
|
|
46
|
+
'flex h-segment w-full min-w-0 items-center justify-between gap-3 rounded-pill border border-neutral-200 px-3 text-xs',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
// The copy button is 28px, so its corner is the well's corner less the inset that centres it.
|
|
50
|
+
const copyButtonRadius = {
|
|
51
|
+
sm: 'rounded-[calc(var(--radius-control)-3px)]',
|
|
52
|
+
md: 'rounded-[calc(var(--radius-control)-(var(--spacing-control-lg)-var(--spacing-control-sm))/2)]',
|
|
53
|
+
} as const;
|
|
54
|
+
|
|
55
|
+
const isEmpty = (value: ReactNode) =>
|
|
56
|
+
value === null || value === undefined || value === false || value === '';
|
|
57
|
+
|
|
58
|
+
// onCopy is the copy button's callback here, not the div's clipboard event.
|
|
59
|
+
export type ReadonlyFieldProps = Omit<ComponentProps<'div'>, 'children' | 'onCopy'> &
|
|
60
|
+
Pick<VariantProps<typeof readonlyFieldWellVariants>, 'size'> & {
|
|
61
|
+
label: ReactNode;
|
|
62
|
+
value?: ReactNode;
|
|
63
|
+
/** `well` stacks the label over a filled box; `vital` is a compact bordered row for one reading. */
|
|
64
|
+
variant?: 'well' | 'vital';
|
|
65
|
+
/** Shown, quieter, when there is no value. */
|
|
66
|
+
emptyText?: ReactNode;
|
|
67
|
+
/** Well only: adds a copy button. */
|
|
68
|
+
copyable?: boolean;
|
|
69
|
+
/** The text copied; defaults to the value when it is a string or number. */
|
|
70
|
+
copyValue?: string;
|
|
71
|
+
onCopy?: (text: string) => void;
|
|
72
|
+
/** The copy button's name and tooltip, and what it says once it has copied. */
|
|
73
|
+
copyLabel?: string;
|
|
74
|
+
copiedLabel?: string;
|
|
75
|
+
/** Vital only: the colour of the dot before the value; leave it out for no dot. */
|
|
76
|
+
tone?: StatusDotTone;
|
|
77
|
+
/**
|
|
78
|
+
* Well only: where a long text value cuts. `end` by default; `middle` for a key, an ID, a
|
|
79
|
+
* hash or a URL, which are told apart by their end (`whsec_9f2c…a71d`).
|
|
80
|
+
*/
|
|
81
|
+
truncate?: 'end' | 'middle';
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** A read-only fact in a form layout: a label over a filled well, or a compact vital row with a status dot. */
|
|
85
|
+
export const ReadonlyField = ({
|
|
86
|
+
label,
|
|
87
|
+
value,
|
|
88
|
+
variant = 'well',
|
|
89
|
+
size,
|
|
90
|
+
emptyText = '—',
|
|
91
|
+
copyable = false,
|
|
92
|
+
copyValue,
|
|
93
|
+
onCopy,
|
|
94
|
+
copyLabel = 'Copy',
|
|
95
|
+
copiedLabel = 'Copied',
|
|
96
|
+
tone,
|
|
97
|
+
truncate = 'end',
|
|
98
|
+
className,
|
|
99
|
+
...props
|
|
100
|
+
}: ReadonlyFieldProps) => {
|
|
101
|
+
const labelId = useId();
|
|
102
|
+
const empty = isEmpty(value);
|
|
103
|
+
const shown = empty ? <span className="text-neutral-600">{emptyText}</span> : value;
|
|
104
|
+
|
|
105
|
+
if (variant === 'vital') {
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
className={cn(readonlyFieldVitalVariants(), className)}
|
|
109
|
+
data-empty={empty || undefined}
|
|
110
|
+
data-slot="readonly-field"
|
|
111
|
+
data-variant="vital"
|
|
112
|
+
{...props}
|
|
113
|
+
>
|
|
114
|
+
<span
|
|
115
|
+
className="min-w-0 truncate font-normal text-neutral-600"
|
|
116
|
+
data-slot="readonly-field-label"
|
|
117
|
+
id={labelId}
|
|
118
|
+
>
|
|
119
|
+
{label}
|
|
120
|
+
</span>
|
|
121
|
+
<span
|
|
122
|
+
className="flex shrink-0 items-center gap-1.5 font-medium text-neutral-950 tabular-nums"
|
|
123
|
+
data-slot="readonly-field-value"
|
|
124
|
+
>
|
|
125
|
+
{tone && !empty && <StatusDot size="sm" tone={tone} />}
|
|
126
|
+
{shown}
|
|
127
|
+
</span>
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const text =
|
|
133
|
+
copyValue ?? (typeof value === 'string' || typeof value === 'number' ? String(value) : '');
|
|
134
|
+
const canCopy = copyable && !empty && text !== '';
|
|
135
|
+
const resolvedSize = size ?? 'md';
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div
|
|
139
|
+
className={cn('flex min-w-0 flex-col gap-1.5', className)}
|
|
140
|
+
data-empty={empty || undefined}
|
|
141
|
+
data-slot="readonly-field"
|
|
142
|
+
data-variant="well"
|
|
143
|
+
{...props}
|
|
144
|
+
>
|
|
145
|
+
<span
|
|
146
|
+
className="font-normal text-neutral-600 text-xs"
|
|
147
|
+
data-slot="readonly-field-label"
|
|
148
|
+
id={labelId}
|
|
149
|
+
>
|
|
150
|
+
{label}
|
|
151
|
+
</span>
|
|
152
|
+
<div
|
|
153
|
+
className={readonlyFieldWellVariants({ size: resolvedSize, copyable: copyable })}
|
|
154
|
+
data-slot="readonly-field-well"
|
|
155
|
+
>
|
|
156
|
+
<span
|
|
157
|
+
className="min-w-0 flex-1 truncate tabular-nums"
|
|
158
|
+
data-slot="readonly-field-value"
|
|
159
|
+
>
|
|
160
|
+
{truncate === 'middle' && typeof value === 'string' && !empty ? (
|
|
161
|
+
<Truncate at="middle">{value}</Truncate>
|
|
162
|
+
) : (
|
|
163
|
+
shown
|
|
164
|
+
)}
|
|
165
|
+
</span>
|
|
166
|
+
{copyable && (
|
|
167
|
+
<CopyButton
|
|
168
|
+
className={copyButtonRadius[resolvedSize]}
|
|
169
|
+
copiedLabel={copiedLabel}
|
|
170
|
+
copyLabel={copyLabel}
|
|
171
|
+
describedBy={labelId}
|
|
172
|
+
disabled={!canCopy}
|
|
173
|
+
onCopy={onCopy}
|
|
174
|
+
text={text}
|
|
175
|
+
/>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
type CopyButtonProps = {
|
|
183
|
+
text: string;
|
|
184
|
+
disabled: boolean;
|
|
185
|
+
className: string;
|
|
186
|
+
/** The field's label, so "Copy" is announced with what it copies. */
|
|
187
|
+
describedBy: string;
|
|
188
|
+
onCopy?: (text: string) => void;
|
|
189
|
+
copyLabel: string;
|
|
190
|
+
copiedLabel: string;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const CopyButton = ({
|
|
194
|
+
text,
|
|
195
|
+
disabled,
|
|
196
|
+
className,
|
|
197
|
+
describedBy,
|
|
198
|
+
onCopy,
|
|
199
|
+
copyLabel,
|
|
200
|
+
copiedLabel,
|
|
201
|
+
}: CopyButtonProps) => {
|
|
202
|
+
const [copied, setCopied] = useState(false);
|
|
203
|
+
const timer = useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
204
|
+
|
|
205
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
206
|
+
|
|
207
|
+
const copy = async () => {
|
|
208
|
+
try {
|
|
209
|
+
await navigator.clipboard.writeText(text);
|
|
210
|
+
} catch {
|
|
211
|
+
// No clipboard (an insecure origin or a denied permission): leave the state alone rather than lie.
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
onCopy?.(text);
|
|
215
|
+
setCopied(true);
|
|
216
|
+
clearTimeout(timer.current);
|
|
217
|
+
timer.current = setTimeout(() => setCopied(false), 1500);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<>
|
|
222
|
+
<Tooltip>
|
|
223
|
+
<TooltipTrigger
|
|
224
|
+
render={
|
|
225
|
+
<Button
|
|
226
|
+
aria-describedby={describedBy}
|
|
227
|
+
aria-label={copied ? copiedLabel : copyLabel}
|
|
228
|
+
className={className}
|
|
229
|
+
data-copied={copied || undefined}
|
|
230
|
+
disabled={disabled}
|
|
231
|
+
onClick={copy}
|
|
232
|
+
size="icon-sm"
|
|
233
|
+
variant="ghost"
|
|
234
|
+
/>
|
|
235
|
+
}
|
|
236
|
+
>
|
|
237
|
+
{/* Both stacked in one cell, so the tick crossfades in over the copy icon and back. */}
|
|
238
|
+
<span className="grid place-items-center *:col-start-1 *:row-start-1 *:transition-[opacity,scale] *:duration-150 *:ease-out-strong motion-reduce:*:scale-100">
|
|
239
|
+
<Copy className={cn(copied && 'scale-[0.8] opacity-0')} strokeWidth={2} />
|
|
240
|
+
<Check className={cn(!copied && 'scale-[0.8] opacity-0')} strokeWidth={2} />
|
|
241
|
+
</span>
|
|
242
|
+
</TooltipTrigger>
|
|
243
|
+
<TooltipContent>{copied ? copiedLabel : copyLabel}</TooltipContent>
|
|
244
|
+
</Tooltip>
|
|
245
|
+
{/* The tooltip is visual only, so the confirmation is announced separately. */}
|
|
246
|
+
<span aria-live="polite" className="sr-only">
|
|
247
|
+
{copied ? copiedLabel : ''}
|
|
248
|
+
</span>
|
|
249
|
+
</>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Toggle } from '@base-ui/react/toggle';
|
|
4
|
+
import { ToggleGroup } from '@base-ui/react/toggle-group';
|
|
5
|
+
import {
|
|
6
|
+
Children,
|
|
7
|
+
type CSSProperties,
|
|
8
|
+
isValidElement,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
useCallback,
|
|
11
|
+
useEffect,
|
|
12
|
+
useLayoutEffect,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from 'react';
|
|
16
|
+
import { cn } from '../lib/cn';
|
|
17
|
+
import { useOverflowScroll } from '../lib/overflow-scroll';
|
|
18
|
+
import { radioToggleRender } from '../lib/radio-toggle-render';
|
|
19
|
+
import { useSingleValue } from '../lib/use-single-value';
|
|
20
|
+
import { focusRing } from './button';
|
|
21
|
+
import { useField, useFieldControl } from './field';
|
|
22
|
+
|
|
23
|
+
// Base UI holds a group's value as an array that may go empty; the public API stays a single string.
|
|
24
|
+
export type SegmentedControlProps = Omit<
|
|
25
|
+
ToggleGroup.Props,
|
|
26
|
+
'className' | 'multiple' | 'value' | 'defaultValue' | 'onValueChange'
|
|
27
|
+
> & {
|
|
28
|
+
className?: string;
|
|
29
|
+
value?: string;
|
|
30
|
+
defaultValue?: string;
|
|
31
|
+
onValueChange?: (value: string) => void;
|
|
32
|
+
/** Shares the full width out evenly between the items, instead of hugging them. */
|
|
33
|
+
fill?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type Thumb = { left: number; width: number; moved: boolean };
|
|
37
|
+
|
|
38
|
+
// The keys Base UI's group moves focus with.
|
|
39
|
+
const selectKeys = new Set(['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End']);
|
|
40
|
+
|
|
41
|
+
/** The value of the first enabled item among the children, for a control given no value at all. */
|
|
42
|
+
const firstItemValue = (children: ReactNode): string | undefined => {
|
|
43
|
+
for (const child of Children.toArray(children)) {
|
|
44
|
+
if (!isValidElement<{ value?: unknown; disabled?: boolean }>(child)) continue;
|
|
45
|
+
const { value, disabled } = child.props;
|
|
46
|
+
if (typeof value === 'string' && !disabled) return value;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Picks one value that reshapes the same content: a view (List · Grid), a range (7d · 30d), a filter.
|
|
53
|
+
* To switch between panels with content of their own, use Tabs instead.
|
|
54
|
+
* Always holds one value: clicking the active segment keeps it selected. The active fill is one
|
|
55
|
+
* thumb under the items, so it slides from the old value to the new one.
|
|
56
|
+
*/
|
|
57
|
+
export const SegmentedControl = ({
|
|
58
|
+
fill,
|
|
59
|
+
value,
|
|
60
|
+
defaultValue,
|
|
61
|
+
onValueChange,
|
|
62
|
+
disabled,
|
|
63
|
+
className,
|
|
64
|
+
children,
|
|
65
|
+
onKeyDown,
|
|
66
|
+
'aria-labelledby': labelledBy,
|
|
67
|
+
'aria-describedby': describedBy,
|
|
68
|
+
...props
|
|
69
|
+
}: SegmentedControlProps) => {
|
|
70
|
+
// Left without a value, it starts on its first item, so it holds one from the start.
|
|
71
|
+
const [current, select] = useSingleValue(
|
|
72
|
+
value,
|
|
73
|
+
defaultValue ?? firstItemValue(children),
|
|
74
|
+
onValueChange,
|
|
75
|
+
);
|
|
76
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
77
|
+
const field = useField();
|
|
78
|
+
// Inside a Field it is named by the FieldLabel, described by the helper and disabled with it.
|
|
79
|
+
// The group is a div, so a <label for> cannot name it; the id stays on the label.
|
|
80
|
+
const control = useFieldControl({ disabled, 'aria-describedby': describedBy });
|
|
81
|
+
|
|
82
|
+
// A radiogroup selects as the arrows move along it; Base UI's group only moves focus, so once it
|
|
83
|
+
// has, the item that took focus is picked.
|
|
84
|
+
const handleKeyDown: NonNullable<ToggleGroup.Props['onKeyDown']> = event => {
|
|
85
|
+
onKeyDown?.(event);
|
|
86
|
+
if (!selectKeys.has(event.key)) return;
|
|
87
|
+
const group = event.currentTarget;
|
|
88
|
+
const from = document.activeElement;
|
|
89
|
+
requestAnimationFrame(() => {
|
|
90
|
+
const item = document.activeElement;
|
|
91
|
+
if (
|
|
92
|
+
item instanceof HTMLElement &&
|
|
93
|
+
item !== from &&
|
|
94
|
+
item.parentElement === group &&
|
|
95
|
+
item.matches('[data-slot=segmented-control-item]:not([data-disabled])')
|
|
96
|
+
) {
|
|
97
|
+
item.click();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
const [thumb, setThumb] = useState<Thumb>();
|
|
102
|
+
|
|
103
|
+
// Measured before paint, so the thumb lands on the first value without sliding to it; it only
|
|
104
|
+
// slides once it has a place to slide from, and follows a resize (a font loading, `fill`) the same way.
|
|
105
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the pressed item is read from the DOM, so a new value re-measures
|
|
106
|
+
useLayoutEffect(() => {
|
|
107
|
+
const group = ref.current;
|
|
108
|
+
if (!group) return;
|
|
109
|
+
const measure = () => {
|
|
110
|
+
const item = group.querySelector<HTMLElement>(
|
|
111
|
+
':scope > [data-slot=segmented-control-item][data-pressed]',
|
|
112
|
+
);
|
|
113
|
+
setThumb(previous =>
|
|
114
|
+
item
|
|
115
|
+
? {
|
|
116
|
+
left: item.offsetLeft,
|
|
117
|
+
width: item.offsetWidth,
|
|
118
|
+
moved: previous !== undefined,
|
|
119
|
+
}
|
|
120
|
+
: undefined,
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
measure();
|
|
124
|
+
const observer = new ResizeObserver(() => measure());
|
|
125
|
+
observer.observe(group);
|
|
126
|
+
return () => observer.disconnect();
|
|
127
|
+
}, [current]);
|
|
128
|
+
|
|
129
|
+
// Items keep their labels' width, so labels never run into each other; more than fit scrolls
|
|
130
|
+
// the track sideways, the picked one kept in view. Only once it overflows, so a track that fits
|
|
131
|
+
// keeps its focus rings whole. More than four options on a narrow page is a Select's job.
|
|
132
|
+
const overflow = useOverflowScroll<HTMLDivElement>();
|
|
133
|
+
const setGroup = useCallback(
|
|
134
|
+
(node: HTMLDivElement | null) => {
|
|
135
|
+
ref.current = node;
|
|
136
|
+
overflow.ref(node);
|
|
137
|
+
},
|
|
138
|
+
[overflow.ref],
|
|
139
|
+
);
|
|
140
|
+
const { overflows } = overflow.edges;
|
|
141
|
+
const { reveal } = overflow;
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (current && overflows) reveal('[data-pressed]');
|
|
144
|
+
}, [current, overflows, reveal]);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<ToggleGroup
|
|
148
|
+
className={cn(
|
|
149
|
+
// Hugs its items even in a stretching flex column, and never outgrows its parent.
|
|
150
|
+
'relative isolate flex h-control max-w-full items-center rounded-control border border-neutral-200 bg-segment-track p-[2px] shadow-control',
|
|
151
|
+
fill ? 'w-full [&>[data-slot=segmented-control-item]]:flex-1' : 'w-fit',
|
|
152
|
+
overflows && 'scrollbar-none overflow-x-auto',
|
|
153
|
+
className,
|
|
154
|
+
)}
|
|
155
|
+
data-slot="segmented-control"
|
|
156
|
+
ref={setGroup}
|
|
157
|
+
style={overflows ? overflow.style : undefined}
|
|
158
|
+
role="radiogroup"
|
|
159
|
+
aria-describedby={control['aria-describedby']}
|
|
160
|
+
aria-labelledby={labelledBy ?? (props['aria-label'] ? undefined : field?.labelId)}
|
|
161
|
+
disabled={control.disabled}
|
|
162
|
+
onKeyDown={handleKeyDown}
|
|
163
|
+
{...props}
|
|
164
|
+
// Clicking the pressed item hands back an empty array, which `select` ignores.
|
|
165
|
+
onValueChange={values => select(values[0] ?? '')}
|
|
166
|
+
value={current ? [current] : []}
|
|
167
|
+
>
|
|
168
|
+
{thumb && (
|
|
169
|
+
<span
|
|
170
|
+
aria-hidden
|
|
171
|
+
className={cn(
|
|
172
|
+
// The item's own corner and raise: an inset ring, so its outline adds no width.
|
|
173
|
+
// The 2px inset is fixed, as h-segment (control − 5px) assumes, at every spacing unit.
|
|
174
|
+
'absolute top-[2px] left-0 -z-10 h-segment rounded-[calc(var(--radius-control)-3px)] bg-segment [box-shadow:inset_0_0_0_1px_var(--color-segment-border),var(--shadow-segment)]',
|
|
175
|
+
thumb.moved &&
|
|
176
|
+
'transition-[translate,width] duration-200 ease-out-strong motion-reduce:transition-none',
|
|
177
|
+
)}
|
|
178
|
+
data-slot="segmented-control-thumb"
|
|
179
|
+
style={{ translate: `${thumb.left}px 0`, width: thumb.width } as CSSProperties}
|
|
180
|
+
/>
|
|
181
|
+
)}
|
|
182
|
+
{children}
|
|
183
|
+
</ToggleGroup>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export type SegmentedControlItemProps = Omit<Toggle.Props, 'className'> & { className?: string };
|
|
188
|
+
|
|
189
|
+
export const SegmentedControlItem = ({ className, ...props }: SegmentedControlItemProps) => (
|
|
190
|
+
<Toggle
|
|
191
|
+
className={cn(
|
|
192
|
+
// The track's radius minus its 2px inset and 1px border, so the curves stay concentric in every theme.
|
|
193
|
+
'inline-flex h-segment shrink-0 cursor-pointer select-none items-center justify-center gap-2 whitespace-nowrap rounded-[calc(var(--radius-control)-3px)] px-2.5 font-medium text-neutral-600 text-xs transition-[background-color,color] duration-150',
|
|
194
|
+
'hover:bg-neutral-950/5 hover:text-neutral-800',
|
|
195
|
+
// The thumb under it is the fill; the item only takes the thumb's text colour.
|
|
196
|
+
'data-pressed:text-segment-fg data-pressed:hover:bg-transparent data-pressed:hover:text-segment-fg',
|
|
197
|
+
'data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg:not([class*=size-])]:size-icon [&_svg]:shrink-0',
|
|
198
|
+
focusRing,
|
|
199
|
+
className,
|
|
200
|
+
)}
|
|
201
|
+
data-slot="segmented-control-item"
|
|
202
|
+
render={radioToggleRender}
|
|
203
|
+
{...props}
|
|
204
|
+
/>
|
|
205
|
+
);
|