@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,450 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Field as BaseField } from "@base-ui/react/field";
|
|
4
|
+
import { ClockIcon } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { DigitRoll, reducedMotion } from "../lib/digit-roll.js";
|
|
8
|
+
import { useLocale, useMessages } from "./locale.js";
|
|
9
|
+
const groupSizes = {
|
|
10
|
+
sm: "min-h-(--control-h-sm) gap-2 pe-2.5 ps-2 text-[13px] [&>svg]:size-3.5",
|
|
11
|
+
default: "min-h-(--control-h) gap-3 pe-3 ps-3 text-base sm:text-[15px] [&>svg]:size-4",
|
|
12
|
+
};
|
|
13
|
+
const EMPTY = { hour: null, minute: null, second: null, period: null };
|
|
14
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
15
|
+
/** The zeros of the digits people type besides 0–9: Arabic-Indic, Persian, Devanagari, Bengali, Thai. */
|
|
16
|
+
const DIGIT_ZEROS = [0x0660, 0x06f0, 0x0966, 0x09e6, 0x0e50];
|
|
17
|
+
/** Text as 0–9 and ASCII punctuation: full-width digits and colons, and the digits of other scripts. */
|
|
18
|
+
const latin = (text) => text
|
|
19
|
+
.normalize("NFKC")
|
|
20
|
+
.replace(/[\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0e50-\u0e59]/g, (ch) => {
|
|
21
|
+
const code = ch.charCodeAt(0);
|
|
22
|
+
return String(code - DIGIT_ZEROS.find((zero) => code >= zero && code <= zero + 9));
|
|
23
|
+
});
|
|
24
|
+
const noSubscribe = () => () => { };
|
|
25
|
+
const defaultMessages = {
|
|
26
|
+
hour: "Hours",
|
|
27
|
+
minute: "Minutes",
|
|
28
|
+
second: "Seconds",
|
|
29
|
+
dayPeriod: "AM/PM",
|
|
30
|
+
empty: "Empty",
|
|
31
|
+
};
|
|
32
|
+
function parse(value, h12) {
|
|
33
|
+
const m = value ? /^(\d{1,2}):(\d{2})(?::(\d{2}))?/.exec(value) : null;
|
|
34
|
+
if (!m)
|
|
35
|
+
return EMPTY;
|
|
36
|
+
const h = Math.min(23, Number(m[1]));
|
|
37
|
+
return {
|
|
38
|
+
hour: h12 ? h % 12 || 12 : h,
|
|
39
|
+
minute: Math.min(59, Number(m[2])),
|
|
40
|
+
second: m[3] ? Math.min(59, Number(m[3])) : 0,
|
|
41
|
+
period: h >= 12 ? "pm" : "am",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** The same time on the other clock: a 24-hour hour as 1–12 with AM/PM, or back. */
|
|
45
|
+
function toClock(s, h12) {
|
|
46
|
+
if (s.hour == null)
|
|
47
|
+
return s;
|
|
48
|
+
if (h12)
|
|
49
|
+
return { ...s, hour: s.hour % 12 || 12, period: s.hour >= 12 ? "pm" : "am" };
|
|
50
|
+
return { ...s, hour: (s.hour % 12) + (s.period === "pm" ? 12 : 0) };
|
|
51
|
+
}
|
|
52
|
+
function format(s, h12, seconds) {
|
|
53
|
+
if (s.hour == null || s.minute == null || (seconds && s.second == null) || (h12 && s.period == null))
|
|
54
|
+
return null;
|
|
55
|
+
const h = h12 ? (s.hour % 12) + (s.period === "pm" ? 12 : 0) : s.hour;
|
|
56
|
+
return `${pad(h)}:${pad(s.minute)}${seconds ? `:${pad(s.second)}` : ""}`;
|
|
57
|
+
}
|
|
58
|
+
/** Seconds since midnight, for comparing a value with `min` / `max`. */
|
|
59
|
+
const toSeconds = (v) => {
|
|
60
|
+
const [h = 0, m = 0, s = 0] = v.split(":").map(Number);
|
|
61
|
+
return h * 3600 + m * 60 + s;
|
|
62
|
+
};
|
|
63
|
+
/** The locale's clock: 12 or 24 hours, the order of the segments, the separator and the AM/PM names. */
|
|
64
|
+
function useClock(locale, hourCycle, seconds) {
|
|
65
|
+
return React.useMemo(() => {
|
|
66
|
+
const options = { hour: "2-digit", minute: "2-digit" };
|
|
67
|
+
if (seconds)
|
|
68
|
+
options.second = "2-digit";
|
|
69
|
+
if (hourCycle)
|
|
70
|
+
options.hourCycle = hourCycle === 12 ? "h12" : "h23";
|
|
71
|
+
let fmt;
|
|
72
|
+
try {
|
|
73
|
+
fmt = new Intl.DateTimeFormat(locale, options);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
fmt = new Intl.DateTimeFormat("en", options);
|
|
77
|
+
}
|
|
78
|
+
const cycle = fmt.resolvedOptions().hourCycle;
|
|
79
|
+
const h12 = cycle === "h11" || cycle === "h12";
|
|
80
|
+
// A fixed date: only the parts' order and literals are read, never the clock.
|
|
81
|
+
const parts = fmt.formatToParts(new Date(2026, 0, 1, 21, 5, 7));
|
|
82
|
+
const order = parts
|
|
83
|
+
.map((p) => p.type)
|
|
84
|
+
.filter((t) => t === "hour" || t === "minute" || t === "second" || t === "dayPeriod");
|
|
85
|
+
const between = parts.findIndex((p) => p.type === "hour");
|
|
86
|
+
const separator = parts[between + 1]?.type === "literal" ? parts[between + 1].value.trim() || ":" : ":";
|
|
87
|
+
const periodName = (h) => fmt.formatToParts(new Date(2026, 0, 1, h)).find((p) => p.type === "dayPeriod")?.value ??
|
|
88
|
+
(h < 12 ? "AM" : "PM");
|
|
89
|
+
return { h12, order, separator, periods: { am: periodName(9), pm: periodName(21) } };
|
|
90
|
+
}, [locale, hourCycle, seconds]);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* TimeField — a time of day entered as segments, `14 : 30`, in a recessed field like `Input`:
|
|
94
|
+
* mono, tabular digits, an AM/PM segment where the clock has 12 hours, and an optional clock icon.
|
|
95
|
+
*
|
|
96
|
+
* Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField),
|
|
97
|
+
* typing fills it and moves on, Backspace clears it. The value is always a 24-hour `"HH:mm"`
|
|
98
|
+
* string, whatever the display. Use it for a time on its own — opening hours, a reminder, a
|
|
99
|
+
* departure — and beside a `DatePicker` for a date and time. The rule people break: a `Select`
|
|
100
|
+
* of 96 quarter hours. Set `step={15}` instead, and let people type.
|
|
101
|
+
*/
|
|
102
|
+
export function TimeField({ value: valueProp, defaultValue, onValueChange, size = "default", hourCycle, locale: localeProp, seconds: secondsProp, step = 1, min, max, name, required = false, disabled: disabledProp = false, readOnly = false, icon = true, segmentLabels, labels: labelsProp, id: idProp, className, onBlur, onMouseDown, onPaste, inputRef, ...props }) {
|
|
103
|
+
const providedLocale = useLocale();
|
|
104
|
+
const locale = localeProp ?? providedLocale;
|
|
105
|
+
const initial = valueProp !== undefined ? valueProp : defaultValue;
|
|
106
|
+
// Decided by the first value: the seconds don't go when a segment is cleared and the value is null.
|
|
107
|
+
const [initialSeconds] = React.useState(() => /^\d{1,2}:\d{2}:\d{2}/.test(initial ?? ""));
|
|
108
|
+
const seconds = secondsProp ?? initialSeconds;
|
|
109
|
+
// Without a `locale` the clock is the browser's, which a server can't know: the server and the
|
|
110
|
+
// hydrating render draw the en-US clock, and the browser's takes over straight after.
|
|
111
|
+
const hydrated = React.useSyncExternalStore(noSubscribe, () => true, () => false);
|
|
112
|
+
const clock = useClock(locale ?? (hydrated ? undefined : "en-US"), hourCycle, seconds);
|
|
113
|
+
const { h12 } = clock;
|
|
114
|
+
const messages = useMessages("timeField", defaultMessages, labelsProp);
|
|
115
|
+
const labels = { ...messages, ...segmentLabels };
|
|
116
|
+
const generatedId = React.useId();
|
|
117
|
+
const id = idProp ?? generatedId;
|
|
118
|
+
const [segs, setSegs] = React.useState(() => parse(initial, h12));
|
|
119
|
+
// A new clock (another `locale` or `hourCycle`) carries the hour across, so the time stays.
|
|
120
|
+
const [segsH12, setSegsH12] = React.useState(h12);
|
|
121
|
+
if (segsH12 !== h12) {
|
|
122
|
+
setSegsH12(h12);
|
|
123
|
+
setSegs(toClock(segs, h12));
|
|
124
|
+
}
|
|
125
|
+
// A controlled value that changes from outside resets the segments; one we emitted does not.
|
|
126
|
+
const [synced, setSynced] = React.useState(valueProp);
|
|
127
|
+
if (valueProp !== undefined && valueProp !== synced) {
|
|
128
|
+
setSynced(valueProp);
|
|
129
|
+
if (valueProp !== format(segs, h12, seconds))
|
|
130
|
+
setSegs(parse(valueProp, h12));
|
|
131
|
+
}
|
|
132
|
+
const segsRef = React.useRef(segs);
|
|
133
|
+
segsRef.current = segs;
|
|
134
|
+
const value = format(segs, h12, seconds);
|
|
135
|
+
const update = (next) => {
|
|
136
|
+
const before = format(segsRef.current, h12, seconds);
|
|
137
|
+
segsRef.current = next;
|
|
138
|
+
setSegs(next);
|
|
139
|
+
const after = format(next, h12, seconds);
|
|
140
|
+
if (after !== before)
|
|
141
|
+
onValueChange?.(after);
|
|
142
|
+
};
|
|
143
|
+
const order = clock.order.filter((t) => (t === "second" ? seconds : t === "dayPeriod" ? h12 : true));
|
|
144
|
+
const refs = React.useRef({});
|
|
145
|
+
const focusSegment = (type) => type && refs.current[type]?.focus();
|
|
146
|
+
const neighbour = (type, by) => order[order.indexOf(type) + by];
|
|
147
|
+
/** The digits typed into the focused segment so far ("1" while waiting to see if it is 1 or 12). */
|
|
148
|
+
const typed = React.useRef("");
|
|
149
|
+
const range = (type) => type === "hour" ? (h12 ? [1, 12] : [0, 23]) : type === "dayPeriod" ? [0, 1] : [0, 59];
|
|
150
|
+
const display = (type, s) => {
|
|
151
|
+
if (type === "dayPeriod")
|
|
152
|
+
return s.period ? clock.periods[s.period] : "––";
|
|
153
|
+
const n = s[type];
|
|
154
|
+
return n == null ? "––" : pad(n);
|
|
155
|
+
};
|
|
156
|
+
/* The digit roll: a step remembers the segment's text before and after, and which way it went. */
|
|
157
|
+
const [rolls, setRolls] = React.useState({});
|
|
158
|
+
const endRoll = React.useMemo(() => {
|
|
159
|
+
const end = (type) => () => setRolls((r) => ({ ...r, [type]: undefined }));
|
|
160
|
+
return { hour: end("hour"), minute: end("minute"), second: end("second"), dayPeriod: end("dayPeriod") };
|
|
161
|
+
}, []);
|
|
162
|
+
const stepSegment = (type, dir) => {
|
|
163
|
+
typed.current = "";
|
|
164
|
+
const s = segsRef.current;
|
|
165
|
+
let next;
|
|
166
|
+
if (type === "dayPeriod") {
|
|
167
|
+
next = { ...s, period: s.period == null ? (dir > 0 ? "am" : "pm") : s.period === "am" ? "pm" : "am" };
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const [lo, hi] = range(type);
|
|
171
|
+
const by = type === "minute" ? Math.max(1, Math.floor(step)) : 1;
|
|
172
|
+
const cur = s[type];
|
|
173
|
+
// The last value a step lands on: 45 for quarter hours.
|
|
174
|
+
const top = lo + Math.floor((hi - lo) / by) * by;
|
|
175
|
+
let n;
|
|
176
|
+
if (cur == null)
|
|
177
|
+
n = dir > 0 ? lo : top;
|
|
178
|
+
else if (dir > 0)
|
|
179
|
+
n = cur >= top ? lo : lo + (Math.floor((cur - lo) / by) + 1) * by;
|
|
180
|
+
else
|
|
181
|
+
n = cur <= lo ? top : lo + (Math.ceil((cur - lo) / by) - 1) * by;
|
|
182
|
+
next = { ...s, [type]: n };
|
|
183
|
+
}
|
|
184
|
+
const from = rolls[type]?.to ?? display(type, s);
|
|
185
|
+
const to = display(type, next);
|
|
186
|
+
if (from !== to && !from.includes("–") && !reducedMotion())
|
|
187
|
+
setRolls((r) => ({ ...r, [type]: { from, to, dir, key: performance.now() } }));
|
|
188
|
+
update(next);
|
|
189
|
+
};
|
|
190
|
+
const setSegment = (type, n) => {
|
|
191
|
+
if (type === "dayPeriod")
|
|
192
|
+
update({ ...segsRef.current, period: n == null ? null : n ? "pm" : "am" });
|
|
193
|
+
else
|
|
194
|
+
update({ ...segsRef.current, [type]: n });
|
|
195
|
+
};
|
|
196
|
+
const typeChar = (type, key) => {
|
|
197
|
+
// A digit typed on another script's keyboard (Arabic, Persian, full-width) is the same digit.
|
|
198
|
+
const ch = latin(key);
|
|
199
|
+
const s = segsRef.current;
|
|
200
|
+
if (/[\s:.,/-]/.test(ch) || ch === clock.separator) {
|
|
201
|
+
// A separator moves on, once there is something to move on from.
|
|
202
|
+
if (type === "dayPeriod" ? s.period : s[type] != null)
|
|
203
|
+
focusSegment(neighbour(type, 1));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (type === "dayPeriod") {
|
|
207
|
+
const c = ch.toLowerCase();
|
|
208
|
+
const am = clock.periods.am.toLowerCase();
|
|
209
|
+
const pm = clock.periods.pm.toLowerCase();
|
|
210
|
+
if (c === "a" || am.startsWith(c))
|
|
211
|
+
setSegment(type, 0);
|
|
212
|
+
else if (c === "p" || pm.startsWith(c))
|
|
213
|
+
setSegment(type, 1);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (!/\d/.test(ch))
|
|
217
|
+
return;
|
|
218
|
+
const [lo, hi] = range(type);
|
|
219
|
+
let buffer = typed.current + ch;
|
|
220
|
+
let n = Number(buffer);
|
|
221
|
+
if (typed.current === "" || n > hi) {
|
|
222
|
+
buffer = ch;
|
|
223
|
+
n = Number(ch);
|
|
224
|
+
}
|
|
225
|
+
const done = buffer.length >= 2 || n * 10 > hi;
|
|
226
|
+
typed.current = done ? "" : buffer;
|
|
227
|
+
setSegment(type, n >= lo ? n : null);
|
|
228
|
+
if (done)
|
|
229
|
+
focusSegment(neighbour(type, 1));
|
|
230
|
+
};
|
|
231
|
+
// Disabled by the prop or by a disabled Field (known once the Field's control renders).
|
|
232
|
+
const disabledRef = React.useRef(disabledProp);
|
|
233
|
+
const isEditable = () => !disabledRef.current && !readOnly;
|
|
234
|
+
const handleKeyDown = (type) => (event) => {
|
|
235
|
+
const { key } = event;
|
|
236
|
+
// An IME's keys are its own while it composes (229 marks them in Safari and on phones).
|
|
237
|
+
if (key === "Tab" ||
|
|
238
|
+
event.metaKey ||
|
|
239
|
+
event.ctrlKey ||
|
|
240
|
+
event.nativeEvent.isComposing ||
|
|
241
|
+
event.keyCode === 229)
|
|
242
|
+
return;
|
|
243
|
+
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
244
|
+
event.preventDefault();
|
|
245
|
+
focusSegment(neighbour(type, key === "ArrowLeft" ? -1 : 1));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// Every other key is ours: the segment is contenteditable only so phones open a keyboard.
|
|
249
|
+
if (key.length === 1 ||
|
|
250
|
+
key === "Enter" ||
|
|
251
|
+
key.startsWith("Arrow") ||
|
|
252
|
+
key === "Backspace" ||
|
|
253
|
+
key === "Delete" ||
|
|
254
|
+
key === "Home" ||
|
|
255
|
+
key === "End")
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
if (!isEditable())
|
|
258
|
+
return;
|
|
259
|
+
if (key === "ArrowUp")
|
|
260
|
+
stepSegment(type, 1);
|
|
261
|
+
else if (key === "ArrowDown")
|
|
262
|
+
stepSegment(type, -1);
|
|
263
|
+
else if (key === "Home" || key === "End") {
|
|
264
|
+
typed.current = "";
|
|
265
|
+
setSegment(type, range(type)[key === "Home" ? 0 : 1]);
|
|
266
|
+
}
|
|
267
|
+
else if (key === "Backspace" || key === "Delete") {
|
|
268
|
+
const s = segsRef.current;
|
|
269
|
+
const empty = type === "dayPeriod" ? s.period == null : s[type] == null;
|
|
270
|
+
typed.current = "";
|
|
271
|
+
if (empty && key === "Backspace")
|
|
272
|
+
focusSegment(neighbour(type, -1));
|
|
273
|
+
else
|
|
274
|
+
setSegment(type, null);
|
|
275
|
+
}
|
|
276
|
+
else if (key.length === 1 && !event.altKey)
|
|
277
|
+
typeChar(type, key);
|
|
278
|
+
};
|
|
279
|
+
/*
|
|
280
|
+
* Phones send their keyboard's input as beforeinput (their keydown carries no key): read it there.
|
|
281
|
+
* An IME (Japanese, Chinese, a phone's text keyboard) writes into the segment as it composes, which
|
|
282
|
+
* can't be cancelled: whatever it writes is put back to the segment's own text, and what the
|
|
283
|
+
* composition settles on is typed when it ends — AM or PM at once, as phones compose even a letter.
|
|
284
|
+
*/
|
|
285
|
+
const handlers = React.useRef({ typeChar, setSegment, text: (type) => display(type, segs) });
|
|
286
|
+
handlers.current = { typeChar, setSegment, text: (type) => display(type, segsRef.current) };
|
|
287
|
+
const segmentRef = (type) => (el) => {
|
|
288
|
+
refs.current[type] = el;
|
|
289
|
+
if (!el)
|
|
290
|
+
return;
|
|
291
|
+
const restore = () => {
|
|
292
|
+
const text = handlers.current.text(type);
|
|
293
|
+
if (el.textContent !== text)
|
|
294
|
+
el.textContent = text;
|
|
295
|
+
};
|
|
296
|
+
const onBeforeInput = (e) => {
|
|
297
|
+
if (e.inputType === "insertCompositionText" || e.inputType === "deleteCompositionText")
|
|
298
|
+
return;
|
|
299
|
+
e.preventDefault();
|
|
300
|
+
if (!isEditable() || e.inputType.includes("Composition"))
|
|
301
|
+
return;
|
|
302
|
+
if (e.inputType === "insertText" && e.data)
|
|
303
|
+
for (const ch of e.data)
|
|
304
|
+
handlers.current.typeChar(type, ch);
|
|
305
|
+
else if (e.inputType.startsWith("delete"))
|
|
306
|
+
handlers.current.setSegment(type, null);
|
|
307
|
+
};
|
|
308
|
+
const onInput = (e) => {
|
|
309
|
+
restore();
|
|
310
|
+
const { inputType, data } = e;
|
|
311
|
+
if (type === "dayPeriod" && inputType === "insertCompositionText" && data && isEditable())
|
|
312
|
+
handlers.current.typeChar(type, data[0]);
|
|
313
|
+
};
|
|
314
|
+
const onCompositionEnd = (e) => {
|
|
315
|
+
restore();
|
|
316
|
+
if (isEditable())
|
|
317
|
+
for (const ch of e.data)
|
|
318
|
+
handlers.current.typeChar(type, ch);
|
|
319
|
+
};
|
|
320
|
+
el.addEventListener("beforeinput", onBeforeInput);
|
|
321
|
+
el.addEventListener("input", onInput);
|
|
322
|
+
el.addEventListener("compositionend", onCompositionEnd);
|
|
323
|
+
return () => {
|
|
324
|
+
el.removeEventListener("beforeinput", onBeforeInput);
|
|
325
|
+
el.removeEventListener("input", onInput);
|
|
326
|
+
el.removeEventListener("compositionend", onCompositionEnd);
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
/* A pasted time ("14:30", "2:30 pm") fills every segment at once. */
|
|
330
|
+
const handlePaste = (event) => {
|
|
331
|
+
onPaste?.(event);
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
if (!isEditable())
|
|
334
|
+
return;
|
|
335
|
+
const text = latin(event.clipboardData.getData("text")).trim();
|
|
336
|
+
const m = /^(\d{1,2})[:.](\d{2})(?:[:.](\d{2}))?\s*([ap])?\.?m?\.?$/i.exec(text);
|
|
337
|
+
if (!m)
|
|
338
|
+
return;
|
|
339
|
+
let h = Number(m[1]);
|
|
340
|
+
if (m[4])
|
|
341
|
+
h = (h % 12) + (m[4].toLowerCase() === "p" ? 12 : 0);
|
|
342
|
+
if (h > 23 || Number(m[2]) > 59)
|
|
343
|
+
return;
|
|
344
|
+
update(parse(`${pad(h)}:${m[2]}${m[3] ? `:${m[3]}` : ""}`, h12));
|
|
345
|
+
};
|
|
346
|
+
/** The Field's input: it holds the value the Field validates. */
|
|
347
|
+
const fieldInput = React.useRef(null);
|
|
348
|
+
React.useImperativeHandle(inputRef, () => fieldInput.current, []);
|
|
349
|
+
/*
|
|
350
|
+
* Leaving the field: a finished time outside min / max is brought back inside, as NumberField does.
|
|
351
|
+
* Then the Field hears the blur — the group's, not a segment's — with the value from its input.
|
|
352
|
+
*/
|
|
353
|
+
const handleBlur = (event, fieldBlur) => {
|
|
354
|
+
onBlur?.(event);
|
|
355
|
+
if (event.currentTarget.contains(event.relatedTarget))
|
|
356
|
+
return;
|
|
357
|
+
typed.current = "";
|
|
358
|
+
if (value && isEditable()) {
|
|
359
|
+
const t = toSeconds(value);
|
|
360
|
+
const bound = min && t < toSeconds(min) ? min : max && t > toSeconds(max) ? max : null;
|
|
361
|
+
if (bound)
|
|
362
|
+
update(parse(bound, h12));
|
|
363
|
+
}
|
|
364
|
+
if (fieldInput.current)
|
|
365
|
+
fieldBlur?.({ currentTarget: fieldInput.current });
|
|
366
|
+
};
|
|
367
|
+
/** The first segment still empty, or the first one: where a click on the field puts the caret. */
|
|
368
|
+
const focusFirstEmpty = () => {
|
|
369
|
+
const s = segsRef.current;
|
|
370
|
+
focusSegment(order.find((t) => (t === "dayPeriod" ? s.period == null : s[t] == null)) ?? order[0]);
|
|
371
|
+
};
|
|
372
|
+
/* A press on the field's padding or icon goes to the first empty segment, as a click on a text field would. */
|
|
373
|
+
const handleMouseDown = (event) => {
|
|
374
|
+
onMouseDown?.(event);
|
|
375
|
+
if (event.defaultPrevented || disabledRef.current)
|
|
376
|
+
return;
|
|
377
|
+
if (event.target.closest('[data-slot="time-field-segment"]'))
|
|
378
|
+
return;
|
|
379
|
+
event.preventDefault();
|
|
380
|
+
focusFirstEmpty();
|
|
381
|
+
};
|
|
382
|
+
// A FieldLabel points at the group, which a label cannot focus: send its clicks to the first segment.
|
|
383
|
+
// (Listened for on the document: the Field links its label to the group only after this mounts.)
|
|
384
|
+
const firstSegment = React.useRef(order[0]);
|
|
385
|
+
firstSegment.current = order[0];
|
|
386
|
+
React.useEffect(() => {
|
|
387
|
+
const onClick = (event) => {
|
|
388
|
+
const label = event.target?.closest?.("label");
|
|
389
|
+
if (label?.htmlFor === id && !disabledRef.current)
|
|
390
|
+
refs.current[firstSegment.current]?.focus();
|
|
391
|
+
};
|
|
392
|
+
document.addEventListener("click", onClick);
|
|
393
|
+
return () => document.removeEventListener("click", onClick);
|
|
394
|
+
}, [id]);
|
|
395
|
+
/* A form's reset puts back the time it started with, as it does a native input's (uncontrolled). */
|
|
396
|
+
const reset = React.useRef(() => { });
|
|
397
|
+
reset.current = () => {
|
|
398
|
+
if (valueProp !== undefined)
|
|
399
|
+
return;
|
|
400
|
+
typed.current = "";
|
|
401
|
+
segsRef.current = parse(defaultValue, h12);
|
|
402
|
+
setSegs(segsRef.current);
|
|
403
|
+
};
|
|
404
|
+
React.useEffect(() => {
|
|
405
|
+
const form = refs.current[firstSegment.current]?.closest("form");
|
|
406
|
+
if (!form)
|
|
407
|
+
return;
|
|
408
|
+
const onReset = () => reset.current();
|
|
409
|
+
form.addEventListener("reset", onReset);
|
|
410
|
+
return () => form.removeEventListener("reset", onReset);
|
|
411
|
+
}, []);
|
|
412
|
+
return (_jsx(BaseField.Control, { ref: fieldInput, id: id, name: name, value: value ?? "", disabled: disabledProp,
|
|
413
|
+
// The group is what the label names and the descriptions and validity mark. The Field's own
|
|
414
|
+
// input, out of sight, keeps the value for forms and carries `required`, as Base UI's Select
|
|
415
|
+
// does: a submit that finds it empty focuses it, and it hands focus on to a segment.
|
|
416
|
+
render: (control) => {
|
|
417
|
+
const { ref, id: controlId, name: controlName, value: controlValue, disabled, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, onChange: fieldChange, onFocus: fieldFocus, onBlur: fieldBlur, onKeyDown: _onKeyDown, className: _className, defaultValue: _defaultValue, autoFocus: _autoFocus, ...state } = control;
|
|
418
|
+
const off = Boolean(disabled);
|
|
419
|
+
disabledRef.current = off;
|
|
420
|
+
const editable = !off && !readOnly;
|
|
421
|
+
const groupLabel = labelledBy ?? (props["aria-label"] || props["aria-labelledby"] ? controlId : undefined);
|
|
422
|
+
return (_jsxs("div", { role: "group", "data-slot": "time-field", "data-size": size, "data-readonly": readOnly ? "" : undefined, "data-disabled": off ? "" : undefined, "aria-disabled": off || undefined, ...state, ...props, id: controlId, "aria-labelledby": labelledBy ?? props["aria-labelledby"], "aria-describedby": describedBy, className: cn("group/time-field flex w-full min-w-0 material-field cursor-text items-center rounded-control font-mono text-foreground tabular-nums",
|
|
423
|
+
// A focused segment gives the field the softer edge of a focused text field.
|
|
424
|
+
"not-data-invalid:has-[[data-slot=time-field-segment]:focus]:border-[color-mix(in_oklab,var(--field-edge),var(--control-focus))]", "[&>svg]:ms-auto [&>svg]:shrink-0 [&>svg]:text-muted-foreground", groupSizes[size], className), onMouseDown: handleMouseDown, onPaste: handlePaste, onFocus: (event) => {
|
|
425
|
+
props.onFocus?.(event);
|
|
426
|
+
fieldFocus?.(event);
|
|
427
|
+
}, onBlur: (event) => handleBlur(event, fieldBlur), children: [_jsx("span", { dir: "ltr", className: "flex min-w-0 items-center", children: order.map((type, i) => {
|
|
428
|
+
const prev = order[i - 1];
|
|
429
|
+
const gap = prev && (type === "dayPeriod" || prev === "dayPeriod");
|
|
430
|
+
const s = segs;
|
|
431
|
+
const n = type === "dayPeriod" ? (s.period == null ? null : s.period === "pm" ? 1 : 0) : s[type];
|
|
432
|
+
const text = display(type, s);
|
|
433
|
+
const roll = rolls[type];
|
|
434
|
+
const [lo, hi] = range(type);
|
|
435
|
+
return (_jsxs(React.Fragment, { children: [prev && !gap && (_jsx("span", { "aria-hidden": true, "data-slot": "time-field-separator", className: "px-px text-muted-foreground", children: clock.separator })), _jsxs("span", { className: cn("relative flex", gap && "ms-1.5"), children: [_jsx("span", { ref: segmentRef(type), id: `${controlId}-${type}`, role: "spinbutton", "data-slot": "time-field-segment", "data-type": type, "data-placeholder": n == null ? "" : undefined, tabIndex: off ? undefined : 0, contentEditable: editable ? "true" : undefined, suppressContentEditableWarning: true, inputMode: type === "dayPeriod" ? "text" : "numeric", enterKeyHint: "next", spellCheck: false, autoCorrect: "off", autoCapitalize: "off", "aria-label": labels[type], "aria-labelledby": groupLabel ? `${groupLabel} ${controlId}-${type}` : undefined, "aria-describedby": describedBy, "aria-invalid": invalid, "aria-readonly": readOnly || undefined, "aria-required": required || undefined, "aria-disabled": off || undefined, "aria-valuemin": lo, "aria-valuemax": hi, "aria-valuenow": n ?? undefined, "aria-valuetext": n == null
|
|
436
|
+
? labels.empty
|
|
437
|
+
: type === "dayPeriod"
|
|
438
|
+
? text
|
|
439
|
+
: // A 12-hour hour reads with its half of the day: "9 PM", not a bare "9".
|
|
440
|
+
type === "hour" && h12 && s.period
|
|
441
|
+
? `${n} ${clock.periods[s.period]}`
|
|
442
|
+
: String(n), onKeyDown: handleKeyDown(type), onFocus: () => (typed.current = ""), className: cn(
|
|
443
|
+
// Focused, outline-hidden rather than none: a contrast theme drops the fill
|
|
444
|
+
// that marks the focused segment, and shows this outline instead.
|
|
445
|
+
"rounded-checkbox px-0.5 whitespace-nowrap caret-transparent outline-none focus:outline-hidden", "transition-[background-color,color] duration-(--duration) ease-(--ease) selection:bg-transparent", "focus:bg-control-hover focus:text-foreground", "data-placeholder:text-control-muted focus:data-placeholder:text-muted-foreground",
|
|
446
|
+
// While the digits roll, the overlay draws them.
|
|
447
|
+
roll && "text-transparent focus:text-transparent"), children: text }), roll && (_jsx(DigitRoll, { roll: roll, slot: "time-field-roll", onDone: endRoll[type] }, roll.key))] })] }, type));
|
|
448
|
+
}) }), icon && _jsx(ClockIcon, { "aria-hidden": true }), _jsx("input", { ref: ref, name: controlName, value: controlValue ?? "", onChange: fieldChange, required: required, disabled: off, readOnly: readOnly, "aria-hidden": true, tabIndex: -1, autoComplete: "off", onFocus: focusFirstEmpty, className: "sr-only" })] }));
|
|
449
|
+
} }));
|
|
450
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export interface TimelineMessages {
|
|
4
|
+
/** Read before TimelineChange's old value. */
|
|
5
|
+
from: string;
|
|
6
|
+
/** Read between the old value and the new one. */
|
|
7
|
+
to: string;
|
|
8
|
+
}
|
|
9
|
+
declare module "./locale" {
|
|
10
|
+
interface Messages {
|
|
11
|
+
timeline: TimelineMessages;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export type TimelineVariant = "activity" | "changelog";
|
|
15
|
+
export interface TimelineProps extends React.ComponentProps<"ol"> {
|
|
16
|
+
/**
|
|
17
|
+
* `activity` (default): a dense log — the actor and action on one line, the time at its end,
|
|
18
|
+
* 20px between entries. `changelog`: releases and milestones — the date as an eyebrow, the
|
|
19
|
+
* title in Licht, the body in reading type and 40px between entries.
|
|
20
|
+
*/
|
|
21
|
+
variant?: TimelineVariant;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Timeline — what happened, in order, on a hairline: an activity feed, a deal's history, a
|
|
25
|
+
* changelog, a project's milestones. Each entry is a dot (or a 24px icon key) on the line, a line
|
|
26
|
+
* of Licht Sans saying who did what, a mono time, and optionally a body — a comment, a changed
|
|
27
|
+
* field.
|
|
28
|
+
*
|
|
29
|
+
* The rule people break: colouring every dot. Markers are monochrome; a status colour marks the
|
|
30
|
+
* entries that are a status (a failed deploy, a won deal), and the entry's text says so too.
|
|
31
|
+
*/
|
|
32
|
+
export declare function Timeline({ variant, className, ...props }: TimelineProps): React.JSX.Element;
|
|
33
|
+
declare const dotStatus: {
|
|
34
|
+
readonly default: "bg-muted-foreground";
|
|
35
|
+
readonly success: "bg-success";
|
|
36
|
+
readonly warning: "bg-warning";
|
|
37
|
+
readonly info: "bg-info";
|
|
38
|
+
readonly destructive: "bg-destructive";
|
|
39
|
+
};
|
|
40
|
+
export type TimelineStatus = keyof typeof dotStatus;
|
|
41
|
+
export interface TimelineItemProps extends React.ComponentProps<"li"> {
|
|
42
|
+
/** A 14px lucide icon in a 24px raised key instead of the dot: the kind of event (a call, a commit). */
|
|
43
|
+
icon?: React.ReactNode;
|
|
44
|
+
/**
|
|
45
|
+
* Colours the dot or icon for an entry that is a status: `success` (shipped, won), `warning`,
|
|
46
|
+
* `info`, `destructive` (failed). Say it in the entry's text too — colour is never the only sign.
|
|
47
|
+
*/
|
|
48
|
+
status?: TimelineStatus;
|
|
49
|
+
/**
|
|
50
|
+
* Not happened yet — a planned milestone: a hollow dot, muted text and a dashed line to it.
|
|
51
|
+
* That is only drawn, so word the title as a plan ("3.0 release planned").
|
|
52
|
+
*/
|
|
53
|
+
upcoming?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* One entry. The marker sits on the first line; the hairline runs from it to the next entry's
|
|
57
|
+
* marker and stops at the last. Put a `TimelineTitle`, a `TimelineTime` and an optional
|
|
58
|
+
* `TimelineContent` inside.
|
|
59
|
+
*/
|
|
60
|
+
export declare function TimelineItem({ icon, status, upcoming, className, children, ...props }: TimelineItemProps): React.JSX.Element;
|
|
61
|
+
/**
|
|
62
|
+
* Who did what: "**Amara Okafor** moved the deal to Won". Licht Sans 14px in `activity`, with
|
|
63
|
+
* the actor in medium weight (`<strong>`); a Licht headline in `changelog`. A `<p>`; in a
|
|
64
|
+
* changelog pass `render={<h3 />}` so each release is a heading.
|
|
65
|
+
*/
|
|
66
|
+
export declare function TimelineTitle({ render, ref, className, ...props }: useRender.ComponentProps<"p">): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
67
|
+
/**
|
|
68
|
+
* When: "2h ago", "30 Sep", "v2.4 · 12 Aug 2026". Licht Mono 12px, muted, tabular. Give it the
|
|
69
|
+
* machine-readable `dateTime`. At the end of the title line in `activity`; above it, as an
|
|
70
|
+
* eyebrow, in `changelog`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function TimelineTime({ className, ...props }: React.ComponentProps<"time">): React.JSX.Element;
|
|
73
|
+
/** The body under the title: a comment, a changed field, a list of what shipped. */
|
|
74
|
+
export declare function TimelineContent({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
75
|
+
/**
|
|
76
|
+
* A comment someone left, as a small 20px card under the entry — it could be quoted or moved on
|
|
77
|
+
* its own. Reading type, 12px by 16px padding.
|
|
78
|
+
*/
|
|
79
|
+
export declare function TimelineComment({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
80
|
+
export interface TimelineChangeProps extends Omit<React.ComponentProps<"p">, "children"> {
|
|
81
|
+
/** What changed: "Stage", "Price", "Assignee". */
|
|
82
|
+
field: React.ReactNode;
|
|
83
|
+
/** The old value. A string becomes a muted `Tag`; pass your own element to colour it. */
|
|
84
|
+
from?: React.ReactNode;
|
|
85
|
+
/** The new value. A string becomes a `Tag`; pass `<Tag variant="success">Won</Tag>` for a status. */
|
|
86
|
+
to: React.ReactNode;
|
|
87
|
+
/** What screen readers hear around the values; a LocaleProvider sets it for every TimelineChange. */
|
|
88
|
+
labels?: Partial<TimelineMessages>;
|
|
89
|
+
}
|
|
90
|
+
/** A field that changed, as "Stage Proposal → Won": the field muted, the values as tags. */
|
|
91
|
+
export declare function TimelineChange({ field, from, to, labels, className, ...props }: TimelineChangeProps): React.JSX.Element;
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
4
|
+
import { ArrowRightIcon } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { useMessages } from "./locale.js";
|
|
8
|
+
import { Tag } from "./tag.js";
|
|
9
|
+
const defaultMessages = { from: "from", to: "to" };
|
|
10
|
+
const TimelineContext = React.createContext("activity");
|
|
11
|
+
/**
|
|
12
|
+
* Timeline — what happened, in order, on a hairline: an activity feed, a deal's history, a
|
|
13
|
+
* changelog, a project's milestones. Each entry is a dot (or a 24px icon key) on the line, a line
|
|
14
|
+
* of Licht Sans saying who did what, a mono time, and optionally a body — a comment, a changed
|
|
15
|
+
* field.
|
|
16
|
+
*
|
|
17
|
+
* The rule people break: colouring every dot. Markers are monochrome; a status colour marks the
|
|
18
|
+
* entries that are a status (a failed deploy, a won deal), and the entry's text says so too.
|
|
19
|
+
*/
|
|
20
|
+
export function Timeline({ variant = "activity", className, ...props }) {
|
|
21
|
+
// A long feed lays out and paints only the entries near the view; they stay in the page, for
|
|
22
|
+
// find-in-page and screen readers. Each entry draws its own line, so nothing crosses between them.
|
|
23
|
+
const long = React.Children.count(props.children) > LONG_FROM;
|
|
24
|
+
return (_jsx(TimelineContext.Provider, { value: variant, children: _jsx("ol", { "data-slot": "timeline", "data-variant": variant, "data-long": long ? "" : undefined, className: cn("m-0 flex w-full list-none flex-col p-0 font-body", long &&
|
|
25
|
+
"[&>li]:[contain-intrinsic-size:auto_4rem] [&>li]:[content-visibility:auto] [&>li]:[overflow-clip-margin:12px]", className), ...props }) }));
|
|
26
|
+
}
|
|
27
|
+
/** Timelines of more entries than this skip laying out those out of view. */
|
|
28
|
+
const LONG_FROM = 100;
|
|
29
|
+
/* Status inks, spelled out so Tailwind sees every class. */
|
|
30
|
+
const dotStatus = {
|
|
31
|
+
default: "bg-muted-foreground",
|
|
32
|
+
success: "bg-success",
|
|
33
|
+
warning: "bg-warning",
|
|
34
|
+
info: "bg-info",
|
|
35
|
+
destructive: "bg-destructive",
|
|
36
|
+
};
|
|
37
|
+
const iconStatus = {
|
|
38
|
+
default: "text-muted-foreground",
|
|
39
|
+
success: "text-success",
|
|
40
|
+
warning: "text-warning",
|
|
41
|
+
info: "text-info",
|
|
42
|
+
destructive: "text-destructive",
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* One entry. The marker sits on the first line; the hairline runs from it to the next entry's
|
|
46
|
+
* marker and stops at the last. Put a `TimelineTitle`, a `TimelineTime` and an optional
|
|
47
|
+
* `TimelineContent` inside.
|
|
48
|
+
*/
|
|
49
|
+
export function TimelineItem({ icon, status = "default", upcoming = false, className, children, ...props }) {
|
|
50
|
+
const variant = React.useContext(TimelineContext);
|
|
51
|
+
return (_jsxs("li", { "data-slot": "timeline-item", "data-status": status === "default" ? undefined : status, "data-upcoming": upcoming ? "" : undefined, className: cn("group/timeline-item relative grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-3",
|
|
52
|
+
// A line that leads to an upcoming entry is dashed: the future is not drawn solid.
|
|
53
|
+
"[&:has(+[data-upcoming])>[data-slot=timeline-connector]]:border-dashed", className), ...props, children: [_jsx("span", { "data-slot": "timeline-marker", "aria-hidden": true, className: "flex h-6 items-center justify-center", children: icon ? (_jsx("span", { className: cn("flex size-6 items-center justify-center rounded-full border border-transparent bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-key [&_svg]:size-3.5", iconStatus[status], upcoming && "opacity-60"), children: icon })) : (_jsx("span", { className: cn("size-2 rounded-full", upcoming ? "border border-muted-foreground bg-transparent" : dotStatus[status]) })) }), _jsx("span", { "data-slot": "timeline-connector", "aria-hidden": true, className: cn("absolute start-[calc(0.75rem-0.5px)] top-7 bottom-1 border-s border-border group-last/timeline-item:hidden", upcoming && "border-dashed") }), _jsx("div", { "data-slot": "timeline-body", className: cn("grid min-w-0 grid-cols-[minmax(0,1fr)_auto] content-start items-baseline gap-x-3", variant === "activity" ? "pb-5" : "pb-10", "group-last/timeline-item:pb-0", upcoming && "[&_[data-slot=timeline-title]]:text-muted-foreground"), children: children })] }));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Who did what: "**Amara Okafor** moved the deal to Won". Licht Sans 14px in `activity`, with
|
|
57
|
+
* the actor in medium weight (`<strong>`); a Licht headline in `changelog`. A `<p>`; in a
|
|
58
|
+
* changelog pass `render={<h3 />}` so each release is a heading.
|
|
59
|
+
*/
|
|
60
|
+
export function TimelineTitle({ render, ref, className, ...props }) {
|
|
61
|
+
const variant = React.useContext(TimelineContext);
|
|
62
|
+
return useRender({
|
|
63
|
+
defaultTagName: "p",
|
|
64
|
+
render,
|
|
65
|
+
ref,
|
|
66
|
+
props: {
|
|
67
|
+
"data-slot": "timeline-title",
|
|
68
|
+
...props,
|
|
69
|
+
className: cn(
|
|
70
|
+
// A long word or link wraps in its column instead of running under the time.
|
|
71
|
+
"m-0 min-w-0 break-words", variant === "activity"
|
|
72
|
+
? "col-start-1 row-start-1 text-sm leading-6 text-foreground-soft [&_strong]:font-medium [&_strong]:text-foreground"
|
|
73
|
+
: "col-span-2 row-start-2 mt-1 display text-[22px] leading-[1.2] text-foreground sm:text-[24px]", className),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* When: "2h ago", "30 Sep", "v2.4 · 12 Aug 2026". Licht Mono 12px, muted, tabular. Give it the
|
|
79
|
+
* machine-readable `dateTime`. At the end of the title line in `activity`; above it, as an
|
|
80
|
+
* eyebrow, in `changelog`.
|
|
81
|
+
*/
|
|
82
|
+
export function TimelineTime({ className, ...props }) {
|
|
83
|
+
const variant = React.useContext(TimelineContext);
|
|
84
|
+
return (_jsx("time", { "data-slot": "timeline-time", className: cn("font-mono text-xs leading-6 whitespace-nowrap text-muted-foreground tabular-nums", variant === "activity"
|
|
85
|
+
? "col-start-2 row-start-1 text-end"
|
|
86
|
+
: "col-span-2 row-start-1 tracking-[0.04em]", className), ...props }));
|
|
87
|
+
}
|
|
88
|
+
/** The body under the title: a comment, a changed field, a list of what shipped. */
|
|
89
|
+
export function TimelineContent({ className, ...props }) {
|
|
90
|
+
const variant = React.useContext(TimelineContext);
|
|
91
|
+
return (_jsx("div", { "data-slot": "timeline-content", className: cn("col-span-2 flex min-w-0 flex-col break-words", variant === "activity"
|
|
92
|
+
? "gap-2 pt-1.5 text-sm text-foreground-soft"
|
|
93
|
+
: "max-w-[68ch] gap-3 pt-3 text-[15px] leading-relaxed text-foreground-soft", className), ...props }));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A comment someone left, as a small 20px card under the entry — it could be quoted or moved on
|
|
97
|
+
* its own. Reading type, 12px by 16px padding.
|
|
98
|
+
*/
|
|
99
|
+
export function TimelineComment({ className, ...props }) {
|
|
100
|
+
return (_jsx("div", { "data-slot": "timeline-comment", className: cn("surface-card text-sm leading-relaxed text-foreground-soft [--card-padding:12px_16px] [&>p]:m-0", className), ...props }));
|
|
101
|
+
}
|
|
102
|
+
/** A field that changed, as "Stage Proposal → Won": the field muted, the values as tags. */
|
|
103
|
+
export function TimelineChange({ field, from, to, labels, className, ...props }) {
|
|
104
|
+
const text = useMessages("timeline", defaultMessages, labels);
|
|
105
|
+
// A value longer than the line ends in an ellipsis inside its tag; the full text is still read.
|
|
106
|
+
const tag = (value, variant) => typeof value === "string" || typeof value === "number" ? (_jsx(Tag, { variant: variant, className: "max-w-full shrink", children: _jsx("span", { className: "min-w-0 truncate leading-normal", children: value }) })) : (value);
|
|
107
|
+
return (_jsxs("p", { "data-slot": "timeline-change", className: cn("m-0 flex flex-wrap items-center gap-x-2 gap-y-1 text-[13px] text-muted-foreground", className), ...props, children: [_jsx("span", { children: field }), from != null && (_jsxs(_Fragment, { children: [_jsx("span", { className: "sr-only", children: text.from }), tag(from, "muted"), _jsx(ArrowRightIcon, { "aria-hidden": true, className: "size-3.5 shrink-0 rtl:-scale-x-100" }), _jsx("span", { className: "sr-only", children: text.to })] })), tag(to, "default")] }));
|
|
108
|
+
}
|