@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,35 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ChartColor } from './lib/color.js';
|
|
3
|
+
export type SparklineLabel = {
|
|
4
|
+
/** The reading the label stands under: its index in `data`. */
|
|
5
|
+
at: number;
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export type SparklineProps = {
|
|
9
|
+
/** The readings, oldest first. */
|
|
10
|
+
data: readonly number[];
|
|
11
|
+
/** `area`, a line over its wash; `line`, the line alone; `bar`, a bar a reading. */
|
|
12
|
+
kind?: 'area' | 'line' | 'bar';
|
|
13
|
+
/**
|
|
14
|
+
* The reading that is now. A line ends its solid stroke there and marks it with a dot;
|
|
15
|
+
* bars before it are quieter and it stands at full strength. What comes after is a
|
|
16
|
+
* forecast: a dashed line, or bars in a faint tint.
|
|
17
|
+
*/
|
|
18
|
+
current?: number;
|
|
19
|
+
/** The series' colour, `series-1` unless given. */
|
|
20
|
+
color?: ChartColor;
|
|
21
|
+
/** The marks' height in px, the labels under them not counted. */
|
|
22
|
+
height?: number;
|
|
23
|
+
/** A few places named under the marks, 11 in the quiet ink: the start, now, the end. */
|
|
24
|
+
labels?: readonly SparklineLabel[];
|
|
25
|
+
/** What the line shows, for a screen reader: "Net revenue, May 2026 to June 2027". */
|
|
26
|
+
'aria-label': string;
|
|
27
|
+
className?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A measure's recent shape in a few dozen pixels, for a stat card: no axes, no grid, no frame,
|
|
31
|
+
* since the card's figure says how much and the line only says which way it went. A few places
|
|
32
|
+
* named under it give the stretch it covers. It reads at a glance or not at all, so it takes
|
|
33
|
+
* no pointer: the readings are in the card's figures and in the chart it opens to.
|
|
34
|
+
*/
|
|
35
|
+
export declare const Sparkline: ({ data, kind, current, color, height, labels, "aria-label": label, className, }: SparklineProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn.js';
|
|
5
|
+
import { chartColor } from './lib/color.js';
|
|
6
|
+
import { areaPath, curvePath } from './lib/path.js';
|
|
7
|
+
import { extent, scalePoint, slotScale } from './lib/scale.js';
|
|
8
|
+
import { useWidth } from './lib/use-size.js';
|
|
9
|
+
/** Bars take this share of their slot, and never more than this wide. */
|
|
10
|
+
const BAR_SHARE = 0.62;
|
|
11
|
+
const BAR_MAX = 12;
|
|
12
|
+
/** Room kept clear over the highest reading, so a dot on it is not cut. */
|
|
13
|
+
const HEADROOM = 4;
|
|
14
|
+
/** The least room between two labels under the marks. */
|
|
15
|
+
const LABEL_GAP = 8;
|
|
16
|
+
/**
|
|
17
|
+
* Where a line's reading sits across: held in from both edges by the dot's reach, since the
|
|
18
|
+
* reveal clips the marks to their box and a dot on the edge would lose its half.
|
|
19
|
+
*/
|
|
20
|
+
const lineX = (index, count, width) => HEADROOM + scalePoint(index, count, width - HEADROOM * 2);
|
|
21
|
+
/**
|
|
22
|
+
* A measure's recent shape in a few dozen pixels, for a stat card: no axes, no grid, no frame,
|
|
23
|
+
* since the card's figure says how much and the line only says which way it went. A few places
|
|
24
|
+
* named under it give the stretch it covers. It reads at a glance or not at all, so it takes
|
|
25
|
+
* no pointer: the readings are in the card's figures and in the chart it opens to.
|
|
26
|
+
*/
|
|
27
|
+
export const Sparkline = ({ data, kind = 'area', current, color = 'series-1', height = 40, labels, 'aria-label': label, className, }) => {
|
|
28
|
+
const [ref, width] = useWidth();
|
|
29
|
+
const id = useId();
|
|
30
|
+
const ink = chartColor(color);
|
|
31
|
+
const now = current ?? data.length - 1;
|
|
32
|
+
return (_jsxs("figure", { "aria-label": label, className: cn('m-0 flex min-w-0 flex-col', className), role: "img", children: [_jsx("div", { className: "relative w-full", ref: ref, style: { height }, children: width > 0 && data.length > 0 && (_jsx("svg", { "aria-hidden": "true", className: "absolute inset-0 overflow-visible motion-safe:animate-reveal", height: height, width: width, children: kind === 'bar' ? (_jsx(Bars, { data: data, height: height, ink: ink, now: now, width: width })) : (_jsx(Line, { data: data, height: height, id: id, ink: ink, now: now, wash: kind === 'area', width: width })) })) }), labels && labels.length > 0 && (_jsx(SparklineLabels, { count: data.length, kind: kind, labels: labels, width: width }))] }));
|
|
33
|
+
};
|
|
34
|
+
const Line = ({ data, width, height, ink, now, wash, id, }) => {
|
|
35
|
+
const { min, max } = extent(data);
|
|
36
|
+
/*
|
|
37
|
+
* A line stands on its own range, not on zero: the shape is what it is for. But never on less
|
|
38
|
+
* than a fifth of its level, so a measure that held steady reads as steady rather than as a
|
|
39
|
+
* swing of a few seconds blown up to the full height.
|
|
40
|
+
*/
|
|
41
|
+
const middle = (min + max) / 2;
|
|
42
|
+
const span = Math.max(max - min, Math.abs(middle) * 0.2) || 1;
|
|
43
|
+
const low = middle - span / 2;
|
|
44
|
+
const points = data.map((value, i) => ({
|
|
45
|
+
x: lineX(i, data.length, width),
|
|
46
|
+
y: HEADROOM + (1 - (value - low) / span) * (height - HEADROOM * 2),
|
|
47
|
+
}));
|
|
48
|
+
const done = points.slice(0, now + 1);
|
|
49
|
+
const ahead = points.slice(now);
|
|
50
|
+
const dot = points[now];
|
|
51
|
+
return (_jsxs(_Fragment, { children: [wash && done.length > 1 && (_jsxs(_Fragment, { children: [_jsx("defs", { children: _jsxs("linearGradient", { id: `${id}-wash`, x1: "0", x2: "0", y1: "0", y2: "1", children: [_jsx("stop", { offset: "0", stopColor: ink, stopOpacity: 0.2 }), _jsx("stop", { offset: "1", stopColor: ink, stopOpacity: 0.04 })] }) }), _jsx("path", { d: areaPath(done, height), fill: `url(#${id}-wash)` })] })), ahead.length > 1 && (_jsx("path", { d: curvePath(ahead), fill: "none", stroke: ink, strokeDasharray: "6 4", strokeOpacity: 0.5, strokeWidth: 1.5 })), done.length > 1 && (_jsx("path", { d: curvePath(done), fill: "none", stroke: ink, strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2 })), dot && (_jsx("circle", { cx: dot.x, cy: dot.y, fill: ink, r: 3, stroke: "var(--color-neutral-50)", strokeWidth: 2 }))] }));
|
|
52
|
+
};
|
|
53
|
+
const Bars = ({ data, width, height, ink, now }) => {
|
|
54
|
+
const { max } = extent([0, ...data]);
|
|
55
|
+
const { slot, center } = slotScale(data.length, width);
|
|
56
|
+
const bar = Math.max(2, Math.min(slot * BAR_SHARE, BAR_MAX));
|
|
57
|
+
const radius = Math.min(3, bar / 2);
|
|
58
|
+
return (_jsx(_Fragment, { children: data.map((value, i) => {
|
|
59
|
+
const size = Math.max(2, (value / (max || 1)) * height);
|
|
60
|
+
// Before now quieter, now itself full, after it a forecast in a faint tint.
|
|
61
|
+
const opacity = i === now ? 1 : i < now ? 0.45 : 0.18;
|
|
62
|
+
return (_jsx("path", { d: barPath(center(i) - bar / 2, height - size, bar, size, radius), fill: ink, fillOpacity: opacity }, i));
|
|
63
|
+
}) }));
|
|
64
|
+
};
|
|
65
|
+
/** A bar flat on the baseline, rounded at its head. */
|
|
66
|
+
const barPath = (x, y, w, h, r) => {
|
|
67
|
+
const radius = Math.min(r, h);
|
|
68
|
+
return `M${x},${y + h} L${x},${y + radius} Q${x},${y} ${x + radius},${y} L${x + w - radius},${y} Q${x + w},${y} ${x + w},${y + radius} L${x + w},${y + h} Z`;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The named places, each under its reading: the first held to the left edge, the last to the
|
|
72
|
+
* right, one between centred on its reading. One that would run into a neighbour is left out,
|
|
73
|
+
* the ends kept first.
|
|
74
|
+
*/
|
|
75
|
+
const SparklineLabels = ({ labels, count, width, kind, }) => {
|
|
76
|
+
const xOf = (at) => kind === 'bar' ? slotScale(count, width).center(at) : lineX(at, count, width);
|
|
77
|
+
const ref = useRef(null);
|
|
78
|
+
// Each label's width as set, measured: the theme's font decides it, not a guess.
|
|
79
|
+
const [sizes, setSizes] = useState([]);
|
|
80
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: new labels are new widths to measure
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
const node = ref.current;
|
|
83
|
+
if (!node || width === 0)
|
|
84
|
+
return;
|
|
85
|
+
setSizes(Array.from(node.children, child => child.offsetWidth));
|
|
86
|
+
}, [width, labels]);
|
|
87
|
+
const lastIndex = labels.length > 1 ? labels.length - 1 : -1;
|
|
88
|
+
const shown = new Set([0, lastIndex]);
|
|
89
|
+
if (sizes.length === labels.length) {
|
|
90
|
+
// The ends stand first; each label between is kept when it clears both its neighbours.
|
|
91
|
+
const end = lastIndex > 0 ? width - (sizes[lastIndex] ?? 0) - LABEL_GAP : width;
|
|
92
|
+
let reach = (sizes[0] ?? 0) + LABEL_GAP;
|
|
93
|
+
for (let i = 1; i < lastIndex; i++) {
|
|
94
|
+
const half = (sizes[i] ?? 0) / 2;
|
|
95
|
+
const x = xOf(labels[i]?.at ?? 0);
|
|
96
|
+
if (x - half >= reach && x + half <= end) {
|
|
97
|
+
shown.add(i);
|
|
98
|
+
reach = x + half + LABEL_GAP;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return (_jsx("div", { className: "relative mt-2 h-3.5 text-[11px] text-neutral-600 tabular-nums leading-3.5", ref: ref, children: labels.map(({ at, label }, i) => (_jsx("span", { className: "absolute top-0 whitespace-nowrap", style: {
|
|
103
|
+
...(i === 0
|
|
104
|
+
? { left: 0 }
|
|
105
|
+
: i === lastIndex
|
|
106
|
+
? { right: 0 }
|
|
107
|
+
: { left: xOf(at), transform: 'translateX(-50%)' }),
|
|
108
|
+
visibility: shown.has(i) ? undefined : 'hidden',
|
|
109
|
+
}, children: label }, i))) }));
|
|
110
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type ChartColor } from './lib/color.js';
|
|
3
|
+
export type ChartTooltipRow = {
|
|
4
|
+
name: ReactNode;
|
|
5
|
+
value: ReactNode;
|
|
6
|
+
/** Left out on a total, which keys nothing. */
|
|
7
|
+
color?: ChartColor;
|
|
8
|
+
};
|
|
9
|
+
export type ChartTooltipProps = {
|
|
10
|
+
/** The x the rows are read at: a date, or the category. */
|
|
11
|
+
title?: ReactNode;
|
|
12
|
+
rows?: readonly ChartTooltipRow[];
|
|
13
|
+
/** Appended under the rows, divided from them: a stacked chart's total. */
|
|
14
|
+
footer?: ReactNode;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Which side the rule it speaks from is on. That bottom corner is left square, so the
|
|
18
|
+
* readout reads as a bubble said from the rule. Only where there is a rule to speak from:
|
|
19
|
+
* beside a bar, or on its own, all four corners are round.
|
|
20
|
+
*/
|
|
21
|
+
tail?: 'left' | 'right' | 'none';
|
|
22
|
+
className?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The readout beside the point a chart is hovered at. Also exported on its own, so a
|
|
26
|
+
* custom readout is written in the same surface as every other chart's.
|
|
27
|
+
*
|
|
28
|
+
* Beside a line's rule it is a bubble: three round corners and one square, the bottom one
|
|
29
|
+
* on the rule's side. Each series is keyed by a short upright stroke of its colour.
|
|
30
|
+
* The value leads and the name follows, the legend's order inverted: here the reader
|
|
31
|
+
* already knows which series they are on and wants the figure.
|
|
32
|
+
*/
|
|
33
|
+
export declare const ChartTooltip: ({ title, rows, footer, children, tail, className, }: ChartTooltipProps) => import("react").JSX.Element;
|
|
34
|
+
/** One series at the read x: its dot and name, then its value. */
|
|
35
|
+
export declare const ChartTooltipRow: ({ name, value, color }: ChartTooltipRow) => import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cn } from '../lib/cn.js';
|
|
4
|
+
import { chartColor } from './lib/color.js';
|
|
5
|
+
/**
|
|
6
|
+
* The readout beside the point a chart is hovered at. Also exported on its own, so a
|
|
7
|
+
* custom readout is written in the same surface as every other chart's.
|
|
8
|
+
*
|
|
9
|
+
* Beside a line's rule it is a bubble: three round corners and one square, the bottom one
|
|
10
|
+
* on the rule's side. Each series is keyed by a short upright stroke of its colour.
|
|
11
|
+
* The value leads and the name follows, the legend's order inverted: here the reader
|
|
12
|
+
* already knows which series they are on and wants the figure.
|
|
13
|
+
*/
|
|
14
|
+
export const ChartTooltip = ({ title, rows, footer, children, tail = 'none', className, }) => (_jsxs("div", { className: cn('min-w-35 overflow-hidden rounded-item border border-neutral-200 bg-neutral-50 shadow-float', tail === 'left' && 'rounded-bl-none', tail === 'right' && 'rounded-br-none', className), "data-slot": "chart-tooltip", children: [_jsxs("div", { className: "p-3", children: [title != null && (_jsx("p", { className: "mb-2 font-medium text-neutral-950 text-xs", "data-slot": "chart-tooltip-title", children: title })), rows && rows.length > 0 && (_jsx("ul", { className: "flex flex-col gap-1.5", "data-slot": "chart-tooltip-rows", children: rows.map((row, index) => (_jsx(ChartTooltipRow
|
|
15
|
+
// A row is its series; two series may share a name, so the place is the key.
|
|
16
|
+
, { ...row }, `${index}-${String(row.name)}`))) })), children] }), footer != null && (
|
|
17
|
+
// The rule runs edge to edge: a divider that stops short of the sides is a box in a box.
|
|
18
|
+
_jsx("div", { className: "border-neutral-200 border-t px-3 py-2", "data-slot": "chart-tooltip-footer", children: footer }))] }));
|
|
19
|
+
/** One series at the read x: its dot and name, then its value. */
|
|
20
|
+
export const ChartTooltipRow = ({ name, value, color }) => (_jsxs("li", { className: "flex items-center justify-between gap-4", "data-slot": "chart-tooltip-row", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [color ? (_jsx("span", { "aria-hidden": true, className: "h-3 w-0.75 shrink-0 rounded-full", style: { background: chartColor(color) } })) : (
|
|
21
|
+
// A total keeps the rows' text aligned without claiming a colour of its own.
|
|
22
|
+
_jsx("span", { "aria-hidden": true, className: "h-3 w-0.75 shrink-0" })), _jsx("span", { className: "truncate text-neutral-600 text-xs", children: name })] }), _jsx("span", { className: "shrink-0 font-medium text-neutral-950 text-xs tabular-nums", children: value })] }));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ChartColor } from './lib/color.js';
|
|
3
|
+
export type TreemapItem = {
|
|
4
|
+
name: string;
|
|
5
|
+
value: number;
|
|
6
|
+
/** The change on the period before, as it should read: "+2.6%". */
|
|
7
|
+
delta?: string;
|
|
8
|
+
/** A 14px icon before the name. */
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
color?: ChartColor;
|
|
11
|
+
};
|
|
12
|
+
export type TreemapProps = {
|
|
13
|
+
/** Says what the chart shows; it names the chart for a screen reader. */
|
|
14
|
+
'aria-label': string;
|
|
15
|
+
data: readonly TreemapItem[];
|
|
16
|
+
height?: number;
|
|
17
|
+
/** Writes a tile's figure; its share of the whole unless given. */
|
|
18
|
+
formatValue?: (value: number, share: number) => string;
|
|
19
|
+
/** While the data loads: the chart's own shape stands in, in the skeleton wash, at the size it will have. */
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Parts of a whole as tiles, each as large as its share and as square as the shares allow.
|
|
25
|
+
* A tile is a tint of its colour, keyed by the same upright stroke the readout uses, and it
|
|
26
|
+
* says as much as it has room for: its name, then its figure, then its change.
|
|
27
|
+
*/
|
|
28
|
+
export declare const Treemap: ({ "aria-label": label, data, height, formatValue, loading, className, }: TreemapProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Badge } from '../components/badge.js';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
import { chartColor, seriesColor } from './lib/color.js';
|
|
7
|
+
import { formatNumber, formatPercent } from './lib/format.js';
|
|
8
|
+
import { PLOT_FRAME } from './lib/frame.js';
|
|
9
|
+
import { squarify } from './lib/layout.js';
|
|
10
|
+
import { useWidth } from './lib/use-size.js';
|
|
11
|
+
import { ChartTooltip } from './tooltip.js';
|
|
12
|
+
/**
|
|
13
|
+
* The stand-in's shares: one part that takes most, a few middling and a small one, as spending
|
|
14
|
+
* or traffic tends to split, so the tiles read as data waiting and not as a grid.
|
|
15
|
+
*/
|
|
16
|
+
const SKELETON_SHARES = [44, 18, 13, 11, 8, 6];
|
|
17
|
+
/** The widths of the stand-in's names, in the tiles large enough to write one. */
|
|
18
|
+
const SKELETON_NAMES = [72, 88, 64, 80, 56, 68];
|
|
19
|
+
/** A bar on a stand-in tile, a step stronger than the tile's own wash so it reads over it. */
|
|
20
|
+
const SKELETON_BAR = 'color-mix(in oklab, var(--color-neutral-950) 7%, transparent)';
|
|
21
|
+
const GAP = 4;
|
|
22
|
+
/**
|
|
23
|
+
* The tiles stand inside their frame's hairline with the same room as between them; the frame's
|
|
24
|
+
* corner is the tiles' corner grown by that inset, so the two stay concentric.
|
|
25
|
+
*/
|
|
26
|
+
const INSET = 1 + GAP;
|
|
27
|
+
/**
|
|
28
|
+
* Parts of a whole as tiles, each as large as its share and as square as the shares allow.
|
|
29
|
+
* A tile is a tint of its colour, keyed by the same upright stroke the readout uses, and it
|
|
30
|
+
* says as much as it has room for: its name, then its figure, then its change.
|
|
31
|
+
*/
|
|
32
|
+
export const Treemap = ({ 'aria-label': label, data, height = 280, formatValue, loading = false, className, }) => {
|
|
33
|
+
const [ref, width] = useWidth();
|
|
34
|
+
const [active, setActive] = useState(null);
|
|
35
|
+
const total = data.reduce((sum, item) => sum + Math.max(0, item.value), 0);
|
|
36
|
+
// While it loads, the stand-in's shares are tiled as the data will be, by the same layout.
|
|
37
|
+
const tiles = squarify(loading ? SKELETON_SHARES : data.map(item => item.value), {
|
|
38
|
+
x: INSET,
|
|
39
|
+
y: INSET,
|
|
40
|
+
width: Math.max(0, width - INSET * 2) + GAP,
|
|
41
|
+
height: Math.max(0, height - INSET * 2) + GAP,
|
|
42
|
+
});
|
|
43
|
+
return (_jsxs("figure", { "aria-busy": loading || undefined, "aria-label": label, className: cn('relative m-0 min-w-0', className), "data-slot": "treemap", children: [_jsxs("div", { className: "relative", ref: ref, style: { height }, children: [_jsxs("div", { className: "absolute inset-0 overflow-hidden", style: { borderRadius: `calc(var(--radius-item) + ${INSET}px)` }, children: [width > 0 && loading && (_jsx("div", { "aria-hidden": true, className: "absolute inset-0", "data-slot": "chart-skeleton", children: tiles.map((tile, index) => {
|
|
44
|
+
if (tile.width <= GAP || tile.height <= GAP)
|
|
45
|
+
return null;
|
|
46
|
+
const w = tile.width - GAP;
|
|
47
|
+
const h = tile.height - GAP;
|
|
48
|
+
return (_jsxs("div", { className: "skeleton absolute flex flex-col justify-between overflow-hidden rounded-item p-5", style: { height: h, left: tile.x, top: tile.y, width: w }, children: [w >= 96 && h >= 56 && (_jsxs("span", { className: "flex min-w-0 items-center text-xs", children: [_jsx("span", { className: "invisible w-0", children: "0" }), _jsx("span", { className: "skeleton h-2.5 min-w-0 rounded-chip", style: {
|
|
49
|
+
backgroundColor: SKELETON_BAR,
|
|
50
|
+
width: SKELETON_NAMES[index] ?? 64,
|
|
51
|
+
} })] })), h >= 84 && w >= 80 && (_jsxs("span", { className: "flex min-w-0 items-center text-lg", children: [_jsx("span", { className: "invisible w-0", children: "0" }), _jsx("span", { className: "skeleton h-[0.75em] w-12 min-w-0 rounded-chip", style: { backgroundColor: SKELETON_BAR } })] }))] }, index));
|
|
52
|
+
}) })), width > 0 &&
|
|
53
|
+
!loading &&
|
|
54
|
+
data.map((item, index) => {
|
|
55
|
+
const tile = tiles[index];
|
|
56
|
+
if (!tile || tile.width <= GAP || tile.height <= GAP)
|
|
57
|
+
return null;
|
|
58
|
+
const w = tile.width - GAP;
|
|
59
|
+
const h = tile.height - GAP;
|
|
60
|
+
const color = chartColor(item.color ?? seriesColor(index));
|
|
61
|
+
const share = total ? item.value / total : 0;
|
|
62
|
+
const named = w >= 96 && h >= 56;
|
|
63
|
+
const figured = h >= 84 && w >= 80;
|
|
64
|
+
return (_jsxs("div", { className: "absolute flex flex-col justify-between overflow-hidden rounded-item p-5 transition-colors duration-150 motion-reduce:transition-none", onPointerEnter: () => setActive(index), onPointerLeave: () => setActive(null), style: {
|
|
65
|
+
background: `color-mix(in oklab, ${color} ${active === index ? 26 : 16}%, transparent)`,
|
|
66
|
+
height: h,
|
|
67
|
+
left: tile.x,
|
|
68
|
+
top: tile.y,
|
|
69
|
+
width: w,
|
|
70
|
+
}, children: [named && (_jsxs("span", { className: "flex min-w-0 items-center gap-2 font-medium text-neutral-950 text-xs", children: [!item.icon && (_jsx("span", { "aria-hidden": true, className: "h-3 w-0.75 shrink-0 rounded-full", style: { background: color } })), item.icon && (_jsx("span", { "aria-hidden": true, className: "flex shrink-0 [&_svg]:size-3.5", style: { color }, children: item.icon })), _jsx("span", { className: "truncate", children: item.name })] })), figured && (_jsxs("span", { className: "flex min-w-0 items-end justify-between gap-2", children: [_jsx("span", { className: "font-medium text-lg text-neutral-950 tabular-nums", children: formatValue
|
|
71
|
+
? formatValue(item.value, share)
|
|
72
|
+
: formatPercent(share) }), item.delta && w >= 120 && (_jsx(Badge, { className: "self-center text-neutral-950 tabular-nums", style: {
|
|
73
|
+
background: `color-mix(in oklab, ${color} 24%, transparent)`,
|
|
74
|
+
}, variant: "pill", children: item.delta }))] }))] }, item.name));
|
|
75
|
+
})] }), (() => {
|
|
76
|
+
// A tile too small to write its own name and figure is read out beside it, in
|
|
77
|
+
// the readout every chart uses.
|
|
78
|
+
const tile = active !== null && !loading ? tiles[active] : undefined;
|
|
79
|
+
const item = active !== null ? data[active] : undefined;
|
|
80
|
+
if (!tile || !item)
|
|
81
|
+
return null;
|
|
82
|
+
const w = tile.width - GAP;
|
|
83
|
+
const h = tile.height - GAP;
|
|
84
|
+
if (w >= 80 && h >= 84)
|
|
85
|
+
return null;
|
|
86
|
+
const share = total ? item.value / total : 0;
|
|
87
|
+
const left = tile.x + w / 2 < width / 2;
|
|
88
|
+
return (_jsx("div", { className: "pointer-events-none absolute z-10", style: {
|
|
89
|
+
left: left ? tile.x + w + 8 : undefined,
|
|
90
|
+
right: left ? undefined : width - tile.x + 8,
|
|
91
|
+
top: Math.max(0, Math.min(height - 64, tile.y)),
|
|
92
|
+
}, children: _jsx(ChartTooltip, { rows: [
|
|
93
|
+
{
|
|
94
|
+
color: item.color ??
|
|
95
|
+
`series-${Math.min((active ?? 0) + 1, 5)}`,
|
|
96
|
+
name: item.name,
|
|
97
|
+
value: formatValue
|
|
98
|
+
? formatValue(item.value, share)
|
|
99
|
+
: formatPercent(share),
|
|
100
|
+
},
|
|
101
|
+
] }) }));
|
|
102
|
+
})(), _jsx("div", { "aria-hidden": true, className: cn(PLOT_FRAME, 'inset-0'), style: { borderRadius: `calc(var(--radius-item) + ${INSET}px)` } })] }), _jsx("div", { className: cn('sr-only', loading && 'hidden'), children: _jsxs("table", { children: [_jsx("caption", { children: label }), _jsx("tbody", { children: data.map(item => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: item.name }), _jsx("td", { children: formatNumber(item.value) }), _jsx("td", { children: formatPercent(total ? item.value / total : 0) })] }, item.name))) })] }) })] }));
|
|
103
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type UptimeState = 'operational' | 'degraded' | 'outage' | 'none';
|
|
3
|
+
export type UptimeDay = {
|
|
4
|
+
date: Date;
|
|
5
|
+
state: UptimeState;
|
|
6
|
+
/** Minutes the service was down that day; an outage without it counts the whole day. */
|
|
7
|
+
downtime?: number;
|
|
8
|
+
/** A line on what happened, read in the readout: "Webhooks queued for 40 minutes". */
|
|
9
|
+
note?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export type UptimeService = {
|
|
12
|
+
name: string;
|
|
13
|
+
/** One entry a day, oldest first. */
|
|
14
|
+
days: readonly UptimeDay[];
|
|
15
|
+
/** The share of the period it was up, 0 to 1; worked out from the days' downtime unless given. */
|
|
16
|
+
uptime?: number;
|
|
17
|
+
};
|
|
18
|
+
export type UptimeStripProps = {
|
|
19
|
+
/** Says what the chart shows; it names the chart for a screen reader. */
|
|
20
|
+
'aria-label': string;
|
|
21
|
+
services: readonly UptimeService[];
|
|
22
|
+
/** How many of the most recent days a row shows at most. */
|
|
23
|
+
days?: number;
|
|
24
|
+
/** The height of a day's block, in px. */
|
|
25
|
+
blockHeight?: number;
|
|
26
|
+
/** Writes the uptime at a row's end; a percentage to two decimals unless given. */
|
|
27
|
+
formatUptime?: (share: number) => string;
|
|
28
|
+
/** The line shown when there is nothing to draw. */
|
|
29
|
+
emptyLabel?: string;
|
|
30
|
+
/** While the data loads: the chart's own shape stands in, in the skeleton wash, at the size it will have. */
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
className?: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A row of days for each service, the most recent at the right, each day a block in the
|
|
36
|
+
* colour of how it went. The blocks share the width between them; where it is too narrow
|
|
37
|
+
* for every day, a row shows the most recent days that fit rather than squeeze a block
|
|
38
|
+
* below a few pixels. The uptime closes the row, and a block names its day when pointed at.
|
|
39
|
+
*/
|
|
40
|
+
export declare const UptimeStrip: ({ "aria-label": label, services, days, blockHeight, formatUptime, emptyLabel, loading, className, }: UptimeStripProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useLayoutEffect, useState } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn.js';
|
|
5
|
+
import { chartColor } from './lib/color.js';
|
|
6
|
+
import { formatDateLong, formatPercent } from './lib/format.js';
|
|
7
|
+
import { PLOT_FRAME } from './lib/frame.js';
|
|
8
|
+
import { useWidth } from './lib/use-size.js';
|
|
9
|
+
import { ChartTooltip } from './tooltip.js';
|
|
10
|
+
const GAP = 2;
|
|
11
|
+
/** Narrower than this a block stops reading as a day, so the row shows fewer days instead. */
|
|
12
|
+
const MIN_BLOCK = 3;
|
|
13
|
+
const DAY_MINUTES = 24 * 60;
|
|
14
|
+
/** Under this the name and the uptime go over the row rather than beside it. */
|
|
15
|
+
const STACK_UNDER = 520;
|
|
16
|
+
const STATES = {
|
|
17
|
+
// The usual day is a tint, so the days that went wrong are the ones that carry.
|
|
18
|
+
operational: {
|
|
19
|
+
label: 'Operational',
|
|
20
|
+
color: `color-mix(in oklab, ${chartColor('success')} 45%, transparent)`,
|
|
21
|
+
},
|
|
22
|
+
degraded: { label: 'Degraded', color: chartColor('warning') },
|
|
23
|
+
outage: { label: 'Outage', color: chartColor('error') },
|
|
24
|
+
none: { label: 'No data', color: 'var(--color-neutral-200)' },
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The stand-in rows while the days load, as the widths of a name and an uptime in px: names of
|
|
28
|
+
* a word, uptimes of a figure like 99.93%, so the columns are near the width they will have.
|
|
29
|
+
*/
|
|
30
|
+
const SKELETON_ROWS = [
|
|
31
|
+
[48, 44],
|
|
32
|
+
[72, 40],
|
|
33
|
+
[64, 44],
|
|
34
|
+
[40, 36],
|
|
35
|
+
];
|
|
36
|
+
/** A line of text standing in as a bar, on the text's own line so the row keeps its height. */
|
|
37
|
+
const SkeletonText = ({ width, end = false, text, figure = false, }) => text ? (_jsxs("span", { className: cn('relative flex min-w-0 items-center text-xs', end && 'justify-end'), children: [_jsx("span", { className: cn('invisible truncate', figure && 'font-medium tabular-nums'), children: text }), _jsx("span", { className: cn('skeleton absolute h-2.5 rounded-chip', end ? 'right-0' : 'left-0'), style: { width: `min(${width}px, 100%)` } })] })) : (_jsxs("span", { className: cn('flex shrink-0 items-center text-xs', end && 'justify-end'), children: [_jsx("span", { className: "invisible w-0", children: "0" }), _jsx("span", { className: "skeleton h-2.5 rounded-chip", style: { width } })] }));
|
|
38
|
+
const downtimeOf = (day) => day.downtime ?? (day.state === 'outage' ? DAY_MINUTES : 0);
|
|
39
|
+
/** The share of the counted days the service was up; days without data are left out. */
|
|
40
|
+
const uptimeOf = (service, days) => {
|
|
41
|
+
if (service.uptime != null)
|
|
42
|
+
return service.uptime;
|
|
43
|
+
const counted = service.days.slice(-days).filter(day => day.state !== 'none');
|
|
44
|
+
if (counted.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
const down = counted.reduce((sum, day) => sum + downtimeOf(day), 0);
|
|
47
|
+
return 1 - down / (counted.length * DAY_MINUTES);
|
|
48
|
+
};
|
|
49
|
+
const writeUptime = (share) => formatPercent(share, share === 1 ? 0 : 2);
|
|
50
|
+
/** "No downtime", "12 min", "1 h 24 min". */
|
|
51
|
+
const writeDowntime = (minutes) => {
|
|
52
|
+
if (minutes <= 0)
|
|
53
|
+
return 'None';
|
|
54
|
+
if (minutes < 60)
|
|
55
|
+
return `${Math.round(minutes)} min`;
|
|
56
|
+
const h = Math.floor(minutes / 60);
|
|
57
|
+
const m = Math.round(minutes % 60);
|
|
58
|
+
return m ? `${h} h ${m} min` : `${h} h`;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A row of days for each service, the most recent at the right, each day a block in the
|
|
62
|
+
* colour of how it went. The blocks share the width between them; where it is too narrow
|
|
63
|
+
* for every day, a row shows the most recent days that fit rather than squeeze a block
|
|
64
|
+
* below a few pixels. The uptime closes the row, and a block names its day when pointed at.
|
|
65
|
+
*/
|
|
66
|
+
export const UptimeStrip = ({ 'aria-label': label, services, days = 90, blockHeight = 28, formatUptime = writeUptime, emptyLabel = 'No services to show.', loading = false, className, }) => {
|
|
67
|
+
const [rootRef, rootWidth] = useWidth();
|
|
68
|
+
// Held in state, not a ref: the first row's strip is a new node when the stand-in rows give
|
|
69
|
+
// way to the services, and the width has to be read from the one on the page.
|
|
70
|
+
const [strip, setStrip] = useState(null);
|
|
71
|
+
const [width, setWidth] = useState(0);
|
|
72
|
+
useLayoutEffect(() => {
|
|
73
|
+
if (!strip)
|
|
74
|
+
return;
|
|
75
|
+
const read = () => setWidth(strip.clientWidth);
|
|
76
|
+
read();
|
|
77
|
+
const observer = new ResizeObserver(read);
|
|
78
|
+
observer.observe(strip);
|
|
79
|
+
return () => observer.disconnect();
|
|
80
|
+
}, [strip]);
|
|
81
|
+
const [active, setActive] = useState(null);
|
|
82
|
+
const stacked = rootWidth > 0 && rootWidth < STACK_UNDER;
|
|
83
|
+
const longest = services.reduce((most, service) => Math.max(most, service.days.length), 0);
|
|
84
|
+
// While it loads there are no days to count, so the row is as long as it was asked to be.
|
|
85
|
+
const period = loading ? days : Math.min(days, longest);
|
|
86
|
+
const fits = width > 0 ? Math.max(1, Math.floor((width + GAP) / (MIN_BLOCK + GAP))) : period;
|
|
87
|
+
const shown = Math.min(period, fits);
|
|
88
|
+
const block = shown > 0 ? (width - GAP * (shown - 1)) / shown : 0;
|
|
89
|
+
const grid = cn('grid min-w-0 items-center',
|
|
90
|
+
// The names and the uptimes keep 8px clear of the frames.
|
|
91
|
+
stacked ? 'grid-cols-1 gap-y-2' : 'grid-cols-[auto_minmax(0,1fr)_auto] gap-x-2 gap-y-3');
|
|
92
|
+
const axis = (_jsxs(_Fragment, { children: [!stacked && _jsx("span", {}), _jsxs("div", { "aria-hidden": true, className: "flex justify-between text-xxs", style: {
|
|
93
|
+
color: 'var(--color-chart-label)',
|
|
94
|
+
// 8px under the last frame, where the rows between them keep 12px.
|
|
95
|
+
marginTop: stacked ? 0 : -4,
|
|
96
|
+
}, children: [_jsxs("span", { children: [shown, " days ago"] }), _jsx("span", { children: "Today" })] }), !stacked && _jsx("span", {})] }));
|
|
97
|
+
if (loading) {
|
|
98
|
+
// As many rows as there are services, when they are known; the days are what loads.
|
|
99
|
+
const count = services.length || SKELETON_ROWS.length - 1;
|
|
100
|
+
return (_jsx("figure", { "aria-busy": true, "aria-label": label, className: cn('m-0 min-w-0', className), "data-slot": "uptime-strip", ref: rootRef, children: _jsxs("div", { "aria-hidden": true, className: grid, "data-slot": "chart-skeleton", children: [Array.from({ length: count }, (_, row) => {
|
|
101
|
+
const [name, uptime] = SKELETON_ROWS[row % SKELETON_ROWS.length] ?? [];
|
|
102
|
+
// A known service lends its name and figure, unseen, so the columns keep their widths.
|
|
103
|
+
const service = services[row];
|
|
104
|
+
const share = service ? uptimeOf(service, period) : null;
|
|
105
|
+
const nameText = service?.name;
|
|
106
|
+
const figureText = share == null ? undefined : formatUptime(share);
|
|
107
|
+
return (
|
|
108
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a stand-in row is its place.
|
|
109
|
+
_jsxs("div", { className: "contents", children: [stacked ? (_jsxs("div", { className: cn('flex min-w-0 items-center justify-between gap-3', row > 0 && 'mt-2'), children: [_jsx(SkeletonText, { text: nameText, width: name ?? 48 }), _jsx(SkeletonText, { end: true, figure: true, text: figureText, width: uptime ?? 44 })] })) : (_jsx("span", { className: "flex min-w-0 max-w-48", children: _jsx(SkeletonText, { text: nameText, width: name ?? 48 }) })), _jsxs("div", { className: "relative min-w-0", children: [_jsx("div", { className: "flex min-w-0 overflow-hidden rounded-item", ref: row === 0 ? setStrip : undefined, style: { gap: GAP, height: blockHeight }, children: width > 0 &&
|
|
110
|
+
Array.from({ length: shown }, (_, index) => (_jsx("span", { className: "skeleton h-full min-w-0 flex-1 rounded-[2px]" }, index))) }), _jsx("div", { "aria-hidden": true, className: cn(PLOT_FRAME, 'inset-0'), "data-slot": "chart-frame" })] }), !stacked && (_jsx(SkeletonText, { end: true, figure: true, text: figureText, width: uptime ?? 44 }))] }, row));
|
|
111
|
+
}), axis] }) }));
|
|
112
|
+
}
|
|
113
|
+
if (services.length === 0 || period === 0) {
|
|
114
|
+
return (_jsx("figure", { "aria-label": label, className: cn('m-0 min-w-0', className), "data-slot": "uptime-strip", children: _jsx("p", { className: "flex h-32 items-center justify-center rounded-item border border-neutral-300 border-dashed text-neutral-600 text-xs", children: emptyLabel }) }));
|
|
115
|
+
}
|
|
116
|
+
const name = (service) => (_jsx("span", { className: "min-w-0 truncate text-neutral-600 text-xs", title: service.name, children: service.name }));
|
|
117
|
+
const uptime = (service) => {
|
|
118
|
+
const share = uptimeOf(service, period);
|
|
119
|
+
return (_jsx("span", { className: "shrink-0 text-right font-medium text-neutral-950 text-xs tabular-nums", children: share == null ? '–' : formatUptime(share) }));
|
|
120
|
+
};
|
|
121
|
+
return (_jsxs("figure", { "aria-label": label, className: cn('m-0 min-w-0', className), "data-slot": "uptime-strip", ref: rootRef, children: [_jsxs("div", { className: grid, children: [services.map((service, row) => {
|
|
122
|
+
const recent = service.days.slice(-shown);
|
|
123
|
+
// A service watched for fewer days than the others starts later, so its days still meet the axis.
|
|
124
|
+
const pad = shown - recent.length;
|
|
125
|
+
return (_jsxs("div", { className: "contents", children: [stacked ? (_jsxs("div", { className: cn('flex min-w-0 items-baseline justify-between gap-3', row > 0 && 'mt-2'), children: [name(service), uptime(service)] })) : (_jsx("span", { className: "flex min-w-0 max-w-48", children: name(service) })), _jsxs("div", { className: "relative min-w-0", onPointerLeave: () => setActive(null), children: [_jsx("div", { className: "flex min-w-0 overflow-hidden rounded-item", ref: row === 0 ? setStrip : undefined, style: { gap: GAP, height: blockHeight }, children: width > 0 &&
|
|
126
|
+
Array.from({ length: shown }, (_, index) => {
|
|
127
|
+
const day = index < pad ? null : recent[index - pad];
|
|
128
|
+
const state = day?.state ?? 'none';
|
|
129
|
+
const lit = active === null ||
|
|
130
|
+
active.row !== row ||
|
|
131
|
+
active.day === index;
|
|
132
|
+
return (_jsx("span", { className: "h-full min-w-0 flex-1 rounded-[2px] transition-opacity duration-150 motion-reduce:transition-none", onPointerEnter: () => setActive({ row, day: index }), style: {
|
|
133
|
+
background: STATES[state].color,
|
|
134
|
+
opacity: lit ? 1 : 0.35,
|
|
135
|
+
} }, index));
|
|
136
|
+
}) }), _jsx("div", { "aria-hidden": true, className: cn(PLOT_FRAME, 'inset-0'), "data-slot": "chart-frame" }), active?.row === row &&
|
|
137
|
+
(() => {
|
|
138
|
+
const day = active.day < pad ? null : recent[active.day - pad];
|
|
139
|
+
const x = active.day * (block + GAP) + block / 2;
|
|
140
|
+
const side = x < 96 ? 'left' : x > width - 96 ? 'right' : 'centre';
|
|
141
|
+
const state = day?.state ?? 'none';
|
|
142
|
+
return (_jsx("div", { className: "pointer-events-none absolute z-10", style: {
|
|
143
|
+
bottom: blockHeight + 6,
|
|
144
|
+
left: side === 'left'
|
|
145
|
+
? Math.max(0, x - block / 2)
|
|
146
|
+
: side === 'centre'
|
|
147
|
+
? x
|
|
148
|
+
: undefined,
|
|
149
|
+
right: side === 'right'
|
|
150
|
+
? Math.max(0, width - x - block / 2)
|
|
151
|
+
: undefined,
|
|
152
|
+
transform: side === 'centre'
|
|
153
|
+
? 'translateX(-50%)'
|
|
154
|
+
: undefined,
|
|
155
|
+
}, children: _jsx(ChartTooltip, { rows: [
|
|
156
|
+
{
|
|
157
|
+
color: STATES[state].color,
|
|
158
|
+
name: 'State',
|
|
159
|
+
value: STATES[state].label,
|
|
160
|
+
},
|
|
161
|
+
...(day && state !== 'none'
|
|
162
|
+
? [
|
|
163
|
+
{
|
|
164
|
+
name: 'Downtime',
|
|
165
|
+
value: writeDowntime(downtimeOf(day)),
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
: []),
|
|
169
|
+
], title: day
|
|
170
|
+
? `${service.name}, ${formatDateLong(day.date)}`
|
|
171
|
+
: service.name, children: day?.note && (_jsx("p", { className: "mt-2 max-w-56 text-neutral-600 text-xxs", children: day.note })) }) }));
|
|
172
|
+
})()] }), !stacked && uptime(service)] }, service.name));
|
|
173
|
+
}), axis] }), _jsx("div", { className: "sr-only", children: _jsxs("table", { children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "Service" }), _jsx("th", { scope: "col", children: "Uptime" }), _jsx("th", { scope: "col", children: "Days degraded" }), _jsx("th", { scope: "col", children: "Days with an outage" })] }) }), _jsx("tbody", { children: services.map(service => {
|
|
174
|
+
const share = uptimeOf(service, period);
|
|
175
|
+
const recent = service.days.slice(-period);
|
|
176
|
+
return (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: service.name }), _jsx("td", { children: share == null ? '–' : formatUptime(share) }), _jsx("td", { children: recent.filter(day => day.state === 'degraded').length }), _jsx("td", { children: recent.filter(day => day.state === 'outage').length })] }, service.name));
|
|
177
|
+
}) })] }) })] }));
|
|
178
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Accordion as AccordionPrimitive } from '@base-ui/react/accordion';
|
|
2
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
3
|
+
import { type WithClassName } from '../lib/cn.js';
|
|
4
|
+
export type AccordionVariant = 'plain' | 'outline';
|
|
5
|
+
export type AccordionProps = WithClassName<ComponentProps<typeof AccordionPrimitive.Root>> & {
|
|
6
|
+
/**
|
|
7
|
+
* `plain` (the default) sets the rows on the page, a hairline between them and one above and
|
|
8
|
+
* below, for a list in a reading column. `outline` puts them in a hairline box on the card
|
|
9
|
+
* corner, for a list that stands on its own beside other boxes.
|
|
10
|
+
*/
|
|
11
|
+
variant?: AccordionVariant;
|
|
12
|
+
};
|
|
13
|
+
export declare const Accordion: ({ variant, className, ...props }: AccordionProps) => import("react").JSX.Element;
|
|
14
|
+
/** One question and its answer. Give it a `value` to open it from outside or by default. */
|
|
15
|
+
export declare const AccordionItem: ({ className, ...props }: WithClassName<ComponentProps<typeof AccordionPrimitive.Item>>) => import("react").JSX.Element;
|
|
16
|
+
export type AccordionTriggerProps = WithClassName<ComponentProps<typeof AccordionPrimitive.Trigger>> & {
|
|
17
|
+
/** The heading the question is: h3 under a section's h2 (the default), h4 one level down. */
|
|
18
|
+
level?: 2 | 3 | 4 | 5 | 6;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The question: the whole row is the button, its chevron at the right end turning as it opens. A
|
|
23
|
+
* long question wraps and the row grows; the chevron stays centred on it.
|
|
24
|
+
*/
|
|
25
|
+
export declare const AccordionTrigger: ({ level, className, children, ...props }: AccordionTriggerProps) => import("react").JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* The answer, under its question: it opens by its own height and fades in, over 200ms, and does
|
|
28
|
+
* neither for a reader who asked for less motion. Its words keep a reading measure however wide the
|
|
29
|
+
* list is.
|
|
30
|
+
*/
|
|
31
|
+
export declare const AccordionPanel: ({ className, children, ...props }: WithClassName<ComponentProps<typeof AccordionPrimitive.Panel>>) => import("react").JSX.Element;
|