@crystal-neuo/react 0.0.0-stage → 4.0.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 +21 -0
- package/README.md +6 -2
- package/dist/Alert.d.ts +11 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Alert.js +7 -0
- package/dist/Alert.js.map +1 -0
- package/dist/Avatar.d.ts +12 -0
- package/dist/Avatar.d.ts.map +1 -0
- package/dist/Avatar.js +14 -0
- package/dist/Avatar.js.map +1 -0
- package/dist/Badge.d.ts +9 -0
- package/dist/Badge.d.ts.map +1 -0
- package/dist/Badge.js +7 -0
- package/dist/Badge.js.map +1 -0
- package/dist/Breadcrumb.d.ts +13 -0
- package/dist/Breadcrumb.d.ts.map +1 -0
- package/dist/Breadcrumb.js +10 -0
- package/dist/Breadcrumb.js.map +1 -0
- package/dist/Button.d.ts +10 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +11 -0
- package/dist/Button.js.map +1 -0
- package/dist/Card.d.ts +9 -0
- package/dist/Card.d.ts.map +1 -0
- package/dist/Card.js +7 -0
- package/dist/Card.js.map +1 -0
- package/dist/Checkbox.d.ts +11 -0
- package/dist/Checkbox.d.ts.map +1 -0
- package/dist/Checkbox.js +28 -0
- package/dist/Checkbox.js.map +1 -0
- package/dist/DatePicker.d.ts +10 -0
- package/dist/DatePicker.d.ts.map +1 -0
- package/dist/DatePicker.js +10 -0
- package/dist/DatePicker.js.map +1 -0
- package/dist/Dialog.d.ts +18 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +15 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/Drawer.d.ts +14 -0
- package/dist/Drawer.d.ts.map +1 -0
- package/dist/Drawer.js +11 -0
- package/dist/Drawer.js.map +1 -0
- package/dist/FileUpload.d.ts +15 -0
- package/dist/FileUpload.d.ts.map +1 -0
- package/dist/FileUpload.js +42 -0
- package/dist/FileUpload.js.map +1 -0
- package/dist/Input.d.ts +11 -0
- package/dist/Input.d.ts.map +1 -0
- package/dist/Input.js +12 -0
- package/dist/Input.js.map +1 -0
- package/dist/List.d.ts +13 -0
- package/dist/List.d.ts.map +1 -0
- package/dist/List.js +10 -0
- package/dist/List.js.map +1 -0
- package/dist/Menu.d.ts +14 -0
- package/dist/Menu.d.ts.map +1 -0
- package/dist/Menu.js +90 -0
- package/dist/Menu.js.map +1 -0
- package/dist/Modal.d.ts +13 -0
- package/dist/Modal.d.ts.map +1 -0
- package/dist/Modal.js +11 -0
- package/dist/Modal.js.map +1 -0
- package/dist/Nav.d.ts +14 -0
- package/dist/Nav.d.ts.map +1 -0
- package/dist/Nav.js +10 -0
- package/dist/Nav.js.map +1 -0
- package/dist/Pagination.d.ts +13 -0
- package/dist/Pagination.d.ts.map +1 -0
- package/dist/Pagination.js +12 -0
- package/dist/Pagination.js.map +1 -0
- package/dist/Progress.d.ts +12 -0
- package/dist/Progress.d.ts.map +1 -0
- package/dist/Progress.js +11 -0
- package/dist/Progress.js.map +1 -0
- package/dist/Radio.d.ts +21 -0
- package/dist/Radio.d.ts.map +1 -0
- package/dist/Radio.js +17 -0
- package/dist/Radio.js.map +1 -0
- package/dist/SegmentedControl.d.ts +23 -0
- package/dist/SegmentedControl.d.ts.map +1 -0
- package/dist/SegmentedControl.js +16 -0
- package/dist/SegmentedControl.js.map +1 -0
- package/dist/Select.d.ts +16 -0
- package/dist/Select.d.ts.map +1 -0
- package/dist/Select.js +10 -0
- package/dist/Select.js.map +1 -0
- package/dist/Sheet.d.ts +12 -0
- package/dist/Sheet.d.ts.map +1 -0
- package/dist/Sheet.js +11 -0
- package/dist/Sheet.js.map +1 -0
- package/dist/Skeleton.d.ts +9 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +7 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/Slider.d.ts +10 -0
- package/dist/Slider.d.ts.map +1 -0
- package/dist/Slider.js +9 -0
- package/dist/Slider.js.map +1 -0
- package/dist/TabBar.d.ts +17 -0
- package/dist/TabBar.d.ts.map +1 -0
- package/dist/TabBar.js +7 -0
- package/dist/TabBar.js.map +1 -0
- package/dist/Table.d.ts +16 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +7 -0
- package/dist/Table.js.map +1 -0
- package/dist/Tabs.d.ts +20 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +49 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Textarea.d.ts +11 -0
- package/dist/Textarea.d.ts.map +1 -0
- package/dist/Textarea.js +12 -0
- package/dist/Textarea.js.map +1 -0
- package/dist/Toast.d.ts +12 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +45 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Toggle.d.ts +9 -0
- package/dist/Toggle.d.ts.map +1 -0
- package/dist/Toggle.js +16 -0
- package/dist/Toggle.js.map +1 -0
- package/dist/Tooltip.d.ts +11 -0
- package/dist/Tooltip.d.ts.map +1 -0
- package/dist/Tooltip.js +36 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/cn.d.ts +2 -0
- package/dist/cn.d.ts.map +1 -0
- package/dist/cn.js +7 -0
- package/dist/cn.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/useFocusTrap.d.ts +11 -0
- package/dist/useFocusTrap.d.ts.map +1 -0
- package/dist/useFocusTrap.js +67 -0
- package/dist/useFocusTrap.js.map +1 -0
- package/dist/useModalDialog.d.ts +20 -0
- package/dist/useModalDialog.d.ts.map +1 -0
- package/dist/useModalDialog.js +81 -0
- package/dist/useModalDialog.js.map +1 -0
- package/package.json +42 -4
- package/src/Alert.tsx +40 -0
- package/src/Avatar.tsx +47 -0
- package/src/Badge.tsx +20 -0
- package/src/Breadcrumb.tsx +52 -0
- package/src/Button.tsx +38 -0
- package/src/Card.tsx +20 -0
- package/src/Checkbox.tsx +65 -0
- package/src/DatePicker.tsx +46 -0
- package/src/Dialog.tsx +81 -0
- package/src/Drawer.tsx +57 -0
- package/src/FileUpload.tsx +116 -0
- package/src/Input.tsx +46 -0
- package/src/List.tsx +35 -0
- package/src/Menu.tsx +141 -0
- package/src/Modal.tsx +40 -0
- package/src/Nav.tsx +40 -0
- package/src/Pagination.tsx +78 -0
- package/src/Progress.tsx +43 -0
- package/src/Radio.tsx +71 -0
- package/src/SegmentedControl.tsx +72 -0
- package/src/Select.tsx +64 -0
- package/src/Sheet.tsx +40 -0
- package/src/Skeleton.tsx +21 -0
- package/src/Slider.tsx +34 -0
- package/src/TabBar.tsx +46 -0
- package/src/Table.tsx +60 -0
- package/src/Tabs.tsx +114 -0
- package/src/Textarea.tsx +54 -0
- package/src/Toast.tsx +97 -0
- package/src/Toggle.tsx +42 -0
- package/src/Tooltip.tsx +70 -0
- package/src/cn.ts +6 -0
- package/src/index.ts +44 -0
- package/src/useFocusTrap.ts +71 -0
- package/src/useModalDialog.ts +83 -0
package/dist/Tabs.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
export function Tabs({ material, className, items, value, defaultValue, onValueChange, variant = "line", size = "md", label, ...props }) {
|
|
5
|
+
const baseId = React.useId();
|
|
6
|
+
const firstEnabled = items.find((it) => !it.disabled)?.value ?? "";
|
|
7
|
+
const [internal, setInternal] = React.useState(defaultValue ?? firstEnabled);
|
|
8
|
+
const requested = value ?? internal;
|
|
9
|
+
// A value that names no enabled tab would leave no tab in the Tab order.
|
|
10
|
+
const active = items.some((it) => it.value === requested && !it.disabled) ? requested : firstEnabled;
|
|
11
|
+
const tabRefs = React.useRef([]);
|
|
12
|
+
function select(next) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
setInternal(next);
|
|
15
|
+
onValueChange?.(next);
|
|
16
|
+
}
|
|
17
|
+
function onKeyDown(e, index) {
|
|
18
|
+
const enabled = items.map((it, i) => ({ it, i })).filter(({ it }) => !it.disabled);
|
|
19
|
+
const pos = enabled.findIndex(({ i }) => i === index);
|
|
20
|
+
// Arrow keys follow the visual order, which flips under dir=rtl.
|
|
21
|
+
const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
|
|
22
|
+
const forward = rtl ? "ArrowLeft" : "ArrowRight";
|
|
23
|
+
const backward = rtl ? "ArrowRight" : "ArrowLeft";
|
|
24
|
+
let nextPos = pos;
|
|
25
|
+
if (e.key === forward)
|
|
26
|
+
nextPos = (pos + 1) % enabled.length;
|
|
27
|
+
else if (e.key === backward)
|
|
28
|
+
nextPos = (pos - 1 + enabled.length) % enabled.length;
|
|
29
|
+
else if (e.key === "Home")
|
|
30
|
+
nextPos = 0;
|
|
31
|
+
else if (e.key === "End")
|
|
32
|
+
nextPos = enabled.length - 1;
|
|
33
|
+
else
|
|
34
|
+
return;
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
const target = enabled[nextPos];
|
|
37
|
+
if (!target)
|
|
38
|
+
return;
|
|
39
|
+
select(target.it.value);
|
|
40
|
+
tabRefs.current[target.i]?.focus();
|
|
41
|
+
}
|
|
42
|
+
return (_jsxs("div", { "data-slot": "tabs", "data-material": material, className: cn("cn-tabs", `cn-tabs--${variant}`, `cn-tabs--size-${size}`, className), ...props, children: [_jsx("div", { className: "cn-tabs__list", role: "tablist", "aria-label": label, children: items.map((it, i) => {
|
|
43
|
+
const selected = it.value === active;
|
|
44
|
+
return (_jsx("button", { ref: (el) => {
|
|
45
|
+
tabRefs.current[i] = el;
|
|
46
|
+
}, role: "tab", type: "button", id: `${baseId}-tab-${i}`, "aria-selected": selected, "aria-controls": `${baseId}-panel-${i}`, tabIndex: selected ? 0 : -1, disabled: it.disabled, className: "cn-tabs__tab", onClick: () => select(it.value), onKeyDown: (e) => onKeyDown(e, i), children: it.label }, it.value));
|
|
47
|
+
}) }), items.map((it, i) => (_jsx("div", { role: "tabpanel", id: `${baseId}-panel-${i}`, "aria-labelledby": `${baseId}-tab-${i}`, hidden: it.value !== active, className: "cn-tabs__panel", children: it.content }, it.value)))] }));
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=Tabs.js.map
|
package/dist/Tabs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tabs.js","sourceRoot":"","sources":["../src/Tabs.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAoB7B,MAAM,UAAU,IAAI,CAAC,EACnB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,OAAO,GAAG,MAAM,EAChB,IAAI,GAAG,IAAI,EACX,KAAK,EACL,GAAG,KAAK,EACE;IACV,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;IACnE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,IAAI,YAAY,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,KAAK,IAAI,QAAQ,CAAC;IACpC,yEAAyE;IACzE,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;IACrG,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAkC,EAAE,CAAC,CAAC;IAElE,SAAS,MAAM,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E,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,YAEhC,EAAE,CAAC,KAAK,IAfJ,EAAE,CAAC,KAAK,CAgBN,CACV,CAAC;gBACJ,CAAC,CAAC,GACE,EACL,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACpB,cAEE,IAAI,EAAC,UAAU,EACf,EAAE,EAAE,GAAG,MAAM,UAAU,CAAC,EAAE,qBACT,GAAG,MAAM,QAAQ,CAAC,EAAE,EACrC,MAAM,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,EAC3B,SAAS,EAAC,gBAAgB,YAEzB,EAAE,CAAC,OAAO,IAPN,EAAE,CAAC,KAAK,CAQT,CACP,CAAC,IACE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TextareaSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
export interface TextareaProps extends Omit<React.ComponentProps<"textarea">, "size"> {
|
|
4
|
+
material?: Material;
|
|
5
|
+
size?: TextareaSize;
|
|
6
|
+
label?: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
hint?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function Textarea({ material, className, size, label, error, hint, id, ...props }: TextareaProps): React.JSX.Element;
|
|
11
|
+
//# sourceMappingURL=Textarea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../src/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGrE,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IACnF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,QAAQ,CAAC,EACvB,QAAQ,EACR,SAAS,EACT,IAAW,EACX,KAAK,EACL,KAAK,EACL,IAAI,EACJ,EAAE,EACF,GAAG,KAAK,EACT,EAAE,aAAa,qBAgCf"}
|
package/dist/Textarea.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
export function Textarea({ material, className, size = "md", label, error, hint, id, ...props }) {
|
|
5
|
+
const autoId = React.useId();
|
|
6
|
+
const taId = id ?? autoId;
|
|
7
|
+
const msgId = `${taId}-msg`;
|
|
8
|
+
const hintId = `${taId}-hint`;
|
|
9
|
+
const describedBy = [error ? msgId : null, hint ? hintId : null].filter(Boolean).join(" ") || undefined;
|
|
10
|
+
return (_jsxs("div", { className: cn("cn-field", className), "data-slot": "textarea-field", "data-material": material, children: [label ? (_jsx("label", { className: "cn-field__label", htmlFor: taId, children: label })) : null, _jsx("textarea", { id: taId, className: cn("cn-textarea", `cn-input--size-${size}`, error && "cn-textarea--error"), "aria-invalid": error ? true : undefined, "aria-describedby": describedBy, ...props }), hint && !error ? (_jsx("span", { className: "cn-field__hint", id: hintId, children: hint })) : null, error ? (_jsx("span", { className: "cn-field__message", id: msgId, children: error })) : null] }));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Textarea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../src/Textarea.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS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C,mBAAmB,EAAC,EAAE,EAAE,KAAK,YAC1C,KAAK,GACD,CACR,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC"}
|
package/dist/Toast.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ToastVariant, Material } from "@crystal-neuo/contract";
|
|
3
|
+
export interface ToastProps extends React.ComponentProps<"div"> {
|
|
4
|
+
material?: Material;
|
|
5
|
+
variant?: ToastVariant;
|
|
6
|
+
/** Auto-dismiss delay in ms; paused while hovered or focused. `0` keeps the toast until dismissed. */
|
|
7
|
+
duration?: number;
|
|
8
|
+
onDismiss?: () => void;
|
|
9
|
+
dismissLabel?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function Toast({ material, className, variant, duration, onDismiss, dismissLabel, children, onMouseEnter, onMouseLeave, onFocus, onBlur, onKeyDown, ...props }: ToastProps): React.JSX.Element | null;
|
|
12
|
+
//# sourceMappingURL=Toast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGrE,MAAM,WAAW,UAAW,SAAQ,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IAC7D,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,sGAAsG;IACtG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,KAAK,CAAC,EACpB,QAAQ,EACR,SAAS,EACT,OAAmB,EACnB,QAAe,EACf,SAAS,EACT,YAAwB,EACxB,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,MAAM,EACN,SAAS,EACT,GAAG,KAAK,EACT,EAAE,UAAU,4BAqEZ"}
|
package/dist/Toast.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
export function Toast({ material, className, variant = "neutral", duration = 6000, onDismiss, dismissLabel = "Dismiss", children, onMouseEnter, onMouseLeave, onFocus, onBlur, onKeyDown, ...props }) {
|
|
5
|
+
const [visible, setVisible] = React.useState(true);
|
|
6
|
+
const [paused, setPaused] = React.useState(false);
|
|
7
|
+
const onDismissRef = React.useRef(onDismiss);
|
|
8
|
+
React.useLayoutEffect(() => {
|
|
9
|
+
onDismissRef.current = onDismiss;
|
|
10
|
+
});
|
|
11
|
+
const dismiss = React.useCallback(() => {
|
|
12
|
+
setVisible(false);
|
|
13
|
+
onDismissRef.current?.();
|
|
14
|
+
}, []);
|
|
15
|
+
React.useEffect(() => {
|
|
16
|
+
if (!visible || paused || duration <= 0)
|
|
17
|
+
return;
|
|
18
|
+
const timer = setTimeout(dismiss, duration);
|
|
19
|
+
return () => clearTimeout(timer);
|
|
20
|
+
}, [visible, paused, duration, dismiss]);
|
|
21
|
+
if (!visible)
|
|
22
|
+
return null;
|
|
23
|
+
const assertive = variant === "danger";
|
|
24
|
+
return (_jsxs("div", { "data-slot": "toast", "data-material": material, role: assertive ? "alert" : "status", "aria-live": assertive ? "assertive" : "polite", className: cn("cn-toast", `cn-toast--${variant}`, className), ...props, onMouseEnter: (e) => {
|
|
25
|
+
onMouseEnter?.(e);
|
|
26
|
+
setPaused(true);
|
|
27
|
+
}, onMouseLeave: (e) => {
|
|
28
|
+
onMouseLeave?.(e);
|
|
29
|
+
setPaused(false);
|
|
30
|
+
}, onFocus: (e) => {
|
|
31
|
+
onFocus?.(e);
|
|
32
|
+
setPaused(true);
|
|
33
|
+
}, onBlur: (e) => {
|
|
34
|
+
onBlur?.(e);
|
|
35
|
+
if (!e.currentTarget.contains(e.relatedTarget))
|
|
36
|
+
setPaused(false);
|
|
37
|
+
}, onKeyDown: (e) => {
|
|
38
|
+
onKeyDown?.(e);
|
|
39
|
+
if (e.key === "Escape" && !e.defaultPrevented) {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
dismiss();
|
|
42
|
+
}
|
|
43
|
+
}, children: [_jsxs("svg", { className: "cn-toast__icon", viewBox: "0 0 20 20", "aria-hidden": "true", children: [_jsx("circle", { cx: "10", cy: "10", r: "8", fill: "none", stroke: "currentColor", strokeWidth: "1.5" }), _jsx("path", { d: "M10 6v5M10 14h.01", stroke: "currentColor", strokeWidth: "1.5", fill: "none" })] }), _jsx("div", { className: "cn-toast__body", children: children }), _jsx("button", { type: "button", className: "cn-button cn-button--ghost cn-button--size-sm cn-toast__close", "aria-label": dismissLabel, onClick: dismiss, children: _jsx("span", { "aria-hidden": "true", children: "\u00D7" }) })] }));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=Toast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.js","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAW7B,MAAM,UAAU,KAAK,CAAC,EACpB,QAAQ,EACR,SAAS,EACT,OAAO,GAAG,SAAS,EACnB,QAAQ,GAAG,IAAI,EACf,SAAS,EACT,YAAY,GAAG,SAAS,EACxB,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,MAAM,EACN,SAAS,EACT,GAAG,KAAK,EACG;IACX,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnD,MAAM,CAAC,MAAM,EAAE,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EhB,8BAAkB,MAAM,uBAAS,GAC1B,IACL,CACP,CAAC;AACJ,CAAC"}
|
package/dist/Toggle.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ToggleSize, Material } from "@crystal-neuo/contract";
|
|
3
|
+
export interface ToggleProps extends Omit<React.ComponentProps<"input">, "size" | "type"> {
|
|
4
|
+
material?: Material;
|
|
5
|
+
size?: ToggleSize;
|
|
6
|
+
label?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function Toggle({ material, className, size, label, id, onKeyDown, ...props }: ToggleProps): React.JSX.Element;
|
|
9
|
+
//# sourceMappingURL=Toggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toggle.d.ts","sourceRoot":"","sources":["../src/Toggle.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGnE,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAW,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,WAAW,qBA+BvG"}
|
package/dist/Toggle.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
export function Toggle({ material, className, size = "md", label, id, onKeyDown, ...props }) {
|
|
5
|
+
const autoId = React.useId();
|
|
6
|
+
const toggleId = id ?? autoId;
|
|
7
|
+
return (_jsxs("label", { className: cn("cn-toggle", `cn-toggle--size-${size}`, className), htmlFor: toggleId, "data-slot": "toggle", "data-material": material, children: [_jsxs("span", { className: "cn-toggle__track", children: [_jsx("input", { id: toggleId, className: "cn-toggle__input", type: "checkbox", role: "switch", ...props, onKeyDown: (e) => {
|
|
8
|
+
onKeyDown?.(e);
|
|
9
|
+
// Switches toggle on Enter as well as Space; a native checkbox only does Space.
|
|
10
|
+
if (e.key === "Enter" && !e.defaultPrevented) {
|
|
11
|
+
e.preventDefault();
|
|
12
|
+
e.currentTarget.click();
|
|
13
|
+
}
|
|
14
|
+
} }), _jsx("span", { className: "cn-toggle__thumb", "aria-hidden": "true" })] }), label ? _jsx("span", { className: "cn-toggle__label", children: label }) : null] }));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=Toggle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toggle.js","sourceRoot":"","sources":["../src/Toggle.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAQ7B,MAAM,UAAU,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,KAAK,EAAe;IACtG,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,EAAE,IAAI,MAAM,CAAC;IAC9B,OAAO,CACL,iBACE,SAAS,EAAE,EAAE,CAAC,WAAW,EAAE,mBAAmB,IAAI,EAAE,EAAE,SAAS,CAAC,EAChE,OAAO,EAAE,QAAQ,eACP,QAAQ,mBACH,QAAQ,aAEvB,gBAAM,SAAS,EAAC,kBAAkB,aAChC,gBACE,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAC,kBAAkB,EAC5B,IAAI,EAAC,UAAU,EACf,IAAI,EAAC,QAAQ,KACT,KAAK,EACT,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;4BACf,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;4BACf,gFAAgF;4BAChF,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;gCAC7C,CAAC,CAAC,cAAc,EAAE,CAAC;gCACnB,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;4BAC1B,CAAC;wBACH,CAAC,GACD,EACF,eAAM,SAAS,EAAC,kBAAkB,iBAAa,MAAM,GAAG,IACnD,EACN,KAAK,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,kBAAkB,YAAE,KAAK,GAAQ,CAAC,CAAC,CAAC,IAAI,IAC3D,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { Material } from "@crystal-neuo/contract";
|
|
3
|
+
export interface TooltipProps extends React.ComponentProps<"span"> {
|
|
4
|
+
material?: Material;
|
|
5
|
+
label: string;
|
|
6
|
+
children: React.ReactElement<{
|
|
7
|
+
"aria-describedby"?: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare function Tooltip({ material, className, label, children, onMouseEnter, onMouseLeave, onFocus, onBlur, ...props }: TooltipProps): React.JSX.Element;
|
|
11
|
+
//# sourceMappingURL=Tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../src/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD,MAAM,WAAW,YAAa,SAAQ,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC;IAChE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC;QAAE,kBAAkB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/D;AAED,wBAAgB,OAAO,CAAC,EACtB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,MAAM,EACN,GAAG,KAAK,EACT,EAAE,YAAY,qBAiDd"}
|
package/dist/Tooltip.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
export function Tooltip({ material, className, label, children, onMouseEnter, onMouseLeave, onFocus, onBlur, ...props }) {
|
|
5
|
+
const [open, setOpen] = React.useState(false);
|
|
6
|
+
const id = React.useId();
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
if (!open)
|
|
9
|
+
return;
|
|
10
|
+
function onKey(e) {
|
|
11
|
+
if (e.key !== "Escape")
|
|
12
|
+
return;
|
|
13
|
+
// Consume the key so an enclosing dialog stays open; a second Escape closes it.
|
|
14
|
+
e.preventDefault();
|
|
15
|
+
setOpen(false);
|
|
16
|
+
}
|
|
17
|
+
document.addEventListener("keydown", onKey);
|
|
18
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
19
|
+
}, [open]);
|
|
20
|
+
// Keep any description the trigger already has.
|
|
21
|
+
const describedBy = [children.props["aria-describedby"], id].filter(Boolean).join(" ");
|
|
22
|
+
return (_jsxs("span", { className: cn("cn-tooltip", className), "data-slot": "tooltip", "data-material": material, ...props, onMouseEnter: (e) => {
|
|
23
|
+
onMouseEnter?.(e);
|
|
24
|
+
setOpen(true);
|
|
25
|
+
}, onMouseLeave: (e) => {
|
|
26
|
+
onMouseLeave?.(e);
|
|
27
|
+
setOpen(false);
|
|
28
|
+
}, onFocus: (e) => {
|
|
29
|
+
onFocus?.(e);
|
|
30
|
+
setOpen(true);
|
|
31
|
+
}, onBlur: (e) => {
|
|
32
|
+
onBlur?.(e);
|
|
33
|
+
setOpen(false);
|
|
34
|
+
}, children: [React.cloneElement(children, { "aria-describedby": describedBy }), _jsx("span", { role: "tooltip", id: id, className: "cn-tooltip__bubble", hidden: !open, children: label })] }));
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../src/Tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAQ7B,MAAM,UAAU,OAAO,CAAC,EACtB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,MAAM,EACN,GAAG,KAAK,EACK;IACb,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAEzB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,SAAS,KAAK,CAAC,CAAgB;YAC7B,IAAI,CAAC,CAAC,GAAG,KAAK,QAAQ;gBAAE,OAAO;YAC/B,gFAAgF;YAChF,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;QACD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC5C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC,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[],"mappings":"AAGA,wBAAgB,EAAE,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,CAE7E"}
|
package/dist/cn.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Minimal class-name joiner. Crystal Neuo components compose `cn-*` classes
|
|
2
|
+
// (not Tailwind utilities), so a dependency-free joiner is enough — no need
|
|
3
|
+
// for clsx/tailwind-merge. Consumer `className` always comes last so it wins.
|
|
4
|
+
export function cn(...parts) {
|
|
5
|
+
return parts.filter(Boolean).join(" ");
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=cn.js.map
|
package/dist/cn.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cn.js","sourceRoot":"","sources":["../src/cn.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,MAAM,UAAU,EAAE,CAAC,GAAG,KAA+C;IACnE,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { Button, type ButtonProps } from "./Button.tsx";
|
|
2
|
+
export { Card, type CardProps } from "./Card.tsx";
|
|
3
|
+
export { Input, type InputProps } from "./Input.tsx";
|
|
4
|
+
export { Toggle, type ToggleProps } from "./Toggle.tsx";
|
|
5
|
+
export { Nav, NavLink, type NavProps, type NavLinkProps } from "./Nav.tsx";
|
|
6
|
+
export { Modal, type ModalProps } from "./Modal.tsx";
|
|
7
|
+
export { Tabs, type TabsProps, type TabItem } from "./Tabs.tsx";
|
|
8
|
+
export { Tooltip, type TooltipProps } from "./Tooltip.tsx";
|
|
9
|
+
export { Badge, type BadgeProps } from "./Badge.tsx";
|
|
10
|
+
export { Select, type SelectProps, type SelectOption } from "./Select.tsx";
|
|
11
|
+
export { Checkbox, type CheckboxProps } from "./Checkbox.tsx";
|
|
12
|
+
export { Radio, type RadioProps, type RadioOption } from "./Radio.tsx";
|
|
13
|
+
export { Slider, type SliderProps } from "./Slider.tsx";
|
|
14
|
+
export { DatePicker, type DatePickerProps } from "./DatePicker.tsx";
|
|
15
|
+
export { Textarea, type TextareaProps } from "./Textarea.tsx";
|
|
16
|
+
export { FileUpload, type FileUploadProps } from "./FileUpload.tsx";
|
|
17
|
+
export { Table, type TableProps, type TableColumn } from "./Table.tsx";
|
|
18
|
+
export { List, ListItem, type ListProps, type ListItemProps } from "./List.tsx";
|
|
19
|
+
export { Avatar, type AvatarProps } from "./Avatar.tsx";
|
|
20
|
+
export { Progress, type ProgressProps } from "./Progress.tsx";
|
|
21
|
+
export { Skeleton, type SkeletonProps } from "./Skeleton.tsx";
|
|
22
|
+
export { Breadcrumb, type BreadcrumbProps, type Crumb } from "./Breadcrumb.tsx";
|
|
23
|
+
export { Pagination, type PaginationProps } from "./Pagination.tsx";
|
|
24
|
+
export { Toast, type ToastProps } from "./Toast.tsx";
|
|
25
|
+
export { Alert, type AlertProps } from "./Alert.tsx";
|
|
26
|
+
export { Dialog, type DialogProps } from "./Dialog.tsx";
|
|
27
|
+
export { Drawer, type DrawerProps } from "./Drawer.tsx";
|
|
28
|
+
export { SegmentedControl, type SegmentedControlProps, type SegmentedOption } from "./SegmentedControl.tsx";
|
|
29
|
+
export { Sheet, type SheetProps } from "./Sheet.tsx";
|
|
30
|
+
export { TabBar, type TabBarProps, type TabBarItem } from "./TabBar.tsx";
|
|
31
|
+
export { Menu, type MenuProps, type MenuEntry } from "./Menu.tsx";
|
|
32
|
+
export { cn } from "./cn.ts";
|
|
33
|
+
export { useFocusTrap } from "./useFocusTrap.ts";
|
|
34
|
+
export { useModalDialog, closeOnScrim } from "./useModalDialog.ts";
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Core
|
|
2
|
+
export { Button } from "./Button.js";
|
|
3
|
+
export { Card } from "./Card.js";
|
|
4
|
+
export { Input } from "./Input.js";
|
|
5
|
+
export { Toggle } from "./Toggle.js";
|
|
6
|
+
export { Nav, NavLink } from "./Nav.js";
|
|
7
|
+
export { Modal } from "./Modal.js";
|
|
8
|
+
export { Tabs } from "./Tabs.js";
|
|
9
|
+
export { Tooltip } from "./Tooltip.js";
|
|
10
|
+
export { Badge } from "./Badge.js";
|
|
11
|
+
// Form
|
|
12
|
+
export { Select } from "./Select.js";
|
|
13
|
+
export { Checkbox } from "./Checkbox.js";
|
|
14
|
+
export { Radio } from "./Radio.js";
|
|
15
|
+
export { Slider } from "./Slider.js";
|
|
16
|
+
export { DatePicker } from "./DatePicker.js";
|
|
17
|
+
export { Textarea } from "./Textarea.js";
|
|
18
|
+
export { FileUpload } from "./FileUpload.js";
|
|
19
|
+
// Data
|
|
20
|
+
export { Table } from "./Table.js";
|
|
21
|
+
export { List, ListItem } from "./List.js";
|
|
22
|
+
export { Avatar } from "./Avatar.js";
|
|
23
|
+
export { Progress } from "./Progress.js";
|
|
24
|
+
export { Skeleton } from "./Skeleton.js";
|
|
25
|
+
export { Breadcrumb } from "./Breadcrumb.js";
|
|
26
|
+
export { Pagination } from "./Pagination.js";
|
|
27
|
+
// Feedback
|
|
28
|
+
export { Toast } from "./Toast.js";
|
|
29
|
+
export { Alert } from "./Alert.js";
|
|
30
|
+
export { Dialog } from "./Dialog.js";
|
|
31
|
+
export { Drawer } from "./Drawer.js";
|
|
32
|
+
// App shell
|
|
33
|
+
export { SegmentedControl } from "./SegmentedControl.js";
|
|
34
|
+
export { Sheet } from "./Sheet.js";
|
|
35
|
+
export { TabBar } from "./TabBar.js";
|
|
36
|
+
export { Menu } from "./Menu.js";
|
|
37
|
+
export { cn } from "./cn.js";
|
|
38
|
+
export { useFocusTrap } from "./useFocusTrap.js";
|
|
39
|
+
export { useModalDialog, closeOnScrim } from "./useModalDialog.js";
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAc,CAAC;AACxD,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAY,CAAC;AAClD,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAc,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAoC,MAAM,UAAW,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAa,CAAC;AACrD,OAAO,EAAE,IAAI,EAAgC,MAAM,WAAY,CAAC;AAChE,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAe,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAa,CAAC;AAErD,OAAO;AACP,OAAO,EAAE,MAAM,EAAuC,MAAM,aAAc,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAgB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAqC,MAAM,YAAa,CAAC;AACvE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAc,CAAC;AACxD,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAkB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAgB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAkB,CAAC;AAEpE,OAAO;AACP,OAAO,EAAE,KAAK,EAAqC,MAAM,YAAa,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAsC,MAAM,WAAY,CAAC;AAChF,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAc,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAgB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAgB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAkB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAkB,CAAC;AAEpE,WAAW;AACX,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAc,CAAC;AACxD,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAc,CAAC;AAExD,YAAY;AACZ,OAAO,EAAE,gBAAgB,EAAoD,MAAM,uBAAwB,CAAC;AAC5G,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAqC,MAAM,aAAc,CAAC;AACzE,OAAO,EAAE,IAAI,EAAkC,MAAM,WAAY,CAAC;AAElE,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Traps focus inside `ref` while `active`, closes on Escape, and restores
|
|
4
|
+
* focus to the previously-focused element on deactivate.
|
|
5
|
+
*
|
|
6
|
+
* For non-modal surfaces that cannot be a native `<dialog>`. Modal, Dialog,
|
|
7
|
+
* and Drawer use `useModalDialog`, which gets inertness and top-layer
|
|
8
|
+
* stacking from the platform instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useFocusTrap(ref: React.RefObject<HTMLElement | null>, active: boolean, onClose: () => void): void;
|
|
11
|
+
//# sourceMappingURL=useFocusTrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTrap.d.ts","sourceRoot":"","sources":["../src/useFocusTrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EACxC,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,MAAM,IAAI,GAClB,IAAI,CAqDN"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const FOCUSABLE = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
3
|
+
/**
|
|
4
|
+
* Traps focus inside `ref` while `active`, closes on Escape, and restores
|
|
5
|
+
* focus to the previously-focused element on deactivate.
|
|
6
|
+
*
|
|
7
|
+
* For non-modal surfaces that cannot be a native `<dialog>`. Modal, Dialog,
|
|
8
|
+
* and Drawer use `useModalDialog`, which gets inertness and top-layer
|
|
9
|
+
* stacking from the platform instead.
|
|
10
|
+
*/
|
|
11
|
+
export function useFocusTrap(ref, active, onClose) {
|
|
12
|
+
// Latest callback without re-running the effect: an inline arrow would
|
|
13
|
+
// otherwise restore and re-grab focus on every parent render.
|
|
14
|
+
const onCloseRef = React.useRef(onClose);
|
|
15
|
+
React.useLayoutEffect(() => {
|
|
16
|
+
onCloseRef.current = onClose;
|
|
17
|
+
});
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
if (!active)
|
|
20
|
+
return;
|
|
21
|
+
const node = ref.current;
|
|
22
|
+
if (!node)
|
|
23
|
+
return;
|
|
24
|
+
const previouslyFocused = document.activeElement;
|
|
25
|
+
const focusables = () => Array.from(node.querySelectorAll(FOCUSABLE));
|
|
26
|
+
// With nothing focusable inside, focus the container itself so Tab cannot
|
|
27
|
+
// walk the page behind it.
|
|
28
|
+
if (!node.hasAttribute("tabindex"))
|
|
29
|
+
node.setAttribute("tabindex", "-1");
|
|
30
|
+
(focusables()[0] ?? node).focus();
|
|
31
|
+
function onKey(e) {
|
|
32
|
+
// A nested surface already handled this key.
|
|
33
|
+
if (e.defaultPrevented)
|
|
34
|
+
return;
|
|
35
|
+
if (e.key === "Escape") {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
onCloseRef.current();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (e.key !== "Tab")
|
|
41
|
+
return;
|
|
42
|
+
const items = focusables();
|
|
43
|
+
if (items.length === 0) {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const first = items[0];
|
|
48
|
+
const last = items[items.length - 1];
|
|
49
|
+
if (e.shiftKey && (document.activeElement === first || document.activeElement === node)) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
last.focus();
|
|
52
|
+
}
|
|
53
|
+
else if (!e.shiftKey && document.activeElement === last) {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
first.focus();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Listen on the trapped node, not document, so Escape is scoped to the
|
|
59
|
+
// surface that has focus.
|
|
60
|
+
node.addEventListener("keydown", onKey);
|
|
61
|
+
return () => {
|
|
62
|
+
node.removeEventListener("keydown", onKey);
|
|
63
|
+
previouslyFocused?.focus?.();
|
|
64
|
+
};
|
|
65
|
+
}, [ref, active]);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=useFocusTrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTrap.js","sourceRoot":"","sources":["../src/useFocusTrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,SAAS,GACb,2IAA2I,CAAC;AAE9I;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAwC,EACxC,MAAe,EACf,O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,CAAC;YACD,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;YACxB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;YACtC,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,aAAa,KAAK,KAAK,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,CAAC,EAAE,CAAC;gBACxF,CAAC,CAAC,cAAc,EAAE,CAAC;gBACnB,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,CAAC;iBAAM,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;gBAC1D,CAAC,CAAC,cAAc,EAAE,CAAC;gBACnB,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;QAED,uEAAuE;QACvE,0BAA0B;QAC1B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACxC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAC3C,iBAAiB,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Drives a native `<dialog>` as a modal overlay from a controlled `open` prop.
|
|
4
|
+
* Shared by Modal, Dialog, and Drawer so their behavior cannot drift.
|
|
5
|
+
*
|
|
6
|
+
* `showModal()` gives the platform guarantees a hand-rolled overlay cannot:
|
|
7
|
+
* the rest of the page becomes inert, the dialog renders in the top layer
|
|
8
|
+
* (no portal, immune to transformed ancestors), only the topmost dialog
|
|
9
|
+
* receives Escape, and focus returns to the opener when it closes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useModalDialog(ref: React.RefObject<HTMLDialogElement | null>, open: boolean, onClose: () => void): void;
|
|
12
|
+
/**
|
|
13
|
+
* The platform returns focus to the opener only if focus is still inside the
|
|
14
|
+
* dialog when it closes. The panel content may already have unmounted (focus
|
|
15
|
+
* fell to <body>), so restore explicitly unless focus has moved on elsewhere.
|
|
16
|
+
*/
|
|
17
|
+
export declare function restoreFocus(dialog: HTMLElement, opener: HTMLElement | null): void;
|
|
18
|
+
/** Close when the press lands on the dialog's own box (the scrim), not its panel. */
|
|
19
|
+
export declare function closeOnScrim(onClose: () => void): (e: React.MouseEvent<HTMLDialogElement>) => void;
|
|
20
|
+
//# sourceMappingURL=useModalDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModalDialog.d.ts","sourceRoot":"","sources":["../src/useModalDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,EAC9C,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,IAAI,GAClB,IAAI,CA6CN;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAIlF;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,IAAI,IACtC,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,UAO/C"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Drives a native `<dialog>` as a modal overlay from a controlled `open` prop.
|
|
4
|
+
* Shared by Modal, Dialog, and Drawer so their behavior cannot drift.
|
|
5
|
+
*
|
|
6
|
+
* `showModal()` gives the platform guarantees a hand-rolled overlay cannot:
|
|
7
|
+
* the rest of the page becomes inert, the dialog renders in the top layer
|
|
8
|
+
* (no portal, immune to transformed ancestors), only the topmost dialog
|
|
9
|
+
* receives Escape, and focus returns to the opener when it closes.
|
|
10
|
+
*/
|
|
11
|
+
export function useModalDialog(ref, open, onClose) {
|
|
12
|
+
// Read the latest callback without re-running the effects below, so an
|
|
13
|
+
// inline `onClose={() => setOpen(false)}` never closes and reopens the dialog.
|
|
14
|
+
const onCloseRef = React.useRef(onClose);
|
|
15
|
+
const openRef = React.useRef(open);
|
|
16
|
+
React.useLayoutEffect(() => {
|
|
17
|
+
onCloseRef.current = onClose;
|
|
18
|
+
openRef.current = open;
|
|
19
|
+
});
|
|
20
|
+
const openerRef = React.useRef(null);
|
|
21
|
+
React.useEffect(() => {
|
|
22
|
+
const dialog = ref.current;
|
|
23
|
+
if (!dialog)
|
|
24
|
+
return;
|
|
25
|
+
if (open && !dialog.open) {
|
|
26
|
+
openerRef.current = document.activeElement;
|
|
27
|
+
dialog.showModal();
|
|
28
|
+
}
|
|
29
|
+
else if (!open && dialog.open) {
|
|
30
|
+
dialog.close();
|
|
31
|
+
restoreFocus(dialog, openerRef.current);
|
|
32
|
+
}
|
|
33
|
+
}, [ref, open]);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
const dialog = ref.current;
|
|
36
|
+
if (!dialog)
|
|
37
|
+
return;
|
|
38
|
+
// Escape fires `cancel`; keep the dialog open until the owner says so.
|
|
39
|
+
function onCancel(e) {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
onCloseRef.current();
|
|
42
|
+
}
|
|
43
|
+
// The browser may still close the dialog itself (repeated Escape without
|
|
44
|
+
// user activation); report it so the controlled `open` state follows.
|
|
45
|
+
function onNativeClose() {
|
|
46
|
+
if (openRef.current)
|
|
47
|
+
onCloseRef.current();
|
|
48
|
+
}
|
|
49
|
+
dialog.addEventListener("cancel", onCancel);
|
|
50
|
+
dialog.addEventListener("close", onNativeClose);
|
|
51
|
+
return () => {
|
|
52
|
+
dialog.removeEventListener("cancel", onCancel);
|
|
53
|
+
dialog.removeEventListener("close", onNativeClose);
|
|
54
|
+
if (dialog.open)
|
|
55
|
+
dialog.close();
|
|
56
|
+
};
|
|
57
|
+
}, [ref]);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The platform returns focus to the opener only if focus is still inside the
|
|
61
|
+
* dialog when it closes. The panel content may already have unmounted (focus
|
|
62
|
+
* fell to <body>), so restore explicitly unless focus has moved on elsewhere.
|
|
63
|
+
*/
|
|
64
|
+
export function restoreFocus(dialog, opener) {
|
|
65
|
+
const active = document.activeElement;
|
|
66
|
+
const lost = !active || active === document.body || dialog.contains(active);
|
|
67
|
+
if (lost && opener?.isConnected)
|
|
68
|
+
opener.focus();
|
|
69
|
+
}
|
|
70
|
+
/** Close when the press lands on the dialog's own box (the scrim), not its panel. */
|
|
71
|
+
export function closeOnScrim(onClose) {
|
|
72
|
+
return (e) => {
|
|
73
|
+
if (e.target !== e.currentTarget)
|
|
74
|
+
return;
|
|
75
|
+
// The press would otherwise move focus to the (now hidden) dialog after it
|
|
76
|
+
// closes, undoing the return of focus to the opener.
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
onClose();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=useModalDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModalDialog.js","sourceRoot":"","sources":["../src/useModalDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,GAA8C,EAC9C,IAAa,EACb,OAAmB;IAEnB,uEAAuE;IACvE,+EAA+E;IAC/E,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,C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