@blockle/blocks-react 3.0.0 → 3.1.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 +138 -0
- package/dist/components/display/Icon/IconMask.d.ts.map +1 -1
- package/dist/components/display/Icon/IconMask.js +1 -0
- package/dist/components/feedback/Alert/Alert.d.ts +6 -0
- package/dist/components/feedback/Alert/Alert.d.ts.map +1 -1
- package/dist/components/feedback/Alert/Alert.js +2 -0
- package/dist/components/feedback/Toast/Toast.css.d.ts +10 -1
- package/dist/components/feedback/Toast/Toast.css.d.ts.map +1 -1
- package/dist/components/feedback/Toast/Toast.css.js +37 -10
- package/dist/components/feedback/Toast/ToastContext.d.ts.map +1 -1
- package/dist/components/feedback/Toast/ToastContext.js +1 -0
- package/dist/components/feedback/Toast/ToastProvider.d.ts +9 -1
- package/dist/components/feedback/Toast/ToastProvider.d.ts.map +1 -1
- package/dist/components/feedback/Toast/ToastProvider.js +47 -24
- package/dist/components/feedback/Toast/useToast.d.ts.map +1 -1
- package/dist/components/feedback/Toast/useToast.js +1 -0
- package/dist/components/form/Checkbox/Checkbox.d.ts +0 -1
- package/dist/components/form/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/components/form/Checkbox/Checkbox.js +0 -2
- package/dist/components/form/Checkbox/checkbox.css.d.ts.map +1 -1
- package/dist/components/form/Checkbox/checkbox.css.js +1 -0
- package/dist/components/form/NumericInput/NumericInput.d.ts.map +1 -1
- package/dist/components/form/NumericInput/NumericInput.js +1 -0
- package/dist/components/form/Radio/Radio.d.ts +0 -1
- package/dist/components/form/Radio/Radio.d.ts.map +1 -1
- package/dist/components/form/Radio/Radio.js +1 -11
- package/dist/components/form/Radio/radio.css.d.ts.map +1 -1
- package/dist/components/form/Radio/radio.css.js +1 -0
- package/dist/components/form/Select/Select.d.ts +2 -1
- package/dist/components/form/Select/Select.d.ts.map +1 -1
- package/dist/components/form/Select/Select.js +2 -1
- package/dist/components/form/Slider/usePointerProgress.d.ts.map +1 -1
- package/dist/components/form/Slider/usePointerProgress.js +1 -0
- package/dist/components/form/Switch/Switch.d.ts +5 -1
- package/dist/components/form/Switch/Switch.d.ts.map +1 -1
- package/dist/components/form/Switch/Switch.js +19 -29
- package/dist/components/form/Switch/switch.css.d.ts.map +1 -1
- package/dist/components/form/Switch/switch.css.js +1 -0
- package/dist/components/form/TextInput/TextInput.d.ts +0 -1
- package/dist/components/form/TextInput/TextInput.d.ts.map +1 -1
- package/dist/components/form/TextInput/TextInput.js +0 -2
- package/dist/components/overlay/Dialog/Dialog.d.ts +4 -1
- package/dist/components/overlay/Dialog/Dialog.d.ts.map +1 -1
- package/dist/components/overlay/Dialog/Dialog.js +19 -46
- package/dist/components/overlay/Drawer/Drawer.d.ts +9 -2
- package/dist/components/overlay/Drawer/Drawer.d.ts.map +1 -1
- package/dist/components/overlay/Drawer/Drawer.js +26 -44
- package/dist/components/overlay/Drawer/drawer.css.d.ts.map +1 -1
- package/dist/components/overlay/Drawer/drawer.css.js +4 -8
- package/dist/components/overlay/Popover/Popover.d.ts +15 -3
- package/dist/components/overlay/Popover/Popover.d.ts.map +1 -1
- package/dist/components/overlay/Popover/Popover.js +35 -11
- package/dist/components/overlay/Popover/popover-utils.d.ts +38 -1
- package/dist/components/overlay/Popover/popover-utils.d.ts.map +1 -1
- package/dist/components/overlay/Popover/popover-utils.js +92 -41
- package/dist/components/overlay/Tooltip/Tooltip.d.ts +8 -0
- package/dist/components/overlay/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/components/overlay/Tooltip/Tooltip.js +3 -2
- package/dist/components/overlay/requestCloseReason.d.ts +6 -0
- package/dist/components/overlay/requestCloseReason.d.ts.map +1 -0
- package/dist/components/overlay/useModalOverlay.d.ts +35 -0
- package/dist/components/overlay/useModalOverlay.d.ts.map +1 -0
- package/dist/components/overlay/useModalOverlay.js +85 -0
- package/dist/components/providers/BlocksProvider/context.d.ts.map +1 -1
- package/dist/components/providers/BlocksProvider/context.js +1 -0
- package/dist/components/typography/Heading/Heading.d.ts.map +1 -1
- package/dist/components/typography/Heading/Heading.js +1 -0
- package/dist/components/typography/Text/Text.d.ts.map +1 -1
- package/dist/components/typography/Text/Text.js +1 -0
- package/dist/hooks/useClickOutside/useClickOutside.d.ts.map +1 -1
- package/dist/hooks/useClickOutside/useClickOutside.js +28 -7
- package/dist/hooks/useComponentStyles/useComponentStyleDefaultProps.d.ts.map +1 -1
- package/dist/hooks/useComponentStyles/useComponentStyleDefaultProps.js +1 -0
- package/dist/hooks/useModalDialog/useModalDialog.d.ts +13 -0
- package/dist/hooks/useModalDialog/useModalDialog.d.ts.map +1 -0
- package/dist/hooks/useModalDialog/useModalDialog.js +39 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/testUtils/browser/pointer.d.ts +18 -0
- package/dist/testUtils/browser/pointer.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/components/overlay/Dialog/dialogHelper.d.ts +0 -7
- package/dist/components/overlay/Dialog/dialogHelper.d.ts.map +0 -1
- package/dist/components/overlay/Dialog/dialogHelper.js +0 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { classnames } from "@blockle/blocks-core";
|
|
4
|
-
import {
|
|
3
|
+
import { composeRefs, classnames } from "@blockle/blocks-core";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
5
|
import { useComponentStyles } from "../../../hooks/useComponentStyles/useComponentStyles.js";
|
|
6
6
|
import { input, container } from "./switch.css.js";
|
|
7
7
|
const Switch = ({
|
|
@@ -9,55 +9,45 @@ const Switch = ({
|
|
|
9
9
|
className,
|
|
10
10
|
defaultChecked,
|
|
11
11
|
onChange,
|
|
12
|
+
ref,
|
|
12
13
|
...restProps
|
|
13
14
|
}) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
15
|
+
const inputRef = useRef(null);
|
|
16
|
+
const [uncontrolledChecked, setUncontrolledChecked] = useState(
|
|
17
|
+
defaultChecked ?? false
|
|
16
18
|
);
|
|
19
|
+
const isControlled = checked !== void 0;
|
|
20
|
+
const isChecked = isControlled ? checked : uncontrolledChecked;
|
|
17
21
|
const baseClassName = useComponentStyles("switch", { root: true });
|
|
18
22
|
const thumbClassName = useComponentStyles("switch", { thumb: true }, false);
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
23
|
+
const onChangeHandler = (event) => {
|
|
24
|
+
if (!isControlled) {
|
|
25
|
+
setUncontrolledChecked(event.target.checked);
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setIsChecked((checked2) => {
|
|
26
|
-
const newValue = !checked2;
|
|
27
|
-
if (onChange) {
|
|
28
|
-
onChange(newValue);
|
|
29
|
-
}
|
|
30
|
-
return newValue;
|
|
31
|
-
});
|
|
32
|
-
}, [onChange]);
|
|
33
|
-
const onChangeHandler = useCallback(
|
|
34
|
-
(event) => {
|
|
35
|
-
setIsChecked(event.target.checked);
|
|
36
|
-
if (onChange) {
|
|
37
|
-
onChange(event.target.checked);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
[onChange]
|
|
41
|
-
);
|
|
27
|
+
onChange?.(event);
|
|
28
|
+
};
|
|
42
29
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
|
|
43
30
|
"div",
|
|
44
31
|
{
|
|
45
32
|
className: classnames(className, container, baseClassName),
|
|
46
33
|
"data-checked": isChecked,
|
|
47
34
|
onClick: (event) => {
|
|
48
|
-
if (event.target
|
|
35
|
+
if (event.target === inputRef.current) {
|
|
49
36
|
return;
|
|
50
37
|
}
|
|
51
|
-
|
|
38
|
+
inputRef.current?.click();
|
|
52
39
|
},
|
|
53
40
|
children: [
|
|
54
41
|
/* @__PURE__ */ jsx(
|
|
55
42
|
"input",
|
|
56
43
|
{
|
|
57
44
|
type: "checkbox",
|
|
45
|
+
role: "switch",
|
|
58
46
|
className: input,
|
|
59
|
-
checked
|
|
47
|
+
checked,
|
|
48
|
+
defaultChecked,
|
|
60
49
|
onChange: onChangeHandler,
|
|
50
|
+
ref: composeRefs(ref, inputRef),
|
|
61
51
|
...restProps
|
|
62
52
|
}
|
|
63
53
|
),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.css.d.ts","sourceRoot":"","sources":["../../../../src/components/form/Switch/switch.css.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"switch.css.d.ts","sourceRoot":"","sources":["../../../../src/components/form/Switch/switch.css.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,QASpB,CAAC;AAEH,eAAO,MAAM,KAAK,QAQhB,CAAC"}
|
|
@@ -2,7 +2,6 @@ import { HTMLElementProps, OptionalLiteral } from '@blockle/blocks-core';
|
|
|
2
2
|
export type TextInputProps = {
|
|
3
3
|
inputClassName?: string;
|
|
4
4
|
endSlot?: React.ReactNode;
|
|
5
|
-
name: string;
|
|
6
5
|
startSlot?: React.ReactNode;
|
|
7
6
|
type?: OptionalLiteral<'email' | 'number' | 'password' | 'tel' | 'text' | 'url'>;
|
|
8
7
|
} & Omit<HTMLElementProps<HTMLInputElement>, 'type'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/form/TextInput/TextInput.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,
|
|
1
|
+
{"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/form/TextInput/TextInput.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC5B,IAAI,CAAC,EAAE,eAAe,CACpB,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CACzD,CAAC;CAEH,GAAG,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,CAAC;AAErD,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAsC9C,CAAC"}
|
|
@@ -8,7 +8,6 @@ const TextInput = ({
|
|
|
8
8
|
className,
|
|
9
9
|
inputClassName,
|
|
10
10
|
endSlot,
|
|
11
|
-
name,
|
|
12
11
|
placeholder,
|
|
13
12
|
startSlot,
|
|
14
13
|
type = "text",
|
|
@@ -31,7 +30,6 @@ const TextInput = ({
|
|
|
31
30
|
/* @__PURE__ */ jsx(
|
|
32
31
|
"input",
|
|
33
32
|
{
|
|
34
|
-
name,
|
|
35
33
|
type,
|
|
36
34
|
placeholder,
|
|
37
35
|
className: classnames(input, inputStyles, inputClassName),
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ComponentThemes, HTMLElementProps } from '@blockle/blocks-core';
|
|
2
|
+
import { RequestCloseReason } from '../requestCloseReason.js';
|
|
2
3
|
type DialogTheme = ComponentThemes['dialog'];
|
|
3
4
|
export type DialogProps = {
|
|
4
5
|
open: boolean;
|
|
5
|
-
onRequestClose: () => void;
|
|
6
|
+
onRequestClose: (reason: RequestCloseReason) => void;
|
|
7
|
+
/** Runs on a close request, before the component prevents it and asks to close */
|
|
8
|
+
onCancel?: React.ReactEventHandler<HTMLDialogElement>;
|
|
6
9
|
className?: string;
|
|
7
10
|
size?: DialogTheme['variants']['size'];
|
|
8
11
|
'aria-label'?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Dialog/Dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Dialog/Dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EAGpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAInE,KAAK,WAAW,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,cAAc,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACrD,kFAAkF;IAClF,QAAQ,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;AAExC,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAkDxC,CAAC"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import { useRef
|
|
5
|
-
import { useClickOutside } from "../../../hooks/useClickOutside/useClickOutside.js";
|
|
3
|
+
import { classnames, composeRefs } from "@blockle/blocks-core";
|
|
4
|
+
import { useRef } from "react";
|
|
6
5
|
import { useComponentStyles } from "../../../hooks/useComponentStyles/useComponentStyles.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { usePreventBodyScroll } from "../../../hooks/usePreventBodyScroll/usePreventBodyScroll.js";
|
|
10
|
-
import { useRestoreFocus } from "../../../hooks/useRestoreFocus/useRestoreFocus.js";
|
|
6
|
+
import { useModalDialog } from "../../../hooks/useModalDialog/useModalDialog.js";
|
|
7
|
+
import { useModalOverlay, DialogContext } from "../useModalOverlay.js";
|
|
11
8
|
import { dialog } from "./dialog.css.js";
|
|
12
|
-
import { useNestedDialog, DialogContext } from "./dialogHelper.js";
|
|
13
9
|
const Dialog = ({
|
|
14
10
|
children,
|
|
15
11
|
open,
|
|
16
12
|
className,
|
|
17
13
|
onRequestClose,
|
|
18
14
|
size,
|
|
15
|
+
ref,
|
|
16
|
+
onKeyDown,
|
|
17
|
+
onKeyDownCapture,
|
|
18
|
+
onCancel,
|
|
19
19
|
...restProps
|
|
20
20
|
}) => {
|
|
21
21
|
const dialogRef = useRef(null);
|
|
@@ -23,55 +23,28 @@ const Dialog = ({
|
|
|
23
23
|
dialog: true,
|
|
24
24
|
variants: { size }
|
|
25
25
|
});
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
onRequestClose();
|
|
35
|
-
},
|
|
36
|
-
[onRequestClose]
|
|
37
|
-
);
|
|
38
|
-
useKeyboard("Escape", onEscape, { enabled: open && enabled });
|
|
39
|
-
useClickOutside(dialogRef, onRequestClose, { enabled: open && enabled });
|
|
40
|
-
useIsomorphicLayoutEffect(() => {
|
|
41
|
-
if (open && visible) {
|
|
42
|
-
if (!dialogRef.current || !dialogRef.current.showModal) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
dialogRef.current.showModal();
|
|
46
|
-
} else if (open) {
|
|
47
|
-
setVisible(true);
|
|
48
|
-
} else {
|
|
49
|
-
if (!hasAnimationDuration(dialogRef.current)) {
|
|
50
|
-
setVisible(false);
|
|
51
|
-
}
|
|
52
|
-
if (dialogRef.current?.close) {
|
|
53
|
-
dialogRef.current.close();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}, [open, visible]);
|
|
57
|
-
const onAnimationEnd = useCallback(() => {
|
|
58
|
-
if (!open) {
|
|
59
|
-
setVisible(false);
|
|
60
|
-
}
|
|
61
|
-
}, [open]);
|
|
26
|
+
const { contextValue, closeRequestProps } = useModalOverlay(dialogRef, {
|
|
27
|
+
open,
|
|
28
|
+
onRequestClose,
|
|
29
|
+
onKeyDown,
|
|
30
|
+
onKeyDownCapture,
|
|
31
|
+
onCancel
|
|
32
|
+
});
|
|
33
|
+
const { visible, onAnimationEnd } = useModalDialog(dialogRef, open);
|
|
62
34
|
if (!visible) {
|
|
63
35
|
return null;
|
|
64
36
|
}
|
|
65
37
|
const dataOpen = typeof window === "undefined" && open ? true : void 0;
|
|
66
|
-
return /* @__PURE__ */ jsx(DialogContext.Provider, { value:
|
|
38
|
+
return /* @__PURE__ */ jsx(DialogContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
67
39
|
"dialog",
|
|
68
40
|
{
|
|
69
|
-
ref: dialogRef,
|
|
41
|
+
ref: composeRefs(ref, dialogRef),
|
|
70
42
|
open: dataOpen,
|
|
71
43
|
className: classnames(dialog, dialogClassName, className),
|
|
72
44
|
onAnimationEnd,
|
|
73
45
|
onTransitionEnd: onAnimationEnd,
|
|
74
46
|
...restProps,
|
|
47
|
+
...closeRequestProps,
|
|
75
48
|
children
|
|
76
49
|
}
|
|
77
50
|
) });
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { HTMLElementProps } from '@blockle/blocks-core';
|
|
1
|
+
import { ComponentThemes, HTMLElementProps } from '@blockle/blocks-core';
|
|
2
|
+
import { RequestCloseReason } from '../requestCloseReason.js';
|
|
2
3
|
import * as styles from './drawer.css.js';
|
|
4
|
+
type DrawerTheme = ComponentThemes['drawer'];
|
|
3
5
|
export type DrawerProps = {
|
|
4
6
|
open: boolean;
|
|
5
|
-
onRequestClose: () => void;
|
|
7
|
+
onRequestClose: (reason: RequestCloseReason) => void;
|
|
8
|
+
/** Runs on a close request, before the component prevents it and asks to close */
|
|
9
|
+
onCancel?: React.ReactEventHandler<HTMLDialogElement>;
|
|
10
|
+
className?: string;
|
|
6
11
|
placement?: keyof typeof styles.placement;
|
|
12
|
+
size?: DrawerTheme['variants']['size'];
|
|
7
13
|
} & HTMLElementProps<HTMLDialogElement>;
|
|
8
14
|
export declare const Drawer: React.FC<DrawerProps>;
|
|
15
|
+
export {};
|
|
9
16
|
//# sourceMappingURL=Drawer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Drawer/Drawer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Drawer/Drawer.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EAGpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAC;AAE1C,KAAK,WAAW,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,cAAc,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACrD,kFAAkF;IAClF,QAAQ,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,OAAO,MAAM,CAAC,SAAS,CAAC;IAC1C,IAAI,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;CACxC,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;AAExC,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAyDxC,CAAC"}
|
|
@@ -1,77 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useRef
|
|
4
|
-
import { useClickOutside } from "../../../hooks/useClickOutside/useClickOutside.js";
|
|
3
|
+
import { classnames, composeRefs } from "@blockle/blocks-core";
|
|
4
|
+
import { useRef } from "react";
|
|
5
5
|
import { useComponentStyles } from "../../../hooks/useComponentStyles/useComponentStyles.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { usePreventBodyScroll } from "../../../hooks/usePreventBodyScroll/usePreventBodyScroll.js";
|
|
6
|
+
import { useModalDialog } from "../../../hooks/useModalDialog/useModalDialog.js";
|
|
7
|
+
import { useModalOverlay, DialogContext } from "../useModalOverlay.js";
|
|
9
8
|
import { drawer, placement } from "./drawer.css.js";
|
|
10
9
|
const Drawer = ({
|
|
11
10
|
open,
|
|
12
11
|
onRequestClose,
|
|
12
|
+
className,
|
|
13
13
|
placement: placement$1 = "left",
|
|
14
|
+
size,
|
|
14
15
|
children,
|
|
16
|
+
ref,
|
|
17
|
+
onKeyDown,
|
|
18
|
+
onKeyDownCapture,
|
|
19
|
+
onCancel,
|
|
15
20
|
...restProps
|
|
16
21
|
}) => {
|
|
17
22
|
const dialogRef = useRef(null);
|
|
18
|
-
const [visible, setVisible] = useState(open);
|
|
19
23
|
const rootClassName = useComponentStyles("drawer", {
|
|
20
24
|
root: true,
|
|
21
|
-
variants: { placement: placement$1 }
|
|
25
|
+
variants: { placement: placement$1, size }
|
|
22
26
|
});
|
|
23
27
|
const dataOpen = typeof window === "undefined" && open ? true : void 0;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
33
|
-
useKeyboard("Escape", onEscape, { enabled: open });
|
|
34
|
-
useIsomorphicLayoutEffect(() => {
|
|
35
|
-
if (open && visible) {
|
|
36
|
-
if (!dialogRef.current || !dialogRef.current.showModal) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
dialogRef.current.showModal();
|
|
40
|
-
} else if (open) {
|
|
41
|
-
setVisible(true);
|
|
42
|
-
} else {
|
|
43
|
-
if (!hasAnimationDuration(dialogRef.current)) {
|
|
44
|
-
setVisible(false);
|
|
45
|
-
}
|
|
46
|
-
if (dialogRef.current?.close) {
|
|
47
|
-
dialogRef.current.close();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, [open, visible]);
|
|
51
|
-
const onAnimationEnd = useCallback(() => {
|
|
52
|
-
if (!open) {
|
|
53
|
-
setVisible(false);
|
|
54
|
-
}
|
|
55
|
-
}, [open]);
|
|
28
|
+
const { contextValue, closeRequestProps } = useModalOverlay(dialogRef, {
|
|
29
|
+
open,
|
|
30
|
+
onRequestClose,
|
|
31
|
+
onKeyDown,
|
|
32
|
+
onKeyDownCapture,
|
|
33
|
+
onCancel
|
|
34
|
+
});
|
|
35
|
+
const { visible, onAnimationEnd } = useModalDialog(dialogRef, open);
|
|
56
36
|
if (!visible) {
|
|
57
37
|
return null;
|
|
58
38
|
}
|
|
59
|
-
return /* @__PURE__ */ jsx(
|
|
39
|
+
return /* @__PURE__ */ jsx(DialogContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
60
40
|
"dialog",
|
|
61
41
|
{
|
|
62
|
-
ref: dialogRef,
|
|
42
|
+
ref: composeRefs(ref, dialogRef),
|
|
63
43
|
open: dataOpen,
|
|
64
44
|
className: classnames(
|
|
65
45
|
drawer,
|
|
66
46
|
placement[placement$1],
|
|
67
|
-
rootClassName
|
|
47
|
+
rootClassName,
|
|
48
|
+
className
|
|
68
49
|
),
|
|
69
50
|
onAnimationEnd,
|
|
70
51
|
onTransitionEnd: onAnimationEnd,
|
|
71
52
|
...restProps,
|
|
53
|
+
...closeRequestProps,
|
|
72
54
|
children
|
|
73
55
|
}
|
|
74
|
-
);
|
|
56
|
+
) });
|
|
75
57
|
};
|
|
76
58
|
export {
|
|
77
59
|
Drawer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drawer.css.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Drawer/drawer.css.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,QAmBjB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;
|
|
1
|
+
{"version":3,"file":"drawer.css.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Drawer/drawer.css.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,QAmBjB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;CAuCrB,CAAC"}
|
|
@@ -29,8 +29,7 @@ const placement = {
|
|
|
29
29
|
top: 0,
|
|
30
30
|
bottom: 0,
|
|
31
31
|
left: 0,
|
|
32
|
-
height: "100%"
|
|
33
|
-
width: "300px"
|
|
32
|
+
height: "100%"
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
}),
|
|
@@ -40,8 +39,7 @@ const placement = {
|
|
|
40
39
|
top: 0,
|
|
41
40
|
right: 0,
|
|
42
41
|
bottom: 0,
|
|
43
|
-
height: "100%"
|
|
44
|
-
width: "300px"
|
|
42
|
+
height: "100%"
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
}),
|
|
@@ -50,8 +48,7 @@ const placement = {
|
|
|
50
48
|
[layers.molecule]: {
|
|
51
49
|
top: 0,
|
|
52
50
|
left: 0,
|
|
53
|
-
width: "100%"
|
|
54
|
-
height: "300px"
|
|
51
|
+
width: "100%"
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
}),
|
|
@@ -60,8 +57,7 @@ const placement = {
|
|
|
60
57
|
[layers.molecule]: {
|
|
61
58
|
bottom: 0,
|
|
62
59
|
left: 0,
|
|
63
|
-
width: "100%"
|
|
64
|
-
height: "300px"
|
|
60
|
+
width: "100%"
|
|
65
61
|
}
|
|
66
62
|
}
|
|
67
63
|
})
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { HTMLElementProps } from '@blockle/blocks-core';
|
|
2
|
-
|
|
2
|
+
import { RequestCloseReason } from '../requestCloseReason.js';
|
|
3
|
+
import { PopoverPlacement } from './popover-utils.js';
|
|
4
|
+
export type { PopoverPlacement };
|
|
3
5
|
export type PopoverProps = {
|
|
4
6
|
anchorElement: React.RefObject<HTMLElement | null>;
|
|
5
|
-
onRequestClose: () => void;
|
|
7
|
+
onRequestClose: (reason: RequestCloseReason) => void;
|
|
6
8
|
open: boolean;
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Side of the anchor to open on, and which of its edges to line up with.
|
|
11
|
+
* Flips to the opposite side when there is no room, and shifts to stay
|
|
12
|
+
* inside the viewport.
|
|
13
|
+
* @default 'top'
|
|
14
|
+
*/
|
|
15
|
+
placement?: PopoverPlacement;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `placement`, which wins when both are passed
|
|
18
|
+
*/
|
|
19
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
8
20
|
sticky?: boolean;
|
|
9
21
|
} & HTMLElementProps<HTMLDivElement>;
|
|
10
22
|
export declare const Popover: React.FC<PopoverProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popover.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Popover/Popover.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Popover.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Popover/Popover.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAIjC,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACnD,cAAc,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACrD,IAAI,EAAE,OAAO,CAAC;IACd;;;;;OAKG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,MAAM,CAAC,EAAE,OAAO,CAAC;CAElB,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;AAErC,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAkJ1C,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { hasAnimationDuration, classnames, composeRefs } from "@blockle/blocks-core";
|
|
4
|
-
import { useRef, useState,
|
|
4
|
+
import { useRef, useState, useCallback, useEffect } from "react";
|
|
5
5
|
import { useClickOutside } from "../../../hooks/useClickOutside/useClickOutside.js";
|
|
6
6
|
import { useComponentStyles } from "../../../hooks/useComponentStyles/useComponentStyles.js";
|
|
7
7
|
import { useIsomorphicLayoutEffect } from "../../../hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js";
|
|
@@ -14,17 +14,32 @@ const Popover = ({
|
|
|
14
14
|
className,
|
|
15
15
|
onRequestClose,
|
|
16
16
|
open,
|
|
17
|
-
|
|
17
|
+
placement: placementProp,
|
|
18
|
+
position,
|
|
19
|
+
ref,
|
|
18
20
|
sticky,
|
|
19
21
|
style,
|
|
20
22
|
...restProps
|
|
21
23
|
}) => {
|
|
24
|
+
const placement = placementProp ?? position ?? "top";
|
|
22
25
|
const popoverRef = useRef(null);
|
|
23
26
|
const [popoverPosition, setPopoverPosition] = useState({ x: 0, y: 0 });
|
|
24
27
|
const [visible, setVisible] = useState(open);
|
|
25
28
|
const popoverClassName = useComponentStyles("popover", { root: true }, false);
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const onEscape = useCallback(
|
|
30
|
+
(event) => {
|
|
31
|
+
if (event.defaultPrevented) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
onRequestClose("escape");
|
|
36
|
+
},
|
|
37
|
+
[onRequestClose]
|
|
38
|
+
);
|
|
39
|
+
useKeyboard("Escape", onEscape, { enabled: open });
|
|
40
|
+
useClickOutside(popoverRef, () => onRequestClose("outside-click"), {
|
|
41
|
+
enabled: open
|
|
42
|
+
});
|
|
28
43
|
useIsomorphicLayoutEffect(() => {
|
|
29
44
|
const element = popoverRef.current;
|
|
30
45
|
if (open && visible) {
|
|
@@ -35,7 +50,7 @@ const Popover = ({
|
|
|
35
50
|
return;
|
|
36
51
|
}
|
|
37
52
|
element.showPopover();
|
|
38
|
-
const [x, y] = getPopoverPosition(
|
|
53
|
+
const [x, y] = getPopoverPosition(placement, anchorElement, popoverRef);
|
|
39
54
|
setPopoverPosition({ x, y });
|
|
40
55
|
} else if (open) {
|
|
41
56
|
setVisible(true);
|
|
@@ -43,21 +58,30 @@ const Popover = ({
|
|
|
43
58
|
if (!hasAnimationDuration(popoverRef.current)) {
|
|
44
59
|
setVisible(false);
|
|
45
60
|
}
|
|
46
|
-
|
|
61
|
+
if (!element) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (typeof element.hidePopover !== "function") {
|
|
65
|
+
console.warn(
|
|
66
|
+
"Popover: hidePopover method is not available on the element."
|
|
67
|
+
);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
element.hidePopover();
|
|
47
71
|
}
|
|
48
72
|
}, [open, visible]);
|
|
49
73
|
useEffect(() => {
|
|
50
74
|
if (open) {
|
|
51
|
-
const [x, y] = getPopoverPosition(
|
|
75
|
+
const [x, y] = getPopoverPosition(placement, anchorElement, popoverRef);
|
|
52
76
|
setPopoverPosition({ x, y });
|
|
53
77
|
}
|
|
54
|
-
}, [open, anchorElement,
|
|
78
|
+
}, [open, anchorElement, placement]);
|
|
55
79
|
useEffect(() => {
|
|
56
80
|
if (!open || !sticky) {
|
|
57
81
|
return;
|
|
58
82
|
}
|
|
59
83
|
function updatePopoverPosition() {
|
|
60
|
-
const [x, y] = getPopoverPosition(
|
|
84
|
+
const [x, y] = getPopoverPosition(placement, anchorElement, popoverRef);
|
|
61
85
|
setPopoverPosition((prev) => {
|
|
62
86
|
if (prev.x === x && prev.y === y) {
|
|
63
87
|
return prev;
|
|
@@ -71,7 +95,7 @@ const Popover = ({
|
|
|
71
95
|
window.removeEventListener("resize", updatePopoverPosition);
|
|
72
96
|
window.removeEventListener("scroll", updatePopoverPosition);
|
|
73
97
|
};
|
|
74
|
-
}, [
|
|
98
|
+
}, [placement, anchorElement, open, sticky]);
|
|
75
99
|
const onAnimationEnd = useCallback(() => {
|
|
76
100
|
if (!open) {
|
|
77
101
|
setVisible(false);
|
|
@@ -83,7 +107,7 @@ const Popover = ({
|
|
|
83
107
|
return /* @__PURE__ */ jsx(
|
|
84
108
|
Box,
|
|
85
109
|
{
|
|
86
|
-
ref: composeRefs(
|
|
110
|
+
ref: composeRefs(ref, popoverRef),
|
|
87
111
|
"data-open": open ? "" : void 0,
|
|
88
112
|
popover: "manual",
|
|
89
113
|
className: classnames(popoverClassName, className),
|
|
@@ -1,3 +1,40 @@
|
|
|
1
1
|
export type PopoverPositions = [x: number, y: number];
|
|
2
|
-
|
|
2
|
+
type PopoverSide = 'top' | 'bottom' | 'left' | 'right';
|
|
3
|
+
type PopoverEdge = 'start' | 'end';
|
|
4
|
+
export type PopoverPlacement = PopoverSide | `${PopoverSide}-${PopoverEdge}`;
|
|
5
|
+
type Rect = {
|
|
6
|
+
top: number;
|
|
7
|
+
left: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
type Margin = {
|
|
12
|
+
top: number;
|
|
13
|
+
right: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
left: number;
|
|
16
|
+
};
|
|
17
|
+
export type ComputePopoverPositionOptions = {
|
|
18
|
+
placement: PopoverPlacement;
|
|
19
|
+
/** The anchor's border box, relative to the viewport */
|
|
20
|
+
anchor: Rect;
|
|
21
|
+
/** The popover's untransformed border-box size and its margins */
|
|
22
|
+
popover: {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
margin: Margin;
|
|
26
|
+
};
|
|
27
|
+
viewport: {
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
scrollX: number;
|
|
31
|
+
scrollY: number;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Returns the popover's `left` and `top`, relative to the document
|
|
36
|
+
*/
|
|
37
|
+
export declare function computePopoverPosition({ placement, anchor, popover, viewport, }: ComputePopoverPositionOptions): PopoverPositions;
|
|
38
|
+
export declare function getPopoverPosition(placement: PopoverPlacement, anchorRef: React.RefObject<HTMLElement | null>, popoverRef: React.RefObject<HTMLElement | null>): PopoverPositions;
|
|
39
|
+
export {};
|
|
3
40
|
//# sourceMappingURL=popover-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-utils.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Popover/popover-utils.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;AAEtD,
|
|
1
|
+
{"version":3,"file":"popover-utils.d.ts","sourceRoot":"","sources":["../../../../src/components/overlay/Popover/popover-utils.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;AAEtD,KAAK,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvD,KAAK,WAAW,GAAG,OAAO,GAAG,KAAK,CAAC;AAEnC,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,GAAG,WAAW,IAAI,WAAW,EAAE,CAAC;AAE7E,KAAK,IAAI,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,KAAK,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,gBAAgB,CAAC;IAC5B,wDAAwD;IACxD,MAAM,EAAE,IAAI,CAAC;IACb,kEAAkE;IAClE,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3D,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/E,CAAC;AAEF;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,SAAS,EACT,MAAM,EACN,OAAO,EACP,QAAQ,GACT,EAAE,6BAA6B,GAAG,gBAAgB,CAyClD;AAoED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,EAC3B,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAC9C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAC9C,gBAAgB,CAyClB"}
|