@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,259 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Select as SelectPrimitive } from '@base-ui/react/select';
|
|
4
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
5
|
+
import { Check, ChevronDown, ChevronRight } from 'lucide-react';
|
|
6
|
+
import { Children, isValidElement, type ReactNode, useMemo } from 'react';
|
|
7
|
+
import { cn, type WithClassName } from '../lib/cn';
|
|
8
|
+
import { focusRing } from './button';
|
|
9
|
+
import { useFieldControl } from './field';
|
|
10
|
+
import { MenuItem } from './menu-item';
|
|
11
|
+
import { ThemeScope, usePortalContainer } from './theme';
|
|
12
|
+
|
|
13
|
+
type SelectItemEntry = { value: unknown; label: ReactNode };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Base UI's value only knows item labels it is given, and the list isn't mounted while closed, so the
|
|
17
|
+
* trigger would show the raw value. Reading the items' text from the JSX tree keeps `<SelectValue />`
|
|
18
|
+
* showing what the list shows, as it did before, without every call site repeating its labels.
|
|
19
|
+
*/
|
|
20
|
+
const collectItems = (node: ReactNode, items: SelectItemEntry[] = []) => {
|
|
21
|
+
Children.forEach(node, child => {
|
|
22
|
+
if (!isValidElement<{ children?: ReactNode; value?: unknown }>(child)) return;
|
|
23
|
+
if (child.type === SelectItem) {
|
|
24
|
+
items.push({ value: child.props.value, label: child.props.children });
|
|
25
|
+
} else {
|
|
26
|
+
collectItems(child.props.children, items);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return items;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type SelectProps<Value = string> = Omit<
|
|
33
|
+
SelectPrimitive.Root.Props<Value>,
|
|
34
|
+
'onValueChange' | 'multiple'
|
|
35
|
+
> & {
|
|
36
|
+
/**
|
|
37
|
+
* The value-to-label map the closed trigger shows. Leave it out when the SelectItems are written
|
|
38
|
+
* inline under <Select>: their labels are read from the JSX. Pass it when the items come from a
|
|
39
|
+
* component of your own (<SelectContent><RangeOptions /></SelectContent>) or a wrapper around
|
|
40
|
+
* SelectItem, since those are not walked, and the trigger would otherwise show the raw value.
|
|
41
|
+
*/
|
|
42
|
+
items?: SelectPrimitive.Root.Props<Value>['items'];
|
|
43
|
+
/** Never called with null: a single select without a null item can't be cleared. */
|
|
44
|
+
onValueChange?: (value: Value, eventDetails: SelectPrimitive.Root.ChangeEventDetails) => void;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Select = <Value = string>({
|
|
48
|
+
children,
|
|
49
|
+
items,
|
|
50
|
+
onValueChange,
|
|
51
|
+
...props
|
|
52
|
+
}: SelectProps<Value>) => {
|
|
53
|
+
const collected = useMemo(() => items ?? collectItems(children), [items, children]);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<SelectPrimitive.Root<Value>
|
|
57
|
+
items={collected}
|
|
58
|
+
onValueChange={
|
|
59
|
+
onValueChange &&
|
|
60
|
+
((value, eventDetails) => {
|
|
61
|
+
if (value !== null) onValueChange(value, eventDetails);
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
{children}
|
|
67
|
+
</SelectPrimitive.Root>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const SelectGroup = (props: SelectPrimitive.Group.Props) => (
|
|
72
|
+
<SelectPrimitive.Group data-slot="select-group" {...props} />
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
export const SelectValue = (props: SelectPrimitive.Value.Props) => (
|
|
76
|
+
<SelectPrimitive.Value data-slot="select-value" {...props} />
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export const selectTriggerVariants = cva(
|
|
80
|
+
[
|
|
81
|
+
'inline-flex shrink-0 cursor-pointer select-none items-center gap-2 whitespace-nowrap rounded-control border bg-control font-medium text-neutral-950 text-xs shadow-control transition-[border-color,background-color,color] duration-150',
|
|
82
|
+
// The placeholder answers the pointer as an Input's does: neutral-600, then neutral-700.
|
|
83
|
+
'data-placeholder:text-neutral-600 not-data-disabled:data-placeholder:hover:text-neutral-700',
|
|
84
|
+
// Base UI may keep a disabled trigger focusable, so the attribute is the reliable hook.
|
|
85
|
+
'disabled:cursor-not-allowed disabled:opacity-50 data-disabled:cursor-not-allowed data-disabled:opacity-50',
|
|
86
|
+
'[&_svg:not([class*=size-])]:size-icon [&_svg]:shrink-0',
|
|
87
|
+
focusRing,
|
|
88
|
+
],
|
|
89
|
+
{
|
|
90
|
+
variants: {
|
|
91
|
+
size: {
|
|
92
|
+
// The same two rows as Input, so a select and a text field sit level.
|
|
93
|
+
sm: 'h-control px-3',
|
|
94
|
+
md: 'h-control-lg px-3 [--spacing-icon:var(--spacing-icon-lg)]',
|
|
95
|
+
},
|
|
96
|
+
invalid: {
|
|
97
|
+
// Its icons turn with the border, as an Input's do.
|
|
98
|
+
true: 'border-error-500 [&_svg]:text-error-500',
|
|
99
|
+
// Open, it stays outlined like an Input with focus or an open DatePicker.
|
|
100
|
+
false: 'border-neutral-200 not-data-disabled:hover:border-neutral-300 not-data-disabled:hover:bg-control-hover data-popup-open:border-neutral-300',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
defaultVariants: {
|
|
104
|
+
size: 'md',
|
|
105
|
+
invalid: false,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
export type SelectTriggerProps = WithClassName<SelectPrimitive.Trigger.Props> &
|
|
111
|
+
Omit<VariantProps<typeof selectTriggerVariants>, 'invalid'> & {
|
|
112
|
+
leadingIcon?: ReactNode;
|
|
113
|
+
/**
|
|
114
|
+
* `right` gives the "Select ›" picker look of a settings row, where the trigger reads as a
|
|
115
|
+
* way into a choice rather than a field; the list still opens below it.
|
|
116
|
+
*/
|
|
117
|
+
indicator?: 'down' | 'right';
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** The library's "select input small/medium"; also the rows-per-page picker in tables. */
|
|
121
|
+
export const SelectTrigger = ({
|
|
122
|
+
size,
|
|
123
|
+
leadingIcon,
|
|
124
|
+
indicator = 'down',
|
|
125
|
+
className,
|
|
126
|
+
children,
|
|
127
|
+
id,
|
|
128
|
+
disabled,
|
|
129
|
+
'aria-describedby': describedBy,
|
|
130
|
+
'aria-invalid': ariaInvalid,
|
|
131
|
+
...props
|
|
132
|
+
}: SelectTriggerProps) => {
|
|
133
|
+
const { invalid, ...control } = useFieldControl({
|
|
134
|
+
id,
|
|
135
|
+
disabled,
|
|
136
|
+
'aria-describedby': describedBy,
|
|
137
|
+
'aria-invalid': ariaInvalid,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<SelectPrimitive.Trigger
|
|
142
|
+
className={cn(selectTriggerVariants({ size, invalid }), className)}
|
|
143
|
+
data-slot="select-trigger"
|
|
144
|
+
{...control}
|
|
145
|
+
{...props}
|
|
146
|
+
>
|
|
147
|
+
{leadingIcon && <span className="flex text-neutral-600">{leadingIcon}</span>}
|
|
148
|
+
{children}
|
|
149
|
+
<SelectPrimitive.Icon
|
|
150
|
+
render={
|
|
151
|
+
indicator === 'right' ? (
|
|
152
|
+
<ChevronRight className="ml-auto text-neutral-600" strokeWidth={2} />
|
|
153
|
+
) : (
|
|
154
|
+
<ChevronDown className="ml-auto text-neutral-600" strokeWidth={2} />
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
/>
|
|
158
|
+
</SelectPrimitive.Trigger>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export type SelectContentProps = WithClassName<SelectPrimitive.Popup.Props> &
|
|
163
|
+
Pick<
|
|
164
|
+
SelectPrimitive.Positioner.Props,
|
|
165
|
+
'side' | 'sideOffset' | 'align' | 'alignOffset' | 'alignItemWithTrigger'
|
|
166
|
+
> & {
|
|
167
|
+
/** Where the list is portalled; the body by default. */
|
|
168
|
+
container?: SelectPrimitive.Portal.Props['container'];
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/** The library's "dropdown": a raised list on the surface colour, at least as wide as its trigger. */
|
|
172
|
+
export const SelectContent = ({
|
|
173
|
+
className,
|
|
174
|
+
children,
|
|
175
|
+
side = 'bottom',
|
|
176
|
+
sideOffset = 4,
|
|
177
|
+
align = 'start',
|
|
178
|
+
alignOffset = 0,
|
|
179
|
+
// A panel under the trigger, not laid over it on the chosen item: the list reads as a dropdown.
|
|
180
|
+
alignItemWithTrigger = false,
|
|
181
|
+
container,
|
|
182
|
+
...props
|
|
183
|
+
}: SelectContentProps) => (
|
|
184
|
+
<SelectPrimitive.Portal container={usePortalContainer(container)}>
|
|
185
|
+
<ThemeScope>
|
|
186
|
+
<SelectPrimitive.Positioner
|
|
187
|
+
align={align}
|
|
188
|
+
alignItemWithTrigger={alignItemWithTrigger}
|
|
189
|
+
alignOffset={alignOffset}
|
|
190
|
+
className="z-50 outline-none"
|
|
191
|
+
data-slot="select-positioner"
|
|
192
|
+
side={side}
|
|
193
|
+
sideOffset={sideOffset}
|
|
194
|
+
>
|
|
195
|
+
<SelectPrimitive.Popup
|
|
196
|
+
className={cn(
|
|
197
|
+
// Never wider than the room beside the trigger, as a Combobox's list.
|
|
198
|
+
'relative flex max-h-(--available-height) min-w-(--anchor-width) max-w-(--available-width) flex-col overflow-hidden rounded-card border border-neutral-200 bg-neutral-50 shadow-float outline-none',
|
|
199
|
+
'origin-(--transform-origin) transition-[opacity,scale] duration-200 ease-out-strong data-ending-style:scale-95 data-starting-style:scale-95 data-ending-style:opacity-0 data-starting-style:opacity-0 motion-reduce:transition-none',
|
|
200
|
+
className,
|
|
201
|
+
)}
|
|
202
|
+
data-slot="select-content"
|
|
203
|
+
{...props}
|
|
204
|
+
>
|
|
205
|
+
{/* The list owns scrolling in Base UI, so the popup only caps the height. */}
|
|
206
|
+
<SelectPrimitive.List
|
|
207
|
+
className="flex min-h-0 flex-col gap-1 overflow-y-auto p-1"
|
|
208
|
+
data-slot="select-list"
|
|
209
|
+
>
|
|
210
|
+
{children}
|
|
211
|
+
</SelectPrimitive.List>
|
|
212
|
+
</SelectPrimitive.Popup>
|
|
213
|
+
</SelectPrimitive.Positioner>
|
|
214
|
+
</ThemeScope>
|
|
215
|
+
</SelectPrimitive.Portal>
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
export const SelectLabel = ({
|
|
219
|
+
className,
|
|
220
|
+
...props
|
|
221
|
+
}: WithClassName<SelectPrimitive.GroupLabel.Props>) => (
|
|
222
|
+
<SelectPrimitive.GroupLabel
|
|
223
|
+
className={cn('px-3 pt-1.5 pb-1 font-medium text-neutral-600 text-xxs', className)}
|
|
224
|
+
data-slot="select-label"
|
|
225
|
+
{...props}
|
|
226
|
+
/>
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
/** An option: a `MenuItem` row, with a check on the picked one. */
|
|
230
|
+
export const SelectItem = ({
|
|
231
|
+
className,
|
|
232
|
+
children,
|
|
233
|
+
...props
|
|
234
|
+
}: WithClassName<SelectPrimitive.Item.Props>) => (
|
|
235
|
+
<MenuItem
|
|
236
|
+
className={className}
|
|
237
|
+
data-slot="select-item"
|
|
238
|
+
render={<SelectPrimitive.Item {...props} />}
|
|
239
|
+
trailing={
|
|
240
|
+
<SelectPrimitive.ItemIndicator className="flex">
|
|
241
|
+
<Check strokeWidth={2} />
|
|
242
|
+
</SelectPrimitive.ItemIndicator>
|
|
243
|
+
}
|
|
244
|
+
>
|
|
245
|
+
{/* A span: rich labels (icon, name, muted year) flow inline in the list and the trigger. */}
|
|
246
|
+
<SelectPrimitive.ItemText render={<span />}>{children}</SelectPrimitive.ItemText>
|
|
247
|
+
</MenuItem>
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
export const SelectSeparator = ({
|
|
251
|
+
className,
|
|
252
|
+
...props
|
|
253
|
+
}: WithClassName<SelectPrimitive.Separator.Props>) => (
|
|
254
|
+
<SelectPrimitive.Separator
|
|
255
|
+
className={cn('-mx-1 h-px bg-neutral-200', className)}
|
|
256
|
+
data-slot="select-separator"
|
|
257
|
+
{...props}
|
|
258
|
+
/>
|
|
259
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Separator as SeparatorPrimitive } from '@base-ui/react/separator';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import { cn } from '../lib/cn';
|
|
4
|
+
|
|
5
|
+
type SeparatorProps = Omit<ComponentProps<typeof SeparatorPrimitive>, 'className'> & {
|
|
6
|
+
className?: string;
|
|
7
|
+
/** Purely visual by default, so screen readers skip it; false announces a real separator. */
|
|
8
|
+
decorative?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** 1px hairline between sections, sidebar groups and toolbar clusters. */
|
|
12
|
+
export const Separator = ({
|
|
13
|
+
orientation = 'horizontal',
|
|
14
|
+
decorative = true,
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}: SeparatorProps) => (
|
|
18
|
+
<SeparatorPrimitive
|
|
19
|
+
// Base UI always announces a separator; a decorative hairline drops out of the tree.
|
|
20
|
+
aria-orientation={decorative ? undefined : orientation}
|
|
21
|
+
className={cn(
|
|
22
|
+
'shrink-0 bg-neutral-200 data-[orientation=horizontal]:h-px data-[orientation=vertical]:h-full data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px',
|
|
23
|
+
className,
|
|
24
|
+
)}
|
|
25
|
+
data-slot="separator"
|
|
26
|
+
orientation={orientation}
|
|
27
|
+
role={decorative ? 'none' : 'separator'}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Children,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
createContext,
|
|
7
|
+
isValidElement,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
useContext,
|
|
10
|
+
useId,
|
|
11
|
+
useMemo,
|
|
12
|
+
} from 'react';
|
|
13
|
+
import { cn } from '../lib/cn';
|
|
14
|
+
import { FieldContext, FieldLabel } from './field';
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* A disabled fieldset only reaches native controls; Base UI's Switch and Select triggers are spans and
|
|
18
|
+
* buttons wired through the Field context, so the group hands its state to each row instead.
|
|
19
|
+
*/
|
|
20
|
+
const SettingGroupDisabledContext = createContext(false);
|
|
21
|
+
|
|
22
|
+
export type SettingRowProps = Omit<ComponentProps<'div'>, 'title'> & {
|
|
23
|
+
title: ReactNode;
|
|
24
|
+
description?: ReactNode;
|
|
25
|
+
/** The trailing control: a <Switch />, a <Select> picker, a <Button />, or nothing. */
|
|
26
|
+
control?: ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the title labels the control. Leave it on for a Switch, Select or Checkbox, so a click
|
|
29
|
+
* on the title toggles or opens it and a screen reader names it by the title. Turn it off for an
|
|
30
|
+
* action button, whose own text ("Add credits") must stay its name.
|
|
31
|
+
*/
|
|
32
|
+
labelControl?: boolean;
|
|
33
|
+
/** Disables a form control in the slot through the Field context and dims the text with it. */
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
/** The id the form control in the slot takes; generated when left out. */
|
|
36
|
+
controlId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The row depends on the one above it (a setting that only matters while its parent is on). In
|
|
39
|
+
* a SettingGroup it sits with that parent, 12 below it behind a guide line, with no hairline between. Disabling it
|
|
40
|
+
* while the parent is off is the caller's, through `disabled`.
|
|
41
|
+
*/
|
|
42
|
+
dependent?: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A setting: title and description on the left, its control on the right. The row is not a button;
|
|
47
|
+
* the title is the control's label, and the description is wired in as its accessible description.
|
|
48
|
+
*/
|
|
49
|
+
export const SettingRow = ({
|
|
50
|
+
title,
|
|
51
|
+
description,
|
|
52
|
+
control,
|
|
53
|
+
labelControl = true,
|
|
54
|
+
disabled: disabledProp = false,
|
|
55
|
+
controlId,
|
|
56
|
+
dependent = false,
|
|
57
|
+
className,
|
|
58
|
+
...props
|
|
59
|
+
}: SettingRowProps) => {
|
|
60
|
+
const disabled = useContext(SettingGroupDisabledContext) || disabledProp;
|
|
61
|
+
const generatedId = useId();
|
|
62
|
+
const id = controlId ?? generatedId;
|
|
63
|
+
const descriptionId = description ? `${id}-description` : undefined;
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* The row opens its own Field context rather than wrapping a <Field>: the Field's stacked layout
|
|
67
|
+
* and helper styling don't fit a row, but its controls already read their id, describedby and
|
|
68
|
+
* disabled state from the context, so a Switch or SelectTrigger dropped in the slot is wired up.
|
|
69
|
+
*/
|
|
70
|
+
const field = useMemo(
|
|
71
|
+
() => ({
|
|
72
|
+
id,
|
|
73
|
+
labelId: `${id}-label`,
|
|
74
|
+
helperId: descriptionId,
|
|
75
|
+
// The description's id is known up front, so nothing needs to register itself.
|
|
76
|
+
setHelperId: () => {},
|
|
77
|
+
invalid: false,
|
|
78
|
+
disabled,
|
|
79
|
+
}),
|
|
80
|
+
[id, descriptionId, disabled],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const titleClassName = 'font-medium text-neutral-950 text-xs';
|
|
84
|
+
|
|
85
|
+
const content = (
|
|
86
|
+
<div
|
|
87
|
+
className={cn(
|
|
88
|
+
// 38px holds a medium select without the row growing when its control changes.
|
|
89
|
+
'flex min-h-control-lg items-center justify-between gap-4',
|
|
90
|
+
className,
|
|
91
|
+
)}
|
|
92
|
+
data-dependent={dependent || undefined}
|
|
93
|
+
data-disabled={disabled || undefined}
|
|
94
|
+
data-slot="setting-row"
|
|
95
|
+
{...props}
|
|
96
|
+
>
|
|
97
|
+
<div
|
|
98
|
+
className={cn('flex min-w-0 flex-col gap-0.5', disabled && 'opacity-50')}
|
|
99
|
+
data-slot="setting-row-text"
|
|
100
|
+
>
|
|
101
|
+
{labelControl && control ? (
|
|
102
|
+
<FieldLabel
|
|
103
|
+
className={cn(
|
|
104
|
+
titleClassName,
|
|
105
|
+
'w-fit',
|
|
106
|
+
disabled ? 'cursor-not-allowed' : 'cursor-pointer',
|
|
107
|
+
)}
|
|
108
|
+
data-slot="setting-row-title"
|
|
109
|
+
>
|
|
110
|
+
{title}
|
|
111
|
+
</FieldLabel>
|
|
112
|
+
) : (
|
|
113
|
+
<p className={titleClassName} data-slot="setting-row-title" id={`${id}-label`}>
|
|
114
|
+
{title}
|
|
115
|
+
</p>
|
|
116
|
+
)}
|
|
117
|
+
{description && (
|
|
118
|
+
<p
|
|
119
|
+
className="font-normal text-neutral-600 text-xs"
|
|
120
|
+
data-slot="setting-row-description"
|
|
121
|
+
id={descriptionId}
|
|
122
|
+
>
|
|
123
|
+
{description}
|
|
124
|
+
</p>
|
|
125
|
+
)}
|
|
126
|
+
</div>
|
|
127
|
+
{control && (
|
|
128
|
+
/*
|
|
129
|
+
* A fieldset, so a disabled row reaches an action button in the slot as well: it does
|
|
130
|
+
* not read the Field context a form control does.
|
|
131
|
+
*/
|
|
132
|
+
<fieldset
|
|
133
|
+
className="flex min-w-0 shrink-0 items-center gap-2"
|
|
134
|
+
data-slot="setting-row-control"
|
|
135
|
+
disabled={disabled || undefined}
|
|
136
|
+
>
|
|
137
|
+
{control}
|
|
138
|
+
</fieldset>
|
|
139
|
+
)}
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// An action button in the slot must not pick up the id or the description meant for a form control.
|
|
144
|
+
return labelControl ? (
|
|
145
|
+
<FieldContext.Provider value={field}>{content}</FieldContext.Provider>
|
|
146
|
+
) : (
|
|
147
|
+
content
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export type SettingGroupProps = Omit<ComponentProps<'fieldset'>, 'title'> & {
|
|
152
|
+
/** A quiet heading over the rows, such as "Notifications"; it also names the group. */
|
|
153
|
+
title?: ReactNode;
|
|
154
|
+
/**
|
|
155
|
+
* `ruled` (the default): settings 24, a hairline and 24 apart, a dependent 12 under its parent
|
|
156
|
+
* behind a guide line, for a group of plain settings. `boxed`: each setting with its dependents
|
|
157
|
+
* a bordered box of its own, 8 apart, for a group whose settings carry dependents that must hold
|
|
158
|
+
* together.
|
|
159
|
+
*/
|
|
160
|
+
layout?: 'ruled' | 'boxed';
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/** Whether a child depends on the setting before it: a `dependent` row, or an eyebrow marked so. */
|
|
164
|
+
const isDependent = (child: ReactNode) =>
|
|
165
|
+
isValidElement<{ dependent?: boolean; 'data-dependent'?: unknown }>(child) &&
|
|
166
|
+
Boolean(child.props.dependent || child.props['data-dependent'] !== undefined);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The children in boxes: a box starts at every setting and takes the dependents after it. Inside, the
|
|
170
|
+
* setting and its dependents are two groups, 20 apart; the dependents are plain rows 12 apart.
|
|
171
|
+
*/
|
|
172
|
+
const boxes = (children: ReactNode) => {
|
|
173
|
+
const runs: { head: ReactNode; dependents: ReactNode[] }[] = [];
|
|
174
|
+
for (const child of Children.toArray(children)) {
|
|
175
|
+
const last = runs[runs.length - 1];
|
|
176
|
+
if (last && isDependent(child)) last.dependents.push(child);
|
|
177
|
+
else runs.push({ head: child, dependents: [] });
|
|
178
|
+
}
|
|
179
|
+
return runs.map((run, index) => (
|
|
180
|
+
<div
|
|
181
|
+
className="flex flex-col gap-5 rounded-control border border-neutral-200 p-4"
|
|
182
|
+
data-slot="setting-box"
|
|
183
|
+
// The runs follow the children's order and never reorder, so the index is a stable key.
|
|
184
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: see above
|
|
185
|
+
key={index}
|
|
186
|
+
>
|
|
187
|
+
{run.head}
|
|
188
|
+
{run.dependents.length > 0 && (
|
|
189
|
+
<div className="flex flex-col gap-3">{run.dependents}</div>
|
|
190
|
+
)}
|
|
191
|
+
</div>
|
|
192
|
+
));
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Setting rows under an optional quiet title, 24, a hairline at the content's width and 24 apart. A
|
|
197
|
+
* `dependent` row sits with the row above it, 12 below with no hairline between, stepped in behind a
|
|
198
|
+
* guide line, so the pair reads as one setting; `layout="boxed"` puts each setting and its
|
|
199
|
+
* dependents in a bordered box instead. Several dependents take
|
|
200
|
+
* an eyebrow naming what they belong to; mark that eyebrow `data-dependent` too, so it stays with
|
|
201
|
+
* the parent.
|
|
202
|
+
*
|
|
203
|
+
* In a card, a titled group is the card's head and stage (theme.css, card-frame): plain, nothing
|
|
204
|
+
* changes; in a theme that frames its cards, the title stands on the frame and the rows on the
|
|
205
|
+
* stage, and a second group in the same card stands a frame's padding below the first. An untitled
|
|
206
|
+
* group has no head, so its rows stay plain on the card; outside a card a group is never framed.
|
|
207
|
+
*/
|
|
208
|
+
export const SettingGroup = ({
|
|
209
|
+
title,
|
|
210
|
+
layout = 'ruled',
|
|
211
|
+
disabled = false,
|
|
212
|
+
className,
|
|
213
|
+
children,
|
|
214
|
+
...props
|
|
215
|
+
}: SettingGroupProps) => {
|
|
216
|
+
const titleId = useId();
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
// A fieldset is the native group: a screen reader names it by the title on entering a control.
|
|
220
|
+
<fieldset
|
|
221
|
+
aria-labelledby={title ? titleId : undefined}
|
|
222
|
+
className={cn(
|
|
223
|
+
'flex min-w-0 flex-col',
|
|
224
|
+
// Framed, the head's padding parts the title from the stage, and a group after another
|
|
225
|
+
// stands the frame's padding off it; plain, 12 and nothing, as ever.
|
|
226
|
+
'[--setting-group-gap:var(--cards-framed)_0px] [--setting-group-space:var(--cards-framed)_var(--spacing)]',
|
|
227
|
+
'gap-(--setting-group-gap,--spacing(3))',
|
|
228
|
+
'[[data-slot=setting-group]+&]:mt-(--setting-group-space,0px)',
|
|
229
|
+
// Only a card frames: outside one, the group is plain in every theme.
|
|
230
|
+
'[&:not(.card-frame_*)]:[--cards-framed:initial]',
|
|
231
|
+
className,
|
|
232
|
+
)}
|
|
233
|
+
data-disabled={disabled || undefined}
|
|
234
|
+
data-slot="setting-group"
|
|
235
|
+
disabled={disabled}
|
|
236
|
+
{...props}
|
|
237
|
+
>
|
|
238
|
+
{title && (
|
|
239
|
+
<p
|
|
240
|
+
className="card-head font-normal text-neutral-600 text-xs"
|
|
241
|
+
data-slot="setting-group-title"
|
|
242
|
+
id={titleId}
|
|
243
|
+
>
|
|
244
|
+
{title}
|
|
245
|
+
</p>
|
|
246
|
+
)}
|
|
247
|
+
{layout === 'boxed' ? (
|
|
248
|
+
<div
|
|
249
|
+
className={cn('flex flex-col gap-2', title && 'card-stage')}
|
|
250
|
+
data-slot="setting-group-rows"
|
|
251
|
+
>
|
|
252
|
+
<SettingGroupDisabledContext.Provider value={disabled}>
|
|
253
|
+
{boxes(children)}
|
|
254
|
+
</SettingGroupDisabledContext.Provider>
|
|
255
|
+
</div>
|
|
256
|
+
) : (
|
|
257
|
+
<div
|
|
258
|
+
className={cn(
|
|
259
|
+
'flex flex-col gap-6',
|
|
260
|
+
title && 'card-stage',
|
|
261
|
+
// 24, a hairline and 24 between settings; a row that depends on the one before has none.
|
|
262
|
+
'[&>*+*:not([data-dependent])]:border-neutral-200 [&>*+*:not([data-dependent])]:border-t [&>*+*:not([data-dependent])]:pt-6',
|
|
263
|
+
// A dependent sits 12 under its parent, stepped in behind a guide line 4 from the edge.
|
|
264
|
+
'[&>[data-dependent]]:-mt-3 [&>[data-dependent]]:ml-1 [&>[data-dependent]]:border-neutral-200 [&>[data-dependent]]:border-l [&>[data-dependent]]:pl-4',
|
|
265
|
+
// Dependents in a row keep the line unbroken: the 12 between them is padding, not a gap.
|
|
266
|
+
'[&>[data-dependent]+[data-dependent]]:-mt-6 [&>[data-dependent]+[data-dependent]]:pt-3',
|
|
267
|
+
)}
|
|
268
|
+
data-slot="setting-group-rows"
|
|
269
|
+
>
|
|
270
|
+
<SettingGroupDisabledContext.Provider value={disabled}>
|
|
271
|
+
{children}
|
|
272
|
+
</SettingGroupDisabledContext.Provider>
|
|
273
|
+
</div>
|
|
274
|
+
)}
|
|
275
|
+
</fieldset>
|
|
276
|
+
);
|
|
277
|
+
};
|