@zonsh/ui 0.0.0 → 0.4.1
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 +43 -0
- package/README.md +81 -1
- package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
- package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction.svg +77 -0
- package/assets/illustrations/drawing/crescent-dark.svg +28 -0
- package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
- package/assets/illustrations/drawing/crescent-guides.svg +33 -0
- package/assets/illustrations/drawing/crescent.svg +28 -0
- package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
- package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
- package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
- package/assets/illustrations/drawing/eclipse.svg +187 -0
- package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
- package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides.svg +31 -0
- package/assets/illustrations/drawing/horizon-dark.svg +30 -0
- package/assets/illustrations/drawing/horizon.svg +30 -0
- package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
- package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
- package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
- package/assets/illustrations/drawing/nib-study.svg +107 -0
- package/assets/illustrations/editorial/assistant-640.webp +0 -0
- package/assets/illustrations/editorial/assistant.webp +0 -0
- package/assets/illustrations/editorial/automation-640.webp +0 -0
- package/assets/illustrations/editorial/automation.webp +0 -0
- package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-left.webp +0 -0
- package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-right.webp +0 -0
- package/assets/illustrations/editorial/custom-software-640.webp +0 -0
- package/assets/illustrations/editorial/custom-software.webp +0 -0
- package/assets/illustrations/editorial/digitalization-640.webp +0 -0
- package/assets/illustrations/editorial/digitalization.webp +0 -0
- package/assets/illustrations/editorial/integration-640.webp +0 -0
- package/assets/illustrations/editorial/integration.webp +0 -0
- package/assets/illustrations/editorial/problem-640.webp +0 -0
- package/assets/illustrations/editorial/problem.webp +0 -0
- package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
- package/assets/illustrations/editorial/process-analysis.webp +0 -0
- package/assets/illustrations/editorial/process-concept-640.webp +0 -0
- package/assets/illustrations/editorial/process-concept.webp +0 -0
- package/assets/illustrations/editorial/process-development-640.webp +0 -0
- package/assets/illustrations/editorial/process-development.webp +0 -0
- package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
- package/assets/illustrations/editorial/process-discovery.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance.webp +0 -0
- package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
- package/assets/illustrations/editorial/process-prototype.webp +0 -0
- package/assets/illustrations/editorial/process-testing-640.webp +0 -0
- package/assets/illustrations/editorial/process-testing.webp +0 -0
- package/assets/illustrations/iso/automation-dark.svg +6 -0
- package/assets/illustrations/iso/automation.svg +6 -0
- package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
- package/assets/illustrations/iso/bar-chart.svg +6 -0
- package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
- package/assets/illustrations/iso/brackets-classic.svg +6 -0
- package/assets/illustrations/iso/brackets-dark.svg +6 -0
- package/assets/illustrations/iso/brackets.svg +6 -0
- package/assets/illustrations/iso/city-dark.svg +6 -0
- package/assets/illustrations/iso/city.svg +6 -0
- package/assets/illustrations/iso/conveyor-dark.svg +6 -0
- package/assets/illustrations/iso/conveyor.svg +6 -0
- package/assets/illustrations/iso/database-dark.svg +6 -0
- package/assets/illustrations/iso/database.svg +6 -0
- package/assets/illustrations/iso/documents-dark.svg +6 -0
- package/assets/illustrations/iso/documents.svg +6 -0
- package/assets/illustrations/iso/inbox-dark.svg +6 -0
- package/assets/illustrations/iso/inbox.svg +6 -0
- package/assets/illustrations/iso/laptop-dark.svg +6 -0
- package/assets/illustrations/iso/laptop.svg +6 -0
- package/assets/illustrations/iso/monitor-dark.svg +6 -0
- package/assets/illustrations/iso/monitor.svg +6 -0
- package/assets/illustrations/iso/pipeline-dark.svg +6 -0
- package/assets/illustrations/iso/pipeline.svg +6 -0
- package/assets/illustrations/iso/platform-dark.svg +6 -0
- package/assets/illustrations/iso/platform.svg +6 -0
- package/assets/illustrations/iso/server-dark.svg +6 -0
- package/assets/illustrations/iso/server.svg +6 -0
- package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
- package/assets/illustrations/iso/spreadsheet.svg +6 -0
- package/assets/illustrations/iso/timeline-dark.svg +6 -0
- package/assets/illustrations/iso/timeline.svg +6 -0
- package/assets/illustrations/sheet/construction.svg +115 -0
- package/assets/illustrations/sheet/crescent.svg +40 -0
- package/assets/illustrations/sheet/limb.svg +42 -0
- package/assets/illustrations/sheet/stress-axis.svg +119 -0
- package/assets/illustrations/sheet/totality.svg +215 -0
- package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
- package/assets/logo-left.svg +1 -0
- package/assets/logo-right.svg +1 -0
- package/assets/logo.svg +1 -0
- package/dist/components/_overlay.d.ts +47 -0
- package/dist/components/_overlay.js +59 -0
- package/dist/components/accordion.d.ts +32 -0
- package/dist/components/accordion.js +39 -0
- package/dist/components/alert-dialog.d.ts +45 -0
- package/dist/components/alert-dialog.js +56 -0
- package/dist/components/alert.d.ts +35 -0
- package/dist/components/alert.js +42 -0
- package/dist/components/ascii-field.d.ts +34 -0
- package/dist/components/ascii-field.js +410 -0
- package/dist/components/aspect-ratio.d.ts +14 -0
- package/dist/components/aspect-ratio.js +17 -0
- package/dist/components/avatar.d.ts +42 -0
- package/dist/components/avatar.js +55 -0
- package/dist/components/badge.d.ts +70 -0
- package/dist/components/badge.js +62 -0
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +31 -0
- package/dist/components/breadcrumb.js +37 -0
- package/dist/components/button-group.d.ts +30 -0
- package/dist/components/button-group.js +47 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +130 -0
- package/dist/components/calendar.d.ts +26 -0
- package/dist/components/calendar.js +179 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +109 -0
- package/dist/components/carousel.js +231 -0
- package/dist/components/chart.d.ts +189 -0
- package/dist/components/chart.js +323 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +55 -0
- package/dist/components/code-block.js +100 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +107 -0
- package/dist/components/color-picker.js +428 -0
- package/dist/components/combobox.d.ts +99 -0
- package/dist/components/combobox.js +172 -0
- package/dist/components/command.d.ts +132 -0
- package/dist/components/command.js +257 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +36 -0
- package/dist/components/conversation.js +303 -0
- package/dist/components/copy-button.d.ts +55 -0
- package/dist/components/copy-button.js +133 -0
- package/dist/components/data-table.d.ts +235 -0
- package/dist/components/data-table.js +655 -0
- package/dist/components/date-picker.d.ts +160 -0
- package/dist/components/date-picker.js +338 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +95 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +69 -0
- package/dist/components/drawer.js +79 -0
- package/dist/components/empty.d.ts +31 -0
- package/dist/components/empty.js +50 -0
- package/dist/components/feature-list.d.ts +54 -0
- package/dist/components/feature-list.js +43 -0
- package/dist/components/field.d.ts +34 -0
- package/dist/components/field.js +81 -0
- package/dist/components/file-drop.d.ts +77 -0
- package/dist/components/file-drop.js +258 -0
- package/dist/components/filter-bar.d.ts +153 -0
- package/dist/components/filter-bar.js +334 -0
- package/dist/components/form.d.ts +35 -0
- package/dist/components/form.js +56 -0
- package/dist/components/graph.d.ts +146 -0
- package/dist/components/graph.js +825 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +138 -0
- package/dist/components/input-group.js +312 -0
- package/dist/components/input.d.ts +16 -0
- package/dist/components/input.js +25 -0
- package/dist/components/item.d.ts +64 -0
- package/dist/components/item.js +116 -0
- package/dist/components/kbd.d.ts +50 -0
- package/dist/components/kbd.js +45 -0
- package/dist/components/label.d.ts +12 -0
- package/dist/components/label.js +24 -0
- package/dist/components/layout.d.ts +136 -0
- package/dist/components/layout.js +162 -0
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +439 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.d.ts +54 -0
- package/dist/components/logo.js +96 -0
- package/dist/components/menu.d.ts +60 -0
- package/dist/components/menu.js +140 -0
- package/dist/components/menubar.d.ts +62 -0
- package/dist/components/menubar.js +223 -0
- package/dist/components/message.d.ts +42 -0
- package/dist/components/message.js +59 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +27 -0
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/native-select.d.ts +26 -0
- package/dist/components/native-select.js +35 -0
- package/dist/components/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu.js +97 -0
- package/dist/components/number-field.d.ts +55 -0
- package/dist/components/number-field.js +164 -0
- package/dist/components/otp-field.d.ts +48 -0
- package/dist/components/otp-field.js +102 -0
- package/dist/components/pagination.d.ts +37 -0
- package/dist/components/pagination.js +81 -0
- package/dist/components/pdf-viewer.d.ts +134 -0
- package/dist/components/pdf-viewer.js +996 -0
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.d.ts +33 -0
- package/dist/components/popover.js +48 -0
- package/dist/components/preview-card.d.ts +25 -0
- package/dist/components/preview-card.js +22 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +25 -0
- package/dist/components/prompt-input.d.ts +156 -0
- package/dist/components/prompt-input.js +415 -0
- package/dist/components/quote.d.ts +22 -0
- package/dist/components/quote.js +15 -0
- package/dist/components/radio-group.d.ts +18 -0
- package/dist/components/radio-group.js +34 -0
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +46 -0
- package/dist/components/reasoning.js +73 -0
- package/dist/components/resizable.d.ts +47 -0
- package/dist/components/resizable.js +44 -0
- package/dist/components/response.d.ts +41 -0
- package/dist/components/response.js +566 -0
- package/dist/components/scroll-area.d.ts +33 -0
- package/dist/components/scroll-area.js +31 -0
- package/dist/components/select.d.ts +35 -0
- package/dist/components/select.js +71 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +163 -0
- package/dist/components/sidebar.js +505 -0
- package/dist/components/site-header.d.ts +93 -0
- package/dist/components/site-header.js +121 -0
- package/dist/components/skeleton.d.ts +31 -0
- package/dist/components/skeleton.js +29 -0
- package/dist/components/slider.d.ts +24 -0
- package/dist/components/slider.js +131 -0
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1258 -0
- package/dist/components/sources.d.ts +40 -0
- package/dist/components/sources.js +42 -0
- package/dist/components/spinner.d.ts +48 -0
- package/dist/components/spinner.js +75 -0
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/suggestions.d.ts +20 -0
- package/dist/components/suggestions.js +18 -0
- package/dist/components/switch.d.ts +14 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table.d.ts +172 -0
- package/dist/components/table.js +895 -0
- package/dist/components/tabs.d.ts +25 -0
- package/dist/components/tabs.js +162 -0
- package/dist/components/tag.d.ts +41 -0
- package/dist/components/tag.js +88 -0
- package/dist/components/tags-input.d.ts +56 -0
- package/dist/components/tags-input.js +271 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +55 -0
- package/dist/components/theme.js +120 -0
- package/dist/components/time-field.d.ts +70 -0
- package/dist/components/time-field.js +450 -0
- package/dist/components/timeline.d.ts +92 -0
- package/dist/components/timeline.js +108 -0
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +88 -0
- package/dist/components/toast.js +205 -0
- package/dist/components/toggle-group.d.ts +41 -0
- package/dist/components/toggle-group.js +140 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +35 -0
- package/dist/components/tool-call.d.ts +63 -0
- package/dist/components/tool-call.js +68 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +39 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +648 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +649 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +284 -0
- package/dist/components/video-player.js +1392 -0
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +94 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +18 -0
- package/dist/lib/code-highlight.js +174 -0
- package/dist/lib/code-theme.d.ts +19 -0
- package/dist/lib/code-theme.js +140 -0
- package/dist/lib/collapse-row.d.ts +9 -0
- package/dist/lib/collapse-row.js +129 -0
- package/dist/lib/digit-roll.d.ts +21 -0
- package/dist/lib/digit-roll.js +31 -0
- package/dist/lib/editorial-assets.d.ts +16 -0
- package/dist/lib/editorial-assets.js +56 -0
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/figure/catalog.d.ts +127 -0
- package/dist/lib/figure/catalog.js +130 -0
- package/dist/lib/figure/figures/automation.d.ts +7 -0
- package/dist/lib/figure/figures/automation.js +143 -0
- package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
- package/dist/lib/figure/figures/bar-chart.js +99 -0
- package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
- package/dist/lib/figure/figures/brackets-classic.js +170 -0
- package/dist/lib/figure/figures/brackets.d.ts +8 -0
- package/dist/lib/figure/figures/brackets.js +84 -0
- package/dist/lib/figure/figures/city.d.ts +7 -0
- package/dist/lib/figure/figures/city.js +93 -0
- package/dist/lib/figure/figures/conveyor.d.ts +7 -0
- package/dist/lib/figure/figures/conveyor.js +97 -0
- package/dist/lib/figure/figures/database.d.ts +7 -0
- package/dist/lib/figure/figures/database.js +65 -0
- package/dist/lib/figure/figures/documents.d.ts +7 -0
- package/dist/lib/figure/figures/documents.js +83 -0
- package/dist/lib/figure/figures/inbox.d.ts +7 -0
- package/dist/lib/figure/figures/inbox.js +92 -0
- package/dist/lib/figure/figures/laptop.d.ts +7 -0
- package/dist/lib/figure/figures/laptop.js +67 -0
- package/dist/lib/figure/figures/monitor.d.ts +7 -0
- package/dist/lib/figure/figures/monitor.js +59 -0
- package/dist/lib/figure/figures/pipeline.d.ts +8 -0
- package/dist/lib/figure/figures/pipeline.js +117 -0
- package/dist/lib/figure/figures/platform.d.ts +7 -0
- package/dist/lib/figure/figures/platform.js +117 -0
- package/dist/lib/figure/figures/server.d.ts +7 -0
- package/dist/lib/figure/figures/server.js +115 -0
- package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
- package/dist/lib/figure/figures/spreadsheet.js +87 -0
- package/dist/lib/figure/figures/timeline.d.ts +7 -0
- package/dist/lib/figure/figures/timeline.js +65 -0
- package/dist/lib/figure/kernel.d.ts +152 -0
- package/dist/lib/figure/kernel.js +576 -0
- package/dist/lib/figure/parts.d.ts +42 -0
- package/dist/lib/figure/parts.js +126 -0
- package/dist/lib/form-reset.d.ts +11 -0
- package/dist/lib/form-reset.js +22 -0
- package/dist/lib/glide.d.ts +53 -0
- package/dist/lib/glide.js +138 -0
- package/dist/lib/graph-layout.d.ts +58 -0
- package/dist/lib/graph-layout.js +209 -0
- package/dist/lib/illustration-drawings.d.ts +89 -0
- package/dist/lib/illustration-drawings.js +539 -0
- package/dist/lib/illustration-info.d.ts +37 -0
- package/dist/lib/illustration-info.js +22 -0
- package/dist/lib/illustration-library.d.ts +87 -0
- package/dist/lib/illustration-library.js +352 -0
- package/dist/lib/logo-geometry.d.ts +29 -0
- package/dist/lib/logo-geometry.js +67 -0
- package/dist/lib/markdown-guard.d.ts +16 -0
- package/dist/lib/markdown-guard.js +123 -0
- package/dist/lib/merge-refs.d.ts +10 -0
- package/dist/lib/merge-refs.js +26 -0
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/motion.d.ts +6 -0
- package/dist/lib/motion.js +12 -0
- package/dist/lib/pdf-worker.d.ts +1 -0
- package/dist/lib/pdf-worker.js +6 -0
- package/dist/lib/pdf.d.ts +19 -0
- package/dist/lib/pdf.js +58 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +38 -0
- package/dist/lib/platform.js +75 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +596 -0
- package/dist/lib/theme-script.d.ts +31 -0
- package/dist/lib/theme-script.js +49 -0
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +203 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +207 -0
- package/dist/styles/material.css +317 -0
- package/dist/styles/parts/ai.css +361 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +774 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +340 -0
- package/dist/styles/parts/foundations.css +166 -0
- package/dist/styles/parts/graph.css +214 -0
- package/dist/styles/parts/inputs.css +261 -0
- package/dist/styles/parts/isometric.css +124 -0
- package/dist/styles/parts/navigation.css +424 -0
- package/dist/styles/parts/overlays.css +250 -0
- package/dist/styles/parts/pdf.css +154 -0
- package/dist/styles/parts/react-flow.css +519 -0
- package/dist/styles/tokens.css +299 -0
- package/dist/vite.d.ts +66 -0
- package/dist/vite.js +29 -0
- package/package.json +183 -5
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as RechartsPrimitive from "recharts";
|
|
5
|
+
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { useLocale } from "./locale.js";
|
|
7
|
+
const ChartContext = React.createContext(null);
|
|
8
|
+
/** The config of the nearest `ChartContainer`. For custom tooltip or legend content. */
|
|
9
|
+
export function useChart() {
|
|
10
|
+
const context = React.useContext(ChartContext);
|
|
11
|
+
if (!context)
|
|
12
|
+
throw new Error("useChart must be used inside <ChartContainer>.");
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A series key as it is written in a CSS name, after `--color-`: letters, digits, `-`, `_` and
|
|
17
|
+
* anything past ASCII stay as they are, anything else is escaped as `CSS.escape` would ("New York"
|
|
18
|
+
* → `New\ York`), so it parses wherever the name is read — and no `</style` survives in it.
|
|
19
|
+
*/
|
|
20
|
+
function cssKey(key) {
|
|
21
|
+
let out = "";
|
|
22
|
+
for (const ch of key) {
|
|
23
|
+
const code = ch.codePointAt(0);
|
|
24
|
+
if (code === 0)
|
|
25
|
+
out += "\uFFFD";
|
|
26
|
+
else if (code < 0x20 || code === 0x7f)
|
|
27
|
+
out += `\\${code.toString(16)} `;
|
|
28
|
+
else if (code >= 0x80 || /[\w-]/.test(ch))
|
|
29
|
+
out += ch;
|
|
30
|
+
else
|
|
31
|
+
out += `\\${ch}`;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* chartColor — a series' colour as CSS: `var(--color-<key>)`, with the key escaped. Use it for a
|
|
37
|
+
* key that is not a plain CSS name — `stroke={chartColor("New York")}`, a `Cell`'s `fill`, the
|
|
38
|
+
* `color` of a `ChartGradient` or `ChartHatch`; for a plain key it is the same as writing the `var()`.
|
|
39
|
+
*/
|
|
40
|
+
export function chartColor(key) {
|
|
41
|
+
return `var(--color-${cssKey(key)})`;
|
|
42
|
+
}
|
|
43
|
+
/* ── Container ─────────────────────────────────────────────────────────────── */
|
|
44
|
+
/* The category tones in the order that keeps neighbours apart. */
|
|
45
|
+
const TONES = ["blue", "orange", "aqua", "magenta", "lime", "violet"];
|
|
46
|
+
/**
|
|
47
|
+
* ChartContainer — the frame every chart sits in. It sizes the Recharts chart responsively
|
|
48
|
+
* (16:9 by default; set a height with `className="aspect-auto h-60"`), writes one
|
|
49
|
+
* `--color-<key>` variable per series from `config`, and themes Recharts in the zon
|
|
50
|
+
* material: 11px Licht Mono muted ticks, `--grid-line` hairlines (horizontal only by
|
|
51
|
+
* default), a hairline cursor, 1.5px lines with no dots except the active one.
|
|
52
|
+
*
|
|
53
|
+
* Series are monochrome by default: the `--chart-1…5` ramp, told apart by value plus dash,
|
|
54
|
+
* hatch or opacity. `palette="tones"` colours them with the category tones when the categories
|
|
55
|
+
* themselves are the point (a share by kind, one line per region). The rule people break:
|
|
56
|
+
* colour without a legend, or a rainbow for one series. Five series at most in grey, six in
|
|
57
|
+
* tones; fold the rest into "Other".
|
|
58
|
+
*/
|
|
59
|
+
export function ChartContainer({ id, config, palette = "mono", grid = "horizontal", className, style, children, ...props }) {
|
|
60
|
+
const uid = React.useId();
|
|
61
|
+
const chartId = `chart-${(id ?? uid).replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
62
|
+
const { vars, rules } = React.useMemo(() => {
|
|
63
|
+
const vars = {};
|
|
64
|
+
let rules = "";
|
|
65
|
+
Object.entries(config).forEach(([key, series], index) => {
|
|
66
|
+
const color = series.color ??
|
|
67
|
+
(palette === "tones"
|
|
68
|
+
? `var(--tone-${TONES[index % TONES.length]})`
|
|
69
|
+
: `var(--chart-${Math.min(index, 4) + 1})`);
|
|
70
|
+
const name = cssKey(key);
|
|
71
|
+
if (name === key)
|
|
72
|
+
vars[`--color-${key}`] = color;
|
|
73
|
+
else {
|
|
74
|
+
// An escaped name cannot be an inline style's: the server writes it as text and the browser
|
|
75
|
+
// sets it as it is. A rule names it, and takes the colour from an inline variable.
|
|
76
|
+
vars[`--chart-key-${index}`] = color;
|
|
77
|
+
rules += `--color-${name}:var(--chart-key-${index});`;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return { vars, rules };
|
|
81
|
+
}, [config, palette]);
|
|
82
|
+
const value = React.useMemo(() => ({ config }), [config]);
|
|
83
|
+
// Pies lift the slice under the pointer (ChartActiveSector): know where it is from the start.
|
|
84
|
+
React.useEffect(track, []);
|
|
85
|
+
return (_jsx(ChartContext.Provider, { value: value, children: _jsxs("div", { "data-slot": "chart", id: id, role: props["aria-label"] || props["aria-labelledby"] ? "figure" : undefined, "data-chart": chartId, "data-grid": grid, className: cn("relative flex aspect-video w-full min-w-0 justify-center font-body text-xs text-foreground-soft", className), style: { ...vars, ...style }, ...props, children: [rules ? _jsx("style", { children: `[data-chart="${chartId}"]{${rules}}` }) : null, _jsx(RechartsPrimitive.ResponsiveContainer, { initialDimension: { width: 320, height: 180 }, children: children })] }) }));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* ChartGradient — the soft vertical fill under an area: the series colour fading to nothing.
|
|
89
|
+
* Put it inside the chart (`<AreaChart>`) and reference it with `fill="url(#id)"`.
|
|
90
|
+
*/
|
|
91
|
+
export function ChartGradient({ id, color, from = 0.24, to = 0.02 }) {
|
|
92
|
+
return (_jsx("defs", { children: _jsxs("linearGradient", { id: id, x1: "0", y1: "0", x2: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: color, stopOpacity: from }), _jsx("stop", { offset: "100%", stopColor: color, stopOpacity: to })] }) }));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* ChartHatch — a diagonal hatch fill, the second channel that separates monochrome series
|
|
96
|
+
* in print, forced colours and for readers who cannot tell two greys apart. Put it inside the
|
|
97
|
+
* chart and reference it with `fill="url(#id)"`; set `pattern: "hatch"` on the series config
|
|
98
|
+
* so the tooltip and legend swatches match.
|
|
99
|
+
*/
|
|
100
|
+
export function ChartHatch({ id, color, angle = 45 }) {
|
|
101
|
+
return (_jsx("defs", { children: _jsxs("pattern", { id: id, width: "5", height: "5", patternUnits: "userSpaceOnUse", patternTransform: `rotate(${angle})`, children: [_jsx("rect", { width: "5", height: "5", fill: color, fillOpacity: 0.14 }), _jsx("line", { x1: "0", y1: "0", x2: "0", y2: "5", stroke: color, strokeWidth: "2" })] }) }));
|
|
102
|
+
}
|
|
103
|
+
/* ── Pie: the active slice ─────────────────────────────────────────────────── */
|
|
104
|
+
const LIFT_PX = 4;
|
|
105
|
+
const SECTOR = ".recharts-pie-sector";
|
|
106
|
+
/* Where the pointer is, for every pie on the page: one passive listener, started by the first
|
|
107
|
+
ChartContainer. `pointerover` too: entering an element is not always preceded by a move. */
|
|
108
|
+
let pointer = { x: -1, y: -1 };
|
|
109
|
+
let tracking = false;
|
|
110
|
+
const track = () => {
|
|
111
|
+
if (tracking || typeof document === "undefined")
|
|
112
|
+
return;
|
|
113
|
+
tracking = true;
|
|
114
|
+
const note = (e) => (pointer = { x: e.clientX, y: e.clientY });
|
|
115
|
+
for (const type of ["pointermove", "pointerover", "pointerdown"])
|
|
116
|
+
document.addEventListener(type, note, { passive: true, capture: true });
|
|
117
|
+
};
|
|
118
|
+
/** The slice under the pointer, looking through the tooltip's cursor and anything else drawn over the pie. */
|
|
119
|
+
const underPointer = () => {
|
|
120
|
+
for (const el of document.elementsFromPoint(pointer.x, pointer.y)) {
|
|
121
|
+
const sector = el.closest(SECTOR);
|
|
122
|
+
if (sector)
|
|
123
|
+
return sector;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
};
|
|
127
|
+
/** Lift the slice under the pointer (once ChartActiveSector has given it a direction) and lower the rest. */
|
|
128
|
+
const lift = (chart, sector) => {
|
|
129
|
+
for (const other of chart.querySelectorAll(`${SECTOR}[data-lifted]`))
|
|
130
|
+
if (other !== sector)
|
|
131
|
+
other.removeAttribute("data-lifted");
|
|
132
|
+
if (sector instanceof SVGElement && sector.style.getPropertyValue("--lift-x"))
|
|
133
|
+
sector.setAttribute("data-lifted", "");
|
|
134
|
+
};
|
|
135
|
+
/* The chart follows the pointer itself: Recharts stops rendering once the tooltip has settled. */
|
|
136
|
+
const bind = (chart) => {
|
|
137
|
+
if (chart.hasAttribute("data-lift-bound"))
|
|
138
|
+
return;
|
|
139
|
+
chart.setAttribute("data-lift-bound", "");
|
|
140
|
+
chart.addEventListener("pointermove", () => lift(chart, underPointer()), { passive: true });
|
|
141
|
+
chart.addEventListener("pointerleave", () => lift(chart, null));
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* ChartActiveSector — lifts the slice under the pointer: it moves 4px out from the centre and
|
|
145
|
+
* grows 3%, on `--duration`, and settles back when the pointer leaves. Pass it as `activeShape`
|
|
146
|
+
* on `Pie`. Recharts calls it as a plain function, re-creates its element on every render and
|
|
147
|
+
* keeps the slice active after the pointer has gone, so the motion cannot live on it: it gives
|
|
148
|
+
* the slice's group, which persists, its direction and the pie's centre, and the chart lifts
|
|
149
|
+
* whichever marked slice the pointer is over; `data-lifted` carries the transition
|
|
150
|
+
* (parts/data.css).
|
|
151
|
+
*/
|
|
152
|
+
export function ChartActiveSector(props) {
|
|
153
|
+
const { cx = 0, cy = 0, midAngle = 0 } = props;
|
|
154
|
+
const angle = (-midAngle * Math.PI) / 180;
|
|
155
|
+
const place = (el) => {
|
|
156
|
+
const sector = el?.closest(SECTOR);
|
|
157
|
+
const chart = sector?.closest(".recharts-wrapper");
|
|
158
|
+
if (!sector || !chart)
|
|
159
|
+
return;
|
|
160
|
+
track();
|
|
161
|
+
bind(chart);
|
|
162
|
+
sector.style.setProperty("--lift-x", `${Math.cos(angle) * LIFT_PX}px`);
|
|
163
|
+
sector.style.setProperty("--lift-y", `${Math.sin(angle) * LIFT_PX}px`);
|
|
164
|
+
sector.style.transformOrigin = `${cx}px ${cy}px`;
|
|
165
|
+
lift(chart, underPointer());
|
|
166
|
+
};
|
|
167
|
+
return (_jsx("g", { ref: place, "data-slot": "chart-active-sector", children: _jsx(RechartsPrimitive.Sector, { ...props }) }));
|
|
168
|
+
}
|
|
169
|
+
/* ── Swatch (internal) ─────────────────────────────────────────────────────── */
|
|
170
|
+
function ChartSwatch({ shape, color, dash, pattern, }) {
|
|
171
|
+
if (shape === "line") {
|
|
172
|
+
return (_jsx("svg", { "aria-hidden": true, "data-slot": "chart-swatch", viewBox: "0 0 14 8", className: "h-2 w-3.5 shrink-0 overflow-visible", children: _jsx("line", { x1: "0.75", y1: "4", x2: "13.25", y2: "4", stroke: color, strokeWidth: "1.5", strokeLinecap: "round", strokeDasharray: dash }) }));
|
|
173
|
+
}
|
|
174
|
+
return (_jsx("span", { "aria-hidden": true, "data-slot": "chart-swatch", className: "size-2 shrink-0 rounded-full", style: pattern === "hatch"
|
|
175
|
+
? {
|
|
176
|
+
backgroundImage: `repeating-linear-gradient(45deg, ${color} 0 1.5px, transparent 1.5px 3.5px)`,
|
|
177
|
+
boxShadow: `inset 0 0 0 1px ${color}`,
|
|
178
|
+
}
|
|
179
|
+
: { backgroundColor: color } }));
|
|
180
|
+
}
|
|
181
|
+
/** Find the config entry for a tooltip or legend item. */
|
|
182
|
+
function getSeriesConfig(config, item, nameKey) {
|
|
183
|
+
const payload = item.payload && typeof item.payload === "object" ? item.payload : undefined;
|
|
184
|
+
const candidates = [
|
|
185
|
+
nameKey ? payload?.[nameKey] : undefined,
|
|
186
|
+
nameKey ? item[nameKey] : undefined,
|
|
187
|
+
item.dataKey,
|
|
188
|
+
item.name,
|
|
189
|
+
];
|
|
190
|
+
for (const candidate of candidates) {
|
|
191
|
+
if ((typeof candidate === "string" || typeof candidate === "number") && String(candidate) in config) {
|
|
192
|
+
return [String(candidate), config[String(candidate)]];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const fallback = String(item.dataKey ?? item.name ?? "value");
|
|
196
|
+
return [fallback, config[fallback]];
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* ChartCursor — the tooltip's cursor, drawn so it glides from point to point instead of jumping:
|
|
200
|
+
* the hairline on lines and areas and the band on bars keep their shape and move by a transform
|
|
201
|
+
* the browser can ease (`--duration`, so still under reduced motion). `ChartTooltip` uses it by
|
|
202
|
+
* default.
|
|
203
|
+
*/
|
|
204
|
+
export function ChartCursor(props) {
|
|
205
|
+
const { points, x, y, width, height, cx, className } = props;
|
|
206
|
+
if (points && points.length === 2) {
|
|
207
|
+
const [a, b] = points;
|
|
208
|
+
return (_jsx("line", { "data-slot": "chart-cursor", className: className, x1: 0, y1: 0, x2: b.x - a.x, y2: b.y - a.y, style: { transform: `translate(${a.x}px, ${a.y}px)` } }));
|
|
209
|
+
}
|
|
210
|
+
if (cx == null && x != null && y != null && width != null && height != null) {
|
|
211
|
+
return (_jsx("rect", { "data-slot": "chart-cursor", className: className, width: width, height: height, style: { transform: `translate(${x}px, ${y}px)` } }));
|
|
212
|
+
}
|
|
213
|
+
// Radial and scatter charts: Recharts' own sector and crosshair.
|
|
214
|
+
return cx != null ? (_jsx(RechartsPrimitive.Sector, { ...props })) : (_jsx(RechartsPrimitive.Cross, { ...props }));
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* ChartTooltip — Recharts' `Tooltip`. Pass `content={<ChartTooltipContent />}`. The cursor is a
|
|
218
|
+
* hairline on lines and areas and a quiet `--control-hover` band on bars, and it glides from
|
|
219
|
+
* point to point (`ChartCursor`); pass `cursor` to draw your own, or `false` for none.
|
|
220
|
+
*/
|
|
221
|
+
export function ChartTooltip(props) {
|
|
222
|
+
return _jsx(RechartsPrimitive.Tooltip, { cursor: _jsx(ChartCursor, {}), ...props });
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* ChartTooltipContent — the tooltip body: menu material at 12px, the category or date in
|
|
226
|
+
* Licht Sans, one row per series with a small swatch, its label and a mono tabular value.
|
|
227
|
+
* Text stays in text tokens; only the swatch carries the series colour.
|
|
228
|
+
*/
|
|
229
|
+
export function ChartTooltipContent({ active, payload, label, indicator = "dot", hideLabel = false, hideIndicator = false, labelFormatter, valueFormatter, nameKey, labelKey, className, }) {
|
|
230
|
+
const { config } = useChart();
|
|
231
|
+
const locale = useLocale();
|
|
232
|
+
if (!active || !payload?.length)
|
|
233
|
+
return null;
|
|
234
|
+
const items = payload.filter((item) => item.type !== "none" && !item.hide);
|
|
235
|
+
if (!items.length)
|
|
236
|
+
return null;
|
|
237
|
+
let heading = null;
|
|
238
|
+
if (!hideLabel) {
|
|
239
|
+
const firstPayload = items[0]?.payload;
|
|
240
|
+
const raw = labelKey
|
|
241
|
+
? (config[labelKey]?.label ?? firstPayload?.[labelKey] ?? label)
|
|
242
|
+
: typeof label === "string" && config[label]?.label != null
|
|
243
|
+
? config[label]?.label
|
|
244
|
+
: label;
|
|
245
|
+
heading = labelFormatter ? labelFormatter(raw, payload) : raw;
|
|
246
|
+
}
|
|
247
|
+
return (_jsxs("div", { "data-slot": "chart-tooltip", className: cn("grid min-w-36 gap-1.5 rounded-button material-menu px-3 py-2 font-body text-[13px] leading-none", className), children: [heading != null && heading !== "" ? (_jsx("div", { "data-slot": "chart-tooltip-label", className: "pb-0.5 font-medium text-foreground", children: heading })) : null, _jsx("div", { className: "grid gap-1.5", children: items.map((item, index) => {
|
|
248
|
+
const [key, series] = getSeriesConfig(config, item, nameKey);
|
|
249
|
+
const color = series
|
|
250
|
+
? chartColor(key)
|
|
251
|
+
: (item.color ?? item.payload?.fill ?? "currentColor");
|
|
252
|
+
const name = series?.label ?? item.name ?? key;
|
|
253
|
+
const dash = indicator === "dashed" ? "3 2" : (series?.dash ?? item.strokeDasharray?.toString());
|
|
254
|
+
const Icon = series?.icon;
|
|
255
|
+
return (_jsxs("div", { "data-slot": "chart-tooltip-item", className: "flex min-h-4 items-center gap-2", children: [hideIndicator ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0 text-muted-foreground" })) : (_jsx(ChartSwatch, { shape: indicator === "dot" ? "dot" : "line", color: color, dash: dash, pattern: series?.pattern })), _jsx("span", { className: "text-foreground-soft", children: name }), item.value != null ? (_jsx("span", { className: "ms-auto ps-4 font-mono text-xs text-foreground tabular-nums", children: valueFormatter
|
|
256
|
+
? valueFormatter(item.value, name, item)
|
|
257
|
+
: typeof item.value === "number"
|
|
258
|
+
? item.value.toLocaleString(locale)
|
|
259
|
+
: String(item.value) })) : null] }, `${key}-${index}`));
|
|
260
|
+
}) })] }));
|
|
261
|
+
}
|
|
262
|
+
/* ── Legend ────────────────────────────────────────────────────────────────── */
|
|
263
|
+
/**
|
|
264
|
+
* ChartLegend — Recharts' `Legend`. Pass `content={<ChartLegendContent />}`. Items keep the
|
|
265
|
+
* order the series are drawn in (Recharts sorts them alphabetically by default).
|
|
266
|
+
*/
|
|
267
|
+
export function ChartLegend({ itemSorter = null, ...props }) {
|
|
268
|
+
return _jsx(RechartsPrimitive.Legend, { itemSorter: itemSorter, ...props });
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* ChartLegendContent — one swatch and a mono 11px label per series. Always show it for two
|
|
272
|
+
* or more series; a single series is named by the chart's title instead.
|
|
273
|
+
*/
|
|
274
|
+
export function ChartLegendContent({ payload, verticalAlign = "bottom", hideIcon = false, nameKey, className, }) {
|
|
275
|
+
const { config } = useChart();
|
|
276
|
+
if (!payload?.length)
|
|
277
|
+
return null;
|
|
278
|
+
return (_jsx("ul", { "data-slot": "chart-legend", className: cn("m-0 flex list-none flex-wrap items-center justify-center gap-x-4 gap-y-1.5 p-0", verticalAlign === "top" ? "pb-3" : "pt-3", className), children: payload
|
|
279
|
+
.filter((item) => item.type !== "none")
|
|
280
|
+
.map((item, index) => {
|
|
281
|
+
const [key, series] = getSeriesConfig(config, { dataKey: item.dataKey, name: item.value, payload: item.payload }, nameKey);
|
|
282
|
+
const color = series ? chartColor(key) : (item.color ?? "currentColor");
|
|
283
|
+
const itemPayload = item.payload;
|
|
284
|
+
const dash = series?.dash ?? itemPayload?.strokeDasharray?.toString();
|
|
285
|
+
const Icon = series?.icon;
|
|
286
|
+
return (_jsxs("li", { "data-slot": "chart-legend-item", "data-inactive": item.inactive ? "" : undefined, className: "flex items-center gap-1.5 font-mono text-[11px] leading-none text-muted-foreground data-inactive:opacity-50", children: [hideIcon ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0" })) : (_jsx(ChartSwatch, { shape: item.type === "line" || series?.dash ? "line" : "dot", color: color, dash: dash, pattern: series?.pattern })), series?.label ?? item.value] }, `${key}-${index}`));
|
|
287
|
+
}) }));
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* downsample — the points of a long series that a chart can show: for each of `buckets` runs of
|
|
291
|
+
* points, its first point and each series' lowest and highest, in order. A line keeps its shape,
|
|
292
|
+
* its peaks and its dips; a chart a few hundred pixels wide draws no more than that anyway, and
|
|
293
|
+
* Recharts takes seconds over tens of thousands of points.
|
|
294
|
+
*
|
|
295
|
+
* <LineChart data={downsample(readings, ["cpu", "memory"])}>
|
|
296
|
+
*/
|
|
297
|
+
export function downsample(data, keys, buckets = 600) {
|
|
298
|
+
if (data.length <= buckets * (keys.length * 2 + 1))
|
|
299
|
+
return [...data];
|
|
300
|
+
const size = data.length / buckets;
|
|
301
|
+
const picked = [];
|
|
302
|
+
for (let b = 0; b < buckets; b++) {
|
|
303
|
+
const from = Math.floor(b * size);
|
|
304
|
+
const to = Math.min(data.length, Math.floor((b + 1) * size));
|
|
305
|
+
const at = new Set([from]);
|
|
306
|
+
for (const key of keys) {
|
|
307
|
+
let low = from;
|
|
308
|
+
let high = from;
|
|
309
|
+
for (let i = from; i < to; i++) {
|
|
310
|
+
const value = Number(data[i][key]);
|
|
311
|
+
if (value < Number(data[low][key]))
|
|
312
|
+
low = i;
|
|
313
|
+
if (value > Number(data[high][key]))
|
|
314
|
+
high = i;
|
|
315
|
+
}
|
|
316
|
+
at.add(low).add(high);
|
|
317
|
+
}
|
|
318
|
+
picked.push(...[...at].sort((a, b) => a - b));
|
|
319
|
+
}
|
|
320
|
+
if (picked.at(-1) !== data.length - 1)
|
|
321
|
+
picked.push(data.length - 1);
|
|
322
|
+
return picked.map((i) => data[i]);
|
|
323
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Checkbox as BaseCheckbox } from "@base-ui/react/checkbox";
|
|
2
|
+
import { CheckboxGroup as BaseCheckboxGroup } from "@base-ui/react/checkbox-group";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
export interface CheckboxProps extends BaseCheckbox.Root.Props {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Checkbox — an 18 × 18px box with 5px corners. Recessed like a field while unticked; ticked
|
|
8
|
+
* (or indeterminate) it takes the primary fill with a fine edge and soft top/bottom shading.
|
|
9
|
+
* Ticking draws the check in; unticking draws it back out (parts/controls.css).
|
|
10
|
+
*
|
|
11
|
+
* Use it for independent on/off choices and consent. Wrap it in `<FieldLabel>` (inside a
|
|
12
|
+
* `<Field>`) so the label text is clickable. The rule people break: a checkbox with no visible
|
|
13
|
+
* label — every checkbox needs readable text beside it, not just an `aria-label`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function Checkbox({ className, ref, ...props }: CheckboxProps): React.JSX.Element;
|
|
16
|
+
export interface CheckboxGroupProps extends BaseCheckboxGroup.Props {
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* CheckboxGroup — shared state for a list of checkboxes; its value is the array of ticked
|
|
20
|
+
* `value`s. Render it through `<Fieldset render={<CheckboxGroup />}>` inside a `<Field name>`
|
|
21
|
+
* so the group gets a legend and joins form validation. Each checkbox needs its own `value`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function CheckboxGroup({ className, ref, ...props }: CheckboxGroupProps): React.JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Checkbox as BaseCheckbox } from "@base-ui/react/checkbox";
|
|
4
|
+
import { CheckboxGroup as BaseCheckboxGroup } from "@base-ui/react/checkbox-group";
|
|
5
|
+
import { CheckIcon, MinusIcon } from "lucide-react";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { sx } from "../lib/cn.js";
|
|
8
|
+
import { useFormReset } from "../lib/form-reset.js";
|
|
9
|
+
import { mergeRefs } from "../lib/merge-refs.js";
|
|
10
|
+
/**
|
|
11
|
+
* Checkbox — an 18 × 18px box with 5px corners. Recessed like a field while unticked; ticked
|
|
12
|
+
* (or indeterminate) it takes the primary fill with a fine edge and soft top/bottom shading.
|
|
13
|
+
* Ticking draws the check in; unticking draws it back out (parts/controls.css).
|
|
14
|
+
*
|
|
15
|
+
* Use it for independent on/off choices and consent. Wrap it in `<FieldLabel>` (inside a
|
|
16
|
+
* `<Field>`) so the label text is clickable. The rule people break: a checkbox with no visible
|
|
17
|
+
* label — every checkbox needs readable text beside it, not just an `aria-label`.
|
|
18
|
+
*/
|
|
19
|
+
export function Checkbox({ className, ref, ...props }) {
|
|
20
|
+
// A form's reset remounts it from its defaults (lib/form-reset).
|
|
21
|
+
const [resetKey, formRef] = useFormReset();
|
|
22
|
+
const refs = React.useMemo(() => mergeRefs(formRef, ref), [formRef, ref]);
|
|
23
|
+
return (_jsx(BaseCheckbox.Root, { ref: refs, "data-slot": "checkbox", className: sx([
|
|
24
|
+
"group/checkbox relative inline-flex size-[18px] shrink-0 material-field cursor-pointer items-center justify-center rounded-checkbox p-0",
|
|
25
|
+
"data-checked:border-transparent data-checked:bg-primary data-checked:bg-none data-checked:text-primary-foreground data-checked:shadow-checked",
|
|
26
|
+
"data-indeterminate:border-transparent data-indeterminate:bg-primary data-indeterminate:bg-none data-indeterminate:text-primary-foreground data-indeterminate:shadow-checked",
|
|
27
|
+
"data-readonly:cursor-default",
|
|
28
|
+
], className), ...props, children: _jsxs(BaseCheckbox.Indicator, { "data-slot": "checkbox-indicator",
|
|
29
|
+
// Its own ink: unticking drops the box's text colour at once, and the check must stay
|
|
30
|
+
// visible on the still-dark fill while it undraws.
|
|
31
|
+
className: "pointer-events-none flex items-center justify-center text-primary-foreground", children: [_jsx(CheckIcon, { className: "size-3.5 group-data-indeterminate/checkbox:hidden", strokeWidth: 3 }), _jsx(MinusIcon, { className: "hidden size-3.5 group-data-indeterminate/checkbox:block", strokeWidth: 3 })] }) }, resetKey));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* CheckboxGroup — shared state for a list of checkboxes; its value is the array of ticked
|
|
35
|
+
* `value`s. Render it through `<Fieldset render={<CheckboxGroup />}>` inside a `<Field name>`
|
|
36
|
+
* so the group gets a legend and joins form validation. Each checkbox needs its own `value`.
|
|
37
|
+
*/
|
|
38
|
+
export function CheckboxGroup({ className, ref, ...props }) {
|
|
39
|
+
// A form's reset remounts the group, and its checkboxes, from its defaults (lib/form-reset).
|
|
40
|
+
const [resetKey, formRef] = useFormReset();
|
|
41
|
+
const refs = React.useMemo(() => mergeRefs(formRef, ref), [formRef, ref]);
|
|
42
|
+
return (_jsx(BaseCheckboxGroup, { ref: refs, "data-slot": "checkbox-group", className: sx("flex flex-col items-start gap-3", className), ...props }, resetKey));
|
|
43
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type CopyButtonMessages } from "./copy-button.js";
|
|
3
|
+
export interface CodeBlockMessages {
|
|
4
|
+
/** The copy button's name. Its confirmation comes from `copyButton`. */
|
|
5
|
+
copy: string;
|
|
6
|
+
}
|
|
7
|
+
declare module "./locale" {
|
|
8
|
+
interface Messages {
|
|
9
|
+
codeBlock: CodeBlockMessages;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export interface CodeBlockProps extends Omit<React.ComponentProps<"figure">, "children"> {
|
|
13
|
+
/** The source to show. Alternatively pass it as the child string. */
|
|
14
|
+
code?: string;
|
|
15
|
+
children?: string;
|
|
16
|
+
/** `region` (default): square, part of the page. `card`: a 20px object, e.g. a standalone snippet. */
|
|
17
|
+
variant?: "region" | "card";
|
|
18
|
+
/** A filename or eyebrow shown in the header, e.g. `"vite.config.ts"`. */
|
|
19
|
+
filename?: React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* The language, e.g. `"tsx"`: shown at the end of the header, and the grammar `highlight`
|
|
22
|
+
* colours the code with.
|
|
23
|
+
*/
|
|
24
|
+
language?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Colour the code by its `language`, in the zon theme. Default `true`; without a `language`, or
|
|
27
|
+
* for one Shiki does not know, the code stays mono either way.
|
|
28
|
+
*/
|
|
29
|
+
highlight?: boolean;
|
|
30
|
+
/** Show muted, mono line numbers. */
|
|
31
|
+
lineNumbers?: boolean;
|
|
32
|
+
/** Wrap long lines instead of scrolling sideways, for prose such as a prompt. */
|
|
33
|
+
wrap?: boolean;
|
|
34
|
+
/** Show the copy button. Defaults to `true`. */
|
|
35
|
+
copyable?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Accessible names for the copy button and its confirmation (see `CopyButton`). A
|
|
38
|
+
* LocaleProvider sets `copy` for every CodeBlock (`messages.codeBlock`) and the confirmation
|
|
39
|
+
* for every CopyButton (`messages.copyButton`).
|
|
40
|
+
*/
|
|
41
|
+
labels?: Partial<CopyButtonMessages>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* CodeBlock — source code in Licht Mono 13px, 1.75 line height, `white-space: pre`, tab size 2,
|
|
45
|
+
* scrolling horizontally rather than wrapping. Give it a height or a max height and the code
|
|
46
|
+
* scrolls under the header. With a `language`, it is coloured in the zon theme (Shiki, loaded the
|
|
47
|
+
* first time a block needs it); without one, or with `highlight={false}`, it stays mono.
|
|
48
|
+
*
|
|
49
|
+
* A **region** by default (square `surface-container`, part of the page); `variant="card"`
|
|
50
|
+
* makes it a 20px object for a snippet that stands on its own. An optional header carries a
|
|
51
|
+
* filename eyebrow over a hairline, and a raised copy button confirms with a check. The rule
|
|
52
|
+
* people break: a theme of their own. Syntax colours are kinds of token, so they come from the
|
|
53
|
+
* category tones (`--code-*`), never a palette brought in from an editor.
|
|
54
|
+
*/
|
|
55
|
+
export declare function CodeBlock({ code, children, variant, filename, language, lineNumbers, wrap, highlight, copyable, labels, className, ...props }: CodeBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useCodeTokens } from "../lib/code-highlight.js";
|
|
5
|
+
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { CopyButton } from "./copy-button.js";
|
|
7
|
+
import { useMessages } from "./locale.js";
|
|
8
|
+
const defaultMessages = { copy: "Copy code" };
|
|
9
|
+
/**
|
|
10
|
+
* CodeBlock — source code in Licht Mono 13px, 1.75 line height, `white-space: pre`, tab size 2,
|
|
11
|
+
* scrolling horizontally rather than wrapping. Give it a height or a max height and the code
|
|
12
|
+
* scrolls under the header. With a `language`, it is coloured in the zon theme (Shiki, loaded the
|
|
13
|
+
* first time a block needs it); without one, or with `highlight={false}`, it stays mono.
|
|
14
|
+
*
|
|
15
|
+
* A **region** by default (square `surface-container`, part of the page); `variant="card"`
|
|
16
|
+
* makes it a 20px object for a snippet that stands on its own. An optional header carries a
|
|
17
|
+
* filename eyebrow over a hairline, and a raised copy button confirms with a check. The rule
|
|
18
|
+
* people break: a theme of their own. Syntax colours are kinds of token, so they come from the
|
|
19
|
+
* category tones (`--code-*`), never a palette brought in from an editor.
|
|
20
|
+
*/
|
|
21
|
+
export function CodeBlock({ code, children, variant = "region", filename, language, lineNumbers = false, wrap = false, highlight = true, copyable = true, labels, className, ...props }) {
|
|
22
|
+
const source = (code ?? children ?? "").replace(/\n$/, "");
|
|
23
|
+
const { tokens, pending } = useCodeTokens(source, language, highlight);
|
|
24
|
+
const lines = React.useMemo(() => {
|
|
25
|
+
if (!tokens)
|
|
26
|
+
return source.split("\n");
|
|
27
|
+
const drawn = tokens.map(renderTokens);
|
|
28
|
+
// Long code takes its colours from the top down: the lines not coloured yet stay plain.
|
|
29
|
+
if (drawn.length > 0 && source.length > 0) {
|
|
30
|
+
const plain = source.split("\n");
|
|
31
|
+
for (let i = drawn.length; i < plain.length; i++)
|
|
32
|
+
drawn.push(plain[i]);
|
|
33
|
+
}
|
|
34
|
+
return drawn;
|
|
35
|
+
}, [tokens, source]);
|
|
36
|
+
const chunked = lines.length > CHUNKED_FROM;
|
|
37
|
+
const widest = React.useMemo(() => chunked && !wrap
|
|
38
|
+
? source.split("\n").reduce((max, line) => Math.max(max, line.replace(/\t/g, " ").length), 0)
|
|
39
|
+
: 0, [chunked, wrap, source]);
|
|
40
|
+
const hasHeader = filename != null || language != null;
|
|
41
|
+
const text = useMessages("codeBlock", defaultMessages);
|
|
42
|
+
const copyButton = copyable && (_jsx(CopyButton, { value: source, labels: { ...labels, copy: labels?.copy ?? text.copy }, "data-slot": "code-block-copy", className: cn(!hasHeader && "absolute top-3 right-3 z-10") }));
|
|
43
|
+
return (_jsxs("figure", { "data-slot": "code-block", "data-variant": variant, "data-highlighted": tokens ? "" : undefined, "data-highlight-pending": pending ? "" : undefined, className: cn("relative m-0 flex min-w-0 flex-col overflow-hidden text-foreground", variant === "card" ? "surface-card [--card-padding:0]" : "rounded-none surface-container", className), ...props, children: [hasHeader && (_jsxs("figcaption", { "data-slot": "code-block-header", className: cn("flex min-h-(--control-h) shrink-0 items-center justify-between gap-3 border-b border-border/60 ps-4",
|
|
44
|
+
// With the copy button, the header is the button plus the same 8px above, below and
|
|
45
|
+
// to the right, so the button sits as far from the top edge as from the right edge.
|
|
46
|
+
copyable ? "py-2 pe-2" : "pe-4"), children: [_jsx("span", { className: "min-w-0 truncate eyebrow text-[11px] tracking-[0.12em] normal-case", children: filename }), _jsxs("span", { className: "flex shrink-0 items-center gap-3", children: [language && _jsx("span", { className: "eyebrow text-[11px]", children: language }), copyButton] })] })), !hasHeader && copyButton, _jsx("pre", { "data-slot": "code-block-pre",
|
|
47
|
+
// Code reads left to right on a right-to-left page too: its brackets and commas stay put.
|
|
48
|
+
dir: "ltr", tabIndex: 0, className: cn(
|
|
49
|
+
// A height or max height on the block scrolls the code under the header, both ways.
|
|
50
|
+
"m-0 min-h-0 grow overflow-auto bg-transparent px-4 py-4 font-mono text-[13px] leading-[1.75] [tab-size:2] focus-ring", wrap ? "[overflow-wrap:anywhere] whitespace-pre-wrap" : "whitespace-pre", !hasHeader && copyable && "pr-14"), children: _jsx("code", { className: cn("font-[inherit]", chunked ? "block" : lineNumbers && "table min-w-full"),
|
|
51
|
+
// Chunks out of view are not laid out: the widest line keeps the width to scroll across.
|
|
52
|
+
style: widest
|
|
53
|
+
? {
|
|
54
|
+
minWidth: `calc(${widest}ch + ${lineNumbers ? `${String(lines.length).length}ch + 1.25rem` : "0px"})`,
|
|
55
|
+
}
|
|
56
|
+
: undefined, children: chunked
|
|
57
|
+
? Array.from({ length: Math.ceil(lines.length / CHUNK) }, (_, c) => (_jsx(CodeChunk, { from: c * CHUNK, lines: lines.slice(c * CHUNK, (c + 1) * CHUNK), numbers: lineNumbers ? String(lines.length).length : 0 }, c)))
|
|
58
|
+
: lineNumbers
|
|
59
|
+
? lines.map((line, i) => (_jsxs("span", { className: "table-row", children: [_jsx("span", { "aria-hidden": true, className: "table-cell w-[1%] pr-5 text-right text-control-muted tabular-nums select-none", children: i + 1 }), _jsx("span", { className: "table-cell", children: isEmpty(line) ? "\n" : line })] }, i)))
|
|
60
|
+
: tokens
|
|
61
|
+
? lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i)))
|
|
62
|
+
: source }) })] }));
|
|
63
|
+
}
|
|
64
|
+
const isEmpty = (line) => line === "" || (Array.isArray(line) && line.length === 0);
|
|
65
|
+
/** Code longer than this many lines is drawn in chunks of CHUNK lines, each laid out only near the view. */
|
|
66
|
+
const CHUNKED_FROM = 400;
|
|
67
|
+
const CHUNK = 100;
|
|
68
|
+
/**
|
|
69
|
+
* CHUNK lines of a long block, skipped by layout and paint while out of view (they stay in the
|
|
70
|
+
* page: found by the browser's search, selected and copied). Drawn again only when one of its
|
|
71
|
+
* lines changes, as colours arrive.
|
|
72
|
+
*/
|
|
73
|
+
const CodeChunk = React.memo(function CodeChunk({ from, lines, numbers }) {
|
|
74
|
+
return (_jsx("span", { "data-slot": "code-block-chunk", className: "block [content-visibility:auto]", style: { containIntrinsicBlockSize: `auto ${lines.length * 1.75}em` }, children: numbers
|
|
75
|
+
? lines.map((line, i) => (_jsxs("span", { className: "flex", children: [_jsx("span", { "aria-hidden": true, className: "shrink-0 pr-5 text-right text-control-muted tabular-nums select-none", style: { width: `calc(${numbers}ch + 1.25rem)` }, children: from + i + 1 }), _jsx("span", { children: isEmpty(line) ? "\n" : line })] }, i)))
|
|
76
|
+
: lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i))) }));
|
|
77
|
+
}, (a, b) => a.from === b.from &&
|
|
78
|
+
a.numbers === b.numbers &&
|
|
79
|
+
a.lines.length === b.lines.length &&
|
|
80
|
+
a.lines.every((line, i) => line === b.lines[i]));
|
|
81
|
+
/**
|
|
82
|
+
* Lines already drawn, by their tokens. The highlighter hands back the same tokens for lines that
|
|
83
|
+
* did not change (code streaming in), and the same elements let React skip them.
|
|
84
|
+
*/
|
|
85
|
+
const drawn = new WeakMap();
|
|
86
|
+
/** One line of tokens as coloured spans; the colours are the zon theme's `var(--code-…)`. */
|
|
87
|
+
function renderTokens(line) {
|
|
88
|
+
let node = drawn.get(line);
|
|
89
|
+
if (node === undefined)
|
|
90
|
+
drawn.set(line, (node = drawLine(line)));
|
|
91
|
+
return node;
|
|
92
|
+
}
|
|
93
|
+
function drawLine(line) {
|
|
94
|
+
return line.map((token, i) => (_jsx("span", { style: {
|
|
95
|
+
color: token.color,
|
|
96
|
+
fontStyle: token.fontStyle && token.fontStyle & 1 ? "italic" : undefined,
|
|
97
|
+
fontWeight: token.fontStyle && token.fontStyle & 2 ? 600 : undefined,
|
|
98
|
+
textDecoration: token.fontStyle && token.fontStyle & 4 ? "underline" : undefined,
|
|
99
|
+
}, children: token.content }, i)));
|
|
100
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Collapsible as BaseCollapsible } from "@base-ui/react/collapsible";
|
|
2
|
+
/**
|
|
3
|
+
* Collapsible — one region that can be shown and hidden by a trigger.
|
|
4
|
+
*
|
|
5
|
+
* Use it for secondary detail ("Show technical notes"), not for a list of questions —
|
|
6
|
+
* that is an `Accordion`. The rule people break: hiding content people need to complete
|
|
7
|
+
* the task. Collapse what is optional, never what is required.
|
|
8
|
+
*
|
|
9
|
+
* The root is full width, so it never shrink-wraps to the open panel: opening and closing
|
|
10
|
+
* only grows and shrinks the panel, and the trigger stays exactly where it is.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Collapsible({ className, ...props }: BaseCollapsible.Root.Props): import("react").JSX.Element;
|
|
13
|
+
export interface CollapsibleTriggerProps extends BaseCollapsible.Trigger.Props {
|
|
14
|
+
/** Show the chevron that rotates when open. Defaults to `true`. */
|
|
15
|
+
showIcon?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** A mono text trigger with a rotating chevron. Use `render` to swap in a `Button`. */
|
|
18
|
+
export declare function CollapsibleTrigger({ showIcon, className, children, ...props }: CollapsibleTriggerProps): import("react").JSX.Element;
|
|
19
|
+
/** The hidden content. Height animates from `--collapsible-panel-height`. */
|
|
20
|
+
export declare function CollapsiblePanel({ className, ...props }: BaseCollapsible.Panel.Props): import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Collapsible as BaseCollapsible } from "@base-ui/react/collapsible";
|
|
4
|
+
import { ChevronRightIcon } from "lucide-react";
|
|
5
|
+
import { sx, triggerSlot } from "../lib/cn.js";
|
|
6
|
+
/**
|
|
7
|
+
* Collapsible — one region that can be shown and hidden by a trigger.
|
|
8
|
+
*
|
|
9
|
+
* Use it for secondary detail ("Show technical notes"), not for a list of questions —
|
|
10
|
+
* that is an `Accordion`. The rule people break: hiding content people need to complete
|
|
11
|
+
* the task. Collapse what is optional, never what is required.
|
|
12
|
+
*
|
|
13
|
+
* The root is full width, so it never shrink-wraps to the open panel: opening and closing
|
|
14
|
+
* only grows and shrinks the panel, and the trigger stays exactly where it is.
|
|
15
|
+
*/
|
|
16
|
+
export function Collapsible({ className, ...props }) {
|
|
17
|
+
return (_jsx(BaseCollapsible.Root, { "data-slot": "collapsible", className: sx("flex w-full flex-col", className), ...props }));
|
|
18
|
+
}
|
|
19
|
+
/** A mono text trigger with a rotating chevron. Use `render` to swap in a `Button`. */
|
|
20
|
+
export function CollapsibleTrigger({ showIcon = true, className, children, ...props }) {
|
|
21
|
+
return (_jsxs(BaseCollapsible.Trigger, { ...triggerSlot("collapsible-trigger", props.render), className: sx([
|
|
22
|
+
"group/collapsible-trigger inline-flex w-fit cursor-pointer items-center gap-2 py-1 font-mono text-[13px] text-foreground-soft focus-ring select-none",
|
|
23
|
+
"transition-colors duration-(--duration) ease-(--ease) hover:text-foreground data-panel-open:text-foreground",
|
|
24
|
+
"data-disabled:pointer-events-none data-disabled:opacity-50",
|
|
25
|
+
], className), ...props, children: [showIcon && (_jsx(ChevronRightIcon, { "aria-hidden": true,
|
|
26
|
+
// Points along the line of reading: mirrored right to left, and down once open.
|
|
27
|
+
className: "size-3.5 shrink-0 transition-[rotate] duration-(--duration) ease-(--ease) group-data-panel-open/collapsible-trigger:rotate-90 rtl:-scale-x-100 rtl:group-data-panel-open/collapsible-trigger:-rotate-90" })), children] }));
|
|
28
|
+
}
|
|
29
|
+
/** The hidden content. Height animates from `--collapsible-panel-height`. */
|
|
30
|
+
export function CollapsiblePanel({ className, ...props }) {
|
|
31
|
+
return (_jsx(BaseCollapsible.Panel, { "data-slot": "collapsible-panel", className: sx("h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-(--duration) ease-(--ease) data-ending-style:h-0 data-starting-style:h-0", className), ...props }));
|
|
32
|
+
}
|