@hyperpackai/hyperui 0.2.0 → 0.3.0
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/README.md +13 -0
- package/dist/components/Accordion/index.d.ts +6 -0
- package/dist/components/Accordion/index.d.ts.map +1 -1
- package/dist/components/Accordion/index.js +65 -9
- package/dist/components/Autocomplete/index.d.ts +12 -2
- package/dist/components/Autocomplete/index.d.ts.map +1 -1
- package/dist/components/Autocomplete/index.js +148 -24
- package/dist/components/Backdrop/index.d.ts +2 -1
- package/dist/components/Backdrop/index.d.ts.map +1 -1
- package/dist/components/Backdrop/index.js +6 -3
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Checkbox/index.d.ts.map +1 -1
- package/dist/components/Checkbox/index.js +6 -2
- package/dist/components/DashboardLayout/index.d.ts +13 -0
- package/dist/components/DashboardLayout/index.d.ts.map +1 -1
- package/dist/components/DashboardLayout/index.js +50 -7
- package/dist/components/DataTable/index.d.ts +43 -0
- package/dist/components/DataTable/index.d.ts.map +1 -1
- package/dist/components/DataTable/index.js +126 -21
- package/dist/components/Dialog/index.d.ts +9 -3
- package/dist/components/Dialog/index.d.ts.map +1 -1
- package/dist/components/Dialog/index.js +46 -30
- package/dist/components/Drawer/index.d.ts +11 -3
- package/dist/components/Drawer/index.d.ts.map +1 -1
- package/dist/components/Drawer/index.js +66 -11
- package/dist/components/DropdownMenu/index.d.ts +5 -3
- package/dist/components/DropdownMenu/index.d.ts.map +1 -1
- package/dist/components/DropdownMenu/index.js +56 -13
- package/dist/components/FocusTrap/index.d.ts.map +1 -1
- package/dist/components/FocusTrap/index.js +34 -32
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/Input/index.d.ts.map +1 -1
- package/dist/components/Input/index.js +18 -4
- package/dist/components/Menu/index.d.ts +6 -2
- package/dist/components/Menu/index.d.ts.map +1 -1
- package/dist/components/Menu/index.js +50 -15
- package/dist/components/Modal/index.d.ts +3 -1
- package/dist/components/Modal/index.d.ts.map +1 -1
- package/dist/components/Modal/index.js +27 -9
- package/dist/components/NestedNavbar/index.d.ts +33 -0
- package/dist/components/NestedNavbar/index.d.ts.map +1 -0
- package/dist/components/NestedNavbar/index.js +435 -0
- package/dist/components/NestedSidebar/index.d.ts +48 -0
- package/dist/components/NestedSidebar/index.d.ts.map +1 -0
- package/dist/components/NestedSidebar/index.js +368 -0
- package/dist/components/Popover/index.d.ts +11 -3
- package/dist/components/Popover/index.d.ts.map +1 -1
- package/dist/components/Popover/index.js +45 -9
- package/dist/components/Radio/index.d.ts +26 -1
- package/dist/components/Radio/index.d.ts.map +1 -1
- package/dist/components/Radio/index.js +61 -2
- package/dist/components/Select/index.d.ts +5 -0
- package/dist/components/Select/index.d.ts.map +1 -1
- package/dist/components/Select/index.js +22 -5
- package/dist/components/Sheet/index.d.ts +9 -3
- package/dist/components/Sheet/index.d.ts.map +1 -1
- package/dist/components/Sheet/index.js +48 -23
- package/dist/components/Sidebar/index.d.ts +20 -1
- package/dist/components/Sidebar/index.d.ts.map +1 -1
- package/dist/components/Sidebar/index.js +285 -8
- package/dist/components/SpeedDial/index.d.ts +10 -0
- package/dist/components/SpeedDial/index.d.ts.map +1 -1
- package/dist/components/SpeedDial/index.js +61 -11
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.d.ts.map +1 -1
- package/dist/components/Switch/index.js +6 -2
- package/dist/components/Tabs/index.d.ts +3 -0
- package/dist/components/Tabs/index.d.ts.map +1 -1
- package/dist/components/Tabs/index.js +47 -8
- package/dist/components/TextField/index.d.ts +2 -0
- package/dist/components/TextField/index.d.ts.map +1 -1
- package/dist/components/TextField/index.js +12 -4
- package/dist/components/Textarea/index.d.ts +5 -0
- package/dist/components/Textarea/index.d.ts.map +1 -1
- package/dist/components/Textarea/index.js +21 -4
- package/dist/components/Transition/index.d.ts +14 -0
- package/dist/components/Transition/index.d.ts.map +1 -0
- package/dist/components/Transition/index.js +49 -0
- package/dist/components/TransitionGroup/index.d.ts +16 -0
- package/dist/components/TransitionGroup/index.d.ts.map +1 -0
- package/dist/components/TransitionGroup/index.js +95 -0
- package/dist/components/data.d.ts +81 -16
- package/dist/components/data.d.ts.map +1 -1
- package/dist/components/data.js +163 -31
- package/dist/components/enterprise.d.ts +85 -26
- package/dist/components/enterprise.d.ts.map +1 -1
- package/dist/components/enterprise.js +211 -36
- package/dist/components/index.d.ts +21 -13
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +7 -2
- package/dist/portal.d.ts.map +1 -1
- package/dist/portal.js +3 -0
- package/dist/theme/index.d.ts +5 -6
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +30 -0
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +11 -0
- package/package.json +6 -1
|
@@ -13,50 +13,51 @@ export function FocusTrap(props) {
|
|
|
13
13
|
const active = props.active ?? true;
|
|
14
14
|
const restoreFocus = props.restoreFocus ?? true;
|
|
15
15
|
const autoFocus = props.autoFocus ?? true;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const onKeyDown = (event) => {
|
|
17
|
+
if (!active)
|
|
18
|
+
return;
|
|
19
|
+
if (event.key === "Escape") {
|
|
20
|
+
props.onEscape?.();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!root || event.key !== "Tab")
|
|
24
|
+
return;
|
|
18
25
|
const getFocusable = () => root
|
|
19
26
|
? Array.from(root.querySelectorAll(FOCUSABLE_SELECTOR))
|
|
20
27
|
.filter((node) => !node.hasAttribute("disabled") && node.getAttribute("aria-hidden") !== "true")
|
|
21
28
|
: [];
|
|
29
|
+
const nodes = getFocusable();
|
|
30
|
+
if (nodes.length === 0) {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
root.focus();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const first = nodes[0];
|
|
36
|
+
const last = nodes[nodes.length - 1];
|
|
37
|
+
const current = document.activeElement;
|
|
38
|
+
if (event.shiftKey && current === first) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
last.focus();
|
|
41
|
+
}
|
|
42
|
+
else if (!event.shiftKey && current === last) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
first.focus();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
if (typeof document !== "undefined" && typeof HTMLElement !== "undefined" && active) {
|
|
48
|
+
const previouslyFocused = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
22
49
|
const focusFirst = () => {
|
|
23
|
-
const nodes =
|
|
50
|
+
const nodes = root
|
|
51
|
+
? Array.from(root.querySelectorAll(FOCUSABLE_SELECTOR))
|
|
52
|
+
.filter((node) => !node.hasAttribute("disabled") && node.getAttribute("aria-hidden") !== "true")
|
|
53
|
+
: [];
|
|
24
54
|
(nodes[0] ?? root)?.focus();
|
|
25
55
|
};
|
|
26
|
-
const onKeyDown = (event) => {
|
|
27
|
-
if (!root)
|
|
28
|
-
return;
|
|
29
|
-
if (event.key === "Escape") {
|
|
30
|
-
props.onEscape?.();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (event.key !== "Tab")
|
|
34
|
-
return;
|
|
35
|
-
const nodes = getFocusable();
|
|
36
|
-
if (nodes.length === 0) {
|
|
37
|
-
event.preventDefault();
|
|
38
|
-
root.focus();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const first = nodes[0];
|
|
42
|
-
const last = nodes[nodes.length - 1];
|
|
43
|
-
const current = document.activeElement;
|
|
44
|
-
if (event.shiftKey && current === first) {
|
|
45
|
-
event.preventDefault();
|
|
46
|
-
last.focus();
|
|
47
|
-
}
|
|
48
|
-
else if (!event.shiftKey && current === last) {
|
|
49
|
-
event.preventDefault();
|
|
50
|
-
first.focus();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
56
|
onMount(() => {
|
|
54
|
-
root?.addEventListener("keydown", onKeyDown);
|
|
55
57
|
if (autoFocus)
|
|
56
58
|
queueMicrotask(focusFirst);
|
|
57
59
|
});
|
|
58
60
|
onCleanup(() => {
|
|
59
|
-
root?.removeEventListener("keydown", onKeyDown);
|
|
60
61
|
if (restoreFocus && previouslyFocused?.isConnected)
|
|
61
62
|
previouslyFocused.focus();
|
|
62
63
|
});
|
|
@@ -64,6 +65,7 @@ export function FocusTrap(props) {
|
|
|
64
65
|
return h("div", {
|
|
65
66
|
class: props.class,
|
|
66
67
|
tabindex: "-1",
|
|
68
|
+
onKeyDown,
|
|
67
69
|
ref: (node) => { root = node; }
|
|
68
70
|
}, props.children);
|
|
69
71
|
}
|
|
@@ -20,11 +20,13 @@ export interface InputProps {
|
|
|
20
20
|
minLength?: number;
|
|
21
21
|
class?: string;
|
|
22
22
|
"aria-label"?: string;
|
|
23
|
+
"aria-describedby"?: string;
|
|
23
24
|
"aria-controls"?: string;
|
|
24
25
|
"aria-expanded"?: string | boolean;
|
|
25
26
|
"aria-activedescendant"?: string;
|
|
26
27
|
onInput?: (e: InputEvent) => void;
|
|
27
28
|
onChange?: (e: Event) => void;
|
|
29
|
+
onValueChange?: (value: string, e: Event) => void;
|
|
28
30
|
onBlur?: (e: FocusEvent) => void;
|
|
29
31
|
onFocus?: (e: FocusEvent) => void;
|
|
30
32
|
onKeyDown?: (e: KeyboardEvent) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Input/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAqCpE,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACn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AAK,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CA4C9C"}
|
|
@@ -33,13 +33,27 @@ const INPUT_CSS = `
|
|
|
33
33
|
.hu-input-helper { font-size: var(--hu-font-size-xs); color: var(--hu-text-2); line-height: 1.45; }
|
|
34
34
|
.hu-input-error-msg { font-size: var(--hu-font-size-xs); color: var(--hu-error); line-height: 1.45; }
|
|
35
35
|
`;
|
|
36
|
+
let inputId = 0;
|
|
36
37
|
export function Input(props) {
|
|
37
38
|
injectCSS("hu-input", INPUT_CSS);
|
|
38
|
-
const { type = "text", size = "md", error, helper, label, prefix, suffix,
|
|
39
|
+
const { type = "text", size = "md", error, helper, label, prefix, suffix, onInput, onValueChange, class: className, ...rest } = props;
|
|
40
|
+
const id = props.id ?? (label || helper || error ? `hu-input-${++inputId}` : undefined);
|
|
41
|
+
const helperId = helper && !error ? `${id}-helper` : undefined;
|
|
42
|
+
const errorId = error ? `${id}-error` : undefined;
|
|
43
|
+
const describedBy = [props["aria-describedby"], errorId, helperId].filter(Boolean).join(" ") || undefined;
|
|
44
|
+
const handleInput = (event) => {
|
|
45
|
+
onInput?.(event);
|
|
46
|
+
onValueChange?.(event.target.value, event);
|
|
47
|
+
};
|
|
39
48
|
const inputEl = h("input", {
|
|
40
|
-
...rest,
|
|
41
|
-
|
|
49
|
+
...rest,
|
|
50
|
+
type,
|
|
51
|
+
id,
|
|
52
|
+
onInput: handleInput,
|
|
53
|
+
"aria-invalid": error ? "true" : undefined,
|
|
54
|
+
"aria-describedby": describedBy,
|
|
55
|
+
class: cn("hu-input", size !== "md" && `hu-input--${size}`, error && "hu-input--error", Boolean(prefix) && "hu-input--has-prefix", Boolean(suffix) && "hu-input--has-suffix", className)
|
|
42
56
|
});
|
|
43
57
|
const field = h("div", { class: "hu-input-field" }, prefix && h("span", { class: "hu-input-prefix" }, prefix), inputEl, suffix && h("span", { class: "hu-input-suffix" }, suffix));
|
|
44
|
-
return h("div", { class: "hu-input-wrap" }, label && Label({ for: id, required: props.required, children: label }), field, error && h("span", { class: "hu-input-error-msg", role: "alert" }, error), !error && helper && h("span", { class: "hu-input-helper" }, helper));
|
|
58
|
+
return h("div", { class: "hu-input-wrap" }, label && Label({ for: id, required: props.required, children: label }), field, error && h("span", { id: errorId, class: "hu-input-error-msg", role: "alert" }, error), !error && helper && h("span", { id: helperId, class: "hu-input-helper" }, helper));
|
|
45
59
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { type Signal } from "@hyperpackai/hyperion";
|
|
1
2
|
import { type VNode } from "../../theme/index.js";
|
|
2
3
|
export type MenuPlacement = "bottom-left" | "bottom-right" | "top-left" | "top-right";
|
|
4
|
+
export type MenuCloseReason = "blur" | "escape" | "item-select" | "programmatic" | "trigger";
|
|
3
5
|
export interface MenuItemDef {
|
|
4
6
|
label: string;
|
|
5
7
|
icon?: unknown;
|
|
@@ -16,8 +18,10 @@ export interface MenuProps {
|
|
|
16
18
|
items: MenuItemDef[];
|
|
17
19
|
placement?: MenuPlacement;
|
|
18
20
|
trigger: unknown;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
open?: boolean | Signal<boolean>;
|
|
22
|
+
defaultOpen?: boolean;
|
|
23
|
+
onOpenChange?: (open: boolean, reason?: MenuCloseReason) => void;
|
|
24
|
+
onClose?: (reason?: MenuCloseReason) => void;
|
|
21
25
|
class?: string;
|
|
22
26
|
}
|
|
23
27
|
export declare function Menu(props: MenuProps): VNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Menu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAiDpE,MAAM,MAAM,aAAa,GAAG,aAAa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pD;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AACD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,CAUpD"}
|
|
@@ -49,33 +49,65 @@ const CSS = `
|
|
|
49
49
|
export function Menu(props) {
|
|
50
50
|
injectCSS("hu-menu", CSS);
|
|
51
51
|
const { items, placement = "bottom-left", trigger } = props;
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const internalOpen = signal(props.defaultOpen ?? false);
|
|
53
|
+
const signalOpen = getSignalProp(props.open);
|
|
54
|
+
const isControlled = typeof props.open === "boolean" || !!signalOpen;
|
|
55
|
+
const isOpen = () => signalOpen ? signalOpen.value : typeof props.open === "boolean" ? props.open : internalOpen.value;
|
|
56
|
+
const setOpen = (next, reason = "programmatic") => {
|
|
57
|
+
if (signalOpen)
|
|
58
|
+
signalOpen.value = next;
|
|
59
|
+
else if (!isControlled)
|
|
60
|
+
internalOpen.value = next;
|
|
61
|
+
props.onOpenChange?.(next, reason);
|
|
56
62
|
if (!next)
|
|
57
|
-
props.onClose?.();
|
|
63
|
+
props.onClose?.(reason);
|
|
58
64
|
};
|
|
59
|
-
const close = () => setOpen(false);
|
|
60
|
-
const toggle = () => setOpen(!isOpen
|
|
61
|
-
const
|
|
65
|
+
const close = (reason = "programmatic") => setOpen(false, reason);
|
|
66
|
+
const toggle = () => setOpen(!isOpen(), "trigger");
|
|
67
|
+
const handleMenuKeyDown = (e) => {
|
|
68
|
+
if (e.key === "Escape") {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
close("escape");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(e.key))
|
|
74
|
+
return;
|
|
75
|
+
const menu = e.currentTarget;
|
|
76
|
+
const items = Array.from(menu.querySelectorAll('[role="menuitem"]:not(:disabled)'));
|
|
77
|
+
if (!items.length)
|
|
78
|
+
return;
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
const activeIndex = items.indexOf((typeof document !== "undefined" ? document.activeElement : null));
|
|
81
|
+
const lastIndex = items.length - 1;
|
|
82
|
+
if (e.key === "Home") {
|
|
83
|
+
items[0]?.focus();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (e.key === "End") {
|
|
87
|
+
items[lastIndex]?.focus();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const delta = e.key === "ArrowDown" ? 1 : -1;
|
|
91
|
+
const nextIndex = activeIndex === -1
|
|
92
|
+
? (delta === 1 ? 0 : lastIndex)
|
|
93
|
+
: (activeIndex + delta + items.length) % items.length;
|
|
94
|
+
items[nextIndex]?.focus();
|
|
95
|
+
};
|
|
96
|
+
const renderMenu = () => isOpen()
|
|
62
97
|
? h("div", {
|
|
63
98
|
class: cn("hu-menu", `hu-menu--${placement}`),
|
|
64
99
|
role: "menu",
|
|
65
100
|
tabindex: "-1",
|
|
66
|
-
onKeyDown:
|
|
67
|
-
if (e.key === "Escape")
|
|
68
|
-
close();
|
|
69
|
-
}
|
|
101
|
+
onKeyDown: handleMenuKeyDown
|
|
70
102
|
}, ...items.map(item => renderMenuItem(item, close)))
|
|
71
103
|
: null;
|
|
72
104
|
return h("div", {
|
|
73
105
|
class: cn("hu-menu-root", props.class),
|
|
74
106
|
onBlur: (e) => {
|
|
75
107
|
if (!e.currentTarget.contains(e.relatedTarget))
|
|
76
|
-
close();
|
|
108
|
+
close("blur");
|
|
77
109
|
}
|
|
78
|
-
}, h("div", { onClick: toggle, style: "display:contents;" }, trigger), renderMenu);
|
|
110
|
+
}, h("div", { onClick: toggle, style: "display:contents;" }, trigger), typeof props.open === "boolean" ? renderMenu() : renderMenu);
|
|
79
111
|
}
|
|
80
112
|
function renderMenuItem(item, close) {
|
|
81
113
|
if (item.type === "divider")
|
|
@@ -86,10 +118,13 @@ function renderMenuItem(item, close) {
|
|
|
86
118
|
class: cn("hu-menu-item", item.selected && "hu-menu-item--selected", item.disabled && "hu-menu-item--disabled", item.destructive && "hu-menu-item--destructive"),
|
|
87
119
|
role: "menuitem",
|
|
88
120
|
disabled: item.disabled,
|
|
89
|
-
onClick:
|
|
121
|
+
onClick: () => { item.onClick?.(); close("item-select"); },
|
|
90
122
|
tabindex: "-1"
|
|
91
123
|
}, item.icon && h("span", { class: "hu-menu-item__icon" }, item.icon), h("span", { class: "hu-menu-item__label" }, item.label), item.shortcut && h("span", { class: "hu-menu-item__shortcut" }, item.shortcut), item.children && h("span", { class: "hu-menu-item__arrow" }, "›"));
|
|
92
124
|
}
|
|
125
|
+
function getSignalProp(value) {
|
|
126
|
+
return typeof value === "object" && value != null && "peek" in value ? value : undefined;
|
|
127
|
+
}
|
|
93
128
|
export function MenuList(props) {
|
|
94
129
|
injectCSS("hu-menu", CSS);
|
|
95
130
|
return h("ul", { class: cn("hu-menu", "hu-menu--static", props.class), role: "menu" }, props.children);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { type Signal } from "@hyperpackai/hyperion";
|
|
1
2
|
import { type VNode } from "../../theme/index.js";
|
|
2
3
|
export interface ModalProps {
|
|
3
|
-
open
|
|
4
|
+
open?: boolean | Signal<boolean>;
|
|
5
|
+
defaultOpen?: boolean;
|
|
4
6
|
onClose?: (reason?: "backdrop" | "escape") => void;
|
|
5
7
|
onOpenChange?: (open: boolean, reason?: "backdrop" | "escape") => void;
|
|
6
8
|
align?: "center" | "top" | "bottom";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAyBpE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAyBpE,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,QAAQ,KAAK,IAAI,CAAC;IACnD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,QAAQ,KAAK,IAAI,CAAC;IACvE,KAAK,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;IACpC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,GAAG,IAAI,CA8CrD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { signal } from "@hyperpackai/hyperion";
|
|
1
2
|
import { injectCSS, cn, h } from "../../theme/index.js";
|
|
2
3
|
import { renderInPortal } from "../../portal.js";
|
|
3
4
|
import { FocusTrap } from "../FocusTrap/index.js";
|
|
@@ -23,29 +24,46 @@ const CSS = `
|
|
|
23
24
|
`;
|
|
24
25
|
export function Modal(props) {
|
|
25
26
|
injectCSS("hu-modal", CSS);
|
|
26
|
-
const {
|
|
27
|
+
const { onClose, onOpenChange, align = "center", disableBackdropClick } = props;
|
|
28
|
+
const uncontrolledOpen = signal(props.defaultOpen ?? false);
|
|
29
|
+
const isSignalOpen = typeof props.open === "object" && props.open != null && "peek" in props.open;
|
|
30
|
+
const isControlled = typeof props.open === "boolean" || isSignalOpen;
|
|
31
|
+
const isOpen = () => {
|
|
32
|
+
if (typeof props.open === "boolean")
|
|
33
|
+
return props.open;
|
|
34
|
+
if (isSignalOpen)
|
|
35
|
+
return props.open.value;
|
|
36
|
+
return uncontrolledOpen.value;
|
|
37
|
+
};
|
|
27
38
|
const close = (reason) => {
|
|
39
|
+
if (!isControlled)
|
|
40
|
+
uncontrolledOpen.value = false;
|
|
41
|
+
if (isSignalOpen)
|
|
42
|
+
props.open.value = false;
|
|
28
43
|
onOpenChange?.(false, reason);
|
|
29
44
|
onClose?.(reason);
|
|
30
45
|
};
|
|
31
|
-
|
|
32
|
-
return null;
|
|
33
|
-
if (!open)
|
|
34
|
-
return h("div", { style: "display:none", "aria-hidden": "true" }, props.children);
|
|
35
|
-
return renderInPortal(h("div", {
|
|
46
|
+
const renderModal = () => renderInPortal(h("div", {
|
|
36
47
|
class: cn("hu-modal", align !== "center" && `hu-modal--align-${align}`, props.class),
|
|
37
48
|
role: "dialog",
|
|
38
49
|
"aria-modal": "true",
|
|
39
|
-
|
|
50
|
+
onKeyDown: !props.disableEscapeKey ? (e) => { if (e.key === "Escape")
|
|
40
51
|
close("escape"); } : undefined
|
|
41
52
|
}, h("div", {
|
|
42
53
|
class: "hu-modal__backdrop",
|
|
43
|
-
onClick: !disableBackdropClick
|
|
54
|
+
onClick: !disableBackdropClick ? () => close("backdrop") : undefined
|
|
44
55
|
}), FocusTrap({
|
|
45
56
|
active: true,
|
|
46
57
|
restoreFocus: true,
|
|
47
58
|
autoFocus: true,
|
|
48
|
-
onEscape: !props.disableEscapeKey
|
|
59
|
+
onEscape: !props.disableEscapeKey ? () => close("escape") : undefined,
|
|
49
60
|
children: h("div", { class: "hu-modal__content", tabindex: "-1" }, props.children)
|
|
50
61
|
})), "modal");
|
|
62
|
+
const renderClosed = () => props.keepMounted
|
|
63
|
+
? h("div", { style: "display:none", "aria-hidden": "true" }, props.children)
|
|
64
|
+
: null;
|
|
65
|
+
if (isControlled && typeof props.open === "boolean") {
|
|
66
|
+
return isOpen() ? renderModal() : renderClosed();
|
|
67
|
+
}
|
|
68
|
+
return (() => isOpen() ? renderModal() : renderClosed());
|
|
51
69
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type VNode } from "../../theme/index.js";
|
|
2
|
+
export interface NavChildItem {
|
|
3
|
+
id?: string;
|
|
4
|
+
label: string;
|
|
5
|
+
href: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
icon?: unknown;
|
|
8
|
+
active?: boolean | (() => boolean);
|
|
9
|
+
onClick?: (event: Event) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface NestedNavItem {
|
|
12
|
+
id?: string;
|
|
13
|
+
label: string;
|
|
14
|
+
href?: string;
|
|
15
|
+
active?: boolean | (() => boolean);
|
|
16
|
+
icon?: unknown;
|
|
17
|
+
children?: NavChildItem[];
|
|
18
|
+
onClick?: (event: Event) => void;
|
|
19
|
+
}
|
|
20
|
+
export type NavbarMobileVariant = "drawer" | "bottom-sheet";
|
|
21
|
+
export interface NestedNavbarProps {
|
|
22
|
+
id?: string;
|
|
23
|
+
brand?: unknown;
|
|
24
|
+
brandHref?: string;
|
|
25
|
+
onBrandClick?: (event: Event) => void;
|
|
26
|
+
items?: NestedNavItem[];
|
|
27
|
+
actions?: unknown;
|
|
28
|
+
mobileVariant?: NavbarMobileVariant;
|
|
29
|
+
mobileTitle?: string;
|
|
30
|
+
class?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function NestedNavbar(props: NestedNavbarProps): VNode;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/NestedNavbar/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAkNpE,MAAM,WAAW,YAAY;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAMD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE5D,MAAM,WAAW,iBAAiB;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,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