@senvenli/react 0.3.2 → 0.3.4
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/dist/action/fab.d.ts +7 -0
- package/dist/action/fab.js +22 -3
- package/dist/action/fab.js.map +1 -1
- package/dist/collection/data-table.d.ts +1 -1
- package/dist/collection/data-table.js +2 -2
- package/dist/collection/data-table.js.map +1 -1
- package/dist/collection/table.d.ts +7 -2
- package/dist/collection/table.js +17 -7
- package/dist/collection/table.js.map +1 -1
- package/dist/i18n.d.ts +8 -0
- package/dist/i18n.js +18 -1
- package/dist/i18n.js.map +1 -1
- package/dist/navigation/index.d.ts +2 -2
- package/dist/navigation/index.js +1 -1
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/sidebar.d.ts +18 -0
- package/dist/navigation/sidebar.js +26 -2
- package/dist/navigation/sidebar.js.map +1 -1
- package/dist/overlay/floating.js +4 -1
- package/dist/overlay/floating.js.map +1 -1
- package/dist/overlay/index.d.ts +2 -0
- package/dist/overlay/index.js +2 -1
- package/dist/overlay/index.js.map +1 -1
- package/dist/overlay/tour.d.ts +88 -0
- package/dist/overlay/tour.js +302 -0
- package/dist/overlay/tour.js.map +1 -0
- package/manifests/data-table.json +1 -1
- package/manifests/index.json +2 -1
- package/manifests/sidebar.json +55 -2
- package/manifests/table.json +2 -2
- package/package.json +2 -2
- package/dist/action/files.d.ts +0 -70
- package/dist/action/files.js +0 -156
- package/dist/action/files.js.map +0 -1
- package/dist/action/theme-toggle.d.ts +0 -43
- package/dist/action/theme-toggle.js +0 -259
- package/dist/action/theme-toggle.js.map +0 -1
- package/dist/display/image-crop.d.ts +0 -106
- package/dist/display/image-crop.js +0 -117
- package/dist/display/image-crop.js.map +0 -1
- package/dist/display/image-cropper.d.ts +0 -68
- package/dist/display/image-cropper.js +0 -284
- package/dist/display/image-cropper.js.map +0 -1
- package/dist/display/lozenge.d.ts +0 -30
- package/dist/display/lozenge.js +0 -55
- package/dist/display/lozenge.js.map +0 -1
- package/dist/display/scroll-area.d.ts +0 -29
- package/dist/display/scroll-area.js +0 -95
- package/dist/display/scroll-area.js.map +0 -1
- package/dist/feedback/cooldown.d.ts +0 -17
- package/dist/feedback/cooldown.js +0 -59
- package/dist/feedback/cooldown.js.map +0 -1
- package/dist/feedback/status-dot.d.ts +0 -23
- package/dist/feedback/status-dot.js +0 -37
- package/dist/feedback/status-dot.js.map +0 -1
- package/dist/form/input-otp.d.ts +0 -35
- package/dist/form/input-otp.js +0 -83
- package/dist/form/input-otp.js.map +0 -1
- package/dist/layout/auth-form-layout.d.ts +0 -71
- package/dist/layout/auth-form-layout.js +0 -61
- package/dist/layout/auth-form-layout.js.map +0 -1
- package/dist/layout/auth-layout.d.ts +0 -59
- package/dist/layout/auth-layout.js +0 -26
- package/dist/layout/auth-layout.js.map +0 -1
- package/dist/layout/pressable.d.ts +0 -40
- package/dist/layout/pressable.js +0 -65
- package/dist/layout/pressable.js.map +0 -1
- package/dist/layout/reset-sent-card.d.ts +0 -39
- package/dist/layout/reset-sent-card.js +0 -22
- package/dist/layout/reset-sent-card.js.map +0 -1
- package/dist/navigation/dock.d.ts +0 -27
- package/dist/navigation/dock.js +0 -47
- package/dist/navigation/dock.js.map +0 -1
- package/dist/navigation/footer.d.ts +0 -43
- package/dist/navigation/footer.js +0 -43
- package/dist/navigation/footer.js.map +0 -1
- package/dist/navigation/language-names.d.ts +0 -19
- package/dist/navigation/language-names.js +0 -79
- package/dist/navigation/language-names.js.map +0 -1
- package/dist/navigation/language-switcher.d.ts +0 -55
- package/dist/navigation/language-switcher.js +0 -53
- package/dist/navigation/language-switcher.js.map +0 -1
- package/dist/navigation/panel-header.d.ts +0 -37
- package/dist/navigation/panel-header.js +0 -50
- package/dist/navigation/panel-header.js.map +0 -1
- package/dist/navigation/toolbar.d.ts +0 -37
- package/dist/navigation/toolbar.js +0 -334
- package/dist/navigation/toolbar.js.map +0 -1
- package/dist/overlay/command-palette.d.ts +0 -53
- package/dist/overlay/command-palette.js +0 -130
- package/dist/overlay/command-palette.js.map +0 -1
- package/dist/overlay/overlay.d.ts +0 -299
- package/dist/overlay/overlay.js +0 -558
- package/dist/overlay/overlay.js.map +0 -1
- package/dist/selection/radio-card.d.ts +0 -31
- package/dist/selection/radio-card.js +0 -29
- package/dist/selection/radio-card.js.map +0 -1
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { cn } from "../utils.js";
|
|
5
|
-
const TABBABLE = 'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
|
|
6
|
-
/** A tabbable descendant that is not hidden or inert. */
|
|
7
|
-
function hasTabbable(root) {
|
|
8
|
-
return Array.from(root.querySelectorAll(TABBABLE)).some((element) => !element.closest("[hidden], [inert]"));
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A fixed-size region with its own native scroll (never hijacked) and the
|
|
12
|
-
* scrollbar contract (thin, a ds-border-bold thumb), plus an overflow
|
|
13
|
-
* shadow on each edge where content continues. When it holds nothing
|
|
14
|
-
* focusable it becomes a focusable region itself, so keyboard users can
|
|
15
|
-
* scroll it with the arrow keys.
|
|
16
|
-
*
|
|
17
|
-
* Known deviation: the design's 6px thumb is drawn by the platform's thin
|
|
18
|
-
* scrollbar (about 8–11px); standard CSS cannot size it further without
|
|
19
|
-
* replacing native scrolling. With `orientation="both"` the edge shadows
|
|
20
|
-
* follow the vertical axis.
|
|
21
|
-
*/
|
|
22
|
-
export function ScrollArea({ children, "aria-label": ariaLabel, maxHeight, fill = false, orientation = "vertical" }) {
|
|
23
|
-
const viewport = React.useRef(null);
|
|
24
|
-
const [edges, setEdges] = React.useState({ start: false, end: false });
|
|
25
|
-
const [needsFocus, setNeedsFocus] = React.useState(false);
|
|
26
|
-
// The thumb shows while scrolling and fades shortly after.
|
|
27
|
-
const [scrolling, setScrolling] = React.useState(false);
|
|
28
|
-
const scrollTimer = React.useRef(undefined);
|
|
29
|
-
React.useEffect(() => () => window.clearTimeout(scrollTimer.current), []);
|
|
30
|
-
// Every scroll event restarts the fade-out, so a long scroll keeps the thumb steady.
|
|
31
|
-
const onScrolling = () => {
|
|
32
|
-
window.clearTimeout(scrollTimer.current);
|
|
33
|
-
setScrolling(true);
|
|
34
|
-
scrollTimer.current = window.setTimeout(() => setScrolling(false), 800);
|
|
35
|
-
};
|
|
36
|
-
const horizontal = orientation === "horizontal";
|
|
37
|
-
const room = () => {
|
|
38
|
-
const frame = viewport.current;
|
|
39
|
-
return frame ? (horizontal ? frame.scrollWidth - frame.clientWidth : frame.scrollHeight - frame.clientHeight) : 0;
|
|
40
|
-
};
|
|
41
|
-
/** Which edges hide content; cheap enough for every scroll event. */
|
|
42
|
-
const measureEdges = React.useCallback(() => {
|
|
43
|
-
const frame = viewport.current;
|
|
44
|
-
if (!frame)
|
|
45
|
-
return;
|
|
46
|
-
// Horizontal scroll positions are negative in RTL; magnitudes work for both directions.
|
|
47
|
-
const position = Math.abs(horizontal ? frame.scrollLeft : frame.scrollTop);
|
|
48
|
-
const space = horizontal ? frame.scrollWidth - frame.clientWidth : frame.scrollHeight - frame.clientHeight;
|
|
49
|
-
const next = { start: position > 1, end: space - position > 1 };
|
|
50
|
-
setEdges((current) => (current.start === next.start && current.end === next.end ? current : next));
|
|
51
|
-
}, [horizontal]);
|
|
52
|
-
/** Whether the region must take focus itself: it scrolls and holds nothing focusable. Runs on size and content changes. */
|
|
53
|
-
const measureFocus = React.useCallback(() => {
|
|
54
|
-
const frame = viewport.current;
|
|
55
|
-
if (!frame)
|
|
56
|
-
return;
|
|
57
|
-
const next = room() > 1 && !hasTabbable(frame);
|
|
58
|
-
// Never pull focus out from under the keyboard: keep the tab stop while the region itself has focus.
|
|
59
|
-
setNeedsFocus((current) => (current && !next && document.activeElement === frame ? current : next));
|
|
60
|
-
}, [horizontal]);
|
|
61
|
-
React.useLayoutEffect(() => {
|
|
62
|
-
measureEdges();
|
|
63
|
-
measureFocus();
|
|
64
|
-
const frame = viewport.current;
|
|
65
|
-
if (!frame)
|
|
66
|
-
return;
|
|
67
|
-
const sized = () => {
|
|
68
|
-
measureEdges();
|
|
69
|
-
measureFocus();
|
|
70
|
-
};
|
|
71
|
-
const resize = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(sized);
|
|
72
|
-
resize?.observe(frame);
|
|
73
|
-
if (frame.firstElementChild)
|
|
74
|
-
resize?.observe(frame.firstElementChild);
|
|
75
|
-
// Children that appear, disappear or change focusability without changing size.
|
|
76
|
-
const mutation = typeof MutationObserver === "undefined" ? undefined : new MutationObserver(sized);
|
|
77
|
-
mutation?.observe(frame, { childList: true, subtree: true, attributes: true, attributeFilter: ["disabled", "tabindex", "hidden", "inert", "href", "contenteditable"] });
|
|
78
|
-
return () => {
|
|
79
|
-
resize?.disconnect();
|
|
80
|
-
mutation?.disconnect();
|
|
81
|
-
};
|
|
82
|
-
}, [measureEdges, measureFocus]);
|
|
83
|
-
const shadow = "pointer-events-none absolute z-[1] shadow-ds-overflow transition-opacity duration-(--ds-duration-instant)";
|
|
84
|
-
return (
|
|
85
|
-
// Clipped: the edge-shadow casters sit just outside the box and only their inward shadow may show,
|
|
86
|
-
// so the area never makes its column (or the page) scroll sideways.
|
|
87
|
-
_jsxs("div", { "data-slot": "scroll-area", "data-orientation": orientation, "data-fill": fill || undefined, className: cn("relative min-h-0 min-w-0 overflow-clip", fill && "h-full"), children: [_jsx("div", { ref: viewport, "data-slot": "scroll-area-viewport", role: needsFocus ? "region" : undefined, "aria-label": needsFocus ? ariaLabel : undefined, tabIndex: needsFocus ? 0 : undefined, onScroll: () => {
|
|
88
|
-
measureEdges();
|
|
89
|
-
onScrolling();
|
|
90
|
-
}, onBlur: measureFocus, "data-scrolling": scrolling || undefined, style: { maxHeight }, className: cn("peer outline-hidden", fill && "h-full",
|
|
91
|
-
// The scrollbar: thin, a ds-border-bold thumb at 70% on no track, shown on hover, keyboard
|
|
92
|
-
// focus and while scrolling. Native underneath, so wheel, touch and keyboard scroll as usual.
|
|
93
|
-
"[scrollbar-width:thin] [scrollbar-color:transparent_transparent]", "hover:[scrollbar-color:color-mix(in_oklab,var(--ds-border-bold)_70%,transparent)_transparent]", "focus-visible:[scrollbar-color:color-mix(in_oklab,var(--ds-border-bold)_70%,transparent)_transparent]", "data-[scrolling]:[scrollbar-color:color-mix(in_oklab,var(--ds-border-bold)_70%,transparent)_transparent]", orientation === "vertical" && "overflow-y-auto overflow-x-hidden", orientation === "horizontal" && "overflow-x-auto overflow-y-hidden", orientation === "both" && "overflow-auto"), children: _jsx("div", { "data-slot": "scroll-area-content", children: children }) }), horizontal ? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, "data-slot": "scroll-area-edge", "data-edge": "start", className: cn(shadow, "inset-y-0 start-0 w-3 [clip-path:inset(0_-12px_0_0)] rtl:[clip-path:inset(0_0_0_-12px)] -translate-x-full rtl:translate-x-full", !edges.start && "opacity-0") }), _jsx("span", { "aria-hidden": true, "data-slot": "scroll-area-edge", "data-edge": "end", className: cn(shadow, "inset-y-0 end-0 w-3 [clip-path:inset(0_0_0_-12px)] rtl:[clip-path:inset(0_-12px_0_0)] translate-x-full rtl:-translate-x-full", !edges.end && "opacity-0") })] })) : (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, "data-slot": "scroll-area-edge", "data-edge": "start", className: cn(shadow, "inset-x-0 top-0 h-3 -translate-y-full [clip-path:inset(0_0_-12px_0)]", !edges.start && "opacity-0") }), _jsx("span", { "aria-hidden": true, "data-slot": "scroll-area-edge", "data-edge": "end", className: cn(shadow, "inset-x-0 bottom-0 h-3 translate-y-full [clip-path:inset(-12px_0_0_0)]", !edges.end && "opacity-0") })] })), _jsx("span", { "aria-hidden": true, "data-slot": "scroll-area-focus", className: "pointer-events-none absolute inset-0 z-[2] peer-focus-visible:inset-ring-2 peer-focus-visible:inset-ring-ds-border-focused" })] }));
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=scroll-area.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-area.js","sourceRoot":"","sources":["../../src/display/scroll-area.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAkB9B,MAAM,QAAQ,GACZ,0LAA0L,CAAC;AAE7L,yDAAyD;AACzD,SAAS,WAAW,CAAC,IAAiB;IACpC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAC9G,CAAC;AAID;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,GAAG,KAAK,EAAE,WAAW,GAAG,UAAU,EAAmB;IAClI,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAC;IACpD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9E,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1D,2DAA2D;IAC3D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MAAM,WAAW,GAAG,KAAK,CAAC,M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AG,IACrL,CACP,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"../utils\";\n\nexport type ScrollAreaProps = {\n children: React.ReactNode;\n /** Names the region; screen readers announce it when focus enters. */\n \"aria-label\": string;\n /** The region's height limit (\"320px\", 320, \"60vh\"); for horizontal areas, set the width on the parent. */\n maxHeight?: number | string;\n /**\n * Fills the parent's height and scrolls inside it, for a pane in a flex column or a grid\n * row that is given its height: a conversation's messages between its header and the reply box, a list\n * beside it. The parent must give the area a definite height (`min-h-0` on a flex or grid child).\n * Leave `maxHeight` out when filling.\n */\n fill?: boolean;\n orientation?: \"vertical\" | \"horizontal\" | \"both\";\n};\n\nconst TABBABLE =\n 'a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"]';\n\n/** A tabbable descendant that is not hidden or inert. */\nfunction hasTabbable(root: HTMLElement) {\n return Array.from(root.querySelectorAll(TABBABLE)).some((element) => !element.closest(\"[hidden], [inert]\"));\n}\n\ntype Edges = { start: boolean; end: boolean };\n\n/**\n * A fixed-size region with its own native scroll (never hijacked) and the\n * scrollbar contract (thin, a ds-border-bold thumb), plus an overflow\n * shadow on each edge where content continues. When it holds nothing\n * focusable it becomes a focusable region itself, so keyboard users can\n * scroll it with the arrow keys.\n *\n * Known deviation: the design's 6px thumb is drawn by the platform's thin\n * scrollbar (about 8–11px); standard CSS cannot size it further without\n * replacing native scrolling. With `orientation=\"both\"` the edge shadows\n * follow the vertical axis.\n */\nexport function ScrollArea({ children, \"aria-label\": ariaLabel, maxHeight, fill = false, orientation = \"vertical\" }: ScrollAreaProps) {\n const viewport = React.useRef<HTMLDivElement>(null);\n const [edges, setEdges] = React.useState<Edges>({ start: false, end: false });\n const [needsFocus, setNeedsFocus] = React.useState(false);\n // The thumb shows while scrolling and fades shortly after.\n const [scrolling, setScrolling] = React.useState(false);\n const scrollTimer = React.useRef<number | undefined>(undefined);\n React.useEffect(() => () => window.clearTimeout(scrollTimer.current), []);\n // Every scroll event restarts the fade-out, so a long scroll keeps the thumb steady.\n const onScrolling = () => {\n window.clearTimeout(scrollTimer.current);\n setScrolling(true);\n scrollTimer.current = window.setTimeout(() => setScrolling(false), 800);\n };\n const horizontal = orientation === \"horizontal\";\n\n const room = () => {\n const frame = viewport.current;\n return frame ? (horizontal ? frame.scrollWidth - frame.clientWidth : frame.scrollHeight - frame.clientHeight) : 0;\n };\n\n /** Which edges hide content; cheap enough for every scroll event. */\n const measureEdges = React.useCallback(() => {\n const frame = viewport.current;\n if (!frame) return;\n // Horizontal scroll positions are negative in RTL; magnitudes work for both directions.\n const position = Math.abs(horizontal ? frame.scrollLeft : frame.scrollTop);\n const space = horizontal ? frame.scrollWidth - frame.clientWidth : frame.scrollHeight - frame.clientHeight;\n const next = { start: position > 1, end: space - position > 1 };\n setEdges((current) => (current.start === next.start && current.end === next.end ? current : next));\n }, [horizontal]);\n\n /** Whether the region must take focus itself: it scrolls and holds nothing focusable. Runs on size and content changes. */\n const measureFocus = React.useCallback(() => {\n const frame = viewport.current;\n if (!frame) return;\n const next = room() > 1 && !hasTabbable(frame);\n // Never pull focus out from under the keyboard: keep the tab stop while the region itself has focus.\n setNeedsFocus((current) => (current && !next && document.activeElement === frame ? current : next));\n }, [horizontal]);\n\n React.useLayoutEffect(() => {\n measureEdges();\n measureFocus();\n const frame = viewport.current;\n if (!frame) return;\n const sized = () => {\n measureEdges();\n measureFocus();\n };\n const resize = typeof ResizeObserver === \"undefined\" ? undefined : new ResizeObserver(sized);\n resize?.observe(frame);\n if (frame.firstElementChild) resize?.observe(frame.firstElementChild);\n // Children that appear, disappear or change focusability without changing size.\n const mutation = typeof MutationObserver === \"undefined\" ? undefined : new MutationObserver(sized);\n mutation?.observe(frame, { childList: true, subtree: true, attributes: true, attributeFilter: [\"disabled\", \"tabindex\", \"hidden\", \"inert\", \"href\", \"contenteditable\"] });\n return () => {\n resize?.disconnect();\n mutation?.disconnect();\n };\n }, [measureEdges, measureFocus]);\n\n const shadow = \"pointer-events-none absolute z-[1] shadow-ds-overflow transition-opacity duration-(--ds-duration-instant)\";\n return (\n // Clipped: the edge-shadow casters sit just outside the box and only their inward shadow may show,\n // so the area never makes its column (or the page) scroll sideways.\n <div\n data-slot=\"scroll-area\"\n data-orientation={orientation}\n data-fill={fill || undefined}\n className={cn(\"relative min-h-0 min-w-0 overflow-clip\", fill && \"h-full\")}\n >\n <div\n ref={viewport}\n data-slot=\"scroll-area-viewport\"\n role={needsFocus ? \"region\" : undefined}\n aria-label={needsFocus ? ariaLabel : undefined}\n tabIndex={needsFocus ? 0 : undefined}\n onScroll={() => {\n measureEdges();\n onScrolling();\n }}\n onBlur={measureFocus}\n data-scrolling={scrolling || undefined}\n style={{ maxHeight }}\n className={cn(\n \"peer outline-hidden\",\n fill && \"h-full\",\n // The scrollbar: thin, a ds-border-bold thumb at 70% on no track, shown on hover, keyboard\n // focus and while scrolling. Native underneath, so wheel, touch and keyboard scroll as usual.\n \"[scrollbar-width:thin] [scrollbar-color:transparent_transparent]\",\n \"hover:[scrollbar-color:color-mix(in_oklab,var(--ds-border-bold)_70%,transparent)_transparent]\",\n \"focus-visible:[scrollbar-color:color-mix(in_oklab,var(--ds-border-bold)_70%,transparent)_transparent]\",\n \"data-[scrolling]:[scrollbar-color:color-mix(in_oklab,var(--ds-border-bold)_70%,transparent)_transparent]\",\n orientation === \"vertical\" && \"overflow-y-auto overflow-x-hidden\",\n orientation === \"horizontal\" && \"overflow-x-auto overflow-y-hidden\",\n orientation === \"both\" && \"overflow-auto\",\n )}\n >\n <div data-slot=\"scroll-area-content\">{children}</div>\n </div>\n {/* Edge shadows where content continues, clipped to fall inward only. */}\n {horizontal ? (\n <>\n <span aria-hidden data-slot=\"scroll-area-edge\" data-edge=\"start\" className={cn(shadow, \"inset-y-0 start-0 w-3 [clip-path:inset(0_-12px_0_0)] rtl:[clip-path:inset(0_0_0_-12px)] -translate-x-full rtl:translate-x-full\", !edges.start && \"opacity-0\")} />\n <span aria-hidden data-slot=\"scroll-area-edge\" data-edge=\"end\" className={cn(shadow, \"inset-y-0 end-0 w-3 [clip-path:inset(0_0_0_-12px)] rtl:[clip-path:inset(0_-12px_0_0)] translate-x-full rtl:-translate-x-full\", !edges.end && \"opacity-0\")} />\n </>\n ) : (\n <>\n <span aria-hidden data-slot=\"scroll-area-edge\" data-edge=\"start\" className={cn(shadow, \"inset-x-0 top-0 h-3 -translate-y-full [clip-path:inset(0_0_-12px_0)]\", !edges.start && \"opacity-0\")} />\n <span aria-hidden data-slot=\"scroll-area-edge\" data-edge=\"end\" className={cn(shadow, \"inset-x-0 bottom-0 h-3 translate-y-full [clip-path:inset(-12px_0_0_0)]\", !edges.end && \"opacity-0\")} />\n </>\n )}\n {/* The keyboard focus border sits above the content, which would cover an inset ring on the viewport. */}\n <span aria-hidden data-slot=\"scroll-area-focus\" className=\"pointer-events-none absolute inset-0 z-[2] peer-focus-visible:inset-ring-2 peer-focus-visible:inset-ring-ds-border-focused\" />\n </div>\n );\n}\n"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type CooldownAction = {
|
|
2
|
-
/** Runs the action; the cooldown starts only after it succeeds. */
|
|
3
|
-
run: () => Promise<boolean>;
|
|
4
|
-
/** Seconds left before the action is available again. */
|
|
5
|
-
remaining: number;
|
|
6
|
-
/** True while the action is running. */
|
|
7
|
-
isPending: boolean;
|
|
8
|
-
/** True after the last run failed (cleared by the next run). */
|
|
9
|
-
failed: boolean;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* The resend pattern (code again, link again): a rejected or throwing action
|
|
13
|
-
* never starts the wait and never escapes as an unhandled rejection
|
|
14
|
-
*; a successful one starts `seconds` of cooldown. `initial` is
|
|
15
|
-
* the wait already running (a code was just sent); a new value restarts it.
|
|
16
|
-
*/
|
|
17
|
-
export declare function useCooldownAction(action: (() => unknown) | undefined, seconds: number, initial?: number): CooldownAction;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
/**
|
|
4
|
-
* The resend pattern (code again, link again): a rejected or throwing action
|
|
5
|
-
* never starts the wait and never escapes as an unhandled rejection
|
|
6
|
-
*; a successful one starts `seconds` of cooldown. `initial` is
|
|
7
|
-
* the wait already running (a code was just sent); a new value restarts it.
|
|
8
|
-
*/
|
|
9
|
-
export function useCooldownAction(action, seconds, initial = 0) {
|
|
10
|
-
const [remaining, setRemaining] = React.useState(initial);
|
|
11
|
-
const [isPending, setPending] = React.useState(false);
|
|
12
|
-
const [failed, setFailed] = React.useState(false);
|
|
13
|
-
const latest = React.useRef(action);
|
|
14
|
-
latest.current = action;
|
|
15
|
-
const running = React.useRef(false);
|
|
16
|
-
const remainingRef = React.useRef(remaining);
|
|
17
|
-
remainingRef.current = remaining;
|
|
18
|
-
// A new initial wait from the parent (a server "retry after") restarts the wait.
|
|
19
|
-
const firstInitial = React.useRef(true);
|
|
20
|
-
React.useEffect(() => {
|
|
21
|
-
if (firstInitial.current) {
|
|
22
|
-
firstInitial.current = false;
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
setRemaining(initial);
|
|
26
|
-
}, [initial]);
|
|
27
|
-
// One interval for the whole wait, counting down with a functional update: no per-tick rescheduling, so a long jump
|
|
28
|
-
// of the clock (a backgrounded tab, fake timers) still lands on the right second.
|
|
29
|
-
const cooling = remaining > 0;
|
|
30
|
-
React.useEffect(() => {
|
|
31
|
-
if (!cooling)
|
|
32
|
-
return;
|
|
33
|
-
const timer = window.setInterval(() => setRemaining((current) => Math.max(0, current - 1)), 1000);
|
|
34
|
-
return () => window.clearInterval(timer);
|
|
35
|
-
}, [cooling]);
|
|
36
|
-
const run = React.useCallback(async () => {
|
|
37
|
-
// One run at a time, and none while the wait is on.
|
|
38
|
-
if (!latest.current || running.current || remainingRef.current > 0)
|
|
39
|
-
return false;
|
|
40
|
-
running.current = true;
|
|
41
|
-
setPending(true);
|
|
42
|
-
setFailed(false);
|
|
43
|
-
try {
|
|
44
|
-
await latest.current();
|
|
45
|
-
setRemaining(seconds);
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
setFailed(true);
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
finally {
|
|
53
|
-
running.current = false;
|
|
54
|
-
setPending(false);
|
|
55
|
-
}
|
|
56
|
-
}, [seconds]);
|
|
57
|
-
return { run, remaining, isPending, failed };
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=cooldown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cooldown.js","sourceRoot":"","sources":["../../src/feedback/cooldown.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAmC,EAAE,OAAe,EAAE,OAAO,GAAG,CAAC;IACjG,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7C,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;IAEjC,iFAAiF;IACjF,MAAM,YAAY,G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AAC,IAAI,CAAC,CAAC;YAChB,OAAO,KAAK,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;YACxB,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nexport type CooldownAction = {\n /** Runs the action; the cooldown starts only after it succeeds. */\n run: () => Promise<boolean>;\n /** Seconds left before the action is available again. */\n remaining: number;\n /** True while the action is running. */\n isPending: boolean;\n /** True after the last run failed (cleared by the next run). */\n failed: boolean;\n};\n\n/**\n * The resend pattern (code again, link again): a rejected or throwing action\n * never starts the wait and never escapes as an unhandled rejection\n *; a successful one starts `seconds` of cooldown. `initial` is\n * the wait already running (a code was just sent); a new value restarts it.\n */\nexport function useCooldownAction(action: (() => unknown) | undefined, seconds: number, initial = 0): CooldownAction {\n const [remaining, setRemaining] = React.useState(initial);\n const [isPending, setPending] = React.useState(false);\n const [failed, setFailed] = React.useState(false);\n const latest = React.useRef(action);\n latest.current = action;\n const running = React.useRef(false);\n const remainingRef = React.useRef(remaining);\n remainingRef.current = remaining;\n\n // A new initial wait from the parent (a server \"retry after\") restarts the wait.\n const firstInitial = React.useRef(true);\n React.useEffect(() => {\n if (firstInitial.current) {\n firstInitial.current = false;\n return;\n }\n setRemaining(initial);\n }, [initial]);\n\n // One interval for the whole wait, counting down with a functional update: no per-tick rescheduling, so a long jump\n // of the clock (a backgrounded tab, fake timers) still lands on the right second.\n const cooling = remaining > 0;\n React.useEffect(() => {\n if (!cooling) return;\n const timer = window.setInterval(() => setRemaining((current) => Math.max(0, current - 1)), 1000);\n return () => window.clearInterval(timer);\n }, [cooling]);\n\n const run = React.useCallback(async () => {\n // One run at a time, and none while the wait is on.\n if (!latest.current || running.current || remainingRef.current > 0) return false;\n running.current = true;\n setPending(true);\n setFailed(false);\n try {\n await latest.current();\n setRemaining(seconds);\n return true;\n } catch {\n setFailed(true);\n return false;\n } finally {\n running.current = false;\n setPending(false);\n }\n }, [seconds]);\n\n return { run, remaining, isPending, failed };\n}\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export type StatusDotTone = "neutral" | "information" | "success" | "warning" | "danger";
|
|
3
|
-
type Base = {
|
|
4
|
-
tone?: StatusDotTone;
|
|
5
|
-
/** A 3px halo for a state that is active right now (connected, syncing). */
|
|
6
|
-
isLive?: boolean;
|
|
7
|
-
};
|
|
8
|
-
export type StatusDotProps = Base & ({
|
|
9
|
-
/** The word: the colour never carries the state alone. */
|
|
10
|
-
children: React.ReactNode;
|
|
11
|
-
"aria-label"?: never;
|
|
12
|
-
} | {
|
|
13
|
-
children?: never;
|
|
14
|
-
/** Only where a visible word is impossible (a dense table cell with its own column header). */
|
|
15
|
-
"aria-label": string;
|
|
16
|
-
});
|
|
17
|
-
/**
|
|
18
|
-
* A live system or connection state as an 8px dot and a word: integration
|
|
19
|
-
* online, GPS signal, sync. For a record's status (order, invoice) use
|
|
20
|
-
* Lozenge.
|
|
21
|
-
*/
|
|
22
|
-
export declare function StatusDot({ tone, isLive, children, "aria-label": ariaLabel }: StatusDotProps): React.JSX.Element;
|
|
23
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { cn } from "../utils.js";
|
|
4
|
-
const DOT = {
|
|
5
|
-
neutral: "bg-ds-icon-subtle",
|
|
6
|
-
information: "bg-ds-icon-information",
|
|
7
|
-
success: "bg-ds-icon-success",
|
|
8
|
-
warning: "bg-ds-icon-warning",
|
|
9
|
-
danger: "bg-ds-icon-danger",
|
|
10
|
-
};
|
|
11
|
-
// The halo sits in the tone's status background.
|
|
12
|
-
const HALO = {
|
|
13
|
-
neutral: "ring-ds-background-neutral",
|
|
14
|
-
information: "ring-ds-background-information",
|
|
15
|
-
success: "ring-ds-background-success",
|
|
16
|
-
warning: "ring-ds-background-warning",
|
|
17
|
-
danger: "ring-ds-background-danger",
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* A live system or connection state as an 8px dot and a word: integration
|
|
21
|
-
* online, GPS signal, sync. For a record's status (order, invoice) use
|
|
22
|
-
* Lozenge.
|
|
23
|
-
*/
|
|
24
|
-
export function StatusDot({ tone = "neutral", isLive, children, "aria-label": ariaLabel }) {
|
|
25
|
-
// null, false and "" are no word either.
|
|
26
|
-
const hasWord = children != null && children !== false && children !== "";
|
|
27
|
-
const dot = (_jsx("span", { "data-slot": "status-dot-mark", "aria-hidden": true, className: cn("size-ds-100 shrink-0 rounded-ds-full", DOT[tone], isLive && cn("ring-3", HALO[tone])) }));
|
|
28
|
-
if (!hasWord) {
|
|
29
|
-
return (
|
|
30
|
-
// Named image with a label; without one it only decorates, never an unnamed image.
|
|
31
|
-
_jsx("span", { role: ariaLabel ? "img" : undefined, "aria-label": ariaLabel, "aria-hidden": ariaLabel ? undefined : true, "data-slot": "status-dot", "data-tone": tone, "data-live": isLive || undefined, className: "inline-flex items-center", children: dot }));
|
|
32
|
-
}
|
|
33
|
-
return (
|
|
34
|
-
// The halo is a shadow and takes no space, so a live dot gets the wider gap to keep the word clear of it.
|
|
35
|
-
_jsxs("span", { "data-slot": "status-dot", "data-tone": tone, "data-live": isLive || undefined, className: cn("inline-flex items-center text-body text-ds-text", isLive ? "gap-ds-100" : "gap-ds-075"), children: [dot, _jsx("span", { "data-slot": "status-dot-label", children: children })] }));
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=status-dot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status-dot.js","sourceRoot":"","sources":["../../src/feedback/status-dot.tsx"],"names":[],"mappings":";AAAA,OAAO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ACL,0GAA0G;IAC1G,6BAAgB,YAAY,eAAY,IAAI,eAAa,MAAM,IAAI,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,iDAAiD,EAAE,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,aACjL,GAAG,EACJ,4BAAgB,kBAAkB,YAAE,QAAQ,GAAQ,IAC/C,CACR,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport { cn } from \"../utils\";\n\nexport type StatusDotTone = \"neutral\" | \"information\" | \"success\" | \"warning\" | \"danger\";\n\nconst DOT: Record<StatusDotTone, string> = {\n neutral: \"bg-ds-icon-subtle\",\n information: \"bg-ds-icon-information\",\n success: \"bg-ds-icon-success\",\n warning: \"bg-ds-icon-warning\",\n danger: \"bg-ds-icon-danger\",\n};\n// The halo sits in the tone's status background.\nconst HALO: Record<StatusDotTone, string> = {\n neutral: \"ring-ds-background-neutral\",\n information: \"ring-ds-background-information\",\n success: \"ring-ds-background-success\",\n warning: \"ring-ds-background-warning\",\n danger: \"ring-ds-background-danger\",\n};\n\ntype Base = {\n tone?: StatusDotTone;\n /** A 3px halo for a state that is active right now (connected, syncing). */\n isLive?: boolean;\n};\n\nexport type StatusDotProps = Base &\n (\n | {\n /** The word: the colour never carries the state alone. */\n children: React.ReactNode;\n \"aria-label\"?: never;\n }\n | {\n children?: never;\n /** Only where a visible word is impossible (a dense table cell with its own column header). */\n \"aria-label\": string;\n }\n );\n\n/**\n * A live system or connection state as an 8px dot and a word: integration\n * online, GPS signal, sync. For a record's status (order, invoice) use\n * Lozenge.\n */\nexport function StatusDot({ tone = \"neutral\", isLive, children, \"aria-label\": ariaLabel }: StatusDotProps) {\n // null, false and \"\" are no word either.\n const hasWord = children != null && children !== false && children !== \"\";\n const dot = (\n <span\n data-slot=\"status-dot-mark\"\n aria-hidden\n className={cn(\"size-ds-100 shrink-0 rounded-ds-full\", DOT[tone], isLive && cn(\"ring-3\", HALO[tone]))}\n />\n );\n if (!hasWord) {\n return (\n // Named image with a label; without one it only decorates, never an unnamed image.\n <span role={ariaLabel ? \"img\" : undefined} aria-label={ariaLabel} aria-hidden={ariaLabel ? undefined : true} data-slot=\"status-dot\" data-tone={tone} data-live={isLive || undefined} className=\"inline-flex items-center\">\n {dot}\n </span>\n );\n }\n return (\n // The halo is a shadow and takes no space, so a live dot gets the wider gap to keep the word clear of it.\n <span data-slot=\"status-dot\" data-tone={tone} data-live={isLive || undefined} className={cn(\"inline-flex items-center text-body text-ds-text\", isLive ? \"gap-ds-100\" : \"gap-ds-075\")}>\n {dot}\n <span data-slot=\"status-dot-label\">{children}</span>\n </span>\n );\n}\n"]}
|
package/dist/form/input-otp.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { type TextFieldProps as AriaTextFieldProps } from "react-aria-components";
|
|
3
|
-
import { type RequiredValidation } from "./validation.js";
|
|
4
|
-
export type InputOTPProps = Omit<AriaTextFieldProps, "className" | "style" | "children" | "type" | "inputMode" | "autoComplete" | "maxLength"> & {
|
|
5
|
-
label: React.ReactNode;
|
|
6
|
-
/** 4 or 6 digits; 6 splits 3 + 3 with a dash. */
|
|
7
|
-
length?: 4 | 6;
|
|
8
|
-
description?: React.ReactNode;
|
|
9
|
-
/** Say what to do: "Wrong code. Enter the latest code from your phone." */
|
|
10
|
-
errorMessage?: React.ReactNode;
|
|
11
|
-
/** Called once the last digit is entered (submit there). */
|
|
12
|
-
onComplete?: (code: string) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
15
|
-
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
16
|
-
* {@link RequiredValidation} for the whole contract.
|
|
17
|
-
*/
|
|
18
|
-
requiredValidation?: RequiredValidation;
|
|
19
|
-
};
|
|
20
|
-
export declare const InputOTP: React.ForwardRefExoticComponent<Omit<AriaTextFieldProps, "style" | "type" | "className" | "children" | "inputMode" | "autoComplete" | "maxLength"> & {
|
|
21
|
-
label: React.ReactNode;
|
|
22
|
-
/** 4 or 6 digits; 6 splits 3 + 3 with a dash. */
|
|
23
|
-
length?: 4 | 6;
|
|
24
|
-
description?: React.ReactNode;
|
|
25
|
-
/** Say what to do: "Wrong code. Enter the latest code from your phone." */
|
|
26
|
-
errorMessage?: React.ReactNode;
|
|
27
|
-
/** Called once the last digit is entered (submit there). */
|
|
28
|
-
onComplete?: (code: string) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS
|
|
31
|
-
* Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See
|
|
32
|
-
* {@link RequiredValidation} for the whole contract.
|
|
33
|
-
*/
|
|
34
|
-
requiredValidation?: RequiredValidation;
|
|
35
|
-
} & React.RefAttributes<HTMLInputElement>>;
|
package/dist/form/input-otp.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { Input, TextField as AriaTextField, } from "react-aria-components";
|
|
5
|
-
import { cn } from "../utils.js";
|
|
6
|
-
import { FieldDescription, FieldError, FieldLabel } from "./field-parts.js";
|
|
7
|
-
import { FIELD_STACK } from "./styles.js";
|
|
8
|
-
import { useFieldValidation } from "./validation.js";
|
|
9
|
-
/**
|
|
10
|
-
* A one-time code: one real input with `autocomplete="one-time-code"` and a
|
|
11
|
-
* numeric keypad, so SMS autofill and paste fill every box at once; the
|
|
12
|
-
* boxes are only its picture. React Aria has no OTP primitive, so this is a TextField with a visual layer.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* The digits to keep from the input's text. The caret is pinned to the end,
|
|
16
|
-
* so a full code pasted or autofilled over an old one arrives appended
|
|
17
|
-
* ("111111" + "222222"): when a whole code was added, the new one wins.
|
|
18
|
-
*/
|
|
19
|
-
function takeCode(text, previous, length) {
|
|
20
|
-
const digits = text.replace(/\D/g, "");
|
|
21
|
-
if (digits.length > length && digits.length - previous.length >= length)
|
|
22
|
-
return digits.slice(-length);
|
|
23
|
-
return digits.slice(0, length);
|
|
24
|
-
}
|
|
25
|
-
export const InputOTP = React.forwardRef(function InputOTP({ label, length = 6, description, errorMessage, onComplete, value, defaultValue, onChange, validate, onBlur, requiredValidation, ...rest }, ref) {
|
|
26
|
-
const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? "");
|
|
27
|
-
const code = (value ?? uncontrolled).replace(/\D/g, "").slice(0, length);
|
|
28
|
-
const [focused, setFocused] = React.useState(false);
|
|
29
|
-
const inputRef = React.useRef(null);
|
|
30
|
-
const setRefs = (node) => {
|
|
31
|
-
inputRef.current = node;
|
|
32
|
-
if (typeof ref === "function")
|
|
33
|
-
ref(node);
|
|
34
|
-
else if (ref)
|
|
35
|
-
ref.current = node;
|
|
36
|
-
};
|
|
37
|
-
const active = Math.min(code.length, length - 1);
|
|
38
|
-
// The last code passed to onComplete: a new full code (pasted over an old one) completes again.
|
|
39
|
-
const completed = React.useRef(code.length === length ? code : null);
|
|
40
|
-
const timing = useFieldValidation({
|
|
41
|
-
validate,
|
|
42
|
-
value: value === undefined ? undefined : code,
|
|
43
|
-
initialValue: defaultValue ?? "",
|
|
44
|
-
isRequired: rest.isRequired,
|
|
45
|
-
requiredValidation,
|
|
46
|
-
onBlur: onBlur,
|
|
47
|
-
onChange: (digits) => {
|
|
48
|
-
if (value === undefined)
|
|
49
|
-
setUncontrolled(digits);
|
|
50
|
-
onChange?.(digits);
|
|
51
|
-
if (digits.length === length) {
|
|
52
|
-
if (completed.current !== digits) {
|
|
53
|
-
completed.current = digits;
|
|
54
|
-
onComplete?.(digits);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else
|
|
58
|
-
completed.current = null;
|
|
59
|
-
},
|
|
60
|
-
validationBehavior: rest.validationBehavior,
|
|
61
|
-
});
|
|
62
|
-
const pinCaret = (input) => {
|
|
63
|
-
const end = input.value.length;
|
|
64
|
-
if (input.selectionStart !== end || input.selectionEnd !== end)
|
|
65
|
-
input.setSelectionRange(end, end);
|
|
66
|
-
};
|
|
67
|
-
return (_jsx(AriaTextField, { ...rest, value: code, validationBehavior: timing.validationBehavior, validate: timing.validate, onBlur: timing.onBlur, onChange: (next) => timing.onChange?.(takeCode(next, code, length)), "data-slot": "input-otp", className: FIELD_STACK, children: ({ isInvalid, isDisabled }) => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { isRequired: rest.isRequired, children: label }), _jsxs("div", { "data-slot": "input-otp-boxes",
|
|
68
|
-
// As wide as its cells, never wider than its column: on a narrow phone the cells shrink instead
|
|
69
|
-
// of pushing the field (and the page) sideways. Codes read left to right in every locale, so the row
|
|
70
|
-
// (cells, separator and the hidden input) stays LTR on an RTL page: "1234" never shows as "4 3 2 1".
|
|
71
|
-
dir: "ltr", className: "relative flex w-full max-w-fit items-center gap-ds-100", onMouseDown: (event) => {
|
|
72
|
-
event.preventDefault();
|
|
73
|
-
inputRef.current?.focus();
|
|
74
|
-
}, children: [_jsx(Input, { ref: setRefs, inputMode: "numeric", autoComplete: "one-time-code",
|
|
75
|
-
// No maxLength: the browser would cut "482 917" to six characters before the digits are picked out.
|
|
76
|
-
pattern: "\\d*", "data-slot": "input-otp-input", onFocus: (event) => {
|
|
77
|
-
setFocused(true);
|
|
78
|
-
pinCaret(event.currentTarget);
|
|
79
|
-
},
|
|
80
|
-
// Boxes fill left to right: arrows, Home and clicks never move the caret off the end.
|
|
81
|
-
onSelect: (event) => pinCaret(event.currentTarget), onKeyUp: (event) => pinCaret(event.currentTarget), onBlur: () => setFocused(false), className: "absolute inset-0 z-10 h-full w-full cursor-text bg-transparent text-transparent caret-transparent outline-hidden selection:bg-transparent" }), Array.from({ length }, (_, index) => (_jsxs(React.Fragment, { children: [length === 6 && index === 3 && (_jsx("span", { "aria-hidden": "true", "data-slot": "input-otp-separator", className: "h-0.5 w-ds-100 shrink-0 rounded-ds-full bg-ds-border-bold" })), _jsxs("span", { "aria-hidden": "true", "data-slot": "input-otp-box", "data-active": focused && index === active ? true : undefined, className: cn("relative inline-flex h-13 w-11 min-w-0 items-center justify-center rounded-ds-medium border bg-ds-background-input", "text-metric-medium tabular-nums text-ds-text", isInvalid ? "border-ds-border-danger" : "border-ds-border-bold", focused && index === active && "border-ds-border-focused outline-1 outline-solid -outline-offset-2 outline-ds-border-focused", isDisabled && "border-transparent bg-ds-background-disabled text-ds-text-disabled"), children: [code[index] ?? "", focused && index === active && code.length < length && (_jsx("span", { className: "h-5 w-px animate-pulse bg-ds-text motion-reduce:animate-none" }))] })] }, index)))] }), description && _jsx(FieldDescription, { children: description }), _jsx(FieldError, { children: errorMessage })] })) }));
|
|
82
|
-
});
|
|
83
|
-
//# sourceMappingURL=input-otp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input-otp.js","sourceRoot":"","sources":["../../src/form/input-otp.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,KAAK,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAsB3E;;;;GAIG;AACH;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAY,EAAE,QAAgB,EAAE,MAAc;IAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,IAAI,MAAM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ACrJ,EACD,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CACpC,MAAC,KAAK,CAAC,QAAQ,eACZ,MAAM,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAC9B,8BAAkB,MAAM,eAAW,qBAAqB,EAAC,SAAS,EAAC,2DAA2D,GAAG,CAClI,EACD,+BACc,MAAM,eACR,eAAe,iBACZ,OAAO,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC3D,SAAS,EAAE,EAAE,CACX,oHAAoH,EACpH,8CAA8C,EAC9C,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,uBAAuB,EAC/D,OAAO,IAAI,KAAK,KAAK,MAAM,IAAI,8FAA8F,EAC7H,UAAU,IAAI,oEAAoE,CACnF,aAEA,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EACjB,OAAO,IAAI,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CACtD,eAAM,SAAS,EAAC,8DAA8D,GAAG,CAClF,IACI,KApBY,KAAK,CAqBT,CAClB,CAAC,IACE,EACL,WAAW,IAAI,KAAC,gBAAgB,cAAE,WAAW,GAAoB,EAClE,KAAC,UAAU,cAAE,YAAY,GAAc,IACtC,CACJ,GACa,CACjB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n Input,\n TextField as AriaTextField,\n type TextFieldProps as AriaTextFieldProps,\n} from \"react-aria-components\";\n\nimport { cn } from \"../utils\";\nimport { FieldDescription, FieldError, FieldLabel } from \"./field-parts\";\nimport { FIELD_STACK } from \"./styles\";\nimport { useFieldValidation, type RequiredValidation } from \"./validation\";\n\nexport type InputOTPProps = Omit<\n AriaTextFieldProps,\n \"className\" | \"style\" | \"children\" | \"type\" | \"inputMode\" | \"autoComplete\" | \"maxLength\"\n> & {\n label: React.ReactNode;\n /** 4 or 6 digits; 6 splits 3 + 3 with a dash. */\n length?: 4 | 6;\n description?: React.ReactNode;\n /** Say what to do: \"Wrong code. Enter the latest code from your phone.\" */\n errorMessage?: React.ReactNode;\n /** Called once the last digit is entered (submit there). */\n onComplete?: (code: string) => void;\n /**\n * Who says an empty required field is missing: `field` (default) or `app`. With `app` a DS\n * Form's `onSubmit` runs with the field empty, and the app's own error must clear on change. See\n * {@link RequiredValidation} for the whole contract.\n */\n requiredValidation?: RequiredValidation;\n};\n\n/**\n * A one-time code: one real input with `autocomplete=\"one-time-code\"` and a\n * numeric keypad, so SMS autofill and paste fill every box at once; the\n * boxes are only its picture. React Aria has no OTP primitive, so this is a TextField with a visual layer.\n */\n/**\n * The digits to keep from the input's text. The caret is pinned to the end,\n * so a full code pasted or autofilled over an old one arrives appended\n * (\"111111\" + \"222222\"): when a whole code was added, the new one wins.\n */\nfunction takeCode(text: string, previous: string, length: number) {\n const digits = text.replace(/\\D/g, \"\");\n if (digits.length > length && digits.length - previous.length >= length) return digits.slice(-length);\n return digits.slice(0, length);\n}\n\nexport const InputOTP = React.forwardRef<HTMLInputElement, InputOTPProps>(function InputOTP(\n { label, length = 6, description, errorMessage, onComplete, value, defaultValue, onChange, validate, onBlur, requiredValidation, ...rest },\n ref,\n) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? \"\");\n const code = (value ?? uncontrolled).replace(/\\D/g, \"\").slice(0, length);\n const [focused, setFocused] = React.useState(false);\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n\n const setRefs = (node: HTMLInputElement | null) => {\n inputRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n };\n\n const active = Math.min(code.length, length - 1);\n // The last code passed to onComplete: a new full code (pasted over an old one) completes again.\n const completed = React.useRef<string | null>(code.length === length ? code : null);\n const timing = useFieldValidation<string>({\n validate,\n value: value === undefined ? undefined : code,\n initialValue: defaultValue ?? \"\",\n isRequired: rest.isRequired,\n requiredValidation,\n onBlur: onBlur as ((event: React.FocusEvent) => void) | undefined,\n onChange: (digits) => {\n if (value === undefined) setUncontrolled(digits);\n onChange?.(digits);\n if (digits.length === length) {\n if (completed.current !== digits) {\n completed.current = digits;\n onComplete?.(digits);\n }\n } else completed.current = null;\n },\n validationBehavior: rest.validationBehavior,\n });\n const pinCaret = (input: HTMLInputElement) => {\n const end = input.value.length;\n if (input.selectionStart !== end || input.selectionEnd !== end) input.setSelectionRange(end, end);\n };\n return (\n <AriaTextField\n {...rest}\n value={code}\n validationBehavior={timing.validationBehavior}\n validate={timing.validate}\n onBlur={timing.onBlur}\n onChange={(next) => timing.onChange?.(takeCode(next, code, length))}\n data-slot=\"input-otp\"\n className={FIELD_STACK}\n >\n {({ isInvalid, isDisabled }) => (\n <>\n <FieldLabel isRequired={rest.isRequired}>{label}</FieldLabel>\n <div\n data-slot=\"input-otp-boxes\"\n // As wide as its cells, never wider than its column: on a narrow phone the cells shrink instead\n // of pushing the field (and the page) sideways. Codes read left to right in every locale, so the row\n // (cells, separator and the hidden input) stays LTR on an RTL page: \"1234\" never shows as \"4 3 2 1\".\n dir=\"ltr\"\n className=\"relative flex w-full max-w-fit items-center gap-ds-100\"\n onMouseDown={(event) => {\n event.preventDefault();\n inputRef.current?.focus();\n }}\n >\n <Input\n ref={setRefs}\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n // No maxLength: the browser would cut \"482 917\" to six characters before the digits are picked out.\n pattern=\"\\d*\"\n data-slot=\"input-otp-input\"\n onFocus={(event) => {\n setFocused(true);\n pinCaret(event.currentTarget);\n }}\n // Boxes fill left to right: arrows, Home and clicks never move the caret off the end.\n onSelect={(event) => pinCaret(event.currentTarget)}\n onKeyUp={(event) => pinCaret(event.currentTarget)}\n onBlur={() => setFocused(false)}\n className=\"absolute inset-0 z-10 h-full w-full cursor-text bg-transparent text-transparent caret-transparent outline-hidden selection:bg-transparent\"\n />\n {Array.from({ length }, (_, index) => (\n <React.Fragment key={index}>\n {length === 6 && index === 3 && (\n <span aria-hidden=\"true\" data-slot=\"input-otp-separator\" className=\"h-0.5 w-ds-100 shrink-0 rounded-ds-full bg-ds-border-bold\" />\n )}\n <span\n aria-hidden=\"true\"\n data-slot=\"input-otp-box\"\n data-active={focused && index === active ? true : undefined}\n className={cn(\n \"relative inline-flex h-13 w-11 min-w-0 items-center justify-center rounded-ds-medium border bg-ds-background-input\",\n \"text-metric-medium tabular-nums text-ds-text\",\n isInvalid ? \"border-ds-border-danger\" : \"border-ds-border-bold\",\n focused && index === active && \"border-ds-border-focused outline-1 outline-solid -outline-offset-2 outline-ds-border-focused\",\n isDisabled && \"border-transparent bg-ds-background-disabled text-ds-text-disabled\",\n )}\n >\n {code[index] ?? \"\"}\n {focused && index === active && code.length < length && (\n <span className=\"h-5 w-px animate-pulse bg-ds-text motion-reduce:animate-none\" />\n )}\n </span>\n </React.Fragment>\n ))}\n </div>\n {description && <FieldDescription>{description}</FieldDescription>}\n <FieldError>{errorMessage}</FieldError>\n </>\n )}\n </AriaTextField>\n );\n});\n"]}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export type AuthFormLayoutSurface = "card" | "plain";
|
|
3
|
-
/** A heading at the given level; the type style is the caller's, so the level never changes the look. */
|
|
4
|
-
export declare function TitleTag({ level, className, children }: {
|
|
5
|
-
level: 1 | 2 | 3;
|
|
6
|
-
className?: string;
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
}): React.JSX.Element;
|
|
9
|
-
export interface AuthFormLayoutProps {
|
|
10
|
-
/**
|
|
11
|
-
* `card` (default) raises the panel onto its own surface; `plain` lets it sit
|
|
12
|
-
* directly on the pane. The default matches the busiest existing screen.
|
|
13
|
-
*/
|
|
14
|
-
surface?: AuthFormLayoutSurface;
|
|
15
|
-
/** The screen's heading. */
|
|
16
|
-
title: React.ReactNode;
|
|
17
|
-
/** One line under the heading. */
|
|
18
|
-
description?: React.ReactNode;
|
|
19
|
-
/**
|
|
20
|
-
* The heading's type style, a DS heading class: `text-heading-large` by default; a screen with a longer title
|
|
21
|
-
* may step down (`text-heading-medium`).
|
|
22
|
-
*/
|
|
23
|
-
titleClassName?: string;
|
|
24
|
-
/** The title's heading level: 1 (the page's own heading, by default), or 2 when the page has its own h1. */
|
|
25
|
-
headingLevel?: 1 | 2 | 3;
|
|
26
|
-
/** Above everything, at the inline end — a language switcher, a back link. */
|
|
27
|
-
headerSlot?: React.ReactNode;
|
|
28
|
-
/** The compact brand header, mobile only: the brand pane is desktop-only. */
|
|
29
|
-
logoSlot?: React.ReactNode;
|
|
30
|
-
/** Under the body — a secondary route out of the screen. */
|
|
31
|
-
footerSlot?: React.ReactNode;
|
|
32
|
-
/** Last, set apart — legal text, a support line. */
|
|
33
|
-
noticeSlot?: React.ReactNode;
|
|
34
|
-
/**
|
|
35
|
-
* The spacing between the form's rows (`space-y-4` by default), merged onto a native form child. The DS `Form`
|
|
36
|
-
* takes no className and keeps its own gap, so this has no effect on it.
|
|
37
|
-
*/
|
|
38
|
-
bodyClassName?: string;
|
|
39
|
-
/**
|
|
40
|
-
* A single element — the screen's own form. The layout renders the body
|
|
41
|
-
* region *through* it, so it keeps its element, its handler and its
|
|
42
|
-
* attributes while the rhythm arrives from here.
|
|
43
|
-
*
|
|
44
|
-
* A form component (rather than a `<form>`) must pass `className` and
|
|
45
|
-
* `data-slot` on to its element, or the rhythm is lost.
|
|
46
|
-
*/
|
|
47
|
-
children: React.ReactNode;
|
|
48
|
-
className?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The panel an auth screen's credentials sit in: surface, header and logo rows,
|
|
52
|
-
* heading and description, the body region's rhythm, and the footer and notice
|
|
53
|
-
* rows beneath it (the auth pattern).
|
|
54
|
-
*
|
|
55
|
-
* Everything a screen *does* stays with the screen — submission, field state,
|
|
56
|
-
* validation, lockout, the submit control. This layout owns only where those
|
|
57
|
-
* things sit. The seam is the body region: the caller passes its own form
|
|
58
|
-
* element as the single child; the layout puts the gap above it on a wrapper and merges the rows' spacing
|
|
59
|
-
* onto the element itself (a native form takes it; the DS Form keeps its own gap and `data-slot`):
|
|
60
|
-
*
|
|
61
|
-
* - The form remains a real element, so its handler, `noValidate` and
|
|
62
|
-
* `aria-busy` behave exactly as they did before this layout existed.
|
|
63
|
-
* - The header, logo, footer and notice rows sit *outside* the form. A control
|
|
64
|
-
* placed there is not the form's to submit.
|
|
65
|
-
*
|
|
66
|
-
* The single-child contract is real: a fragment or two siblings fail at render
|
|
67
|
-
* rather than silently losing the rhythm. Override the spacing with
|
|
68
|
-
* `bodyClassName`, not by adding classes to the child — the merge with the
|
|
69
|
-
* child's own is a concatenation, not a Tailwind-aware one.
|
|
70
|
-
*/
|
|
71
|
-
export declare function AuthFormLayout({ surface, title, description, titleClassName, headingLevel, headerSlot, logoSlot, footerSlot, noticeSlot, bodyClassName, children, className, }: AuthFormLayoutProps): React.JSX.Element;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { cn } from "../utils.js";
|
|
5
|
-
/** A heading at the given level; the type style is the caller's, so the level never changes the look. */
|
|
6
|
-
export function TitleTag({ level, className, children }) {
|
|
7
|
-
const Tag = `h${level}`;
|
|
8
|
-
return _jsx(Tag, { className: className, children: children });
|
|
9
|
-
}
|
|
10
|
-
const REACT_LAZY_TYPE = Symbol.for("react.lazy");
|
|
11
|
-
function isLazyReference(value) {
|
|
12
|
-
return (value !== null &&
|
|
13
|
-
typeof value === "object" &&
|
|
14
|
-
value.$$typeof === REACT_LAZY_TYPE &&
|
|
15
|
-
typeof value._payload?.then === "function");
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* The body region rendered through the screen's own element. A child that a server component passed
|
|
19
|
-
* arrives as a `react.lazy` reference once the Flight payload is split — sometimes a reference to a
|
|
20
|
-
* reference — so each layer is resolved with `use()` before the element is read.
|
|
21
|
-
*/
|
|
22
|
-
function AuthFormBody({ className, children }) {
|
|
23
|
-
let child = children;
|
|
24
|
-
for (let depth = 0; isLazyReference(child) && depth < 8; depth += 1) {
|
|
25
|
-
child = React.use(child._payload);
|
|
26
|
-
}
|
|
27
|
-
const element = React.Children.only(child);
|
|
28
|
-
// As the slot did before: the classes concatenate (CSS order decides, not a Tailwind-aware merge),
|
|
29
|
-
// and a data-slot the child sets itself wins.
|
|
30
|
-
return React.cloneElement(element, {
|
|
31
|
-
"data-slot": element.props["data-slot"] ?? "auth-form-body",
|
|
32
|
-
className: [className, element.props.className].filter(Boolean).join(" "),
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The panel an auth screen's credentials sit in: surface, header and logo rows,
|
|
37
|
-
* heading and description, the body region's rhythm, and the footer and notice
|
|
38
|
-
* rows beneath it (the auth pattern).
|
|
39
|
-
*
|
|
40
|
-
* Everything a screen *does* stays with the screen — submission, field state,
|
|
41
|
-
* validation, lockout, the submit control. This layout owns only where those
|
|
42
|
-
* things sit. The seam is the body region: the caller passes its own form
|
|
43
|
-
* element as the single child; the layout puts the gap above it on a wrapper and merges the rows' spacing
|
|
44
|
-
* onto the element itself (a native form takes it; the DS Form keeps its own gap and `data-slot`):
|
|
45
|
-
*
|
|
46
|
-
* - The form remains a real element, so its handler, `noValidate` and
|
|
47
|
-
* `aria-busy` behave exactly as they did before this layout existed.
|
|
48
|
-
* - The header, logo, footer and notice rows sit *outside* the form. A control
|
|
49
|
-
* placed there is not the form's to submit.
|
|
50
|
-
*
|
|
51
|
-
* The single-child contract is real: a fragment or two siblings fail at render
|
|
52
|
-
* rather than silently losing the rhythm. Override the spacing with
|
|
53
|
-
* `bodyClassName`, not by adding classes to the child — the merge with the
|
|
54
|
-
* child's own is a concatenation, not a Tailwind-aware one.
|
|
55
|
-
*/
|
|
56
|
-
export function AuthFormLayout({ surface = "card", title, description, titleClassName = "text-heading-large", headingLevel = 1, headerSlot, logoSlot, footerSlot, noticeSlot, bodyClassName, children, className, }) {
|
|
57
|
-
return (_jsxs("div", { "data-slot": "auth-card", "data-surface": surface, className: cn("w-full", surface === "card"
|
|
58
|
-
? "max-w-100 rounded-2xl bg-ds-surface-raised p-ds-300 shadow-ds-raised sm:p-7"
|
|
59
|
-
: "max-w-sm", className), children: [headerSlot && _jsx("div", { "data-slot": "auth-card-header", className: "mb-ds-300 flex justify-end", children: headerSlot }), logoSlot && _jsx("div", { "data-slot": "auth-card-logo", className: "mb-7 flex items-center lg:hidden", children: logoSlot }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(TitleTag, { level: headingLevel, className: cn("text-ds-text", titleClassName), children: title }), description && _jsx("p", { className: "text-body text-ds-text-subtle", children: description })] }), _jsx("div", { "data-slot": "auth-form-region", className: "mt-ds-400", children: _jsx(AuthFormBody, { className: cn("space-y-4", bodyClassName), children: children }) }), footerSlot && _jsx("div", { "data-slot": "auth-card-footer", className: "mt-ds-300 flex justify-center", children: footerSlot }), noticeSlot && _jsx("div", { "data-slot": "auth-card-notice", className: "mt-8", children: noticeSlot })] }));
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=auth-form-layout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-form-layout.js","sourceRoot":"","sources":["../../src/layout/auth-form-layout.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAI9B,yGAAyG;AACzG,MAAM,UAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAuE;IAC1H,MAAM,GAAG,GAAG,IAAI,KAAK,EAAW,CAAC;IACjC,OAAO,KAAC,GAAG,IAAC,SAAS,EAAE,SAAS,YAAG,QAAQ,GAAO,CAAC;AACrD,CAAC;A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,SAAS,GACW;IACpB,OAAO,CACL,4BACY,WAAW,kBACP,OAAO,EACrB,SAAS,EAAE,EAAE,CACX,QAAQ,EACR,OAAO,KAAK,MAAM;YAChB,CAAC,CAAC,6EAA6E;YAC/E,CAAC,CAAC,UAAU,EACd,SAAS,CACV,aAEA,UAAU,IAAI,2BAAe,kBAAkB,EAAC,SAAS,EAAC,4BAA4B,YAAE,UAAU,GAAO,EAEzG,QAAQ,IAAI,2BAAe,gBAAgB,EAAC,SAAS,EAAC,kCAAkC,YAAE,QAAQ,GAAO,EAE1G,eAAK,SAAS,EAAC,aAAa,aAC1B,KAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,YAAG,KAAK,GAAY,EAC/F,WAAW,IAAI,YAAG,SAAS,EAAC,+BAA+B,YAAE,WAAW,GAAK,IAC1E,EAIN,2BAAe,kBAAkB,EAAC,SAAS,EAAC,WAAW,YACrD,KAAC,YAAY,IAAC,SAAS,EAAE,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC,YAAG,QAAQ,GAAgB,GAC9E,EAEL,UAAU,IAAI,2BAAe,kBAAkB,EAAC,SAAS,EAAC,+BAA+B,YAAE,UAAU,GAAO,EAE5G,UAAU,IAAI,2BAAe,kBAAkB,EAAC,SAAS,EAAC,MAAM,YAAE,UAAU,GAAO,IAChF,CACP,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"../utils\";\n\nexport type AuthFormLayoutSurface = \"card\" | \"plain\";\n\n/** A heading at the given level; the type style is the caller's, so the level never changes the look. */\nexport function TitleTag({ level, className, children }: { level: 1 | 2 | 3; className?: string; children: React.ReactNode }) {\n const Tag = `h${level}` as const;\n return <Tag className={className}>{children}</Tag>;\n}\n\nexport interface AuthFormLayoutProps {\n /**\n * `card` (default) raises the panel onto its own surface; `plain` lets it sit\n * directly on the pane. The default matches the busiest existing screen.\n */\n surface?: AuthFormLayoutSurface;\n /** The screen's heading. */\n title: React.ReactNode;\n /** One line under the heading. */\n description?: React.ReactNode;\n /**\n * The heading's type style, a DS heading class: `text-heading-large` by default; a screen with a longer title\n * may step down (`text-heading-medium`).\n */\n titleClassName?: string;\n /** The title's heading level: 1 (the page's own heading, by default), or 2 when the page has its own h1. */\n headingLevel?: 1 | 2 | 3;\n /** Above everything, at the inline end — a language switcher, a back link. */\n headerSlot?: React.ReactNode;\n /** The compact brand header, mobile only: the brand pane is desktop-only. */\n logoSlot?: React.ReactNode;\n /** Under the body — a secondary route out of the screen. */\n footerSlot?: React.ReactNode;\n /** Last, set apart — legal text, a support line. */\n noticeSlot?: React.ReactNode;\n /**\n * The spacing between the form's rows (`space-y-4` by default), merged onto a native form child. The DS `Form`\n * takes no className and keeps its own gap, so this has no effect on it.\n */\n bodyClassName?: string;\n /**\n * A single element — the screen's own form. The layout renders the body\n * region *through* it, so it keeps its element, its handler and its\n * attributes while the rhythm arrives from here.\n *\n * A form component (rather than a `<form>`) must pass `className` and\n * `data-slot` on to its element, or the rhythm is lost.\n */\n children: React.ReactNode;\n className?: string;\n}\n\nconst REACT_LAZY_TYPE = Symbol.for(\"react.lazy\");\n\nfunction isLazyReference(value: unknown): value is { _payload: PromiseLike<unknown> } {\n return (\n value !== null &&\n typeof value === \"object\" &&\n (value as { $$typeof?: unknown }).$$typeof === REACT_LAZY_TYPE &&\n typeof (value as { _payload?: { then?: unknown } })._payload?.then === \"function\"\n );\n}\n\n/**\n * The body region rendered through the screen's own element. A child that a server component passed\n * arrives as a `react.lazy` reference once the Flight payload is split — sometimes a reference to a\n * reference — so each layer is resolved with `use()` before the element is read.\n */\nfunction AuthFormBody({ className, children }: { className: string; children: React.ReactNode }) {\n let child: React.ReactNode = children;\n for (let depth = 0; isLazyReference(child) && depth < 8; depth += 1) {\n child = React.use(child._payload) as React.ReactNode;\n }\n const element = React.Children.only(child) as React.ReactElement<{ className?: string; \"data-slot\"?: string }>;\n // As the slot did before: the classes concatenate (CSS order decides, not a Tailwind-aware merge),\n // and a data-slot the child sets itself wins.\n return React.cloneElement(element, {\n \"data-slot\": element.props[\"data-slot\"] ?? \"auth-form-body\",\n className: [className, element.props.className].filter(Boolean).join(\" \"),\n } as React.Attributes & { className?: string });\n}\n\n/**\n * The panel an auth screen's credentials sit in: surface, header and logo rows,\n * heading and description, the body region's rhythm, and the footer and notice\n * rows beneath it (the auth pattern).\n *\n * Everything a screen *does* stays with the screen — submission, field state,\n * validation, lockout, the submit control. This layout owns only where those\n * things sit. The seam is the body region: the caller passes its own form\n * element as the single child; the layout puts the gap above it on a wrapper and merges the rows' spacing\n * onto the element itself (a native form takes it; the DS Form keeps its own gap and `data-slot`):\n *\n * - The form remains a real element, so its handler, `noValidate` and\n * `aria-busy` behave exactly as they did before this layout existed.\n * - The header, logo, footer and notice rows sit *outside* the form. A control\n * placed there is not the form's to submit.\n *\n * The single-child contract is real: a fragment or two siblings fail at render\n * rather than silently losing the rhythm. Override the spacing with\n * `bodyClassName`, not by adding classes to the child — the merge with the\n * child's own is a concatenation, not a Tailwind-aware one.\n */\nexport function AuthFormLayout({\n surface = \"card\",\n title,\n description,\n titleClassName = \"text-heading-large\",\n headingLevel = 1,\n headerSlot,\n logoSlot,\n footerSlot,\n noticeSlot,\n bodyClassName,\n children,\n className,\n}: AuthFormLayoutProps) {\n return (\n <div\n data-slot=\"auth-card\"\n data-surface={surface}\n className={cn(\n \"w-full\",\n surface === \"card\"\n ? \"max-w-100 rounded-2xl bg-ds-surface-raised p-ds-300 shadow-ds-raised sm:p-7\"\n : \"max-w-sm\",\n className,\n )}\n >\n {headerSlot && <div data-slot=\"auth-card-header\" className=\"mb-ds-300 flex justify-end\">{headerSlot}</div>}\n\n {logoSlot && <div data-slot=\"auth-card-logo\" className=\"mb-7 flex items-center lg:hidden\">{logoSlot}</div>}\n\n <div className=\"space-y-1.5\">\n <TitleTag level={headingLevel} className={cn(\"text-ds-text\", titleClassName)}>{title}</TitleTag>\n {description && <p className=\"text-body text-ds-text-subtle\">{description}</p>}\n </div>\n\n {/* The gap above the form sits on a wrapper: the DS Form takes no className (its own gap is its rhythm),\n so a margin merged onto it would be lost. */}\n <div data-slot=\"auth-form-region\" className=\"mt-ds-400\">\n <AuthFormBody className={cn(\"space-y-4\", bodyClassName)}>{children}</AuthFormBody>\n </div>\n\n {footerSlot && <div data-slot=\"auth-card-footer\" className=\"mt-ds-300 flex justify-center\">{footerSlot}</div>}\n\n {noticeSlot && <div data-slot=\"auth-card-notice\" className=\"mt-8\">{noticeSlot}</div>}\n </div>\n );\n}\n"]}
|