@lanfermann/ui 0.0.0-stage → 0.1.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 +24 -0
- package/README.md +17 -2
- package/TRADEMARK.md +10 -0
- package/brand/app-icon.svg +1 -0
- package/brand/avatar.svg +1 -0
- package/brand/favicon.svg +1 -0
- package/dist/components/accordion/accordion.d.ts +26 -0
- package/dist/components/accordion/accordion.js +78 -0
- package/dist/components/alert/alert.d.ts +19 -0
- package/dist/components/alert/alert.js +68 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +20 -0
- package/dist/components/alert-dialog/alert-dialog.js +75 -0
- package/dist/components/anchor-heading/anchor-heading.d.ts +19 -0
- package/dist/components/anchor-heading/anchor-heading.js +39 -0
- package/dist/components/avatar/avatar.d.ts +14 -0
- package/dist/components/avatar/avatar.js +42 -0
- package/dist/components/badge/badge.d.ts +12 -0
- package/dist/components/badge/badge.js +27 -0
- package/dist/components/breadcrumbs/breadcrumbs.d.ts +23 -0
- package/dist/components/breadcrumbs/breadcrumbs.js +63 -0
- package/dist/components/button/button-variants.d.ts +15 -0
- package/dist/components/button/button-variants.js +76 -0
- package/dist/components/button/button.d.ts +25 -0
- package/dist/components/button/button.js +50 -0
- package/dist/components/calendar/calendar-selection.js +216 -0
- package/dist/components/calendar/calendar.d.ts +44 -0
- package/dist/components/calendar/calendar.js +208 -0
- package/dist/components/callout/callout.d.ts +21 -0
- package/dist/components/callout/callout.js +75 -0
- package/dist/components/card/card.d.ts +16 -0
- package/dist/components/card/card.js +53 -0
- package/dist/components/checkbox/checkbox.d.ts +9 -0
- package/dist/components/checkbox/checkbox.js +33 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts +18 -0
- package/dist/components/checkbox-group/checkbox-group.js +33 -0
- package/dist/components/code/code.d.ts +7 -0
- package/dist/components/code/code.js +16 -0
- package/dist/components/code-block/code-block-frame.js +146 -0
- package/dist/components/code-block/code-block-live.d.ts +45 -0
- package/dist/components/code-block/code-block-live.js +51 -0
- package/dist/components/code-block/code-block.d.ts +36 -0
- package/dist/components/code-block/code-block.js +51 -0
- package/dist/components/code-block/code-copy.d.ts +12 -0
- package/dist/components/code-block/code-copy.js +71 -0
- package/dist/components/code-block/code-lines-view.d.ts +16 -0
- package/dist/components/code-block/code-lines-view.js +48 -0
- package/dist/components/code-block/code-lines.js +17 -0
- package/dist/components/code-block/code-scroll.js +29 -0
- package/dist/components/code-block/code-surface.js +13 -0
- package/dist/components/code-block/code-tabs-frame.js +85 -0
- package/dist/components/code-block/code-tabs-store.js +25 -0
- package/dist/components/code-block/code-tabs.d.ts +28 -0
- package/dist/components/code-block/code-tabs.js +29 -0
- package/dist/components/code-block/highlight.d.ts +34 -0
- package/dist/components/code-block/highlight.js +258 -0
- package/dist/components/code-block/lines.d.ts +5 -0
- package/dist/components/code-block/lines.js +40 -0
- package/dist/components/collapsible/collapsible.d.ts +19 -0
- package/dist/components/collapsible/collapsible.js +54 -0
- package/dist/components/combobox/combobox.d.ts +84 -0
- package/dist/components/combobox/combobox.js +169 -0
- package/dist/components/container/container.d.ts +16 -0
- package/dist/components/container/container.js +30 -0
- package/dist/components/copy-pill/copy-pill.d.ts +52 -0
- package/dist/components/copy-pill/copy-pill.js +232 -0
- package/dist/components/cta/cta.d.ts +109 -0
- package/dist/components/cta/cta.js +375 -0
- package/dist/components/date-field/date-field.d.ts +40 -0
- package/dist/components/date-field/date-field.js +99 -0
- package/dist/components/date-range-field/date-range-field.d.ts +41 -0
- package/dist/components/date-range-field/date-range-field.js +155 -0
- package/dist/components/dialog/dialog.d.ts +29 -0
- package/dist/components/dialog/dialog.js +96 -0
- package/dist/components/docs-layout/docs-layout.d.ts +17 -0
- package/dist/components/docs-layout/docs-layout.js +46 -0
- package/dist/components/drawer/drawer.d.ts +39 -0
- package/dist/components/drawer/drawer.js +181 -0
- package/dist/components/field/field.d.ts +18 -0
- package/dist/components/field/field.js +77 -0
- package/dist/components/fieldset/fieldset.d.ts +8 -0
- package/dist/components/fieldset/fieldset.js +25 -0
- package/dist/components/figure/figure.d.ts +14 -0
- package/dist/components/figure/figure.js +35 -0
- package/dist/components/form/form.d.ts +31 -0
- package/dist/components/form/form.js +55 -0
- package/dist/components/ground/ground.d.ts +20 -0
- package/dist/components/ground/ground.js +31 -0
- package/dist/components/heading/heading.d.ts +16 -0
- package/dist/components/heading/heading.js +36 -0
- package/dist/components/icon/icon.d.ts +22 -0
- package/dist/components/icon/icon.js +24 -0
- package/dist/components/input/input.d.ts +19 -0
- package/dist/components/input/input.js +46 -0
- package/dist/components/input-group/input-group.d.ts +34 -0
- package/dist/components/input-group/input-group.js +61 -0
- package/dist/components/kbd/kbd.d.ts +6 -0
- package/dist/components/kbd/kbd.js +15 -0
- package/dist/components/link/link-variants.d.ts +13 -0
- package/dist/components/link/link-variants.js +27 -0
- package/dist/components/link/link.d.ts +9 -0
- package/dist/components/link/link.js +18 -0
- package/dist/components/logo/logo-paths.js +22 -0
- package/dist/components/logo/logomark.d.ts +19 -0
- package/dist/components/logo/logomark.js +49 -0
- package/dist/components/logo/wordmark.d.ts +35 -0
- package/dist/components/logo/wordmark.js +48 -0
- package/dist/components/menu/menu.d.ts +26 -0
- package/dist/components/menu/menu.js +132 -0
- package/dist/components/meter/meter.d.ts +29 -0
- package/dist/components/meter/meter.js +68 -0
- package/dist/components/navigation-menu/navigation-menu-variants.d.ts +12 -0
- package/dist/components/navigation-menu/navigation-menu-variants.js +18 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu/navigation-menu.js +128 -0
- package/dist/components/number-field/number-field.d.ts +32 -0
- package/dist/components/number-field/number-field.js +85 -0
- package/dist/components/page-header/page-header.d.ts +27 -0
- package/dist/components/page-header/page-header.js +48 -0
- package/dist/components/pager/pager.d.ts +24 -0
- package/dist/components/pager/pager.js +51 -0
- package/dist/components/parameter-list/parameter-list.d.ts +34 -0
- package/dist/components/parameter-list/parameter-list.js +70 -0
- package/dist/components/popover/popover.d.ts +15 -0
- package/dist/components/popover/popover.js +64 -0
- package/dist/components/progress/progress.d.ts +19 -0
- package/dist/components/progress/progress.js +67 -0
- package/dist/components/prose/prose.d.ts +13 -0
- package/dist/components/prose/prose.js +22 -0
- package/dist/components/quote/quote.d.ts +21 -0
- package/dist/components/quote/quote.js +46 -0
- package/dist/components/radio/radio.d.ts +12 -0
- package/dist/components/radio/radio.js +37 -0
- package/dist/components/reference-entry/reference-entry.d.ts +25 -0
- package/dist/components/reference-entry/reference-entry.js +66 -0
- package/dist/components/section/section.d.ts +13 -0
- package/dist/components/section/section.js +30 -0
- package/dist/components/segmented-control/segmented-control.d.ts +42 -0
- package/dist/components/segmented-control/segmented-control.js +413 -0
- package/dist/components/select/select.d.ts +70 -0
- package/dist/components/select/select.js +189 -0
- package/dist/components/separator/separator.d.ts +12 -0
- package/dist/components/separator/separator.js +29 -0
- package/dist/components/side-nav/side-nav.d.ts +48 -0
- package/dist/components/side-nav/side-nav.js +89 -0
- package/dist/components/site-footer/site-footer-floor.js +48 -0
- package/dist/components/site-footer/site-footer.d.ts +38 -0
- package/dist/components/site-footer/site-footer.js +96 -0
- package/dist/components/site-header/site-header.d.ts +77 -0
- package/dist/components/site-header/site-header.js +214 -0
- package/dist/components/slider/slider.d.ts +42 -0
- package/dist/components/slider/slider.js +279 -0
- package/dist/components/spinner/spinner.d.ts +15 -0
- package/dist/components/spinner/spinner.js +34 -0
- package/dist/components/switch/switch.d.ts +8 -0
- package/dist/components/switch/switch.js +28 -0
- package/dist/components/table/table.d.ts +83 -0
- package/dist/components/table/table.js +123 -0
- package/dist/components/table-of-contents/table-of-contents.d.ts +32 -0
- package/dist/components/table-of-contents/table-of-contents.js +187 -0
- package/dist/components/tabs/tabs.d.ts +28 -0
- package/dist/components/tabs/tabs.js +124 -0
- package/dist/components/text/text.d.ts +16 -0
- package/dist/components/text/text.js +63 -0
- package/dist/components/textarea/textarea.d.ts +19 -0
- package/dist/components/textarea/textarea.js +30 -0
- package/dist/components/time-field/time-field.d.ts +40 -0
- package/dist/components/time-field/time-field.js +123 -0
- package/dist/components/toast/toast.d.ts +55 -0
- package/dist/components/toast/toast.js +129 -0
- package/dist/components/tooltip/tooltip.d.ts +16 -0
- package/dist/components/tooltip/tooltip.js +41 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +77 -0
- package/dist/internal/arrow.js +41 -0
- package/dist/internal/disclosure.js +20 -0
- package/dist/internal/field-context.js +21 -0
- package/dist/internal/field.d.ts +23 -0
- package/dist/internal/field.js +49 -0
- package/dist/internal/glyphs.js +84 -0
- package/dist/internal/iso-date.d.ts +2 -0
- package/dist/internal/iso-date.js +268 -0
- package/dist/internal/overlay.js +40 -0
- package/dist/internal/picker-sheet.js +74 -0
- package/dist/internal/popup.js +37 -0
- package/dist/internal/range-shape.js +295 -0
- package/dist/internal/reduced-motion.js +19 -0
- package/dist/internal/scroll-edges.js +45 -0
- package/dist/internal/trough.js +39 -0
- package/dist/internal/typed-input.d.ts +16 -0
- package/dist/internal/typed-input.js +133 -0
- package/dist/lib/cn.d.ts +11 -0
- package/dist/lib/cn.js +98 -0
- package/dist/motion/inertia.js +111 -0
- package/dist/motion/spring-step.js +35 -0
- package/dist/motion/springs.d.ts +78 -0
- package/dist/motion/springs.js +81 -0
- package/package.json +107 -4
- package/src/styles/base.css +93 -0
- package/src/styles/calendar.css +117 -0
- package/src/styles/code.css +252 -0
- package/src/styles/density.css +53 -0
- package/src/styles/depth.css +501 -0
- package/src/styles/grounds.css +191 -0
- package/src/styles/marks.css +50 -0
- package/src/styles/motion.css +55 -0
- package/src/styles/motion.generated.css +101 -0
- package/src/styles/prose.css +252 -0
- package/src/styles/radius.css +20 -0
- package/src/styles/segmented.css +208 -0
- package/src/styles/slider.css +110 -0
- package/src/styles/status.css +108 -0
- package/src/styles/tabs.css +39 -0
- package/src/styles/toast.css +106 -0
- package/src/styles/touch.css +41 -0
- package/src/styles/type.css +54 -0
- package/src/styles.css +38 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "../components/button/button.js";
|
|
3
|
+
import { Field, FieldLabel } from "../components/field/field.js";
|
|
4
|
+
import { Icon } from "../components/icon/icon.js";
|
|
5
|
+
import { InputGroupButton } from "../components/input-group/input-group.js";
|
|
6
|
+
import { PopoverClose, PopoverContent, PopoverTrigger } from "../components/popover/popover.js";
|
|
7
|
+
import { TimeField } from "../components/time-field/time-field.js";
|
|
8
|
+
import { FieldDisabledContext } from "./field-context.js";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { Calendar03Icon } from "@hugeicons/core-free-icons";
|
|
11
|
+
import { useContext, useRef } from "react";
|
|
12
|
+
// src/internal/picker-sheet.tsx
|
|
13
|
+
/**
|
|
14
|
+
* The button at the end of a date field that opens its calendar. A field that cannot be changed
|
|
15
|
+
* (disabled, by itself or through its `Field`, or read-only) does not open one.
|
|
16
|
+
*/
|
|
17
|
+
function PickerButton({ size, disabled }) {
|
|
18
|
+
const off = useContext(FieldDisabledContext) || disabled;
|
|
19
|
+
return /* @__PURE__ */ jsx(PopoverTrigger, { render: /* @__PURE__ */ jsx(InputGroupButton, {
|
|
20
|
+
"aria-label": "Kalender öffnen",
|
|
21
|
+
disabled: off,
|
|
22
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
23
|
+
icon: Calendar03Icon,
|
|
24
|
+
size: size === "sm" ? 14 : 16
|
|
25
|
+
})
|
|
26
|
+
}) });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The sheet a date field opens: its calendar and, with times, the boxes for them. It hangs
|
|
30
|
+
* from the whole field, opens with the focus on the chosen day (or today), so the arrows move
|
|
31
|
+
* from where the date is, and with `done` it carries a button to close it: a sheet that stays
|
|
32
|
+
* open after a day was picked needs one, most of all on a phone.
|
|
33
|
+
*/
|
|
34
|
+
function PickerSheet({ anchor, label, done = false, children }) {
|
|
35
|
+
const sheet = useRef(null);
|
|
36
|
+
return /* @__PURE__ */ jsxs(PopoverContent, {
|
|
37
|
+
anchor,
|
|
38
|
+
align: "start",
|
|
39
|
+
sideOffset: 6,
|
|
40
|
+
"aria-label": label,
|
|
41
|
+
className: "w-auto p-3",
|
|
42
|
+
ref: sheet,
|
|
43
|
+
initialFocus: () => sheet.current?.querySelector("[data-slot=\"calendar-day\"][tabindex=\"0\"]") ?? true,
|
|
44
|
+
children: [children, done && /* @__PURE__ */ jsx(PopoverClose, { render: /* @__PURE__ */ jsx(Button, {
|
|
45
|
+
size: "sm",
|
|
46
|
+
variant: "primary",
|
|
47
|
+
className: "self-end",
|
|
48
|
+
children: "Fertig"
|
|
49
|
+
}) })]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A time under the calendar: its name and a small `TimeField`, typed or picked like any other.
|
|
54
|
+
*
|
|
55
|
+
* It stands in a `Field` of its own. The sheet is a popup of the date field, and without that
|
|
56
|
+
* the time's control would join the date's field and take over its label.
|
|
57
|
+
*/
|
|
58
|
+
function PickerTime({ label, hourCycle, ...props }) {
|
|
59
|
+
return /* @__PURE__ */ jsxs(Field, {
|
|
60
|
+
className: "flex-row items-center gap-2",
|
|
61
|
+
children: [/* @__PURE__ */ jsx(FieldLabel, {
|
|
62
|
+
className: "font-normal text-fg-body",
|
|
63
|
+
children: label
|
|
64
|
+
}), /* @__PURE__ */ jsx(TimeField, {
|
|
65
|
+
size: "sm",
|
|
66
|
+
hourCycle,
|
|
67
|
+
className: hourCycle === 12 ? "w-[6.75rem]" : "w-[5.5rem]",
|
|
68
|
+
...props
|
|
69
|
+
})]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** The row under the calendar that holds the times, set off by a hairline. */
|
|
73
|
+
const pickerRow = "flex items-center justify-between gap-3 border-t border-hairline pt-3 text-control text-fg-body";
|
|
74
|
+
export { PickerButton, PickerSheet, PickerTime, pickerRow };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/internal/popup.ts
|
|
2
|
+
/**
|
|
3
|
+
* How every floating sheet (menu, select, popover, tooltip) enters and leaves. Base UI sets
|
|
4
|
+
* `data-starting-style` for the first frame and `data-ending-style` while closing, and keeps the
|
|
5
|
+
* popup mounted until its transition has finished.
|
|
6
|
+
*
|
|
7
|
+
* The sheet grows out of its trigger (`--transform-origin`) on `settle` and leaves on the shorter
|
|
8
|
+
* `leave`, without travel. `data-instant` (keyboard navigation, moving between neighbouring
|
|
9
|
+
* triggers) skips the animation altogether.
|
|
10
|
+
*/
|
|
11
|
+
const popupMotion = [
|
|
12
|
+
"origin-(--transform-origin) transition-[opacity,scale] spring-settle",
|
|
13
|
+
"data-starting-style:scale-(--motion-enter-scale) data-starting-style:opacity-0",
|
|
14
|
+
"data-ending-style:opacity-0 data-ending-style:spring-leave",
|
|
15
|
+
"data-instant:transition-none"
|
|
16
|
+
].join(" ");
|
|
17
|
+
/** The face of a sheet that holds a list (menu, select): 4px of padding around its rows. */
|
|
18
|
+
const listSheet = "rounded-xl bg-sheet p-1 text-fg depth-floating outline-hidden";
|
|
19
|
+
/**
|
|
20
|
+
* A row in such a list. It takes the concentric radius of the sheet. The highlight is instant: it
|
|
21
|
+
* follows the pointer and the arrow keys without lag. Focus stays on the popup, so the row has no
|
|
22
|
+
* outline of its own.
|
|
23
|
+
*/
|
|
24
|
+
const listItem = [
|
|
25
|
+
"flex min-h-(--control-item) cursor-default items-center gap-2.5 rounded-[calc(var(--radius-xl)-4px)] px-2.5 py-1 text-control text-fg outline-none select-none",
|
|
26
|
+
"data-highlighted:bg-hover",
|
|
27
|
+
"forced-colors:data-highlighted:bg-[color:Highlight] forced-colors:data-highlighted:text-[color:HighlightText]",
|
|
28
|
+
"data-disabled:text-on-disabled"
|
|
29
|
+
].join(" ");
|
|
30
|
+
const listGroupLabel = "px-2.5 pt-2 pb-1 text-sm text-fg-muted";
|
|
31
|
+
const listSeparator = "mx-2.5 my-1 h-px bg-hairline forced-colors:bg-[color:GrayText]";
|
|
32
|
+
/**
|
|
33
|
+
* The second, quieter fact of a row (a price, a place, a code), pushed to the right edge with
|
|
34
|
+
* tabular digits so it lines up from row to row. It never shrinks: the label gives way.
|
|
35
|
+
*/
|
|
36
|
+
const listItemDetail = "ml-auto shrink-0 pl-3 whitespace-nowrap text-fg-muted tabular-nums";
|
|
37
|
+
export { listGroupLabel, listItem, listItemDetail, listSeparator, listSheet, popupMotion };
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { weekdayIndex } from "./iso-date.js";
|
|
2
|
+
// src/internal/range-shape.ts
|
|
3
|
+
/**
|
|
4
|
+
* The outline of what is chosen in a month's grid, as one shape.
|
|
5
|
+
*
|
|
6
|
+
* A range that runs over several weeks is a stair: the first week from its first day to Sunday,
|
|
7
|
+
* whole weeks, the last week from Monday to its last day. Drawn as one outline it reads as one
|
|
8
|
+
* thing: round where it turns outwards, round where the rows step inwards, no line where two
|
|
9
|
+
* weeks meet. (Two weeks that do not stand above each other anywhere, Saturday to Tuesday, stay
|
|
10
|
+
* two pieces: there is nothing to join.)
|
|
11
|
+
*
|
|
12
|
+
* There are two ways to get it:
|
|
13
|
+
*
|
|
14
|
+
* - `rangeOutline`, at rest: the points of a CSS `polygon()` with every length written in the
|
|
15
|
+
* calendar's own units (`--u` the pitch from one day to the next, `--g` the gap between days,
|
|
16
|
+
* `--r` the corner radius). The shape follows the density and the pointer without being
|
|
17
|
+
* measured, and can be rendered on a server.
|
|
18
|
+
* - `spanOutline`, on the way from one selection to the next: the same shape in pixels, for
|
|
19
|
+
* rows and columns that need not be whole. Whatever the numbers, it is a proper outline that
|
|
20
|
+
* never crosses itself, so a selection can glide to its new place and be drawn at every
|
|
21
|
+
* instant: a new week grows out of the edge, a neck between two weeks thins and lets go.
|
|
22
|
+
*
|
|
23
|
+
* A quarter circle is drawn as a few short lines; at this size the eye cannot tell.
|
|
24
|
+
*
|
|
25
|
+
* Pure data and functions: no "use client", safe to test without a browser.
|
|
26
|
+
*/
|
|
27
|
+
const RIGHT = [1, 0];
|
|
28
|
+
const DOWN = [0, 1];
|
|
29
|
+
const LEFT = [-1, 0];
|
|
30
|
+
const UP = [0, -1];
|
|
31
|
+
/** The lines a quarter circle is drawn with. */
|
|
32
|
+
const ARC_STEPS = 6;
|
|
33
|
+
const length = (u, g = 0) => ({
|
|
34
|
+
u,
|
|
35
|
+
g,
|
|
36
|
+
r: 0,
|
|
37
|
+
px: 0
|
|
38
|
+
});
|
|
39
|
+
/** The start edge of a column or row, and its end edge: one gap short of the next start. */
|
|
40
|
+
const start = (index) => length(index);
|
|
41
|
+
const end = (index) => length(index + 1, -1);
|
|
42
|
+
/** The four corners of one row's part of the range, clockwise from its top left. */
|
|
43
|
+
function bar(row, from, to) {
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
x: start(from),
|
|
47
|
+
y: start(row),
|
|
48
|
+
in: UP,
|
|
49
|
+
out: RIGHT
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
x: end(to),
|
|
53
|
+
y: start(row),
|
|
54
|
+
in: RIGHT,
|
|
55
|
+
out: DOWN
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
x: end(to),
|
|
59
|
+
y: end(row),
|
|
60
|
+
in: DOWN,
|
|
61
|
+
out: LEFT
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
x: start(from),
|
|
65
|
+
y: end(row),
|
|
66
|
+
in: LEFT,
|
|
67
|
+
out: UP
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The corners of the range, clockwise, as one or two pieces. `first` and `last` are the columns
|
|
73
|
+
* (0 to 6) of its first and last day, `rows` how many weeks it touches, `top` the row of the
|
|
74
|
+
* first of them.
|
|
75
|
+
*/
|
|
76
|
+
function corners(first, last, rows, top) {
|
|
77
|
+
const bottom = top + rows - 1;
|
|
78
|
+
if (rows === 1) return [bar(top, first, last)];
|
|
79
|
+
if (rows === 2 && last < first) return [bar(top, first, 6), bar(bottom, 0, last)];
|
|
80
|
+
const outline = [{
|
|
81
|
+
x: start(first),
|
|
82
|
+
y: start(top),
|
|
83
|
+
in: UP,
|
|
84
|
+
out: RIGHT
|
|
85
|
+
}, {
|
|
86
|
+
x: end(6),
|
|
87
|
+
y: start(top),
|
|
88
|
+
in: RIGHT,
|
|
89
|
+
out: DOWN
|
|
90
|
+
}];
|
|
91
|
+
if (last === 6) outline.push({
|
|
92
|
+
x: end(6),
|
|
93
|
+
y: end(bottom),
|
|
94
|
+
in: DOWN,
|
|
95
|
+
out: LEFT
|
|
96
|
+
});
|
|
97
|
+
else outline.push({
|
|
98
|
+
x: end(6),
|
|
99
|
+
y: end(bottom - 1),
|
|
100
|
+
in: DOWN,
|
|
101
|
+
out: LEFT
|
|
102
|
+
}, {
|
|
103
|
+
x: end(last),
|
|
104
|
+
y: end(bottom - 1),
|
|
105
|
+
in: LEFT,
|
|
106
|
+
out: DOWN
|
|
107
|
+
}, {
|
|
108
|
+
x: end(last),
|
|
109
|
+
y: end(bottom),
|
|
110
|
+
in: DOWN,
|
|
111
|
+
out: LEFT
|
|
112
|
+
});
|
|
113
|
+
outline.push({
|
|
114
|
+
x: start(0),
|
|
115
|
+
y: end(bottom),
|
|
116
|
+
in: LEFT,
|
|
117
|
+
out: UP
|
|
118
|
+
});
|
|
119
|
+
if (first > 0) outline.push({
|
|
120
|
+
x: start(0),
|
|
121
|
+
y: start(top + 1),
|
|
122
|
+
in: UP,
|
|
123
|
+
out: RIGHT
|
|
124
|
+
}, {
|
|
125
|
+
x: start(first),
|
|
126
|
+
y: start(top + 1),
|
|
127
|
+
in: RIGHT,
|
|
128
|
+
out: UP
|
|
129
|
+
});
|
|
130
|
+
return [outline];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* One corner as the points of its arc. `grow` pushes the outline outwards by that many pixels
|
|
134
|
+
* (for the edge drawn around the shape): the corner moves out along both of its sides, an outer
|
|
135
|
+
* arc gets that much larger and an inner one that much smaller.
|
|
136
|
+
*/
|
|
137
|
+
function arc(corner, grow) {
|
|
138
|
+
const [inX, inY] = corner.in;
|
|
139
|
+
const [outX, outY] = corner.out;
|
|
140
|
+
const radiusPx = inX * outY - inY * outX > 0 ? grow : -grow;
|
|
141
|
+
const moveX = grow * (inY + outY);
|
|
142
|
+
const moveY = grow * (-inX - outX);
|
|
143
|
+
const points = [];
|
|
144
|
+
for (let step = 0; step <= ARC_STEPS; step++) {
|
|
145
|
+
const angle = step / ARC_STEPS * (Math.PI / 2);
|
|
146
|
+
const along = Math.sin(angle) - 1;
|
|
147
|
+
const across = 1 - Math.cos(angle);
|
|
148
|
+
const kx = inX * along + outX * across;
|
|
149
|
+
const ky = inY * along + outY * across;
|
|
150
|
+
points.push({
|
|
151
|
+
x: {
|
|
152
|
+
...corner.x,
|
|
153
|
+
r: kx,
|
|
154
|
+
px: corner.x.px + moveX + radiusPx * kx
|
|
155
|
+
},
|
|
156
|
+
y: {
|
|
157
|
+
...corner.y,
|
|
158
|
+
r: ky,
|
|
159
|
+
px: corner.y.px + moveY + radiusPx * ky
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return points;
|
|
164
|
+
}
|
|
165
|
+
/** Pieces as one list: two are joined by a line there and back, which encloses nothing. */
|
|
166
|
+
function joined(pieces) {
|
|
167
|
+
if (pieces.length === 1) return pieces[0];
|
|
168
|
+
return pieces.flatMap((piece) => [...piece, piece[0]]);
|
|
169
|
+
}
|
|
170
|
+
/** The outline of a range at rest as points, clockwise from the top left of its first day. */
|
|
171
|
+
function rangeOutline(first, last, rows, grow = 0, top = 0) {
|
|
172
|
+
return joined(corners(first, last, rows, top).map((piece) => piece.flatMap((corner) => arc(corner, grow))));
|
|
173
|
+
}
|
|
174
|
+
const term = (factor, unit) => {
|
|
175
|
+
const rounded = Math.round(factor * 1e4) / 1e4;
|
|
176
|
+
return rounded === 0 ? "" : ` + ${rounded}${unit}`;
|
|
177
|
+
};
|
|
178
|
+
/** A length as CSS. `pad` is added to every one: the room the drawing keeps around the grid. */
|
|
179
|
+
function css(value, pad) {
|
|
180
|
+
const sum = term(value.u, "*var(--u)") + term(value.g, "*var(--g)") + term(value.r, "*var(--r)") + term(value.px + pad, "px");
|
|
181
|
+
return sum === "" ? "0px" : `calc(${sum.slice(3)})`;
|
|
182
|
+
}
|
|
183
|
+
/** Points as the list a `polygon()` takes. */
|
|
184
|
+
function polygonPoints(points, pad = 0) {
|
|
185
|
+
return points.map((point) => `${css(point.x, pad)} ${css(point.y, pad)}`).join(", ");
|
|
186
|
+
}
|
|
187
|
+
/** A piece never gets thinner than this, in px: thinner, its corners could not be drawn. */
|
|
188
|
+
const THINNEST = 1;
|
|
189
|
+
const box = (left, top, right, bottom) => [
|
|
190
|
+
[left, top],
|
|
191
|
+
[right, top],
|
|
192
|
+
[right, bottom],
|
|
193
|
+
[left, bottom]
|
|
194
|
+
];
|
|
195
|
+
/**
|
|
196
|
+
* A polygon whose sides run along the grid, with its corners rounded. A corner is never rounder
|
|
197
|
+
* than half of its shorter side, so two corners close together share that side instead of
|
|
198
|
+
* running into each other. `grow` as in `arc`.
|
|
199
|
+
*/
|
|
200
|
+
function rounded(corners, radius, grow) {
|
|
201
|
+
const turns = corners.filter((corner, index) => {
|
|
202
|
+
const before = corners[(index + corners.length - 1) % corners.length];
|
|
203
|
+
const after = corners[(index + 1) % corners.length];
|
|
204
|
+
const same = Math.abs(corner[0] - before[0]) + Math.abs(corner[1] - before[1]) < 1e-6;
|
|
205
|
+
const straight = Math.abs(corner[0] - before[0]) < 1e-6 && Math.abs(after[0] - corner[0]) < 1e-6 || Math.abs(corner[1] - before[1]) < 1e-6 && Math.abs(after[1] - corner[1]) < 1e-6;
|
|
206
|
+
return !same && !straight;
|
|
207
|
+
});
|
|
208
|
+
return turns.flatMap(([x, y], index) => {
|
|
209
|
+
const before = turns[(index + turns.length - 1) % turns.length];
|
|
210
|
+
const after = turns[(index + 1) % turns.length];
|
|
211
|
+
const lengthIn = Math.abs(x - before[0]) + Math.abs(y - before[1]);
|
|
212
|
+
const lengthOut = Math.abs(after[0] - x) + Math.abs(after[1] - y);
|
|
213
|
+
const inX = (x - before[0]) / lengthIn;
|
|
214
|
+
const inY = (y - before[1]) / lengthIn;
|
|
215
|
+
const outX = (after[0] - x) / lengthOut;
|
|
216
|
+
const outY = (after[1] - y) / lengthOut;
|
|
217
|
+
const outer = inX * outY - inY * outX > 0;
|
|
218
|
+
const fit = Math.min(radius, lengthIn / 2, lengthOut / 2);
|
|
219
|
+
const r = outer ? fit + grow : Math.max(0, fit - grow);
|
|
220
|
+
const cornerX = x + grow * (inY + outY);
|
|
221
|
+
const cornerY = y + grow * (-inX - outX);
|
|
222
|
+
return Array.from({ length: 7 }, (_, step) => {
|
|
223
|
+
const angle = step / ARC_STEPS * (Math.PI / 2);
|
|
224
|
+
const along = Math.sin(angle) - 1;
|
|
225
|
+
const across = 1 - Math.cos(angle);
|
|
226
|
+
return [cornerX + r * (inX * along + outX * across), cornerY + r * (inY * along + outY * across)];
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* The outline of a span in pixels, clockwise. For whole rows and columns it is the shape
|
|
232
|
+
* `rangeOutline` draws. In between it is what lies between two sliding marks: the first day's
|
|
233
|
+
* week from its left edge on, the last day's week up to its right edge, and everything between
|
|
234
|
+
* those two weeks. So as the numbers move, weeks grow out of an edge as slivers, and the neck
|
|
235
|
+
* between two weeks thins to nothing before they part.
|
|
236
|
+
*/
|
|
237
|
+
function spanOutline(span, sizes, grow = 0) {
|
|
238
|
+
const pitch = sizes.cell + sizes.gap;
|
|
239
|
+
const width = 7 * pitch - sizes.gap;
|
|
240
|
+
const left = Math.min(span.first * pitch, width - THINNEST);
|
|
241
|
+
const right = Math.max((span.last + 1) * pitch - sizes.gap, THINNEST);
|
|
242
|
+
const top = span.top * pitch;
|
|
243
|
+
const firstEnds = top + pitch;
|
|
244
|
+
const lastBegins = span.bottom * pitch - sizes.gap;
|
|
245
|
+
const bottom = span.bottom * pitch + sizes.cell;
|
|
246
|
+
const round = (corners) => rounded(corners, sizes.radius, grow);
|
|
247
|
+
if (lastBegins <= top) return round(box(left, top, Math.max(right, left + THINNEST), bottom));
|
|
248
|
+
if (lastBegins < firstEnds && left > right) return joined([round(box(left, top, width, lastBegins)), round(box(0, firstEnds, right, bottom))]);
|
|
249
|
+
return round([
|
|
250
|
+
[left, top],
|
|
251
|
+
[width, top],
|
|
252
|
+
[width, lastBegins],
|
|
253
|
+
[right, lastBegins],
|
|
254
|
+
[right, bottom],
|
|
255
|
+
[0, bottom],
|
|
256
|
+
[0, firstEnds],
|
|
257
|
+
[left, firstEnds]
|
|
258
|
+
]);
|
|
259
|
+
}
|
|
260
|
+
/** Pixels as the list a `polygon()` takes. `pad` as in `polygonPoints`. */
|
|
261
|
+
function pixelPoints(points, pad = 0) {
|
|
262
|
+
const px = (value) => `${Math.round((value + pad) * 100) / 100}px`;
|
|
263
|
+
return points.map(([x, y]) => `${px(x)} ${px(y)}`).join(", ");
|
|
264
|
+
}
|
|
265
|
+
const DAY = 864e5;
|
|
266
|
+
const daysBetween = (from, to) => Math.round((to.getTime() - from.getTime()) / DAY);
|
|
267
|
+
/** The Monday on or before the 1st of a month: where its grid of six weeks begins. */
|
|
268
|
+
function gridStart(month) {
|
|
269
|
+
const firstOfMonth = new Date(month.getFullYear(), month.getMonth(), 1);
|
|
270
|
+
return new Date(firstOfMonth.getFullYear(), firstOfMonth.getMonth(), 1 - weekdayIndex(firstOfMonth));
|
|
271
|
+
}
|
|
272
|
+
/** The 42 days in the grid of a month, row by row. */
|
|
273
|
+
function gridDays(month) {
|
|
274
|
+
const begin = gridStart(month);
|
|
275
|
+
return Array.from({ length: 42 }, (_, index) => new Date(begin.getFullYear(), begin.getMonth(), begin.getDate() + index));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Where a range stands in the grid of one month: the columns of its first and last day there,
|
|
279
|
+
* the row of the first, and how many rows it touches. The grid starts on the Monday on or
|
|
280
|
+
* before the 1st and shows six weeks; a range that begins before it or goes on after it is cut
|
|
281
|
+
* at its edge. `undefined` if none of the range is in the grid.
|
|
282
|
+
*/
|
|
283
|
+
function rangeInGrid(month, from, to) {
|
|
284
|
+
const begin = Math.max(0, daysBetween(gridStart(month), from));
|
|
285
|
+
const finish = Math.min(41, daysBetween(gridStart(month), to));
|
|
286
|
+
if (begin > finish) return void 0;
|
|
287
|
+
const top = Math.floor(begin / 7);
|
|
288
|
+
return {
|
|
289
|
+
first: begin % 7,
|
|
290
|
+
last: finish % 7,
|
|
291
|
+
top,
|
|
292
|
+
rows: Math.floor(finish / 7) - top + 1
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
export { gridDays, pixelPoints, polygonPoints, rangeInGrid, rangeOutline, spanOutline };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
// src/internal/reduced-motion.ts
|
|
4
|
+
const QUERY = "(prefers-reduced-motion: reduce)";
|
|
5
|
+
function subscribe(notify) {
|
|
6
|
+
const query = window.matchMedia(QUERY);
|
|
7
|
+
query.addEventListener("change", notify);
|
|
8
|
+
return () => query.removeEventListener("change", notify);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether the person asked for less motion. False on the server.
|
|
12
|
+
*
|
|
13
|
+
* CSS answers that question for transitions (`motion-reduce:`). This is for motion a component
|
|
14
|
+
* starts by itself, on a timer, which no stylesheet can switch off.
|
|
15
|
+
*/
|
|
16
|
+
function useReducedMotion() {
|
|
17
|
+
return useSyncExternalStore(subscribe, () => window.matchMedia(QUERY).matches, () => false);
|
|
18
|
+
}
|
|
19
|
+
export { useReducedMotion };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
// src/internal/scroll-edges.ts
|
|
4
|
+
/**
|
|
5
|
+
* Says on a box that scrolls which of its ends has more to show: `data-overflow` holds `start`,
|
|
6
|
+
* `end`, both, or is absent. The stylesheet fades those edges (the code block's lines, a row of
|
|
7
|
+
* tabs, the foot of the site's menu). The state is written straight onto the element, so
|
|
8
|
+
* scrolling never renders. `axis` is the direction the box scrolls in. For a box that mounts
|
|
9
|
+
* later than the component (a popup), pass something that changes when it does as `mounted`,
|
|
10
|
+
* so the edges are watched from then on.
|
|
11
|
+
*/
|
|
12
|
+
function useScrollEdges(ref, axis = "x", mounted) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const scroller = ref.current;
|
|
15
|
+
if (!scroller) return;
|
|
16
|
+
let frame = 0;
|
|
17
|
+
const update = () => {
|
|
18
|
+
frame = 0;
|
|
19
|
+
const start = axis === "x" ? scroller.scrollLeft : scroller.scrollTop;
|
|
20
|
+
const visible = axis === "x" ? scroller.clientWidth : scroller.clientHeight;
|
|
21
|
+
const total = axis === "x" ? scroller.scrollWidth : scroller.scrollHeight;
|
|
22
|
+
const overflow = [start > 1 ? "start" : "", start + visible < total - 1 ? "end" : ""].filter(Boolean).join(" ");
|
|
23
|
+
if (overflow) scroller.dataset.overflow = overflow;
|
|
24
|
+
else delete scroller.dataset.overflow;
|
|
25
|
+
};
|
|
26
|
+
const schedule = () => {
|
|
27
|
+
frame ||= requestAnimationFrame(update);
|
|
28
|
+
};
|
|
29
|
+
update();
|
|
30
|
+
scroller.addEventListener("scroll", schedule, { passive: true });
|
|
31
|
+
const observer = new ResizeObserver(schedule);
|
|
32
|
+
observer.observe(scroller);
|
|
33
|
+
for (const child of scroller.children) observer.observe(child);
|
|
34
|
+
return () => {
|
|
35
|
+
cancelAnimationFrame(frame);
|
|
36
|
+
scroller.removeEventListener("scroll", schedule);
|
|
37
|
+
observer.disconnect();
|
|
38
|
+
};
|
|
39
|
+
}, [
|
|
40
|
+
ref,
|
|
41
|
+
axis,
|
|
42
|
+
mounted
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
export { useScrollEdges };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/internal/trough.ts
|
|
2
|
+
/**
|
|
3
|
+
* A trough that takes a fill: the track of a `Progress`, a `Meter` and a `Slider`.
|
|
4
|
+
*
|
|
5
|
+
* The fill is a child of the trough, so it would cover the trough's shaded edge and lie on top
|
|
6
|
+
* like a sticker. The shade is therefore drawn by `::after`, over the fill: the colour lies IN
|
|
7
|
+
* the trough, as it does in a switch that is on.
|
|
8
|
+
*/
|
|
9
|
+
const troughTrack = ["overflow-hidden rounded-full bg-trough", "after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:depth-trough"].join(" ");
|
|
10
|
+
/**
|
|
11
|
+
* The fill. Its colour is the part's own; in forced colours it is the system's highlight.
|
|
12
|
+
*
|
|
13
|
+
* It is a bar as long as the trough, pushed out of it at the start so that only its end shows
|
|
14
|
+
* (`fillStyle`). It moves by `translate`, which the compositor animates; a width would be laid
|
|
15
|
+
* out again on every frame.
|
|
16
|
+
*/
|
|
17
|
+
const troughFill = "h-full rounded-full translate-x-[calc((var(--fill,1)-1)*100%)] rtl:translate-x-[calc((1-var(--fill,1))*100%)] forced-colors:bg-[Highlight]";
|
|
18
|
+
/** How much of the trough is filled, from 0 to 1. */
|
|
19
|
+
function fillFraction(value, min = 0, max = 100) {
|
|
20
|
+
return max > min ? Math.min(1, Math.max(0, (value - min) / (max - min))) : 0;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The style of a fill that stands at `fraction`. The width overrides the one Base UI sets from
|
|
24
|
+
* the value: here the place says it, not the length.
|
|
25
|
+
*/
|
|
26
|
+
function fillStyle(fraction) {
|
|
27
|
+
return {
|
|
28
|
+
width: "100%",
|
|
29
|
+
"--fill": fraction
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The layout of a labelled gauge (`Progress`, `Meter`, `Slider`): the name at the start, the
|
|
34
|
+
* value at the end of the same line, the track under both.
|
|
35
|
+
*/
|
|
36
|
+
const gaugeRoot = "grid w-full grid-cols-[1fr_auto] items-baseline gap-x-4";
|
|
37
|
+
const gaugeLabel = "text-control font-medium text-fg";
|
|
38
|
+
const gaugeValue = "text-control text-fg-muted tabular-nums";
|
|
39
|
+
export { fillFraction, fillStyle, gaugeLabel, gaugeRoot, gaugeValue, troughFill, troughTrack };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Input } from "../components/input/input.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type TypedInputProps = Omit<ComponentProps<typeof Input>, "value" | "defaultValue" | "onValueChange" | "render" | "type"> & {
|
|
4
|
+
/** What stands in the field: the typed text, or the value written the way it is read. */
|
|
5
|
+
text: string;
|
|
6
|
+
onTextChange: (text: string) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Typing has ended (the field was left, or Enter was pressed): read the text. Return why it
|
|
9
|
+
* cannot be used, or nothing if it can.
|
|
10
|
+
*/
|
|
11
|
+
onCommit: () => string | undefined;
|
|
12
|
+
/** What a form receives under the field's name, whatever the field shows. */
|
|
13
|
+
formValue: string;
|
|
14
|
+
/** Why the current text cannot be used, as last found out; empty when it can. */
|
|
15
|
+
problem: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Input } from "../components/input/input.js";
|
|
3
|
+
import { FieldActionsContext } from "./field-context.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useContext, useEffect, useRef, useState } from "react";
|
|
6
|
+
// src/internal/typed-input.tsx
|
|
7
|
+
/**
|
|
8
|
+
* An input whose text is not its value: it shows "14.11.2026" and submits "2026-11-14". Dates,
|
|
9
|
+
* times and ranges are typed into it.
|
|
10
|
+
*
|
|
11
|
+
* - The text is read when typing ends, never while it goes on: half a date is not a wrong date.
|
|
12
|
+
* - Text that cannot be read stays where it is, to be corrected. The field is flagged at once and
|
|
13
|
+
* the reason becomes its validation message (`setCustomValidity`), so a `Field` shows it through
|
|
14
|
+
* its `FieldError`, as soon as the field is left, and a `Form` does not submit.
|
|
15
|
+
* - The name goes to a hidden input that carries the value. A form posted the native way, or to
|
|
16
|
+
* a Server Action, gets the value under the field's name. `Form` hands the same value to
|
|
17
|
+
* `onFormSubmit` (it looks for `data-form-value`), where Base UI would report the text.
|
|
18
|
+
*
|
|
19
|
+
* It is the `Field`'s control like any `Input`: label, description and focus on an invalid
|
|
20
|
+
* submit all work as usual.
|
|
21
|
+
*/
|
|
22
|
+
function TypedInput({ text, onTextChange, onCommit, formValue, problem, onBlur, onKeyDown, ...props }) {
|
|
23
|
+
const input = useRef(null);
|
|
24
|
+
const field = useContext(FieldActionsContext);
|
|
25
|
+
const told = useRef("");
|
|
26
|
+
const shown = useRef("");
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
let look = shown.current !== problem;
|
|
29
|
+
if (told.current !== problem) {
|
|
30
|
+
told.current = problem;
|
|
31
|
+
input.current?.setCustomValidity(problem);
|
|
32
|
+
look = true;
|
|
33
|
+
}
|
|
34
|
+
if (look) {
|
|
35
|
+
shown.current = problem;
|
|
36
|
+
field?.current?.validate();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const commit = () => {
|
|
40
|
+
told.current = onCommit() ?? "";
|
|
41
|
+
input.current?.setCustomValidity(told.current);
|
|
42
|
+
};
|
|
43
|
+
return /* @__PURE__ */ jsx(Input, {
|
|
44
|
+
autoComplete: "off",
|
|
45
|
+
value: text,
|
|
46
|
+
onValueChange: onTextChange,
|
|
47
|
+
onBlur: (event) => {
|
|
48
|
+
commit();
|
|
49
|
+
onBlur?.(event);
|
|
50
|
+
},
|
|
51
|
+
onKeyDown: (event) => {
|
|
52
|
+
const takesRow = event.currentTarget.hasAttribute("aria-activedescendant");
|
|
53
|
+
if (event.key === "Enter" && !takesRow) commit();
|
|
54
|
+
onKeyDown?.(event);
|
|
55
|
+
},
|
|
56
|
+
...problem ? {
|
|
57
|
+
"aria-invalid": true,
|
|
58
|
+
"data-invalid": ""
|
|
59
|
+
} : null,
|
|
60
|
+
...props,
|
|
61
|
+
render: ({ name, ref, ...visible }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
|
|
62
|
+
...visible,
|
|
63
|
+
ref: (node) => {
|
|
64
|
+
input.current = node;
|
|
65
|
+
if (typeof ref === "function") return ref(node);
|
|
66
|
+
if (ref) ref.current = node;
|
|
67
|
+
}
|
|
68
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
69
|
+
type: "hidden",
|
|
70
|
+
"data-form-value": "",
|
|
71
|
+
name,
|
|
72
|
+
value: formValue,
|
|
73
|
+
disabled: visible.disabled
|
|
74
|
+
})] })
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The state behind a `TypedInput`: the value, the text that stands in the field, and what is
|
|
79
|
+
* wrong with that text. Text that cannot be read reports an empty value and stays in the field.
|
|
80
|
+
*/
|
|
81
|
+
function useTypedValue({ value, defaultValue, onValueChange, read, show }) {
|
|
82
|
+
const [inner, setInner] = useState(defaultValue ?? "");
|
|
83
|
+
const current = value ?? inner;
|
|
84
|
+
const [text, setText] = useState(() => show(current));
|
|
85
|
+
const [problem, setProblem] = useState("");
|
|
86
|
+
const [shown, setShown] = useState(current);
|
|
87
|
+
if (shown !== current) {
|
|
88
|
+
setShown(current);
|
|
89
|
+
setText(show(current));
|
|
90
|
+
setProblem("");
|
|
91
|
+
}
|
|
92
|
+
const latest = useRef(current);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
latest.current = current;
|
|
95
|
+
});
|
|
96
|
+
const change = (next) => {
|
|
97
|
+
if (next === latest.current) return;
|
|
98
|
+
latest.current = next;
|
|
99
|
+
if (value === void 0) setInner(next);
|
|
100
|
+
setShown(next);
|
|
101
|
+
onValueChange?.(next);
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
value: current,
|
|
105
|
+
text,
|
|
106
|
+
setText,
|
|
107
|
+
problem,
|
|
108
|
+
/** A value that was chosen, not typed: from a calendar, an arrow key. */
|
|
109
|
+
set: (next) => {
|
|
110
|
+
setText(show(next));
|
|
111
|
+
setProblem("");
|
|
112
|
+
change(next);
|
|
113
|
+
},
|
|
114
|
+
/** Typing has ended. Returns why the text cannot be used, or nothing. */
|
|
115
|
+
commit: () => {
|
|
116
|
+
if (text.trim() === "") {
|
|
117
|
+
setProblem("");
|
|
118
|
+
change("");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const result = read(text);
|
|
122
|
+
if (typeof result !== "string") {
|
|
123
|
+
setProblem(result.problem);
|
|
124
|
+
change("");
|
|
125
|
+
return result.problem;
|
|
126
|
+
}
|
|
127
|
+
setText(show(result));
|
|
128
|
+
setProblem("");
|
|
129
|
+
change(result);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export { TypedInput, useTypedValue };
|
package/dist/lib/cn.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ClassValue } from "clsx";
|
|
2
|
+
/**
|
|
3
|
+
* Joins class names conditionally and resolves conflicting Tailwind utilities, last one wins.
|
|
4
|
+
* Use it for every `className` a component composes from defaults plus caller overrides.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cn(...inputs: ClassValue[]): string;
|
|
7
|
+
/**
|
|
8
|
+
* Merges a component's own classes with the caller's `className`, which on Base UI parts may be a
|
|
9
|
+
* function of the part's state. The function form is preserved, so callers keep access to state.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergeClassName<State>(base: ClassValue, className: string | ((state: State) => string | undefined) | undefined): string | ((state: State) => string);
|