@hebium-ui/preact 0.1.0-alpha.2 → 0.1.0-alpha.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/components/alert/alert.d.ts +3 -6
- package/dist/components/alert/alert.js +7 -15
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/anchor/anchor.d.ts +1 -4
- package/dist/components/anchor/anchor.js +5 -6
- package/dist/components/anchor/anchor.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +7 -6
- package/dist/components/avatar/avatar.js +16 -19
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/blockquote/blockquote.d.ts +2 -5
- package/dist/components/blockquote/blockquote.js +5 -6
- package/dist/components/blockquote/blockquote.js.map +1 -1
- package/dist/components/button/button.d.ts +12 -4
- package/dist/components/button/button.js +31 -12
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/checkbox/checkbox.d.ts +31 -0
- package/dist/components/checkbox/checkbox.js +84 -0
- package/dist/components/checkbox/checkbox.js.map +1 -0
- package/dist/components/checkbox/index.d.ts +2 -0
- package/dist/components/code/code.d.ts +8 -0
- package/dist/components/code/code.js +20 -0
- package/dist/components/code/code.js.map +1 -0
- package/dist/components/code/index.d.ts +2 -0
- package/dist/components/details/details.d.ts +19 -0
- package/dist/components/details/details.js +27 -0
- package/dist/components/details/details.js.map +1 -0
- package/dist/components/details/index.d.ts +2 -0
- package/dist/components/dialog/dialog.context.js +15 -0
- package/dist/components/dialog/dialog.context.js.map +1 -0
- package/dist/components/dialog/dialog.d.ts +64 -0
- package/dist/components/dialog/dialog.js +144 -0
- package/dist/components/dialog/dialog.js.map +1 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dl/dl.d.ts +15 -0
- package/dist/components/dl/dl.js +47 -0
- package/dist/components/dl/dl.js.map +1 -0
- package/dist/components/dl/index.d.ts +2 -0
- package/dist/components/drawer/drawer.context.js +15 -0
- package/dist/components/drawer/drawer.context.js.map +1 -0
- package/dist/components/drawer/drawer.d.ts +64 -0
- package/dist/components/drawer/drawer.js +124 -0
- package/dist/components/drawer/drawer.js.map +1 -0
- package/dist/components/drawer/index.d.ts +2 -0
- package/dist/components/heading/heading.d.ts +21 -0
- package/dist/components/heading/heading.js +23 -0
- package/dist/components/heading/heading.js.map +1 -0
- package/dist/components/heading/index.d.ts +2 -0
- package/dist/components/index.d.ts +17 -1
- package/dist/components/progress/progress.d.ts +1 -4
- package/dist/components/progress/progress.js +5 -6
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/status-icon/index.d.ts +2 -0
- package/dist/components/status-icon/status-icon.d.ts +19 -0
- package/dist/components/status-icon/status-icon.js +22 -0
- package/dist/components/status-icon/status-icon.js.map +1 -0
- package/dist/components/tabs/tabs.context.d.ts +1 -4
- package/dist/components/tabs/tabs.context.js +1 -2
- package/dist/components/tabs/tabs.d.ts +2 -5
- package/dist/components/tabs/tabs.js +18 -18
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +10 -2
- package/dist/provider/hui-provider.context.d.ts +42 -9
- package/dist/provider/hui-provider.context.js +31 -18
- package/dist/provider/hui-provider.context.js.map +1 -1
- package/dist/provider/hui-provider.d.ts +1 -4
- package/dist/provider/hui-provider.js +1 -2
- package/dist/provider/index.d.ts +2 -2
- package/dist/provider/merge-props.js +1 -2
- package/dist/types/hui-component.d.ts +15 -9
- package/dist/types/index.d.ts +2 -2
- package/dist/types/polymorphic.d.ts +7 -11
- package/dist/utils/unwrap-signalish.js +10 -0
- package/dist/utils/unwrap-signalish.js.map +1 -0
- package/package.json +12 -11
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { DetailsSlots, DetailsVariants } from "@hebium-ui/core";
|
|
4
|
+
import { ComponentChildren, ComponentProps, VNode } from "preact";
|
|
5
|
+
interface DetailsOwnProps {
|
|
6
|
+
/**
|
|
7
|
+
* The summary displayed in the disclosure button.
|
|
8
|
+
*/
|
|
9
|
+
summary: ComponentChildren;
|
|
10
|
+
/**
|
|
11
|
+
* The border style of the details container.
|
|
12
|
+
*
|
|
13
|
+
* @default "block"
|
|
14
|
+
*/
|
|
15
|
+
border?: DetailsVariants["border"] | undefined;
|
|
16
|
+
}
|
|
17
|
+
export type DetailsProps = HuiComponentProps<ComponentProps<"details"> & DetailsOwnProps, DetailsSlots>;
|
|
18
|
+
export declare function Details(rawProps: DetailsProps): VNode;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useHuiClasses, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { detailsRecipe } from "@hebium-ui/core";
|
|
3
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
4
|
+
// src/components/details/details.tsx
|
|
5
|
+
function Details(rawProps) {
|
|
6
|
+
const { summary, border, children, ...restProps } = useHuiProps("Details", rawProps);
|
|
7
|
+
const recipe = detailsRecipe({ border });
|
|
8
|
+
const cls = useHuiClasses("Details", recipe, rawProps);
|
|
9
|
+
const sls = useHuiStyles("Details", rawProps);
|
|
10
|
+
return /* @__PURE__ */ jsxs("details", {
|
|
11
|
+
className: cls.root,
|
|
12
|
+
style: sls.root,
|
|
13
|
+
...restProps,
|
|
14
|
+
children: [/* @__PURE__ */ jsx("summary", {
|
|
15
|
+
className: cls.summary,
|
|
16
|
+
style: sls.summary,
|
|
17
|
+
children: summary
|
|
18
|
+
}), children != null && /* @__PURE__ */ jsx("div", {
|
|
19
|
+
className: cls.content,
|
|
20
|
+
style: sls.content,
|
|
21
|
+
children
|
|
22
|
+
})]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export { Details };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=details.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"details.js","names":[],"sources":["../../../src/components/details/details.tsx"],"sourcesContent":["import { detailsRecipe, type DetailsSlots, type DetailsVariants } from \"@hebium-ui/core\";\nimport { type ComponentChildren, type ComponentProps, type VNode } from \"preact\";\nimport { useHuiClasses, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\n\ninterface DetailsOwnProps {\n /**\n * The summary displayed in the disclosure button.\n */\n summary: ComponentChildren;\n /**\n * The border style of the details container.\n *\n * @default \"block\"\n */\n border?: DetailsVariants[\"border\"] | undefined;\n}\n\nexport type DetailsProps = HuiComponentProps<\n ComponentProps<\"details\"> & DetailsOwnProps,\n DetailsSlots\n>;\n\nexport function Details(rawProps: DetailsProps): VNode {\n const {\n summary,\n border,\n children,\n ...restProps\n } = useHuiProps(\"Details\", rawProps);\n\n const recipe = detailsRecipe({ border });\n const cls = useHuiClasses(\"Details\", recipe, rawProps);\n const sls = useHuiStyles(\"Details\", rawProps);\n\n return (\n <details\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n <summary\n className={cls.summary}\n style={sls.summary}\n >\n {summary}\n </summary>\n {children != null && (\n <div\n className={cls.content}\n style={sls.content}\n >\n {children}\n </div>\n )}\n </details>\n );\n}\n"],"mappings":";;;;AAuBA,SAAgB,QAAQ,UAA+B;CACrD,MAAM,EACJ,SACA,QACA,UACA,GAAG,cACD,YAAY,WAAW,QAAQ;CAEnC,MAAM,SAAS,cAAc,EAAE,OAAO,CAAC;CACvC,MAAM,MAAM,cAAc,WAAW,QAAQ,QAAQ;CACrD,MAAM,MAAM,aAAa,WAAW,QAAQ;CAE5C,OACE,qBAAC,WAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EACX,GAAI;EAHN,UAAA,CAKE,oBAAC,WAAD;GACE,WAAW,IAAI;GACf,OAAO,IAAI;GAEV,UAAA;EACM,CAAA,GACR,YAAY,QACX,oBAAC,OAAD;GACE,WAAW,IAAI;GACf,OAAO,IAAI;GAEV;EACE,CAAA,CAEA;;AAEb"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useContext } from "preact/hooks";
|
|
2
|
+
import { createContext } from "preact";
|
|
3
|
+
// src/components/dialog/dialog.context.ts
|
|
4
|
+
const DialogContext = createContext(null);
|
|
5
|
+
function useDialogContext() {
|
|
6
|
+
const context = useContext(DialogContext);
|
|
7
|
+
if (!context) throw new Error("[Hebium UI] Dialog compound components must be used within <Dialog>");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
function useDialogId() {
|
|
11
|
+
return useDialogContext().dialogId;
|
|
12
|
+
}
|
|
13
|
+
export { DialogContext, useDialogContext, useDialogId };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=dialog.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.context.js","names":[],"sources":["../../../src/components/dialog/dialog.context.ts"],"sourcesContent":["import { createContext } from \"preact\";\nimport { useContext } from \"preact/hooks\";\n\nexport interface DialogContextValue {\n dialogId: string;\n modal: boolean;\n open: () => void;\n}\n\nexport const DialogContext = createContext<DialogContextValue | null>(null);\n\nexport function useDialogContext(): DialogContextValue {\n const context = useContext(DialogContext);\n if (!context) {\n throw new Error(\"[Hebium UI] Dialog compound components must be used within <Dialog>\");\n }\n return context;\n}\n\nexport function useDialogId(): string {\n return useDialogContext().dialogId;\n}\n"],"mappings":";;;AASA,MAAa,gBAAgB,cAAyC,IAAI;AAE1E,SAAgB,mBAAuC;CACrD,MAAM,UAAU,WAAW,aAAa;CACxC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,qEAAqE;CAEvF,OAAO;AACT;AAEA,SAAgB,cAAsB;CACpC,OAAO,iBAAiB,CAAC,CAAC;AAC5B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import { HuiPolymorphicProps } from "../../types/polymorphic.js";
|
|
3
|
+
import "../../types/index.js";
|
|
4
|
+
import { Button, ButtonProps } from "../button/button.js";
|
|
5
|
+
import "../button/index.js";
|
|
6
|
+
import { HeadingProps } from "../heading/heading.js";
|
|
7
|
+
import "../heading/index.js";
|
|
8
|
+
import { ButtonSlots, DialogSlots } from "@hebium-ui/core";
|
|
9
|
+
import { ComponentChildren, ComponentProps, JSX, VNode } from "preact";
|
|
10
|
+
export interface DialogProps {
|
|
11
|
+
/**
|
|
12
|
+
* The id of the dialog content element.
|
|
13
|
+
*/
|
|
14
|
+
id?: string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the dialog should open as a modal dialog.
|
|
17
|
+
*
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
modal?: boolean | undefined;
|
|
21
|
+
children?: ComponentChildren | undefined;
|
|
22
|
+
}
|
|
23
|
+
declare function DialogRoot(rawProps: DialogProps): VNode;
|
|
24
|
+
interface DialogTriggerOwnProps {}
|
|
25
|
+
export type DialogTriggerProps<E extends JSX.ElementType = typeof Button<"button">> = HuiPolymorphicProps<E, DialogTriggerOwnProps, ButtonSlots>;
|
|
26
|
+
declare function Trigger<E extends JSX.ElementType = typeof Button<"button">>(rawProps: DialogTriggerProps<E>): VNode;
|
|
27
|
+
interface DialogContentOwnProps {
|
|
28
|
+
/**
|
|
29
|
+
* The heading rendered at the top of the dialog content.
|
|
30
|
+
*/
|
|
31
|
+
heading?: ComponentChildren | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Additional props passed to the internal heading component.
|
|
34
|
+
*/
|
|
35
|
+
headingProps?: Omit<HeadingProps, "children" | "id" | "class" | "className" | "style"> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The content rendered inside the internal close button. Set to `null` or `false` to hide the button.
|
|
38
|
+
*
|
|
39
|
+
* @default close icon
|
|
40
|
+
*/
|
|
41
|
+
closeButton?: ComponentChildren | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Additional props passed to the internal close button.
|
|
44
|
+
*/
|
|
45
|
+
closeButtonProps?: Omit<DialogCloseProps, "children" | "classes" | "styles"> | undefined;
|
|
46
|
+
}
|
|
47
|
+
export type DialogContentProps = HuiComponentProps<Omit<ComponentProps<"dialog">, "id" | "open"> & DialogContentOwnProps, DialogSlots>;
|
|
48
|
+
declare function Content(rawProps: DialogContentProps): VNode;
|
|
49
|
+
interface DialogCloseOwnProps {
|
|
50
|
+
/**
|
|
51
|
+
* The command used to close the dialog.
|
|
52
|
+
*
|
|
53
|
+
* @default "request-close"
|
|
54
|
+
*/
|
|
55
|
+
command?: "close" | "request-close" | undefined;
|
|
56
|
+
}
|
|
57
|
+
export type DialogCloseProps = Omit<ButtonProps, "as" | keyof DialogCloseOwnProps> & DialogCloseOwnProps;
|
|
58
|
+
declare function Close(rawProps: DialogCloseProps): VNode;
|
|
59
|
+
export declare const Dialog: typeof DialogRoot & {
|
|
60
|
+
Trigger: typeof Trigger;
|
|
61
|
+
Content: typeof Content;
|
|
62
|
+
Close: typeof Close;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useHuiClasses, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { unwrapSignalish } from "../../utils/unwrap-signalish.js";
|
|
3
|
+
import { Button } from "../button/button.js";
|
|
4
|
+
import { Heading } from "../heading/heading.js";
|
|
5
|
+
import { DialogContext, useDialogContext, useDialogId } from "./dialog.context.js";
|
|
6
|
+
import { dialogControl, dialogRecipe, toStrbool } from "@hebium-ui/core";
|
|
7
|
+
import { useCallback, useId, useMemo } from "preact/hooks";
|
|
8
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
9
|
+
// src/components/dialog/dialog.tsx
|
|
10
|
+
const BUTTON_CLASSES = {
|
|
11
|
+
root: "",
|
|
12
|
+
content: "",
|
|
13
|
+
spinner: "",
|
|
14
|
+
status: ""
|
|
15
|
+
};
|
|
16
|
+
function DialogRoot(rawProps) {
|
|
17
|
+
const { id, modal = false, children } = useHuiProps("Dialog", rawProps);
|
|
18
|
+
const tmpId = useId();
|
|
19
|
+
const dialogId = id || tmpId;
|
|
20
|
+
const open = useCallback(() => {
|
|
21
|
+
dialogControl.openDialog(dialogId, modal);
|
|
22
|
+
}, [dialogId, modal]);
|
|
23
|
+
const contextValue = useMemo(() => ({
|
|
24
|
+
dialogId,
|
|
25
|
+
modal,
|
|
26
|
+
open
|
|
27
|
+
}), [
|
|
28
|
+
dialogId,
|
|
29
|
+
modal,
|
|
30
|
+
open
|
|
31
|
+
]);
|
|
32
|
+
return /* @__PURE__ */ jsx(DialogContext.Provider, {
|
|
33
|
+
value: contextValue,
|
|
34
|
+
children
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function Trigger(rawProps) {
|
|
38
|
+
const { as, children, onClick, ...restProps } = useHuiProps("DialogTrigger", rawProps);
|
|
39
|
+
const Component = as ?? Button;
|
|
40
|
+
const cls = useHuiClasses("DialogTrigger", BUTTON_CLASSES, rawProps);
|
|
41
|
+
const sls = useHuiStyles("DialogTrigger", rawProps);
|
|
42
|
+
const { dialogId, modal, open } = useDialogContext();
|
|
43
|
+
const attrs = dialogControl.getTriggerAttributes({ id: dialogId }, {
|
|
44
|
+
modal,
|
|
45
|
+
isButtonElement: as === void 0
|
|
46
|
+
});
|
|
47
|
+
const handleClick = useCallback((e) => {
|
|
48
|
+
onClick?.(e);
|
|
49
|
+
if (modal || e.defaultPrevented) return;
|
|
50
|
+
open();
|
|
51
|
+
}, [
|
|
52
|
+
modal,
|
|
53
|
+
onClick,
|
|
54
|
+
open
|
|
55
|
+
]);
|
|
56
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
57
|
+
...attrs,
|
|
58
|
+
...Component === Button ? {
|
|
59
|
+
classes: cls,
|
|
60
|
+
styles: sls
|
|
61
|
+
} : {
|
|
62
|
+
className: cls.root,
|
|
63
|
+
style: sls.root
|
|
64
|
+
},
|
|
65
|
+
onClick: handleClick,
|
|
66
|
+
...restProps,
|
|
67
|
+
children
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function Content(rawProps) {
|
|
71
|
+
const { children, heading, headingProps, closeButton, closeButtonProps, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...restProps } = useHuiProps("DialogContent", rawProps);
|
|
72
|
+
const { dialogId, modal } = useDialogContext();
|
|
73
|
+
const resolvedHeading = heading !== void 0 && heading !== null && heading !== false ? heading : void 0;
|
|
74
|
+
const state = { id: dialogId };
|
|
75
|
+
const attrs = dialogControl.getContentAttributes(state, {
|
|
76
|
+
hasHeading: resolvedHeading !== void 0,
|
|
77
|
+
ariaLabel: unwrapSignalish(ariaLabel),
|
|
78
|
+
ariaLabelledBy: unwrapSignalish(ariaLabelledBy)
|
|
79
|
+
});
|
|
80
|
+
const headingAttrs = dialogControl.getHeadingAttributes(state);
|
|
81
|
+
const headingId = resolvedHeading !== void 0 ? headingAttrs.id : void 0;
|
|
82
|
+
const headingLevel = headingProps?.level ?? 2;
|
|
83
|
+
const recipe = dialogRecipe({ modal: toStrbool(modal) });
|
|
84
|
+
const cls = useHuiClasses("DialogContent", recipe, rawProps);
|
|
85
|
+
const sls = useHuiStyles("DialogContent", rawProps);
|
|
86
|
+
const closeButtonClasses = useMemo(() => ({ root: cls.closeButton }), [cls.closeButton]);
|
|
87
|
+
const closeButtonStyles = useMemo(() => ({ root: sls.closeButton }), [sls.closeButton]);
|
|
88
|
+
const shouldRenderCloseButton = closeButton !== null && closeButton !== false;
|
|
89
|
+
const shouldRenderHeader = headingId !== void 0 || shouldRenderCloseButton;
|
|
90
|
+
const closeButtonContent = closeButton === void 0 ? /* @__PURE__ */ jsx("span", {
|
|
91
|
+
"aria-hidden": true,
|
|
92
|
+
className: cls.closeButtonIcon,
|
|
93
|
+
style: sls.closeButtonIcon
|
|
94
|
+
}) : closeButton;
|
|
95
|
+
return /* @__PURE__ */ jsxs("dialog", {
|
|
96
|
+
...attrs,
|
|
97
|
+
className: cls.root,
|
|
98
|
+
style: sls.root,
|
|
99
|
+
...restProps,
|
|
100
|
+
children: [shouldRenderHeader && /* @__PURE__ */ jsxs("div", {
|
|
101
|
+
className: cls.header,
|
|
102
|
+
style: sls.header,
|
|
103
|
+
children: [headingId && /* @__PURE__ */ jsx(Heading, {
|
|
104
|
+
margin: "none",
|
|
105
|
+
...headingProps,
|
|
106
|
+
...headingAttrs,
|
|
107
|
+
className: cls.heading,
|
|
108
|
+
style: sls.heading,
|
|
109
|
+
level: headingLevel,
|
|
110
|
+
children: resolvedHeading
|
|
111
|
+
}), shouldRenderCloseButton && /* @__PURE__ */ jsx(Close, {
|
|
112
|
+
classes: closeButtonClasses,
|
|
113
|
+
styles: closeButtonStyles,
|
|
114
|
+
"aria-label": "Close Dialog",
|
|
115
|
+
variant: "ghost",
|
|
116
|
+
color: "neutral",
|
|
117
|
+
shape: "square",
|
|
118
|
+
...closeButtonProps,
|
|
119
|
+
children: closeButtonContent
|
|
120
|
+
})]
|
|
121
|
+
}), children]
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function Close(rawProps) {
|
|
125
|
+
const props = useHuiProps("DialogClose", rawProps);
|
|
126
|
+
const cls = useHuiClasses("DialogClose", BUTTON_CLASSES, rawProps);
|
|
127
|
+
const sls = useHuiStyles("DialogClose", rawProps);
|
|
128
|
+
const dialogId = useDialogId();
|
|
129
|
+
const attrs = dialogControl.getCloseAttributes({ id: dialogId });
|
|
130
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
131
|
+
...attrs,
|
|
132
|
+
...props,
|
|
133
|
+
classes: cls,
|
|
134
|
+
styles: sls
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const Dialog = Object.assign(DialogRoot, {
|
|
138
|
+
Trigger,
|
|
139
|
+
Content,
|
|
140
|
+
Close
|
|
141
|
+
});
|
|
142
|
+
export { Dialog };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.js","names":[],"sources":["../../../src/components/dialog/dialog.tsx"],"sourcesContent":["import { type ButtonSlots, dialogControl, dialogRecipe, type DialogSlots, toStrbool } from \"@hebium-ui/core\";\nimport { type ComponentChildren, type ComponentProps, type JSX, type TargetedMouseEvent, type VNode } from \"preact\";\nimport { useCallback, useId, useMemo } from \"preact/hooks\";\nimport { useHuiClasses, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps, type HuiPolymorphicProps } from \"~/types\";\nimport { unwrapSignalish } from \"~/utils\";\nimport { Button, type ButtonProps } from \"../button\";\nimport { Heading, type HeadingProps } from \"../heading\";\nimport { DialogContext, type DialogContextValue, useDialogContext, useDialogId } from \"./dialog.context\";\n\nconst BUTTON_CLASSES = { root: \"\", content: \"\", spinner: \"\", status: \"\" } satisfies Record<ButtonSlots, string>;\n\nexport interface DialogProps {\n /**\n * The id of the dialog content element.\n */\n id?: string | undefined;\n /**\n * Whether the dialog should open as a modal dialog.\n *\n * @default false\n */\n modal?: boolean | undefined;\n children?: ComponentChildren | undefined;\n}\n\nfunction DialogRoot(rawProps: DialogProps): VNode {\n const {\n id,\n modal = false,\n children,\n } = useHuiProps(\"Dialog\", rawProps);\n\n const tmpId = useId();\n const dialogId = id || tmpId;\n const open = useCallback((): void => {\n dialogControl.openDialog(dialogId, modal);\n }, [dialogId, modal]);\n\n const contextValue = useMemo<DialogContextValue>(() => ({\n dialogId,\n modal,\n open,\n }), [dialogId, modal, open]);\n\n return (\n <DialogContext.Provider value={contextValue}>\n {children}\n </DialogContext.Provider>\n );\n}\n\ninterface DialogTriggerOwnProps {}\nexport type DialogTriggerProps<E extends JSX.ElementType = typeof Button<\"button\">> = HuiPolymorphicProps<\n E,\n DialogTriggerOwnProps,\n ButtonSlots\n>;\n\nfunction Trigger<E extends JSX.ElementType = typeof Button<\"button\">>(rawProps: DialogTriggerProps<E>): VNode {\n const {\n as,\n children,\n onClick,\n ...restProps\n } = useHuiProps(\"DialogTrigger\", rawProps);\n\n const Component = as ?? Button;\n const cls = useHuiClasses(\"DialogTrigger\", BUTTON_CLASSES, rawProps);\n const sls = useHuiStyles(\"DialogTrigger\", rawProps);\n const {\n dialogId,\n modal,\n open,\n } = useDialogContext();\n const attrs = dialogControl.getTriggerAttributes(\n { id: dialogId },\n {\n modal,\n isButtonElement: as === undefined,\n },\n );\n\n const handleClick = useCallback((e: TargetedMouseEvent<HTMLElement>): void => {\n onClick?.(e);\n if (modal || e.defaultPrevented) return;\n\n open();\n }, [modal, onClick, open]);\n\n return (\n <Component\n {...attrs}\n {...(Component === Button\n ? { classes: cls, styles: sls }\n : { className: cls.root, style: sls.root })}\n onClick={handleClick}\n {...restProps}\n >\n {children}\n </Component>\n );\n}\n\ninterface DialogContentOwnProps {\n /**\n * The heading rendered at the top of the dialog content.\n */\n heading?: ComponentChildren | undefined;\n /**\n * Additional props passed to the internal heading component.\n */\n headingProps?: Omit<HeadingProps, \"children\" | \"id\" | \"class\" | \"className\" | \"style\"> | undefined;\n /**\n * The content rendered inside the internal close button. Set to `null` or `false` to hide the button.\n *\n * @default close icon\n */\n closeButton?: ComponentChildren | undefined;\n /**\n * Additional props passed to the internal close button.\n */\n closeButtonProps?: Omit<DialogCloseProps, \"children\" | \"classes\" | \"styles\"> | undefined;\n}\nexport type DialogContentProps = HuiComponentProps<\n Omit<ComponentProps<\"dialog\">, \"id\" | \"open\"> & DialogContentOwnProps,\n DialogSlots\n>;\n\nfunction Content(rawProps: DialogContentProps): VNode {\n const {\n children,\n heading,\n headingProps,\n closeButton,\n closeButtonProps,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n ...restProps\n } = useHuiProps(\"DialogContent\", rawProps);\n\n const {\n dialogId,\n modal,\n } = useDialogContext();\n\n const resolvedHeading = heading !== undefined && heading !== null && heading !== false\n ? heading\n : undefined;\n const state = { id: dialogId };\n const attrs = dialogControl.getContentAttributes(\n state,\n {\n hasHeading: resolvedHeading !== undefined,\n ariaLabel: unwrapSignalish(ariaLabel),\n ariaLabelledBy: unwrapSignalish(ariaLabelledBy),\n },\n );\n const headingAttrs = dialogControl.getHeadingAttributes(state);\n const headingId = resolvedHeading !== undefined ? headingAttrs.id : undefined;\n const headingLevel = headingProps?.level ?? 2;\n\n const recipe = dialogRecipe({ modal: toStrbool(modal) });\n const cls = useHuiClasses(\"DialogContent\", recipe, rawProps);\n const sls = useHuiStyles(\"DialogContent\", rawProps);\n const closeButtonClasses = useMemo(() => ({ root: cls.closeButton }), [cls.closeButton]);\n const closeButtonStyles = useMemo(() => ({ root: sls.closeButton }), [sls.closeButton]);\n\n const shouldRenderCloseButton = closeButton !== null && closeButton !== false;\n const shouldRenderHeader = headingId !== undefined || shouldRenderCloseButton;\n const closeButtonContent = closeButton === undefined\n ? <span aria-hidden className={cls.closeButtonIcon} style={sls.closeButtonIcon} />\n : closeButton;\n\n return (\n <dialog\n {...attrs}\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {shouldRenderHeader && (\n <div className={cls.header} style={sls.header}>\n {headingId && (\n <Heading\n margin=\"none\"\n {...headingProps}\n {...headingAttrs}\n className={cls.heading}\n style={sls.heading}\n level={headingLevel}\n >\n {resolvedHeading}\n </Heading>\n )}\n {shouldRenderCloseButton && (\n <Close\n classes={closeButtonClasses}\n styles={closeButtonStyles}\n aria-label=\"Close Dialog\"\n variant=\"ghost\"\n color=\"neutral\"\n shape=\"square\"\n {...closeButtonProps}\n >\n {closeButtonContent}\n </Close>\n )}\n </div>\n )}\n {children}\n </dialog>\n );\n}\n\ninterface DialogCloseOwnProps {\n /**\n * The command used to close the dialog.\n *\n * @default \"request-close\"\n */\n command?: \"close\" | \"request-close\" | undefined;\n}\nexport type DialogCloseProps = Omit<ButtonProps, \"as\" | keyof DialogCloseOwnProps> & DialogCloseOwnProps;\n\nfunction Close(rawProps: DialogCloseProps): VNode {\n const props = useHuiProps(\"DialogClose\", rawProps);\n const cls = useHuiClasses(\"DialogClose\", BUTTON_CLASSES, rawProps);\n const sls = useHuiStyles(\"DialogClose\", rawProps);\n const dialogId = useDialogId();\n const attrs = dialogControl.getCloseAttributes({ id: dialogId });\n\n return (\n <Button\n {...attrs}\n {...props}\n classes={cls}\n styles={sls}\n />\n );\n}\n\nexport const Dialog = Object.assign(DialogRoot, {\n Trigger,\n Content,\n Close,\n});\n"],"mappings":"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { DdSlots, DlSlots, DtSlots } from "@hebium-ui/core";
|
|
4
|
+
import { ComponentProps, VNode } from "preact";
|
|
5
|
+
export type DlProps = HuiComponentProps<ComponentProps<"dl">, DlSlots>;
|
|
6
|
+
declare function DlRoot(rawProps: DlProps): VNode;
|
|
7
|
+
export type DtProps = HuiComponentProps<ComponentProps<"dt">, DtSlots>;
|
|
8
|
+
declare function Dt(rawProps: DtProps): VNode;
|
|
9
|
+
export type DdProps = HuiComponentProps<ComponentProps<"dd">, DdSlots>;
|
|
10
|
+
declare function Dd(rawProps: DdProps): VNode;
|
|
11
|
+
export declare const Dl: typeof DlRoot & {
|
|
12
|
+
Dt: typeof Dt;
|
|
13
|
+
Dd: typeof Dd;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useHuiClasses, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { ddRecipe, dlRecipe, dtRecipe } from "@hebium-ui/core";
|
|
3
|
+
import { jsx } from "preact/jsx-runtime";
|
|
4
|
+
// src/components/dl/dl.tsx
|
|
5
|
+
function DlRoot(rawProps) {
|
|
6
|
+
const { children, ...restProps } = useHuiProps("Dl", rawProps);
|
|
7
|
+
const recipe = dlRecipe({});
|
|
8
|
+
const cls = useHuiClasses("Dl", recipe, rawProps);
|
|
9
|
+
const sls = useHuiStyles("Dl", rawProps);
|
|
10
|
+
return /* @__PURE__ */ jsx("dl", {
|
|
11
|
+
className: cls.root,
|
|
12
|
+
style: sls.root,
|
|
13
|
+
...restProps,
|
|
14
|
+
children
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function Dt(rawProps) {
|
|
18
|
+
const { children, ...restProps } = useHuiProps("DlDt", rawProps);
|
|
19
|
+
const recipe = dtRecipe({});
|
|
20
|
+
const cls = useHuiClasses("DlDt", recipe, rawProps);
|
|
21
|
+
const sls = useHuiStyles("DlDt", rawProps);
|
|
22
|
+
return /* @__PURE__ */ jsx("dt", {
|
|
23
|
+
className: cls.root,
|
|
24
|
+
style: sls.root,
|
|
25
|
+
...restProps,
|
|
26
|
+
children
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function Dd(rawProps) {
|
|
30
|
+
const { children, ...restProps } = useHuiProps("DlDd", rawProps);
|
|
31
|
+
const recipe = ddRecipe({});
|
|
32
|
+
const cls = useHuiClasses("DlDd", recipe, rawProps);
|
|
33
|
+
const sls = useHuiStyles("DlDd", rawProps);
|
|
34
|
+
return /* @__PURE__ */ jsx("dd", {
|
|
35
|
+
className: cls.root,
|
|
36
|
+
style: sls.root,
|
|
37
|
+
...restProps,
|
|
38
|
+
children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const Dl = Object.assign(DlRoot, {
|
|
42
|
+
Dt,
|
|
43
|
+
Dd
|
|
44
|
+
});
|
|
45
|
+
export { Dl };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=dl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dl.js","names":[],"sources":["../../../src/components/dl/dl.tsx"],"sourcesContent":["import { ddRecipe, type DdSlots, dlRecipe, type DlSlots, dtRecipe, type DtSlots } from \"@hebium-ui/core\";\nimport { type ComponentProps, type VNode } from \"preact\";\nimport { useHuiClasses, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\n\nexport type DlProps = HuiComponentProps<ComponentProps<\"dl\">, DlSlots>;\n\nfunction DlRoot(rawProps: DlProps): VNode {\n const { children, ...restProps } = useHuiProps(\"Dl\", rawProps);\n\n const recipe = dlRecipe({});\n const cls = useHuiClasses(\"Dl\", recipe, rawProps);\n const sls = useHuiStyles(\"Dl\", rawProps);\n return (\n <dl\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </dl>\n );\n}\n\nexport type DtProps = HuiComponentProps<ComponentProps<\"dt\">, DtSlots>;\n\nfunction Dt(rawProps: DtProps): VNode {\n const { children, ...restProps } = useHuiProps(\"DlDt\", rawProps);\n\n const recipe = dtRecipe({});\n const cls = useHuiClasses(\"DlDt\", recipe, rawProps);\n const sls = useHuiStyles(\"DlDt\", rawProps);\n return (\n <dt\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </dt>\n );\n}\n\nexport type DdProps = HuiComponentProps<ComponentProps<\"dd\">, DdSlots>;\n\nfunction Dd(rawProps: DdProps): VNode {\n const { children, ...restProps } = useHuiProps(\"DlDd\", rawProps);\n\n const recipe = ddRecipe({});\n const cls = useHuiClasses(\"DlDd\", recipe, rawProps);\n const sls = useHuiStyles(\"DlDd\", rawProps);\n return (\n <dd\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </dd>\n );\n}\n\nexport const Dl = Object.assign(DlRoot, {\n Dt,\n Dd,\n});\n"],"mappings":";;;;AAOA,SAAS,OAAO,UAA0B;CACxC,MAAM,EAAE,UAAU,GAAG,cAAc,YAAY,MAAM,QAAQ;CAE7D,MAAM,SAAS,SAAS,CAAC,CAAC;CAC1B,MAAM,MAAM,cAAc,MAAM,QAAQ,QAAQ;CAChD,MAAM,MAAM,aAAa,MAAM,QAAQ;CACvC,OACE,oBAAC,MAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EACX,GAAI;EAEH;CACC,CAAA;AAER;AAIA,SAAS,GAAG,UAA0B;CACpC,MAAM,EAAE,UAAU,GAAG,cAAc,YAAY,QAAQ,QAAQ;CAE/D,MAAM,SAAS,SAAS,CAAC,CAAC;CAC1B,MAAM,MAAM,cAAc,QAAQ,QAAQ,QAAQ;CAClD,MAAM,MAAM,aAAa,QAAQ,QAAQ;CACzC,OACE,oBAAC,MAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EACX,GAAI;EAEH;CACC,CAAA;AAER;AAIA,SAAS,GAAG,UAA0B;CACpC,MAAM,EAAE,UAAU,GAAG,cAAc,YAAY,QAAQ,QAAQ;CAE/D,MAAM,SAAS,SAAS,CAAC,CAAC;CAC1B,MAAM,MAAM,cAAc,QAAQ,QAAQ,QAAQ;CAClD,MAAM,MAAM,aAAa,QAAQ,QAAQ;CACzC,OACE,oBAAC,MAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EACX,GAAI;EAEH;CACC,CAAA;AAER;AAEA,MAAa,KAAK,OAAO,OAAO,QAAQ;CACtC;CACA;AACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useContext } from "preact/hooks";
|
|
2
|
+
import { createContext } from "preact";
|
|
3
|
+
// src/components/drawer/drawer.context.ts
|
|
4
|
+
const DrawerContext = createContext(null);
|
|
5
|
+
function useDrawerContext() {
|
|
6
|
+
const context = useContext(DrawerContext);
|
|
7
|
+
if (!context) throw new Error("[Hebium UI] Drawer compound components must be used within <Drawer>");
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
function useDrawerId() {
|
|
11
|
+
return useDrawerContext().drawerId;
|
|
12
|
+
}
|
|
13
|
+
export { DrawerContext, useDrawerContext, useDrawerId };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=drawer.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer.context.js","names":[],"sources":["../../../src/components/drawer/drawer.context.ts"],"sourcesContent":["import { createContext } from \"preact\";\nimport { useContext } from \"preact/hooks\";\n\nexport interface DrawerContextValue {\n drawerId: string;\n}\n\nexport const DrawerContext = createContext<DrawerContextValue | null>(null);\n\nexport function useDrawerContext(): DrawerContextValue {\n const context = useContext(DrawerContext);\n if (!context) {\n throw new Error(\"[Hebium UI] Drawer compound components must be used within <Drawer>\");\n }\n return context;\n}\n\nexport function useDrawerId(): string {\n return useDrawerContext().drawerId;\n}\n"],"mappings":";;;AAOA,MAAa,gBAAgB,cAAyC,IAAI;AAE1E,SAAgB,mBAAuC;CACrD,MAAM,UAAU,WAAW,aAAa;CACxC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,qEAAqE;CAEvF,OAAO;AACT;AAEA,SAAgB,cAAsB;CACpC,OAAO,iBAAiB,CAAC,CAAC;AAC5B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import { HuiPolymorphicProps } from "../../types/polymorphic.js";
|
|
3
|
+
import "../../types/index.js";
|
|
4
|
+
import { Button, ButtonProps } from "../button/button.js";
|
|
5
|
+
import "../button/index.js";
|
|
6
|
+
import { HeadingProps } from "../heading/heading.js";
|
|
7
|
+
import "../heading/index.js";
|
|
8
|
+
import { ButtonSlots, DrawerSlots, DrawerVariants } from "@hebium-ui/core";
|
|
9
|
+
import { ComponentChildren, ComponentProps, JSX, VNode } from "preact";
|
|
10
|
+
export interface DrawerProps {
|
|
11
|
+
/**
|
|
12
|
+
* The id of the drawer content element.
|
|
13
|
+
*/
|
|
14
|
+
id?: string | undefined;
|
|
15
|
+
children?: ComponentChildren | undefined;
|
|
16
|
+
}
|
|
17
|
+
declare function DrawerRoot(rawProps: DrawerProps): VNode;
|
|
18
|
+
interface DrawerTriggerOwnProps {}
|
|
19
|
+
export type DrawerTriggerProps<E extends JSX.ElementType = typeof Button<"button">> = HuiPolymorphicProps<E, DrawerTriggerOwnProps, ButtonSlots>;
|
|
20
|
+
declare function Trigger<E extends JSX.ElementType = typeof Button<"button">>(rawProps: DrawerTriggerProps<E>): VNode;
|
|
21
|
+
interface DrawerContentOwnProps {
|
|
22
|
+
/**
|
|
23
|
+
* The edge from which the drawer enters.
|
|
24
|
+
*
|
|
25
|
+
* @default "inline-end"
|
|
26
|
+
*/
|
|
27
|
+
placement?: DrawerVariants["placement"] | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* The heading rendered at the top of the drawer content.
|
|
30
|
+
*/
|
|
31
|
+
heading?: ComponentChildren | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Additional props passed to the internal heading component.
|
|
34
|
+
*/
|
|
35
|
+
headingProps?: Omit<HeadingProps, "children" | "id" | "class" | "className" | "style"> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The content rendered inside the internal close button. Set to `null` or `false` to hide the button.
|
|
38
|
+
*
|
|
39
|
+
* @default close icon
|
|
40
|
+
*/
|
|
41
|
+
closeButton?: ComponentChildren | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Additional props passed to the internal close button.
|
|
44
|
+
*/
|
|
45
|
+
closeButtonProps?: Omit<DrawerCloseProps, "children" | "classes" | "styles"> | undefined;
|
|
46
|
+
}
|
|
47
|
+
export type DrawerContentProps = HuiComponentProps<Omit<ComponentProps<"dialog">, "id" | "open"> & DrawerContentOwnProps, DrawerSlots>;
|
|
48
|
+
declare function Content(rawProps: DrawerContentProps): VNode;
|
|
49
|
+
interface DrawerCloseOwnProps {
|
|
50
|
+
/**
|
|
51
|
+
* The command used to close the drawer.
|
|
52
|
+
*
|
|
53
|
+
* @default "request-close"
|
|
54
|
+
*/
|
|
55
|
+
command?: "close" | "request-close" | undefined;
|
|
56
|
+
}
|
|
57
|
+
export type DrawerCloseProps = Omit<ButtonProps, "as" | keyof DrawerCloseOwnProps> & DrawerCloseOwnProps;
|
|
58
|
+
declare function Close(rawProps: DrawerCloseProps): VNode;
|
|
59
|
+
export declare const Drawer: typeof DrawerRoot & {
|
|
60
|
+
Trigger: typeof Trigger;
|
|
61
|
+
Content: typeof Content;
|
|
62
|
+
Close: typeof Close;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useHuiClasses, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { unwrapSignalish } from "../../utils/unwrap-signalish.js";
|
|
3
|
+
import { Button } from "../button/button.js";
|
|
4
|
+
import { Heading } from "../heading/heading.js";
|
|
5
|
+
import { DrawerContext, useDrawerContext, useDrawerId } from "./drawer.context.js";
|
|
6
|
+
import { dialogControl, drawerRecipe } from "@hebium-ui/core";
|
|
7
|
+
import { useId, useMemo } from "preact/hooks";
|
|
8
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
9
|
+
// src/components/drawer/drawer.tsx
|
|
10
|
+
const BUTTON_CLASSES = {
|
|
11
|
+
root: "",
|
|
12
|
+
content: "",
|
|
13
|
+
spinner: "",
|
|
14
|
+
status: ""
|
|
15
|
+
};
|
|
16
|
+
function DrawerRoot(rawProps) {
|
|
17
|
+
const { id, children } = useHuiProps("Drawer", rawProps);
|
|
18
|
+
const tmpId = useId();
|
|
19
|
+
const drawerId = id || tmpId;
|
|
20
|
+
const contextValue = useMemo(() => ({ drawerId }), [drawerId]);
|
|
21
|
+
return /* @__PURE__ */ jsx(DrawerContext.Provider, {
|
|
22
|
+
value: contextValue,
|
|
23
|
+
children
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function Trigger(rawProps) {
|
|
27
|
+
const { as, children, onClick, ...restProps } = useHuiProps("DrawerTrigger", rawProps);
|
|
28
|
+
const Component = as ?? Button;
|
|
29
|
+
const cls = useHuiClasses("DrawerTrigger", BUTTON_CLASSES, rawProps);
|
|
30
|
+
const sls = useHuiStyles("DrawerTrigger", rawProps);
|
|
31
|
+
const { drawerId } = useDrawerContext();
|
|
32
|
+
const attrs = dialogControl.getTriggerAttributes({ id: drawerId }, {
|
|
33
|
+
modal: true,
|
|
34
|
+
isButtonElement: as === void 0
|
|
35
|
+
});
|
|
36
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
37
|
+
...attrs,
|
|
38
|
+
...Component === Button ? {
|
|
39
|
+
classes: cls,
|
|
40
|
+
styles: sls
|
|
41
|
+
} : {
|
|
42
|
+
className: cls.root,
|
|
43
|
+
style: sls.root
|
|
44
|
+
},
|
|
45
|
+
onClick,
|
|
46
|
+
...restProps,
|
|
47
|
+
children
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function Content(rawProps) {
|
|
51
|
+
const { placement, children, heading, headingProps, closeButton, closeButtonProps, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...restProps } = useHuiProps("DrawerContent", rawProps);
|
|
52
|
+
const { drawerId } = useDrawerContext();
|
|
53
|
+
const resolvedHeading = heading !== void 0 && heading !== null && heading !== false ? heading : void 0;
|
|
54
|
+
const state = { id: drawerId };
|
|
55
|
+
const attrs = dialogControl.getContentAttributes(state, {
|
|
56
|
+
hasHeading: resolvedHeading !== void 0,
|
|
57
|
+
ariaLabel: unwrapSignalish(ariaLabel),
|
|
58
|
+
ariaLabelledBy: unwrapSignalish(ariaLabelledBy)
|
|
59
|
+
});
|
|
60
|
+
const headingAttrs = dialogControl.getHeadingAttributes(state);
|
|
61
|
+
const headingId = resolvedHeading !== void 0 ? headingAttrs.id : void 0;
|
|
62
|
+
const headingLevel = headingProps?.level ?? 2;
|
|
63
|
+
const recipe = drawerRecipe({ placement });
|
|
64
|
+
const cls = useHuiClasses("DrawerContent", recipe, rawProps);
|
|
65
|
+
const sls = useHuiStyles("DrawerContent", rawProps);
|
|
66
|
+
const closeButtonClasses = useMemo(() => ({ root: cls.closeButton }), [cls.closeButton]);
|
|
67
|
+
const closeButtonStyles = useMemo(() => ({ root: sls.closeButton }), [sls.closeButton]);
|
|
68
|
+
const shouldRenderCloseButton = closeButton !== null && closeButton !== false;
|
|
69
|
+
const shouldRenderHeader = headingId !== void 0 || shouldRenderCloseButton;
|
|
70
|
+
const closeButtonContent = closeButton === void 0 ? /* @__PURE__ */ jsx("span", {
|
|
71
|
+
"aria-hidden": true,
|
|
72
|
+
className: cls.closeButtonIcon,
|
|
73
|
+
style: sls.closeButtonIcon
|
|
74
|
+
}) : closeButton;
|
|
75
|
+
return /* @__PURE__ */ jsxs("dialog", {
|
|
76
|
+
...attrs,
|
|
77
|
+
className: cls.root,
|
|
78
|
+
style: sls.root,
|
|
79
|
+
...restProps,
|
|
80
|
+
children: [shouldRenderHeader && /* @__PURE__ */ jsxs("div", {
|
|
81
|
+
className: cls.header,
|
|
82
|
+
style: sls.header,
|
|
83
|
+
children: [headingId && /* @__PURE__ */ jsx(Heading, {
|
|
84
|
+
margin: "none",
|
|
85
|
+
...headingProps,
|
|
86
|
+
...headingAttrs,
|
|
87
|
+
className: cls.heading,
|
|
88
|
+
style: sls.heading,
|
|
89
|
+
level: headingLevel,
|
|
90
|
+
children: resolvedHeading
|
|
91
|
+
}), shouldRenderCloseButton && /* @__PURE__ */ jsx(Close, {
|
|
92
|
+
classes: closeButtonClasses,
|
|
93
|
+
styles: closeButtonStyles,
|
|
94
|
+
"aria-label": "Close Drawer",
|
|
95
|
+
variant: "ghost",
|
|
96
|
+
color: "neutral",
|
|
97
|
+
shape: "square",
|
|
98
|
+
...closeButtonProps,
|
|
99
|
+
children: closeButtonContent
|
|
100
|
+
})]
|
|
101
|
+
}), children]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function Close(rawProps) {
|
|
105
|
+
const props = useHuiProps("DrawerClose", rawProps);
|
|
106
|
+
const cls = useHuiClasses("DrawerClose", BUTTON_CLASSES, rawProps);
|
|
107
|
+
const sls = useHuiStyles("DrawerClose", rawProps);
|
|
108
|
+
const drawerId = useDrawerId();
|
|
109
|
+
const attrs = dialogControl.getCloseAttributes({ id: drawerId });
|
|
110
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
111
|
+
...attrs,
|
|
112
|
+
...props,
|
|
113
|
+
classes: cls,
|
|
114
|
+
styles: sls
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const Drawer = Object.assign(DrawerRoot, {
|
|
118
|
+
Trigger,
|
|
119
|
+
Content,
|
|
120
|
+
Close
|
|
121
|
+
});
|
|
122
|
+
export { Drawer };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=drawer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawer.js","names":[],"sources":["../../../src/components/drawer/drawer.tsx"],"sourcesContent":["import { type ButtonSlots, dialogControl, drawerRecipe, type DrawerSlots, type DrawerVariants } from \"@hebium-ui/core\";\nimport { type ComponentChildren, type ComponentProps, type JSX, type VNode } from \"preact\";\nimport { useId, useMemo } from \"preact/hooks\";\nimport { useHuiClasses, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps, type HuiPolymorphicProps } from \"~/types\";\nimport { unwrapSignalish } from \"~/utils\";\nimport { Button, type ButtonProps } from \"../button\";\nimport { Heading, type HeadingProps } from \"../heading\";\nimport { DrawerContext, type DrawerContextValue, useDrawerContext, useDrawerId } from \"./drawer.context\";\n\nconst BUTTON_CLASSES = { root: \"\", content: \"\", spinner: \"\", status: \"\" } satisfies Record<ButtonSlots, string>;\n\nexport interface DrawerProps {\n /**\n * The id of the drawer content element.\n */\n id?: string | undefined;\n children?: ComponentChildren | undefined;\n}\n\nfunction DrawerRoot(rawProps: DrawerProps): VNode {\n const {\n id,\n children,\n } = useHuiProps(\"Drawer\", rawProps);\n\n const tmpId = useId();\n const drawerId = id || tmpId;\n\n const contextValue = useMemo<DrawerContextValue>(() => ({\n drawerId,\n }), [drawerId]);\n\n return (\n <DrawerContext.Provider value={contextValue}>\n {children}\n </DrawerContext.Provider>\n );\n}\n\ninterface DrawerTriggerOwnProps {}\nexport type DrawerTriggerProps<E extends JSX.ElementType = typeof Button<\"button\">> = HuiPolymorphicProps<\n E,\n DrawerTriggerOwnProps,\n ButtonSlots\n>;\n\nfunction Trigger<E extends JSX.ElementType = typeof Button<\"button\">>(rawProps: DrawerTriggerProps<E>): VNode {\n const {\n as,\n children,\n onClick,\n ...restProps\n } = useHuiProps(\"DrawerTrigger\", rawProps);\n\n const Component = as ?? Button;\n const cls = useHuiClasses(\"DrawerTrigger\", BUTTON_CLASSES, rawProps);\n const sls = useHuiStyles(\"DrawerTrigger\", rawProps);\n const {\n drawerId,\n } = useDrawerContext();\n const attrs = dialogControl.getTriggerAttributes(\n { id: drawerId },\n {\n modal: true,\n isButtonElement: as === undefined,\n },\n );\n\n return (\n <Component\n {...attrs}\n {...(Component === Button\n ? { classes: cls, styles: sls }\n : { className: cls.root, style: sls.root })}\n onClick={onClick}\n {...restProps}\n >\n {children}\n </Component>\n );\n}\n\ninterface DrawerContentOwnProps {\n /**\n * The edge from which the drawer enters.\n *\n * @default \"inline-end\"\n */\n placement?: DrawerVariants[\"placement\"] | undefined;\n /**\n * The heading rendered at the top of the drawer content.\n */\n heading?: ComponentChildren | undefined;\n /**\n * Additional props passed to the internal heading component.\n */\n headingProps?: Omit<HeadingProps, \"children\" | \"id\" | \"class\" | \"className\" | \"style\"> | undefined;\n /**\n * The content rendered inside the internal close button. Set to `null` or `false` to hide the button.\n *\n * @default close icon\n */\n closeButton?: ComponentChildren | undefined;\n /**\n * Additional props passed to the internal close button.\n */\n closeButtonProps?: Omit<DrawerCloseProps, \"children\" | \"classes\" | \"styles\"> | undefined;\n}\nexport type DrawerContentProps = HuiComponentProps<\n Omit<ComponentProps<\"dialog\">, \"id\" | \"open\"> & DrawerContentOwnProps,\n DrawerSlots\n>;\n\nfunction Content(rawProps: DrawerContentProps): VNode {\n const {\n placement,\n children,\n heading,\n headingProps,\n closeButton,\n closeButtonProps,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n ...restProps\n } = useHuiProps(\"DrawerContent\", rawProps);\n\n const {\n drawerId,\n } = useDrawerContext();\n\n const resolvedHeading = heading !== undefined && heading !== null && heading !== false\n ? heading\n : undefined;\n const state = { id: drawerId };\n const attrs = dialogControl.getContentAttributes(\n state,\n {\n hasHeading: resolvedHeading !== undefined,\n ariaLabel: unwrapSignalish(ariaLabel),\n ariaLabelledBy: unwrapSignalish(ariaLabelledBy),\n },\n );\n const headingAttrs = dialogControl.getHeadingAttributes(state);\n const headingId = resolvedHeading !== undefined ? headingAttrs.id : undefined;\n const headingLevel = headingProps?.level ?? 2;\n const recipe = drawerRecipe({ placement });\n const cls = useHuiClasses(\"DrawerContent\", recipe, rawProps);\n const sls = useHuiStyles(\"DrawerContent\", rawProps);\n const closeButtonClasses = useMemo(() => ({ root: cls.closeButton }), [cls.closeButton]);\n const closeButtonStyles = useMemo(() => ({ root: sls.closeButton }), [sls.closeButton]);\n\n const shouldRenderCloseButton = closeButton !== null && closeButton !== false;\n const shouldRenderHeader = headingId !== undefined || shouldRenderCloseButton;\n const closeButtonContent = closeButton === undefined\n ? <span aria-hidden className={cls.closeButtonIcon} style={sls.closeButtonIcon} />\n : closeButton;\n\n return (\n <dialog\n {...attrs}\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {shouldRenderHeader && (\n <div className={cls.header} style={sls.header}>\n {headingId && (\n <Heading\n margin=\"none\"\n {...headingProps}\n {...headingAttrs}\n className={cls.heading}\n style={sls.heading}\n level={headingLevel}\n >\n {resolvedHeading}\n </Heading>\n )}\n {shouldRenderCloseButton && (\n <Close\n classes={closeButtonClasses}\n styles={closeButtonStyles}\n aria-label=\"Close Drawer\"\n variant=\"ghost\"\n color=\"neutral\"\n shape=\"square\"\n {...closeButtonProps}\n >\n {closeButtonContent}\n </Close>\n )}\n </div>\n )}\n {children}\n </dialog>\n );\n}\n\ninterface DrawerCloseOwnProps {\n /**\n * The command used to close the drawer.\n *\n * @default \"request-close\"\n */\n command?: \"close\" | \"request-close\" | undefined;\n}\nexport type DrawerCloseProps = Omit<ButtonProps, \"as\" | keyof DrawerCloseOwnProps> & DrawerCloseOwnProps;\n\nfunction Close(rawProps: DrawerCloseProps): VNode {\n const props = useHuiProps(\"DrawerClose\", rawProps);\n const cls = useHuiClasses(\"DrawerClose\", BUTTON_CLASSES, rawProps);\n const sls = useHuiStyles(\"DrawerClose\", rawProps);\n const drawerId = useDrawerId();\n const attrs = dialogControl.getCloseAttributes({ id: drawerId });\n\n return (\n <Button\n {...attrs}\n {...props}\n classes={cls}\n styles={sls}\n />\n );\n}\n\nexport const Drawer = Object.assign(DrawerRoot, {\n Trigger,\n Content,\n Close,\n});\n"],"mappings":"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"}
|