@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,804 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Collapsible as CollapsiblePrimitive } from '@base-ui/react/collapsible';
|
|
4
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
5
|
+
import { ChevronDown, ChevronLeft, PanelLeft } from 'lucide-react';
|
|
6
|
+
import {
|
|
7
|
+
type ComponentProps,
|
|
8
|
+
createContext,
|
|
9
|
+
type MouseEvent,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
type Ref,
|
|
12
|
+
type RefObject,
|
|
13
|
+
useCallback,
|
|
14
|
+
useContext,
|
|
15
|
+
useEffect,
|
|
16
|
+
useId,
|
|
17
|
+
useMemo,
|
|
18
|
+
useRef,
|
|
19
|
+
useState,
|
|
20
|
+
} from 'react';
|
|
21
|
+
import { cn } from '../lib/cn';
|
|
22
|
+
import { Badge } from './badge';
|
|
23
|
+
import { focusRing, touchTarget } from './button';
|
|
24
|
+
|
|
25
|
+
/** The shell's navigation drawer, as the parts inside an `AppShell` share it. */
|
|
26
|
+
export type AppShellNav = {
|
|
27
|
+
/** Where the navigation sits: a `Sidebar` beside the panel, or a `TopNav` over it. */
|
|
28
|
+
nav: 'side' | 'top';
|
|
29
|
+
/** Whether the drawer is open. It only shows on a shell narrower than the sidebar's width. */
|
|
30
|
+
open: boolean;
|
|
31
|
+
setOpen: (open: boolean) => void;
|
|
32
|
+
/** Whether the shell has a drawer to open: a `Sidebar`, or a `TopNav`'s sections. */
|
|
33
|
+
hasDrawer: boolean;
|
|
34
|
+
/** The drawer's id, for a toggle's `aria-controls`. */
|
|
35
|
+
drawerId: string | undefined;
|
|
36
|
+
/** The control that opened the drawer, where focus goes back to when it closes. */
|
|
37
|
+
opener: RefObject<HTMLElement | null>;
|
|
38
|
+
/** Takes the drawer's element; the `Sidebar` and the `TopNav` set it themselves. */
|
|
39
|
+
setDrawer: (node: HTMLElement | null) => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const AppShellContext = createContext<AppShellNav | null>(null);
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Whether a part sits inside an AppPanel. The shell's own navigation is the panel's sibling; a
|
|
46
|
+
* Sidebar or a TopNav drawn inside the panel (a preview of one, say) is content, so it never
|
|
47
|
+
* becomes the shell's drawer.
|
|
48
|
+
*/
|
|
49
|
+
const InPanelContext = createContext(false);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The shell's drawer, for a custom bar's own toggle; null outside an `AppShell`. `inPanel` says
|
|
53
|
+
* whether the caller sits inside the panel: the shell's own navigation is the panel's sibling.
|
|
54
|
+
*/
|
|
55
|
+
export const useAppShellNav = () => {
|
|
56
|
+
const shell = useContext(AppShellContext);
|
|
57
|
+
const inPanel = useContext(InPanelContext);
|
|
58
|
+
return shell && { ...shell, inPanel };
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** The shell, for a part that may be its navigation: null for one drawn inside the panel. */
|
|
62
|
+
const useShellNavigation = () => {
|
|
63
|
+
const shell = useContext(AppShellContext);
|
|
64
|
+
return useContext(InPanelContext) ? null : shell;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const assignRef = <T,>(ref: Ref<T> | undefined, node: T | null) => {
|
|
68
|
+
if (typeof ref === 'function') ref(node);
|
|
69
|
+
else if (ref) ref.current = node;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** One callback ref that sets both, so a part keeps the caller's ref while the shell holds it too. */
|
|
73
|
+
const useBothRefs = <T,>(a: Ref<T> | undefined, b: Ref<T> | undefined) =>
|
|
74
|
+
useCallback(
|
|
75
|
+
(node: T | null) => {
|
|
76
|
+
assignRef(a, node);
|
|
77
|
+
assignRef(b, node);
|
|
78
|
+
},
|
|
79
|
+
[a, b],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const focusable =
|
|
83
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The navigation on a shell too narrow for it: it leaves the canvas and slides in over the panel
|
|
87
|
+
* from the left, on the canvas's colour with the sheet's shadow, 256px and never closer than 48px
|
|
88
|
+
* to the far edge, so the page still shows beside it. Closed, it is hidden, which also takes it out
|
|
89
|
+
* of the tab order; under reduced motion it appears without sliding. On a wide shell none of it
|
|
90
|
+
* applies. A sidebar goes under the sidebar's width (1024); a top nav, whose sections scroll along
|
|
91
|
+
* the bar rather than take width from the panel, only under the compact width (640).
|
|
92
|
+
*/
|
|
93
|
+
export const navDrawerClasses = (open: boolean, nav: 'side' | 'top' = 'side') =>
|
|
94
|
+
nav === 'top'
|
|
95
|
+
? cn(
|
|
96
|
+
'@max-shell-compact/shell:absolute @max-shell-compact/shell:inset-y-0 @max-shell-compact/shell:left-0 @max-shell-compact/shell:z-50 @max-shell-compact/shell:w-sidebar @max-shell-compact/shell:max-w-[calc(100%-48px)]',
|
|
97
|
+
'@max-shell-compact/shell:bg-neutral-100 @max-shell-compact/shell:shadow-sheet @max-shell-compact/shell:outline-none',
|
|
98
|
+
'@max-shell-compact/shell:duration-200 @max-shell-compact/shell:ease-out-strong @max-shell-compact/shell:motion-reduce:transition-none',
|
|
99
|
+
open
|
|
100
|
+
? '@max-shell-compact/shell:transition-[translate]'
|
|
101
|
+
: '@max-shell-compact/shell:invisible @max-shell-compact/shell:-translate-x-full @max-shell-compact/shell:transition-[translate,visibility]',
|
|
102
|
+
)
|
|
103
|
+
: cn(
|
|
104
|
+
'@max-shell-sidebar/shell:absolute @max-shell-sidebar/shell:inset-y-0 @max-shell-sidebar/shell:left-0 @max-shell-sidebar/shell:z-50 @max-shell-sidebar/shell:w-sidebar @max-shell-sidebar/shell:max-w-[calc(100%-48px)]',
|
|
105
|
+
'@max-shell-sidebar/shell:bg-neutral-100 @max-shell-sidebar/shell:shadow-sheet @max-shell-sidebar/shell:outline-none',
|
|
106
|
+
// Visibility switches at once on open, so focus can move in, and waits for the slide on close.
|
|
107
|
+
'@max-shell-sidebar/shell:duration-200 @max-shell-sidebar/shell:ease-out-strong @max-shell-sidebar/shell:motion-reduce:transition-none',
|
|
108
|
+
open
|
|
109
|
+
? '@max-shell-sidebar/shell:transition-[translate]'
|
|
110
|
+
: '@max-shell-sidebar/shell:invisible @max-shell-sidebar/shell:-translate-x-full @max-shell-sidebar/shell:transition-[translate,visibility]',
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
type AppShellProps = ComponentProps<'div'> & {
|
|
114
|
+
/** Where the navigation sits on the canvas: a `Sidebar` beside the panel, or a `TopNav` over it. */
|
|
115
|
+
nav?: 'side' | 'top';
|
|
116
|
+
/**
|
|
117
|
+
* Whether the navigation's drawer is open, on a shell too narrow for the sidebar. Left out, the
|
|
118
|
+
* shell keeps it itself, starting from `defaultNavOpen`.
|
|
119
|
+
*/
|
|
120
|
+
navOpen?: boolean;
|
|
121
|
+
defaultNavOpen?: boolean;
|
|
122
|
+
onNavOpenChange?: (open: boolean) => void;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The canvas-and-panel shell: the navigation sits straight on the canvas, the
|
|
127
|
+
* page on an inset panel with an 8px gutter.
|
|
128
|
+
*
|
|
129
|
+
* It is the container its parts answer to, so they follow the shell's width rather than the
|
|
130
|
+
* screen's, and a shell shown narrow inside a page or an embed behaves as it would on a phone.
|
|
131
|
+
* Below the sidebar's width the sidebar becomes a drawer, opened from a toggle at the start of the
|
|
132
|
+
* header bar, over a 40% scrim; a top nav's sections do the same below the compact width. Escape, the scrim or choosing a page closes it,
|
|
133
|
+
* and focus goes back to the toggle. The panel keeps its gutter, corners and hairline at every
|
|
134
|
+
* width, so a phone shows the same shell as a desktop, only without the sidebar beside it.
|
|
135
|
+
*/
|
|
136
|
+
export const AppShell = ({
|
|
137
|
+
nav = 'side',
|
|
138
|
+
navOpen,
|
|
139
|
+
defaultNavOpen = false,
|
|
140
|
+
onNavOpenChange,
|
|
141
|
+
className,
|
|
142
|
+
children,
|
|
143
|
+
ref,
|
|
144
|
+
...props
|
|
145
|
+
}: AppShellProps) => {
|
|
146
|
+
const [shell, setShell] = useState<HTMLDivElement | null>(null);
|
|
147
|
+
const [drawer, setDrawer] = useState<HTMLElement | null>(null);
|
|
148
|
+
// Unknown until measured, so a drawer asked to start open isn't closed before the shell is.
|
|
149
|
+
const [narrow, setNarrow] = useState<boolean>();
|
|
150
|
+
const [ownOpen, setOwnOpen] = useState(defaultNavOpen);
|
|
151
|
+
const open = navOpen ?? ownOpen;
|
|
152
|
+
const opener = useRef<HTMLElement | null>(null);
|
|
153
|
+
const latest = useRef({ open, onNavOpenChange });
|
|
154
|
+
latest.current = { open, onNavOpenChange };
|
|
155
|
+
const shellRef = useBothRefs(ref, setShell);
|
|
156
|
+
|
|
157
|
+
const setOpen = useCallback((next: boolean) => {
|
|
158
|
+
if (next === latest.current.open) return;
|
|
159
|
+
setOwnOpen(next);
|
|
160
|
+
latest.current.onNavOpenChange?.(next);
|
|
161
|
+
}, []);
|
|
162
|
+
|
|
163
|
+
// The same width the parts' container queries use, read from the token so the two agree.
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (!shell) return;
|
|
166
|
+
const measure = () => {
|
|
167
|
+
const limit =
|
|
168
|
+
Number.parseFloat(
|
|
169
|
+
getComputedStyle(shell).getPropertyValue(
|
|
170
|
+
nav === 'top' ? '--container-shell-compact' : '--container-shell-sidebar',
|
|
171
|
+
),
|
|
172
|
+
) || (nav === 'top' ? 640 : 1024);
|
|
173
|
+
setNarrow(shell.clientWidth < limit);
|
|
174
|
+
};
|
|
175
|
+
measure();
|
|
176
|
+
const observer = new ResizeObserver(measure);
|
|
177
|
+
observer.observe(shell);
|
|
178
|
+
return () => observer.disconnect();
|
|
179
|
+
}, [shell, nav]);
|
|
180
|
+
|
|
181
|
+
// A shell that grows wide enough for the sidebar shuts the drawer, so it doesn't spring open
|
|
182
|
+
// again the next time the shell narrows.
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (open && narrow === false) setOpen(false);
|
|
185
|
+
}, [open, narrow, setOpen]);
|
|
186
|
+
|
|
187
|
+
const shown = open && narrow === true && drawer !== null;
|
|
188
|
+
|
|
189
|
+
// Open, the drawer is the only thing to use: the rest of the shell goes inert, focus moves in
|
|
190
|
+
// (to the current page if it can be seen), Escape closes it, and focus goes back on close.
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (!shown || !shell || !drawer) return;
|
|
193
|
+
const rest = Array.from(shell.children).filter(
|
|
194
|
+
(child): child is HTMLElement =>
|
|
195
|
+
child instanceof HTMLElement &&
|
|
196
|
+
!child.contains(drawer) &&
|
|
197
|
+
child.dataset.slot !== 'app-shell-scrim',
|
|
198
|
+
);
|
|
199
|
+
for (const child of rest) child.inert = true;
|
|
200
|
+
|
|
201
|
+
const active = document.activeElement;
|
|
202
|
+
if (!opener.current && active instanceof HTMLElement && active !== document.body) {
|
|
203
|
+
opener.current = active;
|
|
204
|
+
}
|
|
205
|
+
const first = [
|
|
206
|
+
drawer.querySelector('[aria-current=page]'),
|
|
207
|
+
...drawer.querySelectorAll(focusable),
|
|
208
|
+
].find(
|
|
209
|
+
(node): node is HTMLElement =>
|
|
210
|
+
node instanceof HTMLElement && node.checkVisibility?.() !== false,
|
|
211
|
+
);
|
|
212
|
+
(first ?? drawer).focus({ preventScroll: true });
|
|
213
|
+
|
|
214
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
215
|
+
if (event.key !== 'Escape' || event.defaultPrevented) return;
|
|
216
|
+
// A menu portalled out of the drawer handles its own Escape.
|
|
217
|
+
const focused = document.activeElement;
|
|
218
|
+
if (focused && focused !== document.body && !drawer.contains(focused)) return;
|
|
219
|
+
setOpen(false);
|
|
220
|
+
};
|
|
221
|
+
document.addEventListener('keydown', onKeyDown);
|
|
222
|
+
|
|
223
|
+
return () => {
|
|
224
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
225
|
+
for (const child of rest) child.inert = false;
|
|
226
|
+
const focused = document.activeElement;
|
|
227
|
+
if (!focused || focused === document.body || drawer.contains(focused)) {
|
|
228
|
+
opener.current?.focus({ preventScroll: true });
|
|
229
|
+
}
|
|
230
|
+
opener.current = null;
|
|
231
|
+
};
|
|
232
|
+
}, [shown, shell, drawer, setOpen]);
|
|
233
|
+
|
|
234
|
+
const value = useMemo<AppShellNav>(
|
|
235
|
+
() => ({
|
|
236
|
+
nav,
|
|
237
|
+
open,
|
|
238
|
+
setOpen,
|
|
239
|
+
hasDrawer: drawer !== null,
|
|
240
|
+
drawerId: drawer?.id || undefined,
|
|
241
|
+
opener,
|
|
242
|
+
setDrawer,
|
|
243
|
+
}),
|
|
244
|
+
[nav, open, setOpen, drawer],
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<AppShellContext.Provider value={value}>
|
|
249
|
+
<InPanelContext.Provider value={false}>
|
|
250
|
+
<div
|
|
251
|
+
className={cn(
|
|
252
|
+
// Positioned and isolated, so the drawer and its scrim lie over this shell alone.
|
|
253
|
+
'@container/shell relative isolate flex min-h-screen bg-neutral-100',
|
|
254
|
+
// Under a top nav the page is one surface from the bar down: no canvas round it.
|
|
255
|
+
nav === 'top' && 'flex-col bg-neutral-50',
|
|
256
|
+
className,
|
|
257
|
+
)}
|
|
258
|
+
data-nav={nav}
|
|
259
|
+
data-slot="app-shell"
|
|
260
|
+
ref={shellRef}
|
|
261
|
+
{...props}
|
|
262
|
+
>
|
|
263
|
+
{children}
|
|
264
|
+
{drawer && (
|
|
265
|
+
// Black rather than a neutral step, as a dialog's scrim: the ramp flips in dark mode.
|
|
266
|
+
<div
|
|
267
|
+
aria-hidden
|
|
268
|
+
className={cn(
|
|
269
|
+
'absolute inset-0 z-40 hidden bg-black/40 transition-[opacity,visibility] duration-200 ease-out-strong motion-reduce:transition-none',
|
|
270
|
+
nav === 'top'
|
|
271
|
+
? '@max-shell-compact/shell:block'
|
|
272
|
+
: '@max-shell-sidebar/shell:block',
|
|
273
|
+
!open && 'invisible opacity-0',
|
|
274
|
+
)}
|
|
275
|
+
data-slot="app-shell-scrim"
|
|
276
|
+
onClick={() => setOpen(false)}
|
|
277
|
+
/>
|
|
278
|
+
)}
|
|
279
|
+
</div>
|
|
280
|
+
</InPanelContext.Provider>
|
|
281
|
+
</AppShellContext.Provider>
|
|
282
|
+
);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export const AppPanel = ({ className, ...props }: ComponentProps<'main'>) => {
|
|
286
|
+
const shell = useShellNavigation();
|
|
287
|
+
|
|
288
|
+
return (
|
|
289
|
+
<InPanelContext.Provider value={true}>
|
|
290
|
+
<main
|
|
291
|
+
className={cn(
|
|
292
|
+
// The gutter opens on every side but the navigation's.
|
|
293
|
+
'relative m-2 ml-0 flex min-w-0 flex-1 flex-col overflow-hidden rounded-panel border border-neutral-200 bg-neutral-50',
|
|
294
|
+
// Under a top nav the page lies flat under the bar's hairline: no gutter, corners or frame.
|
|
295
|
+
'[[data-nav=top]>&]:m-0 [[data-nav=top]>&]:rounded-none [[data-nav=top]>&]:border-0',
|
|
296
|
+
// With the sidebar gone to a drawer, the gutter opens on its side too.
|
|
297
|
+
shell?.hasDrawer && shell.nav === 'side' && '@max-shell-sidebar/shell:ml-2',
|
|
298
|
+
className,
|
|
299
|
+
)}
|
|
300
|
+
data-slot="app-panel"
|
|
301
|
+
{...props}
|
|
302
|
+
/>
|
|
303
|
+
</InPanelContext.Provider>
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
export type SidebarProps = ComponentProps<'aside'> & {
|
|
308
|
+
/**
|
|
309
|
+
* A hairline round it, on panel corners, with the gutter the AppPanel keeps: the sidebar as a
|
|
310
|
+
* panel of its own beside the page. Off by default, so the sidebar shares the canvas.
|
|
311
|
+
*/
|
|
312
|
+
bordered?: boolean;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The email sequencing sidebar: no fill of its own, so it shares the canvas,
|
|
317
|
+
* with a logo row, blocks of navigation and an account footer. In an `AppShell` narrower than
|
|
318
|
+
* the sidebar's width it becomes the shell's drawer.
|
|
319
|
+
*/
|
|
320
|
+
export const Sidebar = ({ className, id, ref, bordered = false, ...props }: SidebarProps) => {
|
|
321
|
+
const shell = useShellNavigation();
|
|
322
|
+
const ownId = useId();
|
|
323
|
+
const drawerRef = useBothRefs(ref, shell?.setDrawer);
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<aside
|
|
327
|
+
className={cn(
|
|
328
|
+
'flex w-sidebar shrink-0 flex-col overflow-hidden',
|
|
329
|
+
bordered && 'm-2 rounded-panel border border-neutral-200',
|
|
330
|
+
shell && navDrawerClasses(shell.open),
|
|
331
|
+
className,
|
|
332
|
+
)}
|
|
333
|
+
data-bordered={bordered || undefined}
|
|
334
|
+
data-slot="sidebar"
|
|
335
|
+
id={shell ? (id ?? ownId) : id}
|
|
336
|
+
ref={shell ? drawerRef : ref}
|
|
337
|
+
// Open, it can take focus itself, for when nothing in it can.
|
|
338
|
+
tabIndex={shell?.open ? -1 : undefined}
|
|
339
|
+
{...props}
|
|
340
|
+
/>
|
|
341
|
+
);
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/** The 56px logo row: a logo on the left, the collapse toggle on the right. */
|
|
345
|
+
export const SidebarHeader = ({ className, ...props }: ComponentProps<'div'>) => (
|
|
346
|
+
<div
|
|
347
|
+
className={cn(
|
|
348
|
+
// Centred in the row with the logo 2px low, so a theme's height scale never squeezes it out.
|
|
349
|
+
'flex h-nav shrink-0 items-center justify-between pt-1 pr-3.5 pl-2',
|
|
350
|
+
className,
|
|
351
|
+
)}
|
|
352
|
+
data-slot="sidebar-header"
|
|
353
|
+
{...props}
|
|
354
|
+
/>
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
/** A 26px mark in ink, on no tile, centred in a 36px box. */
|
|
358
|
+
export const SidebarLogo = ({ className, children, ...props }: ComponentProps<'span'>) => (
|
|
359
|
+
<span
|
|
360
|
+
className={cn('grid size-9 shrink-0 place-items-center', className)}
|
|
361
|
+
data-slot="sidebar-logo"
|
|
362
|
+
{...props}
|
|
363
|
+
>
|
|
364
|
+
<span className="grid size-6.5 place-items-center text-neutral-950 [&_svg:not([class*=size-])]:size-4">
|
|
365
|
+
{children}
|
|
366
|
+
</span>
|
|
367
|
+
</span>
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
type SidebarToggleProps = ComponentProps<'button'> & {
|
|
371
|
+
/**
|
|
372
|
+
* Whether the sidebar it opens and closes is open now: it sets `aria-expanded` and turns the
|
|
373
|
+
* default name from "Expand sidebar" to "Collapse sidebar". Left out, the button states neither
|
|
374
|
+
* and is named "Collapse sidebar", as a toggle in an open sidebar's header is.
|
|
375
|
+
*/
|
|
376
|
+
expanded?: boolean;
|
|
377
|
+
/** Its names for screen readers while the sidebar is open and while it is closed. */
|
|
378
|
+
collapseLabel?: string;
|
|
379
|
+
expandLabel?: string;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Opens and closes the sidebar; give it `expanded` and `aria-controls` so its state is announced.
|
|
384
|
+
* Inside an `AppShell`, without an `onClick` of its own, it opens and closes the shell's drawer, so
|
|
385
|
+
* the one in the drawer's header closes it.
|
|
386
|
+
*/
|
|
387
|
+
export const SidebarToggle = ({
|
|
388
|
+
className,
|
|
389
|
+
type = 'button',
|
|
390
|
+
expanded,
|
|
391
|
+
collapseLabel = 'Collapse sidebar',
|
|
392
|
+
expandLabel = 'Expand sidebar',
|
|
393
|
+
'aria-label': label = expanded === false ? expandLabel : collapseLabel,
|
|
394
|
+
onClick,
|
|
395
|
+
...props
|
|
396
|
+
}: SidebarToggleProps) => {
|
|
397
|
+
const shell = useContext(AppShellContext);
|
|
398
|
+
const drives = !onClick && shell?.hasDrawer;
|
|
399
|
+
|
|
400
|
+
return (
|
|
401
|
+
<button
|
|
402
|
+
aria-controls={drives ? shell.drawerId : undefined}
|
|
403
|
+
aria-expanded={expanded}
|
|
404
|
+
aria-label={label}
|
|
405
|
+
className={cn(
|
|
406
|
+
'grid size-7 cursor-pointer place-items-center rounded-chip text-neutral-300 transition-colors duration-150 hover:text-neutral-600',
|
|
407
|
+
touchTarget,
|
|
408
|
+
focusRing,
|
|
409
|
+
className,
|
|
410
|
+
)}
|
|
411
|
+
data-slot="sidebar-toggle"
|
|
412
|
+
onClick={
|
|
413
|
+
drives
|
|
414
|
+
? (event: MouseEvent<HTMLButtonElement>) => {
|
|
415
|
+
if (!shell.open) shell.opener.current = event.currentTarget;
|
|
416
|
+
shell.setOpen(!shell.open);
|
|
417
|
+
}
|
|
418
|
+
: onClick
|
|
419
|
+
}
|
|
420
|
+
type={type}
|
|
421
|
+
{...props}
|
|
422
|
+
>
|
|
423
|
+
<PanelLeft className="size-4" strokeWidth={2} />
|
|
424
|
+
</button>
|
|
425
|
+
);
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* A group's or a section's count: how many it holds. A plain figure in `neutral-500`, in the type
|
|
430
|
+
* of its row, tabular, at the row's end: a fact about the group, not something waiting.
|
|
431
|
+
*/
|
|
432
|
+
const SidebarCount = ({ children }: { children: ReactNode }) => (
|
|
433
|
+
<span className="shrink-0 font-normal text-neutral-500 tabular-nums" data-slot="sidebar-count">
|
|
434
|
+
{children}
|
|
435
|
+
</span>
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* An item's count: how many wait for the reader there (an inbox's new mail, invoices to send). A
|
|
440
|
+
* primary count badge, so what waits stands out from the rows around it.
|
|
441
|
+
*/
|
|
442
|
+
const SidebarItemCount = ({ children }: { children: ReactNode }) => (
|
|
443
|
+
<Badge data-slot="sidebar-count" tone="primary" variant="count">
|
|
444
|
+
{children}
|
|
445
|
+
</Badge>
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
type SidebarGroupProps = ComponentProps<'nav'> & {
|
|
449
|
+
/** Small heading above the group ("Projects"). */
|
|
450
|
+
label?: ReactNode;
|
|
451
|
+
/** How many the group holds, or what a search leaves of them, at the label's end. */
|
|
452
|
+
count?: ReactNode;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* A block of navigation. Items sit 2px apart, inset 8px left and 12px right.
|
|
457
|
+
* Blocks are told apart by space, not a hairline: one that follows another
|
|
458
|
+
* starts 24px down.
|
|
459
|
+
*/
|
|
460
|
+
export const SidebarGroup = ({
|
|
461
|
+
label,
|
|
462
|
+
count,
|
|
463
|
+
className,
|
|
464
|
+
children,
|
|
465
|
+
...props
|
|
466
|
+
}: SidebarGroupProps) => (
|
|
467
|
+
<nav
|
|
468
|
+
className={cn(
|
|
469
|
+
'flex shrink-0 flex-col gap-1 pt-2 pr-3 pl-2 [[data-slot=sidebar-group]+&]:pt-6',
|
|
470
|
+
className,
|
|
471
|
+
)}
|
|
472
|
+
data-slot="sidebar-group"
|
|
473
|
+
{...props}
|
|
474
|
+
>
|
|
475
|
+
{label && (
|
|
476
|
+
<p
|
|
477
|
+
className="flex items-center gap-2 py-1 pr-2 pl-2.5 font-normal text-neutral-600 text-xs"
|
|
478
|
+
data-slot="sidebar-label"
|
|
479
|
+
>
|
|
480
|
+
<span className="min-w-0 flex-1 truncate">{label}</span>
|
|
481
|
+
{count !== undefined && <SidebarCount>{count}</SidebarCount>}
|
|
482
|
+
</p>
|
|
483
|
+
)}
|
|
484
|
+
<div className="flex flex-col gap-0.5">{children}</div>
|
|
485
|
+
</nav>
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
export const sidebarItemClasses = [
|
|
489
|
+
'flex w-full cursor-pointer select-none items-center gap-2 rounded-item py-2 pr-2 pl-2.5 text-left font-normal transition-[background-color,color] duration-150',
|
|
490
|
+
'hover:bg-neutral-950/5',
|
|
491
|
+
// The active item as the theme draws it: the wash by default, tinted, filled or raised.
|
|
492
|
+
'aria-[current=page]:bg-nav-active aria-[current=page]:text-nav-active-fg aria-[current=page]:hover:bg-nav-active',
|
|
493
|
+
'aria-[current=page]:[box-shadow:inset_0_0_0_1px_var(--color-nav-active-border),var(--shadow-nav-active)] aria-[current=page]:[background-image:var(--nav-active-image)]',
|
|
494
|
+
// In a foldout, the piece of its guide line beside the page you are on, in the text's colour.
|
|
495
|
+
'in-data-[slot=sidebar-section-rows]:relative in-data-[slot=sidebar-section-rows]:aria-[current=page]:before:absolute in-data-[slot=sidebar-section-rows]:aria-[current=page]:before:inset-y-1.5 in-data-[slot=sidebar-section-rows]:aria-[current=page]:before:-left-1.5 in-data-[slot=sidebar-section-rows]:aria-[current=page]:before:w-px in-data-[slot=sidebar-section-rows]:aria-[current=page]:before:bg-neutral-950 in-data-[slot=sidebar-section-rows]:aria-[current=page]:before:content-[""]',
|
|
496
|
+
'[&_svg:not([class*=size-])]:size-icon [&_svg]:shrink-0',
|
|
497
|
+
focusRing,
|
|
498
|
+
];
|
|
499
|
+
|
|
500
|
+
type SidebarItemProps = ComponentProps<'button'> & {
|
|
501
|
+
/** Swaps the button for another element, e.g. `render={<a href="/inbox" />}`. */
|
|
502
|
+
render?: useRender.RenderProp;
|
|
503
|
+
active?: boolean;
|
|
504
|
+
/** Leading 14px icon or emoji. */
|
|
505
|
+
icon?: ReactNode;
|
|
506
|
+
/** How many wait for the reader there, as a count badge at the row's end. */
|
|
507
|
+
count?: ReactNode;
|
|
508
|
+
/** Anything else at the row's end: a Kbd, or a chevron on a place that drills in. */
|
|
509
|
+
trailing?: ReactNode;
|
|
510
|
+
/**
|
|
511
|
+
* `primary` is the call to action at the top ("New Sequence"), set 16px
|
|
512
|
+
* above the list; `project` is a 14px row in a project list ("All
|
|
513
|
+
* projects"); `inset` is a page under a project, in the quieter grey, indented by the
|
|
514
|
+
* foldout it sits in.
|
|
515
|
+
*/
|
|
516
|
+
variant?: 'default' | 'primary' | 'project' | 'inset';
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* A sidebar row, on the control row's 34px. The selected row gets a 5% wash
|
|
521
|
+
* rather than colour, set via aria-current so router links that set it
|
|
522
|
+
* themselves work too. Chosen in the shell's drawer, it closes the drawer.
|
|
523
|
+
*/
|
|
524
|
+
export const SidebarItem = ({
|
|
525
|
+
render,
|
|
526
|
+
active,
|
|
527
|
+
icon,
|
|
528
|
+
count,
|
|
529
|
+
trailing,
|
|
530
|
+
variant = 'default',
|
|
531
|
+
className,
|
|
532
|
+
children,
|
|
533
|
+
type = 'button',
|
|
534
|
+
onClick,
|
|
535
|
+
...props
|
|
536
|
+
}: SidebarItemProps) => {
|
|
537
|
+
const shell = useShellNavigation();
|
|
538
|
+
|
|
539
|
+
return useRender({
|
|
540
|
+
defaultTagName: 'button',
|
|
541
|
+
render,
|
|
542
|
+
props: {
|
|
543
|
+
'aria-current': active ? 'page' : undefined,
|
|
544
|
+
className: cn(
|
|
545
|
+
sidebarItemClasses,
|
|
546
|
+
variant === 'default' && 'h-control text-neutral-950 text-xs',
|
|
547
|
+
variant === 'project' && 'h-control text-neutral-950 text-sm',
|
|
548
|
+
variant === 'inset' &&
|
|
549
|
+
'h-control text-neutral-700 text-sm aria-[current=page]:text-nav-active-fg',
|
|
550
|
+
variant === 'primary' &&
|
|
551
|
+
'mb-3.5 h-control bg-action text-on-action text-xs shadow-action [background-image:var(--action-gradient)] hover:bg-action-hover hover:[background-image:none]',
|
|
552
|
+
className,
|
|
553
|
+
),
|
|
554
|
+
'data-slot': 'sidebar-item',
|
|
555
|
+
'data-variant': variant,
|
|
556
|
+
// A rendered link or router element is not a button, so it gets no type.
|
|
557
|
+
type: render ? undefined : type,
|
|
558
|
+
...props,
|
|
559
|
+
onClick: (event: MouseEvent<HTMLButtonElement>) => {
|
|
560
|
+
onClick?.(event);
|
|
561
|
+
if (shell && !event.defaultPrevented) shell.setOpen(false);
|
|
562
|
+
},
|
|
563
|
+
children: (
|
|
564
|
+
<>
|
|
565
|
+
{icon}
|
|
566
|
+
<span className="min-w-0 flex-1 truncate">{children}</span>
|
|
567
|
+
{(count !== undefined || trailing) && (
|
|
568
|
+
<span className="ml-auto flex shrink-0 items-center gap-2">
|
|
569
|
+
{count !== undefined && <SidebarItemCount>{count}</SidebarItemCount>}
|
|
570
|
+
{trailing}
|
|
571
|
+
</span>
|
|
572
|
+
)}
|
|
573
|
+
</>
|
|
574
|
+
),
|
|
575
|
+
},
|
|
576
|
+
});
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
/** @deprecated Use `SidebarItem`. */
|
|
580
|
+
export const NavItem = SidebarItem;
|
|
581
|
+
|
|
582
|
+
/** @deprecated Use `sidebarItemClasses`. */
|
|
583
|
+
export const navItemClasses = sidebarItemClasses;
|
|
584
|
+
|
|
585
|
+
type SidebarLevelProps = ComponentProps<'div'> & {
|
|
586
|
+
/**
|
|
587
|
+
* The side it comes in from: `end` for a level opened from the one above it, `start` for the
|
|
588
|
+
* level returned to.
|
|
589
|
+
*/
|
|
590
|
+
from?: 'start' | 'end';
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* One level of a sidebar that drills down: the top level's places, or the index of one of them
|
|
595
|
+
* under a `SidebarBack`. Render the level that is open; it comes in 8px from its side as it fades
|
|
596
|
+
* in, and only fades under reduced motion. Give each level a key, so a change of level enters anew.
|
|
597
|
+
*/
|
|
598
|
+
export const SidebarLevel = ({ from = 'end', className, ...props }: SidebarLevelProps) => (
|
|
599
|
+
<div
|
|
600
|
+
className={cn(
|
|
601
|
+
'flex min-w-0 flex-col starting:opacity-0 transition-[opacity,translate] duration-200 ease-out-strong motion-reduce:transition-none',
|
|
602
|
+
from === 'end'
|
|
603
|
+
? 'motion-safe:starting:translate-x-2'
|
|
604
|
+
: 'motion-safe:starting:-translate-x-2',
|
|
605
|
+
className,
|
|
606
|
+
)}
|
|
607
|
+
data-slot="sidebar-level"
|
|
608
|
+
{...props}
|
|
609
|
+
/>
|
|
610
|
+
);
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* The head of a nested level: its `SidebarBack`, then anything that works on the whole level (a
|
|
614
|
+
* search). It stays at the top while the level's list scrolls under it, on the sidebar's canvas,
|
|
615
|
+
* with a hairline at its foot; 12 above, 8 between its rows and 12 below, in a group's insets.
|
|
616
|
+
*/
|
|
617
|
+
export const SidebarLevelHead = ({ className, ...props }: ComponentProps<'div'>) => (
|
|
618
|
+
<div
|
|
619
|
+
className={cn(
|
|
620
|
+
'sticky top-0 z-10 flex shrink-0 flex-col gap-2 border-neutral-200 border-b bg-neutral-100 pt-3 pr-3 pb-3 pl-2',
|
|
621
|
+
className,
|
|
622
|
+
)}
|
|
623
|
+
data-slot="sidebar-level-head"
|
|
624
|
+
{...props}
|
|
625
|
+
/>
|
|
626
|
+
);
|
|
627
|
+
|
|
628
|
+
type SidebarBackProps = Omit<ComponentProps<'button'>, 'children'> & {
|
|
629
|
+
/** The level's name, shown after the chevron: "Components". */
|
|
630
|
+
children: ReactNode;
|
|
631
|
+
/** Spoken before the name, so the button says where it goes: "Back to the menu". */
|
|
632
|
+
backLabel?: string;
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* The head of a nested level: a chevron back and the level's name, on a sidebar item's row.
|
|
637
|
+
* It takes the reader back to the level above; the page that is open stays.
|
|
638
|
+
*/
|
|
639
|
+
export const SidebarBack = ({
|
|
640
|
+
backLabel = 'Back',
|
|
641
|
+
className,
|
|
642
|
+
children,
|
|
643
|
+
type = 'button',
|
|
644
|
+
...props
|
|
645
|
+
}: SidebarBackProps) => (
|
|
646
|
+
<button
|
|
647
|
+
className={cn(sidebarItemClasses, 'h-control text-neutral-950 text-xs', className)}
|
|
648
|
+
data-slot="sidebar-back"
|
|
649
|
+
type={type}
|
|
650
|
+
{...props}
|
|
651
|
+
>
|
|
652
|
+
<ChevronLeft aria-hidden strokeWidth={2} />
|
|
653
|
+
<span className="sr-only">{backLabel}: </span>
|
|
654
|
+
<span className="min-w-0 flex-1 truncate">{children}</span>
|
|
655
|
+
</button>
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
type SidebarSectionProps = Omit<ComponentProps<typeof CollapsiblePrimitive.Root>, 'className'> & {
|
|
659
|
+
className?: string;
|
|
660
|
+
/** Leading 14px icon or emoji. */
|
|
661
|
+
icon?: ReactNode;
|
|
662
|
+
label: ReactNode;
|
|
663
|
+
/** How many pages it holds, as a count badge at the row's end, after the chevron. */
|
|
664
|
+
count?: ReactNode;
|
|
665
|
+
/**
|
|
666
|
+
* Holds the page you are on. Found by itself among its rows, open or closed; set it where the
|
|
667
|
+
* page is not one of them (a page under it that the sidebar does not list).
|
|
668
|
+
*/
|
|
669
|
+
current?: boolean;
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
/*
|
|
673
|
+
* Where the guide line runs: down the middle of the section's 14px icon, 16px into its row (the
|
|
674
|
+
* row's 10 and half the icon's 14, less half the line). The rows hang 5px off it, so a page's label
|
|
675
|
+
* starts 32px in, where the section's own label does (10 + 14 + 8).
|
|
676
|
+
*/
|
|
677
|
+
const guide = 'ml-4 border-neutral-200 border-l pl-1.25';
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* A section that folds open to its pages, as deep as it needs: a foldout's rows can be foldouts
|
|
681
|
+
* too. Each level hangs off a guide line from the icon above it, one icon's width further in.
|
|
682
|
+
*
|
|
683
|
+
* Open or closed, the row stays a plain row: open is told by the chevron and the rows under it.
|
|
684
|
+
* A background always means "you are here": the page you are on takes the theme's active look,
|
|
685
|
+
* every foldout that holds it the theme's quieter section look, and the guide line beside the
|
|
686
|
+
* page darkens, so the way from a section to its page can be followed. The chevron shows on
|
|
687
|
+
* hover when closed (always on a touch screen, which has none) and turns as the group opens.
|
|
688
|
+
*/
|
|
689
|
+
export const SidebarSection = ({
|
|
690
|
+
icon,
|
|
691
|
+
label,
|
|
692
|
+
count,
|
|
693
|
+
current,
|
|
694
|
+
className,
|
|
695
|
+
children,
|
|
696
|
+
...props
|
|
697
|
+
}: SidebarSectionProps) => (
|
|
698
|
+
<CollapsiblePrimitive.Root
|
|
699
|
+
className={cn('flex flex-col', className)}
|
|
700
|
+
data-current={current || undefined}
|
|
701
|
+
data-slot="sidebar-section"
|
|
702
|
+
{...props}
|
|
703
|
+
>
|
|
704
|
+
{/* Base UI marks only the open trigger (data-panel-open), so closed is the default look. */}
|
|
705
|
+
<CollapsiblePrimitive.Trigger
|
|
706
|
+
className={cn(
|
|
707
|
+
sidebarItemClasses,
|
|
708
|
+
'group h-control text-neutral-700 text-sm data-panel-open:text-neutral-950',
|
|
709
|
+
// The section that holds the page: set, or found among its rows, open or closed.
|
|
710
|
+
'[[data-current]>&]:bg-nav-section [[data-current]>&]:text-nav-section-fg',
|
|
711
|
+
'[[data-slot=sidebar-section]:has([aria-current=page])>&]:bg-nav-section',
|
|
712
|
+
'[[data-slot=sidebar-section]:has([aria-current=page])>&]:text-nav-section-fg',
|
|
713
|
+
'[[data-slot=sidebar-section]:has([aria-current=page])>&]:hover:bg-nav-section',
|
|
714
|
+
// A foldout inside a foldout that holds the page darkens its piece of the guide line too.
|
|
715
|
+
'[[data-slot=sidebar-section-rows]>[data-slot=sidebar-section]:has([aria-current=page])>&]:relative [[data-slot=sidebar-section-rows]>[data-slot=sidebar-section]:has([aria-current=page])>&]:before:absolute [[data-slot=sidebar-section-rows]>[data-slot=sidebar-section]:has([aria-current=page])>&]:before:inset-y-1.5 [[data-slot=sidebar-section-rows]>[data-slot=sidebar-section]:has([aria-current=page])>&]:before:-left-1.5 [[data-slot=sidebar-section-rows]>[data-slot=sidebar-section]:has([aria-current=page])>&]:before:w-px [[data-slot=sidebar-section-rows]>[data-slot=sidebar-section]:has([aria-current=page])>&]:before:bg-neutral-950 [[data-slot=sidebar-section-rows]>[data-slot=sidebar-section]:has([aria-current=page])>&]:before:content-[""]',
|
|
716
|
+
)}
|
|
717
|
+
data-slot="sidebar-section-trigger"
|
|
718
|
+
>
|
|
719
|
+
{icon && (
|
|
720
|
+
<span className="grid size-icon shrink-0 place-items-center text-xs">{icon}</span>
|
|
721
|
+
)}
|
|
722
|
+
<span className="min-w-0 flex-1 truncate">{label}</span>
|
|
723
|
+
<ChevronDown
|
|
724
|
+
className="-rotate-90 opacity-0 pointer-coarse:opacity-100 transition-[opacity,rotate] duration-200 ease-out-strong group-hover:opacity-100 group-data-panel-open:rotate-0 group-data-panel-open:opacity-100 motion-reduce:transition-none"
|
|
725
|
+
strokeWidth={2}
|
|
726
|
+
/>
|
|
727
|
+
{/* After the chevron, so its count lines up with the items' and the labels' at the row's end. */}
|
|
728
|
+
{count !== undefined && <SidebarCount>{count}</SidebarCount>}
|
|
729
|
+
</CollapsiblePrimitive.Trigger>
|
|
730
|
+
<CollapsiblePrimitive.Panel
|
|
731
|
+
className={cn(
|
|
732
|
+
// Opens to its own height and closes back, the rows fading with it.
|
|
733
|
+
'h-(--collapsible-panel-height) overflow-hidden transition-[height,opacity] duration-200 ease-out-strong',
|
|
734
|
+
'data-ending-style:h-0 data-starting-style:h-0 data-ending-style:opacity-0 data-starting-style:opacity-0',
|
|
735
|
+
'motion-reduce:transition-opacity',
|
|
736
|
+
)}
|
|
737
|
+
data-slot="sidebar-section-content"
|
|
738
|
+
// Kept in the page while closed, so a closed section still knows it holds the page.
|
|
739
|
+
keepMounted
|
|
740
|
+
>
|
|
741
|
+
{/* The padding sits inside, so a closed panel is truly 0px tall. */}
|
|
742
|
+
<div
|
|
743
|
+
className={cn('my-1 flex flex-col gap-0.5', guide)}
|
|
744
|
+
data-slot="sidebar-section-rows"
|
|
745
|
+
>
|
|
746
|
+
{children}
|
|
747
|
+
</div>
|
|
748
|
+
</CollapsiblePrimitive.Panel>
|
|
749
|
+
</CollapsiblePrimitive.Root>
|
|
750
|
+
);
|
|
751
|
+
|
|
752
|
+
/** @deprecated Use `SidebarSection`. */
|
|
753
|
+
export const NavGroup = SidebarSection;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Pushed to the bottom: who is signed in, and a bell. Inset 18px on the left, the group's 8px and a
|
|
757
|
+
* row's 10px, so the avatar's edge lines up with the logo, the switcher's mark and the item icons
|
|
758
|
+
* above it; 14px on the right, so a 28 icon button's icon centres on the column the switcher's
|
|
759
|
+
* chevron and the items' chevrons and counts share.
|
|
760
|
+
*/
|
|
761
|
+
export const SidebarFooter = ({ className, ...props }: ComponentProps<'div'>) => (
|
|
762
|
+
<div
|
|
763
|
+
className={cn(
|
|
764
|
+
'mt-auto flex shrink-0 items-center gap-3 pt-4 pr-3.5 pb-6 pl-4.5',
|
|
765
|
+
className,
|
|
766
|
+
)}
|
|
767
|
+
data-slot="sidebar-footer"
|
|
768
|
+
{...props}
|
|
769
|
+
/>
|
|
770
|
+
);
|
|
771
|
+
|
|
772
|
+
type SidebarAccountProps = ComponentProps<'div'> & {
|
|
773
|
+
/** A 28 logo or avatar, the switcher's mark size: whatever is passed fills it. */
|
|
774
|
+
avatar?: ReactNode;
|
|
775
|
+
/** The first line: who or what is signed in (a person, a workspace). */
|
|
776
|
+
name: ReactNode;
|
|
777
|
+
/** The quieter line under it, whatever says more about it: an email, a plan, a role, a place. */
|
|
778
|
+
detail?: ReactNode;
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
export const SidebarAccount = ({
|
|
782
|
+
avatar,
|
|
783
|
+
name,
|
|
784
|
+
detail,
|
|
785
|
+
className,
|
|
786
|
+
...props
|
|
787
|
+
}: SidebarAccountProps) => (
|
|
788
|
+
<div
|
|
789
|
+
// The switcher's row again: a 28 mark, 10 to the name, so the two names start on one line.
|
|
790
|
+
className={cn('flex min-w-0 flex-1 items-center gap-2.5', className)}
|
|
791
|
+
data-slot="sidebar-account"
|
|
792
|
+
{...props}
|
|
793
|
+
>
|
|
794
|
+
{avatar && (
|
|
795
|
+
<span className="grid size-7 shrink-0 place-items-center overflow-hidden rounded-chip *:size-full [&>img]:object-cover">
|
|
796
|
+
{avatar}
|
|
797
|
+
</span>
|
|
798
|
+
)}
|
|
799
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
800
|
+
<span className="truncate font-medium text-neutral-600 text-xs">{name}</span>
|
|
801
|
+
{detail && <span className="truncate text-neutral-600 text-xxs">{detail}</span>}
|
|
802
|
+
</span>
|
|
803
|
+
</div>
|
|
804
|
+
);
|