@blockle/blocks 0.8.8 → 0.8.10
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/index.cjs +79 -738
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +58 -716
- package/dist/momotaro.chunk.d.ts +159 -146
- package/dist/reset.css.d.mts +2 -0
- package/dist/reset.css.d.ts +1 -1
- package/dist/styles/components/display/Divider/Divider.cjs +226 -0
- package/dist/styles/components/display/Divider/Divider.mjs +227 -0
- package/dist/styles/components/{Divider → display/Divider}/divider.css.cjs +2 -2
- package/dist/styles/components/{Divider → display/Divider}/divider.css.mjs +2 -2
- package/dist/styles/components/form/Button/Button.cjs +55 -0
- package/dist/styles/components/{Button → form/Button}/Button.css.cjs +2 -2
- package/dist/styles/components/{Button → form/Button}/Button.css.mjs +2 -2
- package/dist/styles/components/form/Button/Button.mjs +56 -0
- package/dist/styles/components/form/Checkbox/Checkbox.cjs +47 -0
- package/dist/styles/components/form/Checkbox/Checkbox.mjs +48 -0
- package/dist/styles/components/{Checkbox → form/Checkbox}/checkbox.css.cjs +2 -2
- package/dist/styles/components/{Checkbox → form/Checkbox}/checkbox.css.mjs +2 -2
- package/dist/styles/components/form/Input/Input.cjs +27 -0
- package/dist/styles/components/form/Input/Input.mjs +28 -0
- package/dist/styles/components/{Input → form/Input}/input.css.cjs +2 -2
- package/dist/styles/components/{Input → form/Input}/input.css.mjs +2 -2
- package/dist/styles/components/form/Radio/Radio.cjs +23 -0
- package/dist/styles/components/form/Radio/Radio.mjs +24 -0
- package/dist/styles/components/{Radio → form/Radio}/radio.css.cjs +2 -2
- package/dist/styles/components/{Radio → form/Radio}/radio.css.mjs +2 -2
- package/dist/styles/components/form/Switch/Switch.cjs +61 -0
- package/dist/styles/components/form/Switch/Switch.mjs +62 -0
- package/dist/styles/components/{Switch → form/Switch}/switch.css.cjs +2 -2
- package/dist/styles/components/{Switch → form/Switch}/switch.css.mjs +2 -2
- package/dist/styles/components/other/BlocksProvider/BlocksProvider.cjs +20 -0
- package/dist/styles/components/other/BlocksProvider/BlocksProvider.mjs +21 -0
- package/dist/styles/components/overlay/Dialog/Dialog.cjs +245 -0
- package/dist/styles/components/overlay/Dialog/Dialog.mjs +246 -0
- package/dist/styles/components/{Dialog → overlay/Dialog}/dialog.css.cjs +2 -2
- package/dist/styles/components/{Dialog → overlay/Dialog}/dialog.css.mjs +2 -2
- package/dist/styles/components/typography/Heading/Heading.cjs +14 -0
- package/dist/styles/components/typography/Heading/Heading.mjs +15 -0
- package/dist/styles/components/{Heading → typography/Heading}/heading.css.cjs +2 -2
- package/dist/styles/components/{Heading → typography/Heading}/heading.css.mjs +2 -2
- package/dist/styles/components/typography/Text/Text.cjs +9 -0
- package/dist/styles/components/typography/Text/Text.mjs +10 -0
- package/dist/styles/components/{Text → typography/Text}/text.css.cjs +2 -2
- package/dist/styles/components/{Text → typography/Text}/text.css.mjs +2 -2
- package/dist/styles/lib/css/atoms/atoms.cjs +1 -0
- package/dist/styles/lib/css/atoms/atoms.mjs +1 -0
- package/dist/styles/lib/css/atoms/sprinkles.css.cjs +2 -6
- package/dist/styles/lib/css/atoms/sprinkles.css.mjs +2 -6
- package/dist/styles/lib/css/layers/layers.css.cjs +1 -1
- package/dist/styles/lib/css/layers/layers.css.mjs +1 -1
- package/dist/styles/lib/theme/vars.css.cjs +1 -1
- package/dist/styles/lib/theme/vars.css.mjs +1 -1
- package/dist/styles/lib/utils/atom-props.cjs +15 -0
- package/dist/styles/lib/utils/atom-props.mjs +16 -0
- package/dist/styles/themes/momotaro/components/button.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/button.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/checkbox.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/checkbox.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/dialog.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/dialog.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/divider.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/divider.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/dropdown.css.cjs +54 -0
- package/dist/styles/themes/momotaro/components/dropdown.css.mjs +55 -0
- package/dist/styles/themes/momotaro/components/helpers.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/helpers.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/index.cjs +2 -0
- package/dist/styles/themes/momotaro/components/index.mjs +2 -0
- package/dist/styles/themes/momotaro/components/input.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/input.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/label.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/label.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/link.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/link.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/progress.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/progress.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/radio.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/radio.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/spinner.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/spinner.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/switch.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/switch.css.mjs +1 -1
- package/dist/styles/themes/momotaro/index.cjs +1 -0
- package/dist/styles/themes/momotaro/index.mjs +1 -0
- package/dist/styles/themes/momotaro/momotaro.css.cjs +1 -1
- package/dist/styles/themes/momotaro/momotaro.css.mjs +1 -1
- package/dist/styles/themes/momotaro/tokens.css.cjs +1 -1
- package/dist/styles/themes/momotaro/tokens.css.mjs +1 -1
- package/dist/themes/momotaro.d.mts +1 -0
- package/package.json +47 -37
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
|
|
5
|
+
const styles_components_form_Switch_switch_css_cjs = require("./switch.css.cjs");
|
|
6
|
+
const Switch = react.forwardRef(function Switch2({ className, checked, onChange, defaultChecked, ...restProps }, ref) {
|
|
7
|
+
const [isChecked, setIsChecked] = react.useState(defaultChecked || checked || false);
|
|
8
|
+
const baseClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("switch", { base: true });
|
|
9
|
+
const sliderClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("switch", { slider: true }, false);
|
|
10
|
+
react.useEffect(() => {
|
|
11
|
+
if (checked !== void 0) {
|
|
12
|
+
setIsChecked(checked);
|
|
13
|
+
}
|
|
14
|
+
}, [checked]);
|
|
15
|
+
const toggle = react.useCallback(() => {
|
|
16
|
+
setIsChecked((checked2) => {
|
|
17
|
+
const newValue = !checked2;
|
|
18
|
+
if (onChange) {
|
|
19
|
+
onChange(newValue);
|
|
20
|
+
}
|
|
21
|
+
return newValue;
|
|
22
|
+
});
|
|
23
|
+
}, [onChange]);
|
|
24
|
+
const onChangeHandler = react.useCallback(
|
|
25
|
+
(event) => {
|
|
26
|
+
setIsChecked(event.target.checked);
|
|
27
|
+
if (onChange) {
|
|
28
|
+
onChange(event.target.checked);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
[onChange]
|
|
32
|
+
);
|
|
33
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
34
|
+
"div",
|
|
35
|
+
{
|
|
36
|
+
className: styles_components_display_Divider_Divider_cjs.classnames(className, styles_components_form_Switch_switch_css_cjs.container, baseClassName),
|
|
37
|
+
"data-checked": isChecked,
|
|
38
|
+
onClick: (event) => {
|
|
39
|
+
if (event.target.tagName === "INPUT") {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
toggle();
|
|
43
|
+
},
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
46
|
+
"input",
|
|
47
|
+
{
|
|
48
|
+
ref,
|
|
49
|
+
type: "checkbox",
|
|
50
|
+
className: styles_components_form_Switch_switch_css_cjs.input,
|
|
51
|
+
checked: isChecked,
|
|
52
|
+
onChange: onChangeHandler,
|
|
53
|
+
...restProps
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: sliderClassName, "data-checked": isChecked })
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
) });
|
|
60
|
+
});
|
|
61
|
+
exports.Switch = Switch;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useEffect, useCallback } from "react";
|
|
3
|
+
import { useComponentStyles, classnames } from "../../display/Divider/Divider.mjs";
|
|
4
|
+
import { container, input } from "./switch.css.mjs";
|
|
5
|
+
const Switch = forwardRef(function Switch2({ className, checked, onChange, defaultChecked, ...restProps }, ref) {
|
|
6
|
+
const [isChecked, setIsChecked] = useState(defaultChecked || checked || false);
|
|
7
|
+
const baseClassName = useComponentStyles("switch", { base: true });
|
|
8
|
+
const sliderClassName = useComponentStyles("switch", { slider: true }, false);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (checked !== void 0) {
|
|
11
|
+
setIsChecked(checked);
|
|
12
|
+
}
|
|
13
|
+
}, [checked]);
|
|
14
|
+
const toggle = useCallback(() => {
|
|
15
|
+
setIsChecked((checked2) => {
|
|
16
|
+
const newValue = !checked2;
|
|
17
|
+
if (onChange) {
|
|
18
|
+
onChange(newValue);
|
|
19
|
+
}
|
|
20
|
+
return newValue;
|
|
21
|
+
});
|
|
22
|
+
}, [onChange]);
|
|
23
|
+
const onChangeHandler = useCallback(
|
|
24
|
+
(event) => {
|
|
25
|
+
setIsChecked(event.target.checked);
|
|
26
|
+
if (onChange) {
|
|
27
|
+
onChange(event.target.checked);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
[onChange]
|
|
31
|
+
);
|
|
32
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
|
|
33
|
+
"div",
|
|
34
|
+
{
|
|
35
|
+
className: classnames(className, container, baseClassName),
|
|
36
|
+
"data-checked": isChecked,
|
|
37
|
+
onClick: (event) => {
|
|
38
|
+
if (event.target.tagName === "INPUT") {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
toggle();
|
|
42
|
+
},
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsx(
|
|
45
|
+
"input",
|
|
46
|
+
{
|
|
47
|
+
ref,
|
|
48
|
+
type: "checkbox",
|
|
49
|
+
className: input,
|
|
50
|
+
checked: isChecked,
|
|
51
|
+
onChange: onChangeHandler,
|
|
52
|
+
...restProps
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
/* @__PURE__ */ jsx("div", { className: sliderClassName, "data-checked": isChecked })
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
) });
|
|
59
|
+
});
|
|
60
|
+
export {
|
|
61
|
+
Switch
|
|
62
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
|
-
const styles_lib_css_layers_layers_css_cjs = require("
|
|
5
|
-
fileScope.setFileScope("src/components/Switch/switch.css.ts
|
|
4
|
+
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Switch/switch.css.ts", "blocks");
|
|
6
6
|
const container = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
|
-
import { blocksLayer } from "
|
|
4
|
-
setFileScope("src/components/Switch/switch.css.ts
|
|
3
|
+
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
+
setFileScope("src/components/form/Switch/switch.css.ts", "blocks");
|
|
5
5
|
const container = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const styles_lib_css_atoms_sprinkles_css_cjs = require("../../../lib/css/atoms/sprinkles.css.cjs");
|
|
4
|
+
const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
|
|
5
|
+
const BlocksProvider = ({
|
|
6
|
+
children,
|
|
7
|
+
theme,
|
|
8
|
+
className,
|
|
9
|
+
...restProps
|
|
10
|
+
}) => {
|
|
11
|
+
return /* @__PURE__ */ jsxRuntime.jsx(styles_components_display_Divider_Divider_cjs.BlocksProviderContext.Provider, { value: theme, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12
|
+
"div",
|
|
13
|
+
{
|
|
14
|
+
className: styles_components_display_Divider_Divider_cjs.classnames(theme.vars, styles_lib_css_atoms_sprinkles_css_cjs.atoms({ fontFamily: "primary" }), className),
|
|
15
|
+
...restProps,
|
|
16
|
+
children
|
|
17
|
+
}
|
|
18
|
+
) });
|
|
19
|
+
};
|
|
20
|
+
exports.BlocksProvider = BlocksProvider;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { atoms } from "../../../lib/css/atoms/sprinkles.css.mjs";
|
|
3
|
+
import { BlocksProviderContext, classnames } from "../../display/Divider/Divider.mjs";
|
|
4
|
+
const BlocksProvider = ({
|
|
5
|
+
children,
|
|
6
|
+
theme,
|
|
7
|
+
className,
|
|
8
|
+
...restProps
|
|
9
|
+
}) => {
|
|
10
|
+
return /* @__PURE__ */ jsx(BlocksProviderContext.Provider, { value: theme, children: /* @__PURE__ */ jsx(
|
|
11
|
+
"div",
|
|
12
|
+
{
|
|
13
|
+
className: classnames(theme.vars, atoms({ fontFamily: "primary" }), className),
|
|
14
|
+
...restProps,
|
|
15
|
+
children
|
|
16
|
+
}
|
|
17
|
+
) });
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
BlocksProvider
|
|
21
|
+
};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
|
|
5
|
+
const styles_components_overlay_Dialog_dialog_css_cjs = require("./dialog.css.cjs");
|
|
6
|
+
const reactDom = require("react-dom");
|
|
7
|
+
const styles_components_other_BlocksProvider_BlocksProvider_cjs = require("../../other/BlocksProvider/BlocksProvider.cjs");
|
|
8
|
+
const Portal = ({ children, container }) => {
|
|
9
|
+
const context = styles_components_display_Divider_Divider_cjs.useTheme();
|
|
10
|
+
return reactDom.createPortal(
|
|
11
|
+
/* @__PURE__ */ jsxRuntime.jsx(styles_components_other_BlocksProvider_BlocksProvider_cjs.BlocksProvider, { theme: context, children }),
|
|
12
|
+
container || document.body
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
const focusableSelectors = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
16
|
+
const getFirstFocusableElement = (container) => {
|
|
17
|
+
const focusable = container.querySelector(focusableSelectors);
|
|
18
|
+
return focusable || null;
|
|
19
|
+
};
|
|
20
|
+
const focusFirstElement = (container) => {
|
|
21
|
+
const focusable = getFirstFocusableElement(container);
|
|
22
|
+
if (focusable) {
|
|
23
|
+
focusable.focus();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const useFocusLock = ({ ref, active }) => {
|
|
27
|
+
react.useEffect(() => {
|
|
28
|
+
if (!active) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const handleFocus = (event) => {
|
|
32
|
+
if (ref.current && event.target instanceof HTMLElement && !ref.current.contains(event.target)) {
|
|
33
|
+
focusFirstElement(ref.current);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
document.addEventListener("focusin", handleFocus);
|
|
37
|
+
return () => {
|
|
38
|
+
document.removeEventListener("focusin", handleFocus);
|
|
39
|
+
};
|
|
40
|
+
}, [active, ref]);
|
|
41
|
+
};
|
|
42
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
43
|
+
const useKeyboard = (key, callback, { enabled = true, type = "keydown" } = {}) => {
|
|
44
|
+
react.useEffect(() => {
|
|
45
|
+
if (!enabled) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
function handleKeyDown(event) {
|
|
49
|
+
if (event.key === key) {
|
|
50
|
+
callback();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
document.addEventListener(type, handleKeyDown);
|
|
54
|
+
return () => {
|
|
55
|
+
document.removeEventListener(type, handleKeyDown);
|
|
56
|
+
};
|
|
57
|
+
}, [callback, enabled, key, type]);
|
|
58
|
+
};
|
|
59
|
+
const useLayer = () => {
|
|
60
|
+
const layerRef = react.useRef();
|
|
61
|
+
react.useEffect(
|
|
62
|
+
() => () => {
|
|
63
|
+
if (layerRef.current) {
|
|
64
|
+
layerRef.current.remove();
|
|
65
|
+
layerRef.current = void 0;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
[]
|
|
69
|
+
);
|
|
70
|
+
return () => {
|
|
71
|
+
if (!layerRef.current) {
|
|
72
|
+
const div = document.createElement("div");
|
|
73
|
+
div.dataset.layer = "blocks";
|
|
74
|
+
layerRef.current = div;
|
|
75
|
+
document.body.append(layerRef.current);
|
|
76
|
+
}
|
|
77
|
+
return layerRef.current;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const usePreventBodyScroll = (enabled = true) => {
|
|
81
|
+
useIsomorphicLayoutEffect(() => {
|
|
82
|
+
if (!enabled) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const prevOverflow = document.body.style.getPropertyValue("overflow");
|
|
86
|
+
const prevScrollTop = document.documentElement.scrollTop;
|
|
87
|
+
if (document.body.scrollHeight > window.innerHeight) {
|
|
88
|
+
document.body.style.position = "fixed";
|
|
89
|
+
document.body.style.overflow = "hidden";
|
|
90
|
+
document.body.style.overflowY = "scroll";
|
|
91
|
+
document.body.style.width = "100%";
|
|
92
|
+
document.body.style.top = `-${prevScrollTop}px`;
|
|
93
|
+
} else {
|
|
94
|
+
document.body.style.overflow = "hidden";
|
|
95
|
+
}
|
|
96
|
+
return () => {
|
|
97
|
+
document.body.style.position = "";
|
|
98
|
+
document.body.style.overflow = prevOverflow;
|
|
99
|
+
document.body.style.overflowY = "";
|
|
100
|
+
document.body.style.width = "";
|
|
101
|
+
document.body.style.top = "";
|
|
102
|
+
document.documentElement.scrollTop = prevScrollTop;
|
|
103
|
+
};
|
|
104
|
+
}, [enabled]);
|
|
105
|
+
};
|
|
106
|
+
const isBrowser = typeof window !== "undefined";
|
|
107
|
+
const useRestoreFocus = (active) => {
|
|
108
|
+
const target = react.useRef(null);
|
|
109
|
+
if (isBrowser && active && !target.current) {
|
|
110
|
+
target.current = document.activeElement;
|
|
111
|
+
}
|
|
112
|
+
react.useEffect(() => {
|
|
113
|
+
if (target.current && !active && target.current instanceof HTMLElement) {
|
|
114
|
+
target.current.focus();
|
|
115
|
+
}
|
|
116
|
+
if (!active) {
|
|
117
|
+
target.current = null;
|
|
118
|
+
}
|
|
119
|
+
}, [active]);
|
|
120
|
+
};
|
|
121
|
+
const useVisibilityState = (open) => {
|
|
122
|
+
const [visible, setVisible] = react.useState(open);
|
|
123
|
+
const hide = react.useCallback(() => {
|
|
124
|
+
setVisible(false);
|
|
125
|
+
}, []);
|
|
126
|
+
react.useEffect(() => {
|
|
127
|
+
if (open) {
|
|
128
|
+
setVisible(true);
|
|
129
|
+
}
|
|
130
|
+
}, [open]);
|
|
131
|
+
return [visible, hide];
|
|
132
|
+
};
|
|
133
|
+
function hasAnimationDuration(element) {
|
|
134
|
+
if (!element) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
const style = window.getComputedStyle(element);
|
|
138
|
+
return style.transitionDuration !== "0s" || style.animationDuration !== "0s";
|
|
139
|
+
}
|
|
140
|
+
const DialogContext = react.createContext(void 0);
|
|
141
|
+
const useNestedDialog = (open) => {
|
|
142
|
+
const parentDialog = react.useContext(DialogContext);
|
|
143
|
+
react.useEffect(() => {
|
|
144
|
+
if (!parentDialog || !open) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
parentDialog.setEnabled(false);
|
|
148
|
+
return () => {
|
|
149
|
+
parentDialog.setEnabled(true);
|
|
150
|
+
};
|
|
151
|
+
}, [parentDialog, open]);
|
|
152
|
+
return !!parentDialog;
|
|
153
|
+
};
|
|
154
|
+
const Dialog = ({
|
|
155
|
+
children,
|
|
156
|
+
open,
|
|
157
|
+
className,
|
|
158
|
+
onRequestClose,
|
|
159
|
+
size,
|
|
160
|
+
...restProps
|
|
161
|
+
}) => {
|
|
162
|
+
const backdropClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("dialog", { backdrop: true }, false);
|
|
163
|
+
const dialogClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("dialog", { dialog: true, variants: { size } });
|
|
164
|
+
const backdropRef = react.useRef(null);
|
|
165
|
+
const dialogRef = react.useRef(null);
|
|
166
|
+
const layer = useLayer();
|
|
167
|
+
const [visible, hide] = useVisibilityState(open);
|
|
168
|
+
const [enabled, setEnabled] = react.useState(true);
|
|
169
|
+
const onBackdropClick = react.useCallback(
|
|
170
|
+
(event) => {
|
|
171
|
+
if (event.target === event.currentTarget) {
|
|
172
|
+
onRequestClose();
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
[onRequestClose]
|
|
176
|
+
);
|
|
177
|
+
useFocusLock({ ref: dialogRef, active: open && enabled });
|
|
178
|
+
useRestoreFocus(open);
|
|
179
|
+
const isNested = useNestedDialog(visible);
|
|
180
|
+
usePreventBodyScroll(visible && !isNested);
|
|
181
|
+
useKeyboard("Escape", onRequestClose, { enabled: open && enabled });
|
|
182
|
+
useIsomorphicLayoutEffect(() => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
if (!open) {
|
|
185
|
+
(_a = backdropRef.current) == null ? void 0 : _a.removeAttribute("data-open");
|
|
186
|
+
(_b = dialogRef.current) == null ? void 0 : _b.removeAttribute("data-open");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
let timer = requestAnimationFrame(() => {
|
|
190
|
+
timer = requestAnimationFrame(() => {
|
|
191
|
+
var _a2, _b2;
|
|
192
|
+
(_a2 = backdropRef.current) == null ? void 0 : _a2.setAttribute("data-open", "");
|
|
193
|
+
(_b2 = dialogRef.current) == null ? void 0 : _b2.setAttribute("data-open", "");
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
return () => {
|
|
197
|
+
cancelAnimationFrame(timer);
|
|
198
|
+
};
|
|
199
|
+
}, [open, visible]);
|
|
200
|
+
const onAnimationEnd = react.useCallback(() => {
|
|
201
|
+
if (!open) {
|
|
202
|
+
hide();
|
|
203
|
+
}
|
|
204
|
+
}, [hide, open]);
|
|
205
|
+
react.useEffect(() => {
|
|
206
|
+
if (open) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!hasAnimationDuration(dialogRef.current)) {
|
|
210
|
+
hide();
|
|
211
|
+
}
|
|
212
|
+
}, [hide, open]);
|
|
213
|
+
if (!visible) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
const dataOpen = typeof window === "undefined" && open ? "" : void 0;
|
|
217
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsxRuntime.jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
218
|
+
styles_components_display_Divider_Divider_cjs.Box,
|
|
219
|
+
{
|
|
220
|
+
ref: backdropRef,
|
|
221
|
+
className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_overlay_Dialog_dialog_css_cjs.backdrop, backdropClassName),
|
|
222
|
+
"data-open": dataOpen,
|
|
223
|
+
onClick: onBackdropClick,
|
|
224
|
+
onAnimationEnd,
|
|
225
|
+
onTransitionEnd: onAnimationEnd,
|
|
226
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
227
|
+
"dialog",
|
|
228
|
+
{
|
|
229
|
+
ref: dialogRef,
|
|
230
|
+
"aria-modal": "true",
|
|
231
|
+
open: true,
|
|
232
|
+
"data-open": dataOpen,
|
|
233
|
+
className: styles_components_display_Divider_Divider_cjs.classnames(dialogClassName, className),
|
|
234
|
+
...restProps,
|
|
235
|
+
children
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
) }) });
|
|
240
|
+
};
|
|
241
|
+
exports.Dialog = Dialog;
|
|
242
|
+
exports.Portal = Portal;
|
|
243
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
244
|
+
exports.useKeyboard = useKeyboard;
|
|
245
|
+
exports.usePreventBodyScroll = usePreventBodyScroll;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState, useCallback, createContext, useContext } from "react";
|
|
3
|
+
import { useTheme, useComponentStyles, Box, classnames } from "../../display/Divider/Divider.mjs";
|
|
4
|
+
import { backdrop } from "./dialog.css.mjs";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import { BlocksProvider } from "../../other/BlocksProvider/BlocksProvider.mjs";
|
|
7
|
+
const Portal = ({ children, container }) => {
|
|
8
|
+
const context = useTheme();
|
|
9
|
+
return createPortal(
|
|
10
|
+
/* @__PURE__ */ jsx(BlocksProvider, { theme: context, children }),
|
|
11
|
+
container || document.body
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
const focusableSelectors = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
15
|
+
const getFirstFocusableElement = (container) => {
|
|
16
|
+
const focusable = container.querySelector(focusableSelectors);
|
|
17
|
+
return focusable || null;
|
|
18
|
+
};
|
|
19
|
+
const focusFirstElement = (container) => {
|
|
20
|
+
const focusable = getFirstFocusableElement(container);
|
|
21
|
+
if (focusable) {
|
|
22
|
+
focusable.focus();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const useFocusLock = ({ ref, active }) => {
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!active) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const handleFocus = (event) => {
|
|
31
|
+
if (ref.current && event.target instanceof HTMLElement && !ref.current.contains(event.target)) {
|
|
32
|
+
focusFirstElement(ref.current);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
document.addEventListener("focusin", handleFocus);
|
|
36
|
+
return () => {
|
|
37
|
+
document.removeEventListener("focusin", handleFocus);
|
|
38
|
+
};
|
|
39
|
+
}, [active, ref]);
|
|
40
|
+
};
|
|
41
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
42
|
+
const useKeyboard = (key, callback, { enabled = true, type = "keydown" } = {}) => {
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!enabled) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
function handleKeyDown(event) {
|
|
48
|
+
if (event.key === key) {
|
|
49
|
+
callback();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
document.addEventListener(type, handleKeyDown);
|
|
53
|
+
return () => {
|
|
54
|
+
document.removeEventListener(type, handleKeyDown);
|
|
55
|
+
};
|
|
56
|
+
}, [callback, enabled, key, type]);
|
|
57
|
+
};
|
|
58
|
+
const useLayer = () => {
|
|
59
|
+
const layerRef = useRef();
|
|
60
|
+
useEffect(
|
|
61
|
+
() => () => {
|
|
62
|
+
if (layerRef.current) {
|
|
63
|
+
layerRef.current.remove();
|
|
64
|
+
layerRef.current = void 0;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[]
|
|
68
|
+
);
|
|
69
|
+
return () => {
|
|
70
|
+
if (!layerRef.current) {
|
|
71
|
+
const div = document.createElement("div");
|
|
72
|
+
div.dataset.layer = "blocks";
|
|
73
|
+
layerRef.current = div;
|
|
74
|
+
document.body.append(layerRef.current);
|
|
75
|
+
}
|
|
76
|
+
return layerRef.current;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const usePreventBodyScroll = (enabled = true) => {
|
|
80
|
+
useIsomorphicLayoutEffect(() => {
|
|
81
|
+
if (!enabled) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const prevOverflow = document.body.style.getPropertyValue("overflow");
|
|
85
|
+
const prevScrollTop = document.documentElement.scrollTop;
|
|
86
|
+
if (document.body.scrollHeight > window.innerHeight) {
|
|
87
|
+
document.body.style.position = "fixed";
|
|
88
|
+
document.body.style.overflow = "hidden";
|
|
89
|
+
document.body.style.overflowY = "scroll";
|
|
90
|
+
document.body.style.width = "100%";
|
|
91
|
+
document.body.style.top = `-${prevScrollTop}px`;
|
|
92
|
+
} else {
|
|
93
|
+
document.body.style.overflow = "hidden";
|
|
94
|
+
}
|
|
95
|
+
return () => {
|
|
96
|
+
document.body.style.position = "";
|
|
97
|
+
document.body.style.overflow = prevOverflow;
|
|
98
|
+
document.body.style.overflowY = "";
|
|
99
|
+
document.body.style.width = "";
|
|
100
|
+
document.body.style.top = "";
|
|
101
|
+
document.documentElement.scrollTop = prevScrollTop;
|
|
102
|
+
};
|
|
103
|
+
}, [enabled]);
|
|
104
|
+
};
|
|
105
|
+
const isBrowser = typeof window !== "undefined";
|
|
106
|
+
const useRestoreFocus = (active) => {
|
|
107
|
+
const target = useRef(null);
|
|
108
|
+
if (isBrowser && active && !target.current) {
|
|
109
|
+
target.current = document.activeElement;
|
|
110
|
+
}
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (target.current && !active && target.current instanceof HTMLElement) {
|
|
113
|
+
target.current.focus();
|
|
114
|
+
}
|
|
115
|
+
if (!active) {
|
|
116
|
+
target.current = null;
|
|
117
|
+
}
|
|
118
|
+
}, [active]);
|
|
119
|
+
};
|
|
120
|
+
const useVisibilityState = (open) => {
|
|
121
|
+
const [visible, setVisible] = useState(open);
|
|
122
|
+
const hide = useCallback(() => {
|
|
123
|
+
setVisible(false);
|
|
124
|
+
}, []);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (open) {
|
|
127
|
+
setVisible(true);
|
|
128
|
+
}
|
|
129
|
+
}, [open]);
|
|
130
|
+
return [visible, hide];
|
|
131
|
+
};
|
|
132
|
+
function hasAnimationDuration(element) {
|
|
133
|
+
if (!element) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
const style = window.getComputedStyle(element);
|
|
137
|
+
return style.transitionDuration !== "0s" || style.animationDuration !== "0s";
|
|
138
|
+
}
|
|
139
|
+
const DialogContext = createContext(void 0);
|
|
140
|
+
const useNestedDialog = (open) => {
|
|
141
|
+
const parentDialog = useContext(DialogContext);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (!parentDialog || !open) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
parentDialog.setEnabled(false);
|
|
147
|
+
return () => {
|
|
148
|
+
parentDialog.setEnabled(true);
|
|
149
|
+
};
|
|
150
|
+
}, [parentDialog, open]);
|
|
151
|
+
return !!parentDialog;
|
|
152
|
+
};
|
|
153
|
+
const Dialog = ({
|
|
154
|
+
children,
|
|
155
|
+
open,
|
|
156
|
+
className,
|
|
157
|
+
onRequestClose,
|
|
158
|
+
size,
|
|
159
|
+
...restProps
|
|
160
|
+
}) => {
|
|
161
|
+
const backdropClassName = useComponentStyles("dialog", { backdrop: true }, false);
|
|
162
|
+
const dialogClassName = useComponentStyles("dialog", { dialog: true, variants: { size } });
|
|
163
|
+
const backdropRef = useRef(null);
|
|
164
|
+
const dialogRef = useRef(null);
|
|
165
|
+
const layer = useLayer();
|
|
166
|
+
const [visible, hide] = useVisibilityState(open);
|
|
167
|
+
const [enabled, setEnabled] = useState(true);
|
|
168
|
+
const onBackdropClick = useCallback(
|
|
169
|
+
(event) => {
|
|
170
|
+
if (event.target === event.currentTarget) {
|
|
171
|
+
onRequestClose();
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
[onRequestClose]
|
|
175
|
+
);
|
|
176
|
+
useFocusLock({ ref: dialogRef, active: open && enabled });
|
|
177
|
+
useRestoreFocus(open);
|
|
178
|
+
const isNested = useNestedDialog(visible);
|
|
179
|
+
usePreventBodyScroll(visible && !isNested);
|
|
180
|
+
useKeyboard("Escape", onRequestClose, { enabled: open && enabled });
|
|
181
|
+
useIsomorphicLayoutEffect(() => {
|
|
182
|
+
var _a, _b;
|
|
183
|
+
if (!open) {
|
|
184
|
+
(_a = backdropRef.current) == null ? void 0 : _a.removeAttribute("data-open");
|
|
185
|
+
(_b = dialogRef.current) == null ? void 0 : _b.removeAttribute("data-open");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
let timer = requestAnimationFrame(() => {
|
|
189
|
+
timer = requestAnimationFrame(() => {
|
|
190
|
+
var _a2, _b2;
|
|
191
|
+
(_a2 = backdropRef.current) == null ? void 0 : _a2.setAttribute("data-open", "");
|
|
192
|
+
(_b2 = dialogRef.current) == null ? void 0 : _b2.setAttribute("data-open", "");
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
return () => {
|
|
196
|
+
cancelAnimationFrame(timer);
|
|
197
|
+
};
|
|
198
|
+
}, [open, visible]);
|
|
199
|
+
const onAnimationEnd = useCallback(() => {
|
|
200
|
+
if (!open) {
|
|
201
|
+
hide();
|
|
202
|
+
}
|
|
203
|
+
}, [hide, open]);
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (open) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!hasAnimationDuration(dialogRef.current)) {
|
|
209
|
+
hide();
|
|
210
|
+
}
|
|
211
|
+
}, [hide, open]);
|
|
212
|
+
if (!visible) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const dataOpen = typeof window === "undefined" && open ? "" : void 0;
|
|
216
|
+
return /* @__PURE__ */ jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsx(
|
|
217
|
+
Box,
|
|
218
|
+
{
|
|
219
|
+
ref: backdropRef,
|
|
220
|
+
className: classnames(backdrop, backdropClassName),
|
|
221
|
+
"data-open": dataOpen,
|
|
222
|
+
onClick: onBackdropClick,
|
|
223
|
+
onAnimationEnd,
|
|
224
|
+
onTransitionEnd: onAnimationEnd,
|
|
225
|
+
children: /* @__PURE__ */ jsx(
|
|
226
|
+
"dialog",
|
|
227
|
+
{
|
|
228
|
+
ref: dialogRef,
|
|
229
|
+
"aria-modal": "true",
|
|
230
|
+
open: true,
|
|
231
|
+
"data-open": dataOpen,
|
|
232
|
+
className: classnames(dialogClassName, className),
|
|
233
|
+
...restProps,
|
|
234
|
+
children
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
) }) });
|
|
239
|
+
};
|
|
240
|
+
export {
|
|
241
|
+
Dialog,
|
|
242
|
+
Portal,
|
|
243
|
+
useIsomorphicLayoutEffect,
|
|
244
|
+
useKeyboard,
|
|
245
|
+
usePreventBodyScroll
|
|
246
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
|
-
const styles_lib_css_layers_layers_css_cjs = require("
|
|
5
|
-
fileScope.setFileScope("src/components/Dialog/dialog.css.ts
|
|
4
|
+
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
+
fileScope.setFileScope("src/components/overlay/Dialog/dialog.css.ts", "blocks");
|
|
6
6
|
const backdrop = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|