@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,235 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
4
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
5
|
+
import { PanelLeft } from 'lucide-react';
|
|
6
|
+
import {
|
|
7
|
+
type ComponentProps,
|
|
8
|
+
type CSSProperties,
|
|
9
|
+
createContext,
|
|
10
|
+
useContext,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from 'react';
|
|
15
|
+
import { cn } from '../lib/cn';
|
|
16
|
+
import { focusRing } from './button';
|
|
17
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip';
|
|
18
|
+
|
|
19
|
+
type RailContextValue = { expanded: boolean; setExpanded: (expanded: boolean) => void };
|
|
20
|
+
|
|
21
|
+
const NavRailContext = createContext<RailContextValue>({ expanded: false, setExpanded: () => {} });
|
|
22
|
+
|
|
23
|
+
type Pill = { top: number; height: number; moved: boolean };
|
|
24
|
+
|
|
25
|
+
export type NavRailProps = ComponentProps<'nav'> & {
|
|
26
|
+
/** Open with each item's label beside its icon; closed it is icons, named in tooltips. */
|
|
27
|
+
expanded?: boolean;
|
|
28
|
+
defaultExpanded?: boolean;
|
|
29
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The app's main navigation as a floating island at the page's edge: 52px of icons, or 208px with
|
|
34
|
+
* each item's label once expanded (a `NavRailToggle` opens and closes it). The current item sits on
|
|
35
|
+
* one action pill that slides from the old item to the new one, and the icons keep their place
|
|
36
|
+
* as the rail widens, so only the labels arrive.
|
|
37
|
+
*/
|
|
38
|
+
export const NavRail = ({
|
|
39
|
+
expanded: expandedProp,
|
|
40
|
+
defaultExpanded = false,
|
|
41
|
+
onExpandedChange,
|
|
42
|
+
className,
|
|
43
|
+
style,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
}: NavRailProps) => {
|
|
47
|
+
const [expandedState, setExpandedState] = useState(defaultExpanded);
|
|
48
|
+
const expanded = expandedProp ?? expandedState;
|
|
49
|
+
const setExpanded = (value: boolean) => {
|
|
50
|
+
setExpandedState(value);
|
|
51
|
+
onExpandedChange?.(value);
|
|
52
|
+
};
|
|
53
|
+
const ref = useRef<HTMLElement>(null);
|
|
54
|
+
const [pill, setPill] = useState<Pill>();
|
|
55
|
+
|
|
56
|
+
// Measured before paint after every render, so the pill finds the current item however it was
|
|
57
|
+
// set; it lands on the first one in place and slides from then on.
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
const item = ref.current?.querySelector<HTMLElement>(
|
|
60
|
+
'[data-slot=rail-item][aria-current=page]',
|
|
61
|
+
);
|
|
62
|
+
setPill(previous => {
|
|
63
|
+
if (!item) return undefined;
|
|
64
|
+
const next = { top: item.offsetTop, height: item.offsetHeight };
|
|
65
|
+
if (previous && previous.top === next.top && previous.height === next.height)
|
|
66
|
+
return previous;
|
|
67
|
+
return { ...next, moved: previous !== undefined };
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<NavRailContext.Provider value={{ expanded, setExpanded }}>
|
|
73
|
+
<nav
|
|
74
|
+
className={cn(
|
|
75
|
+
'group/rail relative isolate flex shrink-0 flex-col gap-0.5 overflow-hidden rounded-dock border border-neutral-200 bg-neutral-50 p-[8px]',
|
|
76
|
+
'transition-[width] duration-300 ease-out-strong motion-reduce:transition-none',
|
|
77
|
+
expanded ? 'w-rail-open' : 'w-rail',
|
|
78
|
+
className,
|
|
79
|
+
)}
|
|
80
|
+
data-expanded={expanded || undefined}
|
|
81
|
+
data-slot="rail"
|
|
82
|
+
ref={ref}
|
|
83
|
+
style={style}
|
|
84
|
+
{...props}
|
|
85
|
+
>
|
|
86
|
+
{pill && (
|
|
87
|
+
<span
|
|
88
|
+
aria-hidden
|
|
89
|
+
className={cn(
|
|
90
|
+
'absolute inset-x-[8px] top-0 -z-10 rounded-item bg-action shadow-action [background-image:var(--action-gradient)]',
|
|
91
|
+
pill.moved &&
|
|
92
|
+
'transition-[translate,height] duration-200 ease-out-strong motion-reduce:transition-none',
|
|
93
|
+
)}
|
|
94
|
+
data-slot="rail-pill"
|
|
95
|
+
style={
|
|
96
|
+
{ translate: `0 ${pill.top}px`, height: pill.height } as CSSProperties
|
|
97
|
+
}
|
|
98
|
+
/>
|
|
99
|
+
)}
|
|
100
|
+
{children}
|
|
101
|
+
</nav>
|
|
102
|
+
</NavRailContext.Provider>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const NavRailSeparator = ({ className, ...props }: ComponentProps<'hr'>) => (
|
|
107
|
+
<hr
|
|
108
|
+
className={cn('my-1.5 h-px w-full shrink-0 border-0 bg-neutral-200', className)}
|
|
109
|
+
data-slot="rail-separator"
|
|
110
|
+
{...props}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
* A control-tall row the rail's inner width: closed, the icon sits centred in it, and open it stays
|
|
116
|
+
* put. The rail is a fixed 52px box, so its insets are fixed pixels too, not the spacing unit: 8px
|
|
117
|
+
* round the rows and (52 − 2 border − 16 inset − 16 icon) / 2 = 9px either side of the icon.
|
|
118
|
+
*/
|
|
119
|
+
const railRowClass =
|
|
120
|
+
'flex h-control w-full shrink-0 cursor-pointer items-center gap-2.5 overflow-hidden rounded-item px-[calc((var(--spacing-control)-16px)/2)] text-neutral-600 transition-[background-color,color] duration-150 hover:bg-neutral-950/5 hover:text-neutral-800 [&_svg:not([class*=size-])]:size-4 [&_svg]:shrink-0';
|
|
121
|
+
|
|
122
|
+
// The label beside the icon: there while open, faded out and clipped while closed.
|
|
123
|
+
const NavRailLabel = ({ children }: { children: string }) => (
|
|
124
|
+
<span
|
|
125
|
+
className="min-w-0 truncate font-medium text-xs opacity-0 transition-opacity duration-200 group-data-expanded/rail:opacity-100"
|
|
126
|
+
data-slot="rail-label"
|
|
127
|
+
>
|
|
128
|
+
{children}
|
|
129
|
+
</span>
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
type RailItemProps = useRender.ComponentProps<'button'> & {
|
|
133
|
+
/** Beside the icon when the rail is open, in a tooltip when it is closed, and the accessible name. */
|
|
134
|
+
label: string;
|
|
135
|
+
/** The current section; also set by passing aria-current="page" yourself. */
|
|
136
|
+
active?: boolean;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** One section: its 16px icon as children. Pass `render={<a href="…" />}` to make it a link. */
|
|
140
|
+
export const NavRailItem = ({
|
|
141
|
+
label,
|
|
142
|
+
active,
|
|
143
|
+
render,
|
|
144
|
+
ref,
|
|
145
|
+
className,
|
|
146
|
+
children,
|
|
147
|
+
type = 'button',
|
|
148
|
+
...props
|
|
149
|
+
}: RailItemProps) => {
|
|
150
|
+
const { expanded } = useContext(NavRailContext);
|
|
151
|
+
|
|
152
|
+
// The item is built first and handed to the trigger, so the tooltip wires
|
|
153
|
+
// itself onto the button or link rather than wrapping it in another one.
|
|
154
|
+
const item = useRender({
|
|
155
|
+
defaultTagName: 'button',
|
|
156
|
+
render,
|
|
157
|
+
ref,
|
|
158
|
+
// State keys become data attributes, so this sets data-slot="rail-item".
|
|
159
|
+
state: { slot: 'rail-item' },
|
|
160
|
+
props: mergeProps<'button'>(
|
|
161
|
+
{
|
|
162
|
+
'aria-current': active ? 'page' : undefined,
|
|
163
|
+
'aria-label': label,
|
|
164
|
+
className: cn(
|
|
165
|
+
railRowClass,
|
|
166
|
+
// The pill under it is the current look; the item only takes the pill's text colour.
|
|
167
|
+
'aria-[current=page]:text-on-action aria-[current=page]:hover:bg-transparent aria-[current=page]:hover:text-on-action',
|
|
168
|
+
focusRing,
|
|
169
|
+
className,
|
|
170
|
+
),
|
|
171
|
+
children: (
|
|
172
|
+
<>
|
|
173
|
+
{/* A 16px column, so a 24px avatar centres on the icons above it as they do. */}
|
|
174
|
+
<span className="flex w-4 shrink-0 justify-center" data-slot="rail-icon">
|
|
175
|
+
{children}
|
|
176
|
+
</span>
|
|
177
|
+
<NavRailLabel>{label}</NavRailLabel>
|
|
178
|
+
</>
|
|
179
|
+
),
|
|
180
|
+
type: render ? undefined : type,
|
|
181
|
+
},
|
|
182
|
+
props,
|
|
183
|
+
),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
// Open, the label is on the row already, so the tooltip stands down.
|
|
188
|
+
<Tooltip disabled={expanded}>
|
|
189
|
+
<TooltipTrigger render={item} />
|
|
190
|
+
<TooltipContent side="right">{label}</TooltipContent>
|
|
191
|
+
</Tooltip>
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/** Opens and closes the rail; usually its first row. */
|
|
196
|
+
export const NavRailToggle = ({
|
|
197
|
+
className,
|
|
198
|
+
onClick,
|
|
199
|
+
collapseLabel = 'Collapse navigation',
|
|
200
|
+
expandLabel = 'Expand navigation',
|
|
201
|
+
...props
|
|
202
|
+
}: ComponentProps<'button'> & {
|
|
203
|
+
/** Its names for screen readers and the tooltip while the rail is open and while it is closed. */
|
|
204
|
+
collapseLabel?: string;
|
|
205
|
+
expandLabel?: string;
|
|
206
|
+
}) => {
|
|
207
|
+
const { expanded, setExpanded } = useContext(NavRailContext);
|
|
208
|
+
// Named for what it holds, the app's navigation, since "rail" is the library's word, not the reader's.
|
|
209
|
+
const label = expanded ? collapseLabel : expandLabel;
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<Tooltip disabled={expanded}>
|
|
213
|
+
<TooltipTrigger
|
|
214
|
+
render={
|
|
215
|
+
<button
|
|
216
|
+
aria-expanded={expanded}
|
|
217
|
+
aria-label={label}
|
|
218
|
+
className={cn(railRowClass, focusRing, className)}
|
|
219
|
+
data-slot="rail-toggle"
|
|
220
|
+
onClick={event => {
|
|
221
|
+
onClick?.(event);
|
|
222
|
+
setExpanded(!expanded);
|
|
223
|
+
}}
|
|
224
|
+
type="button"
|
|
225
|
+
{...props}
|
|
226
|
+
>
|
|
227
|
+
<PanelLeft aria-hidden strokeWidth={2} />
|
|
228
|
+
<NavRailLabel>Collapse</NavRailLabel>
|
|
229
|
+
</button>
|
|
230
|
+
}
|
|
231
|
+
/>
|
|
232
|
+
<TooltipContent side="right">{label}</TooltipContent>
|
|
233
|
+
</Tooltip>
|
|
234
|
+
);
|
|
235
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Check } from 'lucide-react';
|
|
4
|
+
import {
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
useCallback,
|
|
8
|
+
useEffect,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { cn } from '../lib/cn';
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Only the icon carries the tone, at the step an alert's takes (700, 600 for the error red, so it
|
|
16
|
+
* reaches 3:1): the tab stays the bar's surface, and the colour is the accent that says how it went.
|
|
17
|
+
*/
|
|
18
|
+
const noticeTones = {
|
|
19
|
+
neutral: '[&_svg]:text-neutral-500',
|
|
20
|
+
primary: '[&_svg]:text-primary-700',
|
|
21
|
+
success: '[&_svg]:text-success-700',
|
|
22
|
+
warning: '[&_svg]:text-warning-700',
|
|
23
|
+
error: '[&_svg]:text-error-600',
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
export type NoticeTone = keyof typeof noticeTones;
|
|
27
|
+
|
|
28
|
+
export type NoticeProps = Omit<ComponentProps<'output'>, 'children'> & {
|
|
29
|
+
/** What just happened, in a word or two: "Saved", "Link copied". Nothing hides the notice. */
|
|
30
|
+
message?: ReactNode;
|
|
31
|
+
/** Leads the message; a tick by default. Pass a `<Spinner size="sm" />` while it is still working. */
|
|
32
|
+
icon?: ReactNode;
|
|
33
|
+
/** Colours the icon. Success for the default tick, neutral for an icon of your own, as a spinner. */
|
|
34
|
+
tone?: NoticeTone;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The quiet toast: for small actions that need no undo, a tab slides out from under a bar's
|
|
39
|
+
* hairline, centred, and the hairline runs round it. Place it in a positioned bar with a bottom
|
|
40
|
+
* border (the header bar, a sheet's or a panel's header); it is drawn in the bar's own surface and
|
|
41
|
+
* border, so it reads as the bar saying something, not as something laid over the page. Bigger
|
|
42
|
+
* news, or anything with an undo, is a toast at the foot instead.
|
|
43
|
+
*/
|
|
44
|
+
export const Notice = ({ message, icon, tone, className, ...props }: NoticeProps) => {
|
|
45
|
+
// The last message stays while the tab slides away, so it does not empty as it leaves.
|
|
46
|
+
const [shown, setShown] = useState<{ message: ReactNode; icon: ReactNode; tone: NoticeTone }>();
|
|
47
|
+
const open = message !== undefined && message !== null && message !== false;
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (open) setShown({ message, icon, tone: tone ?? (icon ? 'neutral' : 'success') });
|
|
51
|
+
}, [open, message, icon, tone]);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
// The clip starts on the bar's hairline (just past its padding box), so the tab comes out of
|
|
55
|
+
// that edge rather than out of nowhere, and covers the hairline where it hangs.
|
|
56
|
+
<output
|
|
57
|
+
aria-live="polite"
|
|
58
|
+
className={cn(
|
|
59
|
+
// Padded by the fillets' size, so the clip keeps them. The fillet follows the tab's
|
|
60
|
+
// corner (8px at the default 10px), so a square theme squares it too.
|
|
61
|
+
'pointer-events-none absolute top-full left-1/2 z-20 -translate-x-1/2 overflow-hidden px-(--fillet) pb-px [--fillet:calc(var(--radius-item)*0.8)]',
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
data-slot="notice"
|
|
65
|
+
{...props}
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
className={cn(
|
|
69
|
+
'pointer-events-auto relative flex h-cell items-center gap-1.5 whitespace-nowrap rounded-b-item border border-neutral-200 border-t-0 bg-neutral-50 px-3 text-neutral-700 text-xs',
|
|
70
|
+
/*
|
|
71
|
+
* Where the bar's hairline turns down into the tab, it bends round a curve the
|
|
72
|
+
* fillet's size instead of a corner: a square either side, filled with the bar's
|
|
73
|
+
* surface outside a quarter circle and drawn with its border on the curve,
|
|
74
|
+
* transparent inside. At a 0 corner the squares are 0 and the turn is square.
|
|
75
|
+
*/
|
|
76
|
+
"before:absolute before:top-0 before:left-[calc(var(--fillet)*-1)] before:size-(--fillet) before:content-[''] before:[background:radial-gradient(circle_at_0_100%,transparent_calc(var(--fillet)_-_1.25px),var(--color-neutral-200)_calc(var(--fillet)_-_0.75px),var(--color-neutral-200)_calc(var(--fillet)_-_0.25px),var(--color-neutral-50)_calc(var(--fillet)_+_0.25px))]",
|
|
77
|
+
"after:absolute after:top-0 after:right-[calc(var(--fillet)*-1)] after:size-(--fillet) after:content-[''] after:[background:radial-gradient(circle_at_100%_100%,transparent_calc(var(--fillet)_-_1.25px),var(--color-neutral-200)_calc(var(--fillet)_-_0.75px),var(--color-neutral-200)_calc(var(--fillet)_-_0.25px),var(--color-neutral-50)_calc(var(--fillet)_+_0.25px))]",
|
|
78
|
+
'[&_svg:not([class*=size-])]:size-3.5 [&_svg]:shrink-0',
|
|
79
|
+
noticeTones[shown?.tone ?? 'neutral'],
|
|
80
|
+
'transition-[translate,opacity] duration-200 ease-out-strong motion-reduce:translate-y-0 motion-reduce:transition-opacity',
|
|
81
|
+
open ? 'translate-y-0 opacity-100' : '-translate-y-full opacity-0',
|
|
82
|
+
)}
|
|
83
|
+
data-open={open || undefined}
|
|
84
|
+
data-slot="notice-tab"
|
|
85
|
+
>
|
|
86
|
+
{shown && (
|
|
87
|
+
<>
|
|
88
|
+
{shown.icon ?? <Check strokeWidth={2} />}
|
|
89
|
+
{shown.message}
|
|
90
|
+
</>
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
</output>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type NoticeOptions = {
|
|
98
|
+
icon?: ReactNode;
|
|
99
|
+
tone?: NoticeTone;
|
|
100
|
+
/** How long it shows, in ms; 0 keeps it until the next one or `clear`. */
|
|
101
|
+
timeout?: number;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* State for a `Notice`: `show("Saved")` raises it and it leaves by itself after a moment.
|
|
106
|
+
* Spread `notice` on the notice: `<HeaderBarNotice {...notice} />`.
|
|
107
|
+
*/
|
|
108
|
+
export const useNotice = (defaultTimeout = 1800) => {
|
|
109
|
+
const [notice, setNotice] = useState<{
|
|
110
|
+
message?: ReactNode;
|
|
111
|
+
icon?: ReactNode;
|
|
112
|
+
tone?: NoticeTone;
|
|
113
|
+
}>({});
|
|
114
|
+
const timer = useRef<number | undefined>(undefined);
|
|
115
|
+
|
|
116
|
+
const clear = useCallback(() => {
|
|
117
|
+
window.clearTimeout(timer.current);
|
|
118
|
+
setNotice(current => ({ ...current, message: undefined }));
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
const show = useCallback(
|
|
122
|
+
(message: ReactNode, { icon, tone, timeout = defaultTimeout }: NoticeOptions = {}) => {
|
|
123
|
+
window.clearTimeout(timer.current);
|
|
124
|
+
setNotice({ message, icon, tone });
|
|
125
|
+
if (timeout > 0) timer.current = window.setTimeout(clear, timeout);
|
|
126
|
+
},
|
|
127
|
+
[clear, defaultTimeout],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
131
|
+
|
|
132
|
+
return { notice, show, clear };
|
|
133
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { useToast } from './toast';
|
|
5
|
+
|
|
6
|
+
export type OptimisticAction = {
|
|
7
|
+
/** Shows the change at once, as though it were done. */
|
|
8
|
+
apply: () => void;
|
|
9
|
+
/** Puts the thing back exactly as it was, in its place in the list. */
|
|
10
|
+
revert: () => void;
|
|
11
|
+
/** Sends the change. It runs as the change shows; if it rejects, the change is reverted and an error toast says so. */
|
|
12
|
+
commit?: () => unknown;
|
|
13
|
+
/** Sends the reverse, when Undo is pressed. */
|
|
14
|
+
undo?: () => unknown;
|
|
15
|
+
/** The toast's title: the thing it happened to ("Northwind Q3 review"). */
|
|
16
|
+
title: string;
|
|
17
|
+
/** What happened to it ("Moved to Archive"). */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** An optional tab over the toast ("Report archived"). */
|
|
20
|
+
tab?: string;
|
|
21
|
+
/** The error toast's words when the commit fails. */
|
|
22
|
+
failed?: { title: string; description?: string };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An optimistic update with Undo, on the toast: the change shows at once, a toast says what happened
|
|
27
|
+
* with Undo for its 5s, and the request goes as the change shows. Undo reverts it and sends the
|
|
28
|
+
* reverse; a request that fails reverts it and says so in an `error` toast. For a reversible action
|
|
29
|
+
* that almost always succeeds (archive, move, mark as read, delete to a bin). Needs a ToastProvider.
|
|
30
|
+
*/
|
|
31
|
+
export const useOptimisticUndo = () => {
|
|
32
|
+
const toast = useToast();
|
|
33
|
+
|
|
34
|
+
return useCallback(
|
|
35
|
+
({ apply, revert, commit, undo, title, description, tab, failed }: OptimisticAction) => {
|
|
36
|
+
let undone = false;
|
|
37
|
+
apply();
|
|
38
|
+
const id: string = toast.add({
|
|
39
|
+
title,
|
|
40
|
+
description,
|
|
41
|
+
data: { tab, undo: true },
|
|
42
|
+
actionProps: {
|
|
43
|
+
children: 'Undo',
|
|
44
|
+
onClick: () => {
|
|
45
|
+
undone = true;
|
|
46
|
+
revert();
|
|
47
|
+
undo?.();
|
|
48
|
+
toast.close(id);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
Promise.resolve()
|
|
53
|
+
.then(commit)
|
|
54
|
+
.catch(() => {
|
|
55
|
+
if (undone) return;
|
|
56
|
+
toast.close(id);
|
|
57
|
+
revert();
|
|
58
|
+
toast.add({
|
|
59
|
+
title: failed?.title ?? title,
|
|
60
|
+
description:
|
|
61
|
+
failed?.description ?? 'It didn’t go through, so nothing changed',
|
|
62
|
+
type: 'error',
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
[toast],
|
|
67
|
+
);
|
|
68
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
import { cn } from '../lib/cn';
|
|
3
|
+
import { IconTile } from './icon-tile';
|
|
4
|
+
|
|
5
|
+
export type OptionRowProps = Omit<ComponentProps<'label'>, 'title'> & {
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
label: ReactNode;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
/** The control the row toggles: a <Checkbox /> or <RadioGroupItem />. */
|
|
10
|
+
control?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The report generator's selectable row: 48px with an icon tile, 44px for the
|
|
15
|
+
* plain radio rows. Being a <label>, a click anywhere on it toggles the control
|
|
16
|
+
* in the trailing slot.
|
|
17
|
+
*/
|
|
18
|
+
export const OptionRow = ({
|
|
19
|
+
icon,
|
|
20
|
+
label,
|
|
21
|
+
description,
|
|
22
|
+
control,
|
|
23
|
+
className,
|
|
24
|
+
...props
|
|
25
|
+
}: OptionRowProps) => (
|
|
26
|
+
// biome-ignore lint/a11y/noLabelWithoutControl: the control arrives through the `control` slot
|
|
27
|
+
<label
|
|
28
|
+
className={cn(
|
|
29
|
+
'flex cursor-pointer items-center justify-between gap-3 rounded-item border border-neutral-200 py-2 pr-3 pl-2 transition-[border-color] duration-150',
|
|
30
|
+
// The control inside carries the disabled state: its hidden input, or Base UI's data attribute.
|
|
31
|
+
'not-has-disabled:not-has-data-disabled:hover:border-neutral-300',
|
|
32
|
+
'has-data-disabled:cursor-not-allowed has-disabled:cursor-not-allowed has-data-disabled:opacity-50 has-disabled:opacity-50',
|
|
33
|
+
!icon && 'p-3',
|
|
34
|
+
className,
|
|
35
|
+
)}
|
|
36
|
+
data-slot="option-row"
|
|
37
|
+
{...props}
|
|
38
|
+
>
|
|
39
|
+
<span className="flex min-w-0 items-center gap-3">
|
|
40
|
+
{icon && <IconTile>{icon}</IconTile>}
|
|
41
|
+
<span className="flex min-w-0 flex-col">
|
|
42
|
+
<span className="font-normal text-neutral-950 text-sm">{label}</span>
|
|
43
|
+
{description && (
|
|
44
|
+
<span className="font-normal text-neutral-600 text-xs">{description}</span>
|
|
45
|
+
)}
|
|
46
|
+
</span>
|
|
47
|
+
</span>
|
|
48
|
+
{control}
|
|
49
|
+
</label>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export const OptionList = ({ className, ...props }: ComponentProps<'div'>) => (
|
|
53
|
+
<div className={cn('flex flex-col gap-2', className)} data-slot="option-list" {...props} />
|
|
54
|
+
);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import { cn } from '../lib/cn';
|
|
4
|
+
|
|
5
|
+
export const pageContentVariants = cva(
|
|
6
|
+
// Content-box, so the cap is the content's width and the side padding sits outside it. A page
|
|
7
|
+
// starts clear of the header bar: 64px at every width. In a compact shell (a phone) the screen
|
|
8
|
+
// can't spare that: 16px a side and 40px down.
|
|
9
|
+
'mx-auto box-content min-w-0 px-4 pt-16 sm:px-6 @max-shell-compact/shell:px-4 @max-shell-compact/shell:pt-10',
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
width: {
|
|
13
|
+
/** 640: one object made or edited, its fields stacked (a new post, a new customer), and settings. */
|
|
14
|
+
narrow: 'max-w-content-narrow',
|
|
15
|
+
/** 896: overviews, details, documents. */
|
|
16
|
+
default: 'max-w-content',
|
|
17
|
+
/** 1080: content that needs the width, like a list with several columns. */
|
|
18
|
+
wide: 'max-w-content-wide',
|
|
19
|
+
/** 1280: a very dense table. */
|
|
20
|
+
dense: 'max-w-content-dense',
|
|
21
|
+
/** Lots of information, several dense tables: the panel less 64px a side, 128px on the largest screens. */
|
|
22
|
+
inset: 'lg:px-16 2xl:px-content-inset',
|
|
23
|
+
/** Only when asked for: the panel's whole width, edge to edge. */
|
|
24
|
+
full: 'px-0 sm:px-0 @max-shell-compact/shell:px-0',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: { width: 'default' },
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export type PageContentProps = ComponentProps<'div'> & VariantProps<typeof pageContentVariants>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The centred column a page's content sits in. Its width follows how dense the
|
|
35
|
+
* content is, not the screen: a page never runs to the panel's edges.
|
|
36
|
+
*/
|
|
37
|
+
export const PageContent = ({ width, className, ...props }: PageContentProps) => (
|
|
38
|
+
<div
|
|
39
|
+
className={cn(pageContentVariants({ width }), className)}
|
|
40
|
+
data-slot="page-content"
|
|
41
|
+
data-width={width ?? 'default'}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
);
|