@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,182 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
4
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
5
|
+
import { cn } from '../lib/cn';
|
|
6
|
+
import { focusRing } from './button';
|
|
7
|
+
|
|
8
|
+
export type PaginationButtonProps = ComponentProps<'button'> & {
|
|
9
|
+
/** Marks the current page (aria-current="page"). */
|
|
10
|
+
current?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** A square page button on the control row's 34px; the current page only darkens its label. */
|
|
14
|
+
export const PaginationButton = ({
|
|
15
|
+
current,
|
|
16
|
+
className,
|
|
17
|
+
type = 'button',
|
|
18
|
+
...props
|
|
19
|
+
}: PaginationButtonProps) => (
|
|
20
|
+
<button
|
|
21
|
+
aria-current={current ? 'page' : undefined}
|
|
22
|
+
className={cn(
|
|
23
|
+
'inline-flex size-control shrink-0 cursor-pointer select-none items-center justify-center rounded-control border border-neutral-200 font-medium text-neutral-600 text-sm tabular-nums transition-[border-color,color] duration-150',
|
|
24
|
+
'hover:border-neutral-300 hover:text-neutral-950 aria-[current=page]:text-neutral-950',
|
|
25
|
+
// Disabled as every control is: half strength, no pointer.
|
|
26
|
+
'disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-icon [&_svg]:shrink-0',
|
|
27
|
+
focusRing,
|
|
28
|
+
className,
|
|
29
|
+
)}
|
|
30
|
+
data-slot="pagination-button"
|
|
31
|
+
type={type}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const PaginationPrevious = ({
|
|
37
|
+
'aria-label': label = 'Previous page',
|
|
38
|
+
...props
|
|
39
|
+
}: ComponentProps<'button'>) => (
|
|
40
|
+
<PaginationButton aria-label={label} {...props}>
|
|
41
|
+
<ChevronLeft strokeWidth={2} />
|
|
42
|
+
</PaginationButton>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export const PaginationNext = ({
|
|
46
|
+
'aria-label': label = 'Next page',
|
|
47
|
+
...props
|
|
48
|
+
}: ComponentProps<'button'>) => (
|
|
49
|
+
<PaginationButton aria-label={label} {...props}>
|
|
50
|
+
<ChevronRight strokeWidth={2} />
|
|
51
|
+
</PaginationButton>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
type PageItem = number | 'start-ellipsis' | 'end-ellipsis';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Always the same number of slots (first, last, the current page with its
|
|
58
|
+
* siblings, and an ellipsis on either side), so the row never changes width.
|
|
59
|
+
*/
|
|
60
|
+
export const getPageItems = (page: number, pageCount: number, siblings = 1): PageItem[] => {
|
|
61
|
+
const slots = siblings * 2 + 5;
|
|
62
|
+
if (pageCount <= slots) return Array.from({ length: pageCount }, (_, i) => i + 1);
|
|
63
|
+
|
|
64
|
+
const range = (from: number, to: number) =>
|
|
65
|
+
Array.from({ length: to - from + 1 }, (_, i) => from + i);
|
|
66
|
+
const inner = siblings * 2 + 3;
|
|
67
|
+
|
|
68
|
+
if (page <= siblings + 3) return [...range(1, inner), 'end-ellipsis', pageCount];
|
|
69
|
+
if (page >= pageCount - siblings - 2)
|
|
70
|
+
return [1, 'start-ellipsis', ...range(pageCount - inner + 1, pageCount)];
|
|
71
|
+
|
|
72
|
+
return [
|
|
73
|
+
1,
|
|
74
|
+
'start-ellipsis',
|
|
75
|
+
...range(page - siblings, page + siblings),
|
|
76
|
+
'end-ellipsis',
|
|
77
|
+
pageCount,
|
|
78
|
+
];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// `results` is also a legacy attribute of <nav>, so it is dropped before the slot is typed.
|
|
82
|
+
export type PaginationProps = Omit<ComponentProps<'nav'>, 'children' | 'results'> & {
|
|
83
|
+
/** Current page, starting at 1. */
|
|
84
|
+
page: number;
|
|
85
|
+
pageCount: number;
|
|
86
|
+
onPageChange: (page: number) => void;
|
|
87
|
+
/** Pages shown either side of the current one. */
|
|
88
|
+
siblings?: number;
|
|
89
|
+
/** Left slot, e.g. "Results: 1 - 10 of 96". */
|
|
90
|
+
results?: ReactNode;
|
|
91
|
+
/** Right slot, e.g. a rows-per-page select. */
|
|
92
|
+
end?: ReactNode;
|
|
93
|
+
/** The previous button's accessible name; "Previous page" by default. */
|
|
94
|
+
previousLabel?: string;
|
|
95
|
+
/** The next button's accessible name; "Next page" by default. */
|
|
96
|
+
nextLabel?: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** The library's pagination bar: results on the left, pages centred, an optional right slot. */
|
|
100
|
+
export const Pagination = ({
|
|
101
|
+
page,
|
|
102
|
+
pageCount,
|
|
103
|
+
onPageChange,
|
|
104
|
+
siblings = 1,
|
|
105
|
+
results,
|
|
106
|
+
end,
|
|
107
|
+
previousLabel,
|
|
108
|
+
nextLabel,
|
|
109
|
+
className,
|
|
110
|
+
'aria-label': label = 'Pagination',
|
|
111
|
+
...props
|
|
112
|
+
}: PaginationProps) => {
|
|
113
|
+
const count = Math.max(1, pageCount);
|
|
114
|
+
const current = Math.min(Math.max(1, page), count);
|
|
115
|
+
|
|
116
|
+
// Its own container, so it answers the room it is given wherever it sits. Under 720 the results
|
|
117
|
+
// line goes and the pages fold into "‹ 3 of 25 ›": the way along cannot go, so it gets smaller.
|
|
118
|
+
return (
|
|
119
|
+
<nav
|
|
120
|
+
aria-label={label}
|
|
121
|
+
className={cn('@container/pagination', className)}
|
|
122
|
+
data-slot="pagination"
|
|
123
|
+
{...props}
|
|
124
|
+
>
|
|
125
|
+
{/* Narrow, a row: the pages centred on their own, or at the start with the end slot at the end. */}
|
|
126
|
+
<div className="@max-[720px]/pagination:flex grid grid-cols-[1fr_auto_1fr] items-center @max-[720px]/pagination:justify-center @max-[720px]/pagination:gap-3 gap-12">
|
|
127
|
+
<div
|
|
128
|
+
className="@max-[720px]/pagination:hidden min-w-0 whitespace-nowrap font-medium text-neutral-800 text-xs"
|
|
129
|
+
data-slot="pagination-results"
|
|
130
|
+
>
|
|
131
|
+
{results}
|
|
132
|
+
</div>
|
|
133
|
+
<div className="flex items-center gap-2">
|
|
134
|
+
<PaginationPrevious
|
|
135
|
+
aria-label={previousLabel}
|
|
136
|
+
disabled={current <= 1}
|
|
137
|
+
onClick={() => onPageChange(current - 1)}
|
|
138
|
+
/>
|
|
139
|
+
<div
|
|
140
|
+
className="flex @max-[720px]/pagination:hidden items-center gap-2"
|
|
141
|
+
data-slot="pagination-pages"
|
|
142
|
+
>
|
|
143
|
+
{getPageItems(current, count, siblings).map(item =>
|
|
144
|
+
typeof item === 'number' ? (
|
|
145
|
+
<PaginationButton
|
|
146
|
+
current={item === current}
|
|
147
|
+
key={item}
|
|
148
|
+
onClick={() => onPageChange(item)}
|
|
149
|
+
>
|
|
150
|
+
{item}
|
|
151
|
+
</PaginationButton>
|
|
152
|
+
) : (
|
|
153
|
+
<span
|
|
154
|
+
aria-hidden
|
|
155
|
+
className="inline-flex size-control items-center justify-center font-medium text-neutral-600 text-sm"
|
|
156
|
+
key={item}
|
|
157
|
+
>
|
|
158
|
+
…
|
|
159
|
+
</span>
|
|
160
|
+
),
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
<span
|
|
164
|
+
className="@max-[720px]/pagination:inline-flex hidden h-control min-w-control items-center justify-center whitespace-nowrap px-1 font-medium text-neutral-800 text-xs tabular-nums"
|
|
165
|
+
data-slot="pagination-position"
|
|
166
|
+
>
|
|
167
|
+
<span className="sr-only">Page </span>
|
|
168
|
+
{current} of {count}
|
|
169
|
+
</span>
|
|
170
|
+
<PaginationNext
|
|
171
|
+
aria-label={nextLabel}
|
|
172
|
+
disabled={current >= count}
|
|
173
|
+
onClick={() => onPageChange(current + 1)}
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
<div className="@max-[720px]/pagination:ml-auto flex min-w-0 items-center justify-end @max-[720px]/pagination:empty:hidden">
|
|
177
|
+
{end}
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
</nav>
|
|
181
|
+
);
|
|
182
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Popover as PopoverPrimitive } from '@base-ui/react/popover';
|
|
4
|
+
import type { ComponentProps } from 'react';
|
|
5
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
6
|
+
import { ThemeScope, usePortalContainer } from './theme';
|
|
7
|
+
|
|
8
|
+
/** A handle that lets a trigger outside the Popover open it (detached triggers). */
|
|
9
|
+
export const createPopoverHandle = PopoverPrimitive.createHandle;
|
|
10
|
+
|
|
11
|
+
/** Small anchored panels that hold controls: filters, a date picker, column settings. */
|
|
12
|
+
export const Popover = <Payload,>(props: PopoverPrimitive.Root.Props<Payload>) => (
|
|
13
|
+
<PopoverPrimitive.Root data-slot="popover" {...props} />
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
/** Opens the popover; pass `render={<Button />}` to use one of the system's controls. */
|
|
17
|
+
export const PopoverTrigger = <Payload,>(props: PopoverPrimitive.Trigger.Props<Payload>) => (
|
|
18
|
+
<PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export type PopoverContentProps = WithClassName<PopoverPrimitive.Popup.Props> &
|
|
22
|
+
Pick<
|
|
23
|
+
PopoverPrimitive.Positioner.Props,
|
|
24
|
+
| 'align'
|
|
25
|
+
| 'alignOffset'
|
|
26
|
+
| 'side'
|
|
27
|
+
| 'sideOffset'
|
|
28
|
+
| 'anchor'
|
|
29
|
+
| 'positionMethod'
|
|
30
|
+
| 'collisionPadding'
|
|
31
|
+
> & {
|
|
32
|
+
/** Where the panel is portalled; the body by default. */
|
|
33
|
+
container?: PopoverPrimitive.Portal.Props['container'];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The panel. It is a card-sized surface rather than a menu, so it takes the card radius and p-3; it
|
|
38
|
+
* grows from the trigger (95% to 100%) so it reads as coming out of it, and fades out faster than it
|
|
39
|
+
* comes in.
|
|
40
|
+
*/
|
|
41
|
+
export const PopoverContent = ({
|
|
42
|
+
className,
|
|
43
|
+
side = 'bottom',
|
|
44
|
+
align = 'center',
|
|
45
|
+
sideOffset = 4,
|
|
46
|
+
alignOffset = 0,
|
|
47
|
+
anchor,
|
|
48
|
+
positionMethod,
|
|
49
|
+
collisionPadding,
|
|
50
|
+
container,
|
|
51
|
+
...props
|
|
52
|
+
}: PopoverContentProps) => (
|
|
53
|
+
<PopoverPrimitive.Portal container={usePortalContainer(container)}>
|
|
54
|
+
{/* Portalled content leaves the Theme subtree, so the theme is opened again here. */}
|
|
55
|
+
<ThemeScope>
|
|
56
|
+
<PopoverPrimitive.Positioner
|
|
57
|
+
align={align}
|
|
58
|
+
alignOffset={alignOffset}
|
|
59
|
+
anchor={anchor}
|
|
60
|
+
className="isolate z-50"
|
|
61
|
+
collisionPadding={collisionPadding}
|
|
62
|
+
data-slot="popover-positioner"
|
|
63
|
+
positionMethod={positionMethod}
|
|
64
|
+
side={side}
|
|
65
|
+
sideOffset={sideOffset}
|
|
66
|
+
>
|
|
67
|
+
<PopoverPrimitive.Popup
|
|
68
|
+
className={cn(
|
|
69
|
+
'flex max-h-(--available-height) w-popover flex-col gap-3 overflow-y-auto rounded-card border border-neutral-200 bg-neutral-50 p-3 text-neutral-700 text-xs shadow-float outline-none',
|
|
70
|
+
'origin-(--transform-origin) transition-[opacity,scale] duration-150 ease-out-strong data-ending-style:scale-95 data-starting-style:scale-95 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-100 motion-reduce:transition-none',
|
|
71
|
+
className,
|
|
72
|
+
)}
|
|
73
|
+
data-slot="popover-content"
|
|
74
|
+
{...props}
|
|
75
|
+
/>
|
|
76
|
+
</PopoverPrimitive.Positioner>
|
|
77
|
+
</ThemeScope>
|
|
78
|
+
</PopoverPrimitive.Portal>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
/** Title and description stacked tight, above the popover's controls. */
|
|
82
|
+
export const PopoverHeader = ({ className, ...props }: ComponentProps<'div'>) => (
|
|
83
|
+
<div className={cn('flex flex-col gap-0.5', className)} data-slot="popover-header" {...props} />
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
/** Labels the popup for assistive tech through aria-labelledby. */
|
|
87
|
+
export const PopoverTitle = ({
|
|
88
|
+
className,
|
|
89
|
+
...props
|
|
90
|
+
}: WithClassName<PopoverPrimitive.Title.Props>) => (
|
|
91
|
+
<PopoverPrimitive.Title
|
|
92
|
+
className={cn('font-medium text-neutral-950 text-sm', className)}
|
|
93
|
+
data-slot="popover-title"
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
/** Describes the popup for assistive tech through aria-describedby. */
|
|
99
|
+
export const PopoverDescription = ({
|
|
100
|
+
className,
|
|
101
|
+
...props
|
|
102
|
+
}: WithClassName<PopoverPrimitive.Description.Props>) => (
|
|
103
|
+
<PopoverPrimitive.Description
|
|
104
|
+
className={cn('text-neutral-600 text-xs', className)}
|
|
105
|
+
data-slot="popover-description"
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
/** Closes the popover; pass `render={<Button />}` to use one of the system's controls. */
|
|
111
|
+
export const PopoverClose = (props: PopoverPrimitive.Close.Props) => (
|
|
112
|
+
<PopoverPrimitive.Close data-slot="popover-close" {...props} />
|
|
113
|
+
);
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Meter as MeterPrimitive } from '@base-ui/react/meter';
|
|
4
|
+
import { Progress as ProgressPrimitive } from '@base-ui/react/progress';
|
|
5
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
6
|
+
import { type ReactNode, useId } from 'react';
|
|
7
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Both bars draw a track in the hairline colour, the step the slider's track uses, so a bar
|
|
11
|
+
* sits in a card the way a divider would. The track rounds fully at 4 and 8px in every theme.
|
|
12
|
+
*/
|
|
13
|
+
export const progressTrackVariants = cva(
|
|
14
|
+
'relative w-full overflow-hidden rounded-full bg-neutral-200',
|
|
15
|
+
{
|
|
16
|
+
variants: {
|
|
17
|
+
size: {
|
|
18
|
+
sm: 'h-1',
|
|
19
|
+
md: 'h-2',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
defaultVariants: { size: 'sm' },
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const progressIndicatorVariants = cva(
|
|
27
|
+
[
|
|
28
|
+
// Base UI sets the width inline; only that width animates, and never for reduced motion.
|
|
29
|
+
'h-full rounded-full transition-[width] duration-200 ease-out-strong motion-reduce:transition-none',
|
|
30
|
+
// An indeterminate task has no width to show, so the whole track fills faintly and holds still.
|
|
31
|
+
'data-indeterminate:w-full data-indeterminate:opacity-30',
|
|
32
|
+
],
|
|
33
|
+
{
|
|
34
|
+
variants: {
|
|
35
|
+
tone: {
|
|
36
|
+
action: 'bg-action [background-image:var(--action-gradient)]',
|
|
37
|
+
success: 'bg-success-500',
|
|
38
|
+
warning: 'bg-warning-500',
|
|
39
|
+
error: 'bg-error-500',
|
|
40
|
+
chart: 'bg-chart-1',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
defaultVariants: { tone: 'action' },
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
type BarVariants = VariantProps<typeof progressTrackVariants> &
|
|
48
|
+
VariantProps<typeof progressIndicatorVariants>;
|
|
49
|
+
|
|
50
|
+
type BarOwnProps = BarVariants & {
|
|
51
|
+
/** Names the bar for screen readers too; without it, pass `aria-label`. */
|
|
52
|
+
label?: ReactNode;
|
|
53
|
+
/** Trailing text on the label row, e.g. "Resets in 10 days"; read as the bar's description. */
|
|
54
|
+
caption?: ReactNode;
|
|
55
|
+
/** Shows the formatted value on the label row when there is no caption. */
|
|
56
|
+
showValue?: boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const rootClassName = 'flex w-full min-w-0 flex-col gap-2';
|
|
60
|
+
const labelClassName = 'min-w-0 truncate font-medium text-neutral-900 text-xs';
|
|
61
|
+
// Without a label the trailing text still sits at the end of the row.
|
|
62
|
+
const valueClassName = 'ms-auto shrink-0 font-normal text-neutral-600 text-xs tabular-nums';
|
|
63
|
+
// A caption is a sentence and can outrun a narrow row, so it truncates rather than pushing out.
|
|
64
|
+
const captionClassName = 'ms-auto min-w-0 truncate font-normal text-neutral-600 text-xs';
|
|
65
|
+
|
|
66
|
+
/** The label left and the value or caption right, sharing a baseline. */
|
|
67
|
+
const LabelRow = ({ slot, children }: { slot: string; children: ReactNode }) => (
|
|
68
|
+
<div className="flex min-w-0 items-baseline justify-between gap-3" data-slot={slot}>
|
|
69
|
+
{children}
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
/** The caption describes rather than names, so it is linked by id instead of through the label. */
|
|
74
|
+
const useCaption = (caption: ReactNode, describedBy: string | undefined) => {
|
|
75
|
+
const id = useId();
|
|
76
|
+
const has = caption != null && caption !== false && caption !== '';
|
|
77
|
+
return {
|
|
78
|
+
has,
|
|
79
|
+
id: `${id}-caption`,
|
|
80
|
+
describedBy:
|
|
81
|
+
[describedBy, has ? `${id}-caption` : undefined].filter(Boolean).join(' ') || undefined,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type ProgressProps = Omit<WithClassName<ProgressPrimitive.Root.Props>, 'children'> &
|
|
86
|
+
BarOwnProps;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Task progress on Base UI Progress: a 4 or 8px bar with an optional label row. `value={null}`
|
|
90
|
+
* makes it indeterminate, which fills the track faintly rather than animating.
|
|
91
|
+
*/
|
|
92
|
+
export const Progress = ({
|
|
93
|
+
label,
|
|
94
|
+
caption,
|
|
95
|
+
showValue = false,
|
|
96
|
+
size,
|
|
97
|
+
tone,
|
|
98
|
+
className,
|
|
99
|
+
'aria-describedby': ariaDescribedBy,
|
|
100
|
+
...props
|
|
101
|
+
}: ProgressProps) => {
|
|
102
|
+
const captionLink = useCaption(caption, ariaDescribedBy);
|
|
103
|
+
const hasHeader = label != null || captionLink.has || showValue;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<ProgressPrimitive.Root
|
|
107
|
+
aria-describedby={captionLink.describedBy}
|
|
108
|
+
className={cn(rootClassName, className)}
|
|
109
|
+
data-size={size ?? 'sm'}
|
|
110
|
+
data-slot="progress"
|
|
111
|
+
data-tone={tone ?? 'action'}
|
|
112
|
+
{...props}
|
|
113
|
+
>
|
|
114
|
+
{hasHeader && (
|
|
115
|
+
<LabelRow slot="progress-header">
|
|
116
|
+
{label != null ? (
|
|
117
|
+
<ProgressPrimitive.Label
|
|
118
|
+
className={labelClassName}
|
|
119
|
+
data-slot="progress-label"
|
|
120
|
+
>
|
|
121
|
+
{label}
|
|
122
|
+
</ProgressPrimitive.Label>
|
|
123
|
+
) : null}
|
|
124
|
+
{captionLink.has ? (
|
|
125
|
+
<span
|
|
126
|
+
className={captionClassName}
|
|
127
|
+
data-slot="progress-caption"
|
|
128
|
+
id={captionLink.id}
|
|
129
|
+
>
|
|
130
|
+
{caption}
|
|
131
|
+
</span>
|
|
132
|
+
) : (
|
|
133
|
+
showValue && (
|
|
134
|
+
// aria-valuetext already speaks the value, so the visible copy stays out of the way.
|
|
135
|
+
<ProgressPrimitive.Value
|
|
136
|
+
aria-hidden
|
|
137
|
+
className={valueClassName}
|
|
138
|
+
data-slot="progress-value"
|
|
139
|
+
/>
|
|
140
|
+
)
|
|
141
|
+
)}
|
|
142
|
+
</LabelRow>
|
|
143
|
+
)}
|
|
144
|
+
<ProgressPrimitive.Track
|
|
145
|
+
className={progressTrackVariants({ size })}
|
|
146
|
+
data-slot="progress-track"
|
|
147
|
+
>
|
|
148
|
+
<ProgressPrimitive.Indicator
|
|
149
|
+
className={progressIndicatorVariants({ tone })}
|
|
150
|
+
data-slot="progress-indicator"
|
|
151
|
+
/>
|
|
152
|
+
</ProgressPrimitive.Track>
|
|
153
|
+
</ProgressPrimitive.Root>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export type MeterProps = Omit<WithClassName<MeterPrimitive.Root.Props>, 'children'> & BarOwnProps;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A value within a known range on Base UI Meter, such as credits used of a plan's total:
|
|
161
|
+
* the same bar as Progress, always determinate. Base UI clamps the fill to the range.
|
|
162
|
+
*/
|
|
163
|
+
export const Meter = ({
|
|
164
|
+
label,
|
|
165
|
+
caption,
|
|
166
|
+
showValue = false,
|
|
167
|
+
size,
|
|
168
|
+
tone,
|
|
169
|
+
className,
|
|
170
|
+
'aria-describedby': ariaDescribedBy,
|
|
171
|
+
...props
|
|
172
|
+
}: MeterProps) => {
|
|
173
|
+
const captionLink = useCaption(caption, ariaDescribedBy);
|
|
174
|
+
const hasHeader = label != null || captionLink.has || showValue;
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<MeterPrimitive.Root
|
|
178
|
+
aria-describedby={captionLink.describedBy}
|
|
179
|
+
className={cn(rootClassName, className)}
|
|
180
|
+
data-size={size ?? 'sm'}
|
|
181
|
+
data-slot="meter"
|
|
182
|
+
data-tone={tone ?? 'action'}
|
|
183
|
+
{...props}
|
|
184
|
+
>
|
|
185
|
+
{hasHeader && (
|
|
186
|
+
<LabelRow slot="meter-header">
|
|
187
|
+
{label != null ? (
|
|
188
|
+
<MeterPrimitive.Label className={labelClassName} data-slot="meter-label">
|
|
189
|
+
{label}
|
|
190
|
+
</MeterPrimitive.Label>
|
|
191
|
+
) : null}
|
|
192
|
+
{captionLink.has ? (
|
|
193
|
+
<span
|
|
194
|
+
className={captionClassName}
|
|
195
|
+
data-slot="meter-caption"
|
|
196
|
+
id={captionLink.id}
|
|
197
|
+
>
|
|
198
|
+
{caption}
|
|
199
|
+
</span>
|
|
200
|
+
) : (
|
|
201
|
+
showValue && (
|
|
202
|
+
<MeterPrimitive.Value
|
|
203
|
+
aria-hidden
|
|
204
|
+
className={valueClassName}
|
|
205
|
+
data-slot="meter-value"
|
|
206
|
+
/>
|
|
207
|
+
)
|
|
208
|
+
)}
|
|
209
|
+
</LabelRow>
|
|
210
|
+
)}
|
|
211
|
+
<MeterPrimitive.Track
|
|
212
|
+
className={progressTrackVariants({ size })}
|
|
213
|
+
data-slot="meter-track"
|
|
214
|
+
>
|
|
215
|
+
<MeterPrimitive.Indicator
|
|
216
|
+
className={progressIndicatorVariants({ tone })}
|
|
217
|
+
data-slot="meter-indicator"
|
|
218
|
+
/>
|
|
219
|
+
</MeterPrimitive.Track>
|
|
220
|
+
</MeterPrimitive.Root>
|
|
221
|
+
);
|
|
222
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Radio as RadioPrimitive } from '@base-ui/react/radio';
|
|
4
|
+
import { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group';
|
|
5
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
6
|
+
import { focusRing, touchTarget } from './button';
|
|
7
|
+
import { FieldContext, useField, useFieldControl } from './field';
|
|
8
|
+
|
|
9
|
+
/** A stack of radios; inside a Field it is named by the FieldLabel and described by the helper. */
|
|
10
|
+
export const RadioGroup = <Value,>({
|
|
11
|
+
className,
|
|
12
|
+
disabled,
|
|
13
|
+
'aria-labelledby': labelledBy,
|
|
14
|
+
'aria-describedby': describedBy,
|
|
15
|
+
'aria-invalid': ariaInvalid,
|
|
16
|
+
...props
|
|
17
|
+
}: WithClassName<RadioGroupPrimitive.Props<Value>>) => {
|
|
18
|
+
const field = useField();
|
|
19
|
+
// The group is a div, so a <label for> cannot name it; the id stays on the label.
|
|
20
|
+
const {
|
|
21
|
+
id: _id,
|
|
22
|
+
invalid: _invalid,
|
|
23
|
+
...control
|
|
24
|
+
} = useFieldControl({
|
|
25
|
+
disabled,
|
|
26
|
+
'aria-describedby': describedBy,
|
|
27
|
+
'aria-invalid': ariaInvalid,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
// The group has used its Field; items must not take that Field's id, or its label would name
|
|
32
|
+
// the first radio. An item only answers to a Field nested inside the group (one per option).
|
|
33
|
+
<FieldContext.Provider value={null}>
|
|
34
|
+
<RadioGroupPrimitive<Value>
|
|
35
|
+
aria-labelledby={labelledBy ?? (props['aria-label'] ? undefined : field?.labelId)}
|
|
36
|
+
className={cn('flex flex-col gap-2', className)}
|
|
37
|
+
data-slot="radio-group"
|
|
38
|
+
{...control}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
</FieldContext.Provider>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** The library radiobutton: a hairline ring with a 14px action dot, as in the report generator. */
|
|
46
|
+
export const RadioGroupItem = <Value,>({
|
|
47
|
+
className,
|
|
48
|
+
id,
|
|
49
|
+
'aria-describedby': describedBy,
|
|
50
|
+
...props
|
|
51
|
+
}: WithClassName<RadioPrimitive.Root.Props<Value>>) => {
|
|
52
|
+
// A radio in its own Field (label beside each option) takes that Field's id, so the
|
|
53
|
+
// label's for= names it and a click on the label selects it, as with Checkbox and Switch.
|
|
54
|
+
const field = useField();
|
|
55
|
+
const control = useFieldControl({ id, 'aria-describedby': describedBy });
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<RadioPrimitive.Root<Value>
|
|
59
|
+
className={cn(
|
|
60
|
+
'inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-full border border-neutral-300 bg-transparent shadow-control transition-[border-color] duration-150',
|
|
61
|
+
// A 44px square a finger can find round the 20px ring, on a touch screen only.
|
|
62
|
+
touchTarget,
|
|
63
|
+
// The root is a span, not a button, so the disabled state comes from its data attribute.
|
|
64
|
+
'not-data-disabled:hover:border-neutral-400 data-disabled:cursor-not-allowed data-disabled:opacity-50',
|
|
65
|
+
'[[aria-invalid=true]_&]:border-error-500',
|
|
66
|
+
focusRing,
|
|
67
|
+
className,
|
|
68
|
+
)}
|
|
69
|
+
data-slot="radio-group-item"
|
|
70
|
+
id={control.id}
|
|
71
|
+
aria-describedby={field ? control['aria-describedby'] : describedBy}
|
|
72
|
+
{...props}
|
|
73
|
+
>
|
|
74
|
+
<RadioPrimitive.Indicator
|
|
75
|
+
className="size-3.5 rounded-full bg-action [background-image:var(--action-gradient)]"
|
|
76
|
+
data-slot="radio-group-indicator"
|
|
77
|
+
/>
|
|
78
|
+
</RadioPrimitive.Root>
|
|
79
|
+
);
|
|
80
|
+
};
|