@blockle/blocks 0.12.1 → 0.13.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/dist/index.cjs +5 -22
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +8 -25
- package/dist/momotaro.chunk.d.ts +297 -279
- package/dist/styles/components/display/Divider/Divider.cjs +43 -59
- package/dist/styles/components/display/Divider/Divider.mjs +43 -59
- package/dist/styles/components/form/Button/Button.cjs +4 -4
- package/dist/styles/components/form/Button/Button.mjs +3 -3
- package/dist/styles/components/overlay/Dialog/Dialog.cjs +18 -21
- package/dist/styles/components/overlay/Dialog/Dialog.mjs +18 -21
- package/dist/styles/themes/momotaro/components/divider.css.cjs +4 -0
- package/dist/styles/themes/momotaro/components/divider.css.mjs +4 -0
- package/package.json +1 -2
|
@@ -88,20 +88,6 @@ const classnames = (...args) => {
|
|
|
88
88
|
const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
|
|
89
89
|
return className || void 0;
|
|
90
90
|
};
|
|
91
|
-
function setRef(ref, value) {
|
|
92
|
-
if (typeof ref === "function") {
|
|
93
|
-
ref(value);
|
|
94
|
-
} else if (ref !== null && ref !== void 0) {
|
|
95
|
-
ref.current = value;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function composeRefs(...refs) {
|
|
99
|
-
return (node) => {
|
|
100
|
-
for (const ref of refs) {
|
|
101
|
-
setRef(ref, node);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
91
|
function mergeProps(slotProps, childProps) {
|
|
106
92
|
const overrideProps = {};
|
|
107
93
|
for (const propName in childProps) {
|
|
@@ -122,82 +108,81 @@ function mergeProps(slotProps, childProps) {
|
|
|
122
108
|
} else if (propName === "style") {
|
|
123
109
|
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
124
110
|
} else if (propName === "className") {
|
|
125
|
-
overrideProps[propName] =
|
|
111
|
+
overrideProps[propName] = classnames(slotPropValue, childPropValue);
|
|
126
112
|
} else {
|
|
127
113
|
overrideProps[propName] = childPropValue;
|
|
128
114
|
}
|
|
129
115
|
}
|
|
130
116
|
return { ...slotProps, ...overrideProps };
|
|
131
117
|
}
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
118
|
+
function setRef(ref, value) {
|
|
119
|
+
if (typeof ref === "function") {
|
|
120
|
+
ref(value);
|
|
121
|
+
} else if (ref !== null && ref !== void 0) {
|
|
122
|
+
ref.current = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function composeRefs(...refs) {
|
|
126
|
+
return (node) => {
|
|
127
|
+
for (const ref of refs) {
|
|
128
|
+
setRef(ref, node);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function createAsChildTemplate(defaultElement) {
|
|
133
|
+
const Tag = defaultElement;
|
|
134
|
+
const Template2 = react.forwardRef(function Template22({ asChild, children, ...rootProps }, ref) {
|
|
136
135
|
if (!asChild) {
|
|
137
|
-
|
|
136
|
+
const tagProps = { ref, ...rootProps };
|
|
137
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { ...tagProps, children });
|
|
138
138
|
}
|
|
139
139
|
const childrenArray = react.Children.toArray(children);
|
|
140
|
-
const
|
|
140
|
+
const slotIndex = childrenArray.findIndex((child) => {
|
|
141
141
|
if (!react.isValidElement(child)) {
|
|
142
142
|
return false;
|
|
143
143
|
}
|
|
144
|
-
return child.type === Slot;
|
|
144
|
+
return child.type === Slot$1;
|
|
145
145
|
});
|
|
146
|
+
const slot = childrenArray[slotIndex];
|
|
146
147
|
if (!slot) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (process.env.NODE_ENV === "development") {
|
|
150
|
-
console.warn("Slottable: First child is not a valid React element");
|
|
151
|
-
}
|
|
152
|
-
return null;
|
|
148
|
+
if (process.env.NODE_ENV === "development") {
|
|
149
|
+
console.error("Template: No Slot provided");
|
|
153
150
|
}
|
|
154
|
-
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
return react.cloneElement(
|
|
158
|
-
Slot2,
|
|
159
|
-
{
|
|
160
|
-
...mergeProps(slotProps, Slot2.props),
|
|
161
|
-
ref: composeRefs(ref, Slot2.ref)
|
|
162
|
-
},
|
|
163
|
-
Slot2.props.children
|
|
164
|
-
);
|
|
151
|
+
return null;
|
|
165
152
|
}
|
|
166
153
|
if (!react.isValidElement(slot) || !react.isValidElement(slot.props.children)) {
|
|
167
154
|
return null;
|
|
168
155
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
return child;
|
|
172
|
-
}
|
|
173
|
-
if (child.type === Slot) {
|
|
174
|
-
return slot.props.children.props.children;
|
|
175
|
-
}
|
|
176
|
-
return child;
|
|
177
|
-
});
|
|
156
|
+
const nextChildren = [...childrenArray];
|
|
157
|
+
nextChildren[slotIndex] = slot.props.children.props.children;
|
|
178
158
|
return react.cloneElement(
|
|
179
159
|
slot.props.children,
|
|
180
160
|
{
|
|
181
|
-
...mergeProps(
|
|
161
|
+
...mergeProps(rootProps, slot.props.children.props),
|
|
182
162
|
ref: composeRefs(ref, slot.props.children.ref)
|
|
183
163
|
},
|
|
184
|
-
|
|
164
|
+
nextChildren
|
|
185
165
|
);
|
|
186
|
-
}
|
|
187
|
-
return
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
Template: Template2,
|
|
169
|
+
Slot: Slot$1
|
|
170
|
+
};
|
|
188
171
|
}
|
|
189
|
-
const Slot = ({ children }) =>
|
|
190
|
-
|
|
172
|
+
const Slot$1 = ({ children }) => {
|
|
173
|
+
return children;
|
|
174
|
+
};
|
|
175
|
+
const { Template, Slot } = createAsChildTemplate("div");
|
|
191
176
|
const Box = react.forwardRef(function Box2({ asChild, className, children, ...restProps }, ref) {
|
|
192
177
|
const [atomsProps, otherProps] = styles_lib_utils_atomProps_cjs.getAtomsAndProps(restProps);
|
|
193
178
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
194
|
-
|
|
179
|
+
Template,
|
|
195
180
|
{
|
|
196
181
|
ref,
|
|
197
182
|
asChild,
|
|
198
183
|
className: classnames(className, styles_lib_css_atoms_sprinkles_css_cjs.atoms(atomsProps)),
|
|
199
184
|
...otherProps,
|
|
200
|
-
children
|
|
185
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Slot, { children })
|
|
201
186
|
}
|
|
202
187
|
);
|
|
203
188
|
});
|
|
@@ -208,7 +193,7 @@ const Divider = ({ className, color, ...restProps }) => {
|
|
|
208
193
|
Box,
|
|
209
194
|
{
|
|
210
195
|
role: "separator",
|
|
211
|
-
|
|
196
|
+
inlineSize: "full",
|
|
212
197
|
backgroundColor: color ?? dividerDefaults.color,
|
|
213
198
|
className: classnames(className, dividerClass, styles_components_display_Divider_divider_css_cjs.divider),
|
|
214
199
|
...restProps
|
|
@@ -218,10 +203,9 @@ const Divider = ({ className, color, ...restProps }) => {
|
|
|
218
203
|
exports.BlocksProviderContext = BlocksProviderContext;
|
|
219
204
|
exports.Box = Box;
|
|
220
205
|
exports.Divider = Divider;
|
|
221
|
-
exports.Slot = Slot;
|
|
222
206
|
exports.classnames = classnames;
|
|
223
207
|
exports.composeRefs = composeRefs;
|
|
224
|
-
exports.
|
|
208
|
+
exports.createAsChildTemplate = createAsChildTemplate;
|
|
225
209
|
exports.useComponentStyleDefaultProps = useComponentStyleDefaultProps;
|
|
226
210
|
exports.useComponentStyles = useComponentStyles;
|
|
227
211
|
exports.useTheme = useTheme;
|
|
@@ -87,20 +87,6 @@ const classnames = (...args) => {
|
|
|
87
87
|
const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
|
|
88
88
|
return className || void 0;
|
|
89
89
|
};
|
|
90
|
-
function setRef(ref, value) {
|
|
91
|
-
if (typeof ref === "function") {
|
|
92
|
-
ref(value);
|
|
93
|
-
} else if (ref !== null && ref !== void 0) {
|
|
94
|
-
ref.current = value;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function composeRefs(...refs) {
|
|
98
|
-
return (node) => {
|
|
99
|
-
for (const ref of refs) {
|
|
100
|
-
setRef(ref, node);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
90
|
function mergeProps(slotProps, childProps) {
|
|
105
91
|
const overrideProps = {};
|
|
106
92
|
for (const propName in childProps) {
|
|
@@ -121,82 +107,81 @@ function mergeProps(slotProps, childProps) {
|
|
|
121
107
|
} else if (propName === "style") {
|
|
122
108
|
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
123
109
|
} else if (propName === "className") {
|
|
124
|
-
overrideProps[propName] =
|
|
110
|
+
overrideProps[propName] = classnames(slotPropValue, childPropValue);
|
|
125
111
|
} else {
|
|
126
112
|
overrideProps[propName] = childPropValue;
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
115
|
return { ...slotProps, ...overrideProps };
|
|
130
116
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
117
|
+
function setRef(ref, value) {
|
|
118
|
+
if (typeof ref === "function") {
|
|
119
|
+
ref(value);
|
|
120
|
+
} else if (ref !== null && ref !== void 0) {
|
|
121
|
+
ref.current = value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function composeRefs(...refs) {
|
|
125
|
+
return (node) => {
|
|
126
|
+
for (const ref of refs) {
|
|
127
|
+
setRef(ref, node);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function createAsChildTemplate(defaultElement) {
|
|
132
|
+
const Tag = defaultElement;
|
|
133
|
+
const Template2 = forwardRef(function Template22({ asChild, children, ...rootProps }, ref) {
|
|
135
134
|
if (!asChild) {
|
|
136
|
-
|
|
135
|
+
const tagProps = { ref, ...rootProps };
|
|
136
|
+
return /* @__PURE__ */ jsx(Tag, { ...tagProps, children });
|
|
137
137
|
}
|
|
138
138
|
const childrenArray = Children.toArray(children);
|
|
139
|
-
const
|
|
139
|
+
const slotIndex = childrenArray.findIndex((child) => {
|
|
140
140
|
if (!isValidElement(child)) {
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
|
-
return child.type === Slot;
|
|
143
|
+
return child.type === Slot$1;
|
|
144
144
|
});
|
|
145
|
+
const slot = childrenArray[slotIndex];
|
|
145
146
|
if (!slot) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (process.env.NODE_ENV === "development") {
|
|
149
|
-
console.warn("Slottable: First child is not a valid React element");
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
147
|
+
if (process.env.NODE_ENV === "development") {
|
|
148
|
+
console.error("Template: No Slot provided");
|
|
152
149
|
}
|
|
153
|
-
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
return cloneElement(
|
|
157
|
-
Slot2,
|
|
158
|
-
{
|
|
159
|
-
...mergeProps(slotProps, Slot2.props),
|
|
160
|
-
ref: composeRefs(ref, Slot2.ref)
|
|
161
|
-
},
|
|
162
|
-
Slot2.props.children
|
|
163
|
-
);
|
|
150
|
+
return null;
|
|
164
151
|
}
|
|
165
152
|
if (!isValidElement(slot) || !isValidElement(slot.props.children)) {
|
|
166
153
|
return null;
|
|
167
154
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
return child;
|
|
171
|
-
}
|
|
172
|
-
if (child.type === Slot) {
|
|
173
|
-
return slot.props.children.props.children;
|
|
174
|
-
}
|
|
175
|
-
return child;
|
|
176
|
-
});
|
|
155
|
+
const nextChildren = [...childrenArray];
|
|
156
|
+
nextChildren[slotIndex] = slot.props.children.props.children;
|
|
177
157
|
return cloneElement(
|
|
178
158
|
slot.props.children,
|
|
179
159
|
{
|
|
180
|
-
...mergeProps(
|
|
160
|
+
...mergeProps(rootProps, slot.props.children.props),
|
|
181
161
|
ref: composeRefs(ref, slot.props.children.ref)
|
|
182
162
|
},
|
|
183
|
-
|
|
163
|
+
nextChildren
|
|
184
164
|
);
|
|
185
|
-
}
|
|
186
|
-
return
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
Template: Template2,
|
|
168
|
+
Slot: Slot$1
|
|
169
|
+
};
|
|
187
170
|
}
|
|
188
|
-
const Slot = ({ children }) =>
|
|
189
|
-
|
|
171
|
+
const Slot$1 = ({ children }) => {
|
|
172
|
+
return children;
|
|
173
|
+
};
|
|
174
|
+
const { Template, Slot } = createAsChildTemplate("div");
|
|
190
175
|
const Box = forwardRef(function Box2({ asChild, className, children, ...restProps }, ref) {
|
|
191
176
|
const [atomsProps, otherProps] = getAtomsAndProps(restProps);
|
|
192
177
|
return /* @__PURE__ */ jsx(
|
|
193
|
-
|
|
178
|
+
Template,
|
|
194
179
|
{
|
|
195
180
|
ref,
|
|
196
181
|
asChild,
|
|
197
182
|
className: classnames(className, atoms(atomsProps)),
|
|
198
183
|
...otherProps,
|
|
199
|
-
children
|
|
184
|
+
children: /* @__PURE__ */ jsx(Slot, { children })
|
|
200
185
|
}
|
|
201
186
|
);
|
|
202
187
|
});
|
|
@@ -207,7 +192,7 @@ const Divider = ({ className, color, ...restProps }) => {
|
|
|
207
192
|
Box,
|
|
208
193
|
{
|
|
209
194
|
role: "separator",
|
|
210
|
-
|
|
195
|
+
inlineSize: "full",
|
|
211
196
|
backgroundColor: color ?? dividerDefaults.color,
|
|
212
197
|
className: classnames(className, dividerClass, divider),
|
|
213
198
|
...restProps
|
|
@@ -218,10 +203,9 @@ export {
|
|
|
218
203
|
BlocksProviderContext,
|
|
219
204
|
Box,
|
|
220
205
|
Divider,
|
|
221
|
-
Slot,
|
|
222
206
|
classnames,
|
|
223
207
|
composeRefs,
|
|
224
|
-
|
|
208
|
+
createAsChildTemplate,
|
|
225
209
|
useComponentStyleDefaultProps,
|
|
226
210
|
useComponentStyles,
|
|
227
211
|
useTheme
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const jsxRuntime = require("react/jsx-runtime");
|
|
3
3
|
const react = require("react");
|
|
4
|
-
const styles_lib_utils_atomProps_cjs = require("../../../lib/utils/atom-props.cjs");
|
|
5
4
|
const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
|
|
5
|
+
const styles_lib_utils_atomProps_cjs = require("../../../lib/utils/atom-props.cjs");
|
|
6
6
|
const styles_components_form_Button_Button_css_cjs = require("./Button.css.cjs");
|
|
7
7
|
const styles_lib_css_atoms_sprinkles_css_cjs = require("../../../lib/css/atoms/sprinkles.css.cjs");
|
|
8
8
|
const Spinner = ({ className, size, color, ...restProps }) => {
|
|
9
9
|
const spinnerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("spinner", { base: true, variants: { size, color } });
|
|
10
10
|
return /* @__PURE__ */ jsxRuntime.jsx(styles_components_display_Divider_Divider_cjs.Box, { color, className: styles_components_display_Divider_Divider_cjs.classnames(spinnerClassName, className), ...restProps });
|
|
11
11
|
};
|
|
12
|
-
const
|
|
12
|
+
const { Template, Slot } = styles_components_display_Divider_Divider_cjs.createAsChildTemplate("button");
|
|
13
13
|
const Button = react.forwardRef(function Button2({
|
|
14
14
|
children,
|
|
15
15
|
className,
|
|
@@ -35,7 +35,7 @@ const Button = react.forwardRef(function Button2({
|
|
|
35
35
|
});
|
|
36
36
|
const [atomsProps, otherProps] = styles_lib_utils_atomProps_cjs.getAtomsAndProps(restProps);
|
|
37
37
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
38
|
-
|
|
38
|
+
Template,
|
|
39
39
|
{
|
|
40
40
|
ref,
|
|
41
41
|
asChild,
|
|
@@ -45,7 +45,7 @@ const Button = react.forwardRef(function Button2({
|
|
|
45
45
|
children: [
|
|
46
46
|
startSlot && /* @__PURE__ */ jsxRuntime.jsx("div", { children: startSlot }),
|
|
47
47
|
loading && /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size }),
|
|
48
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
48
|
+
/* @__PURE__ */ jsxRuntime.jsx(Slot, { children }),
|
|
49
49
|
endSlot && /* @__PURE__ */ jsxRuntime.jsx("div", { children: endSlot })
|
|
50
50
|
]
|
|
51
51
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
+
import { useComponentStyles, Box, classnames, createAsChildTemplate } from "../../display/Divider/Divider.mjs";
|
|
3
4
|
import { getAtomsAndProps } from "../../../lib/utils/atom-props.mjs";
|
|
4
|
-
import { useComponentStyles, Box, classnames, createSlottable, Slot } from "../../display/Divider/Divider.mjs";
|
|
5
5
|
import { buttonReset } from "./Button.css.mjs";
|
|
6
6
|
import { atoms } from "../../../lib/css/atoms/sprinkles.css.mjs";
|
|
7
7
|
const Spinner = ({ className, size, color, ...restProps }) => {
|
|
8
8
|
const spinnerClassName = useComponentStyles("spinner", { base: true, variants: { size, color } });
|
|
9
9
|
return /* @__PURE__ */ jsx(Box, { color, className: classnames(spinnerClassName, className), ...restProps });
|
|
10
10
|
};
|
|
11
|
-
const
|
|
11
|
+
const { Template, Slot } = createAsChildTemplate("button");
|
|
12
12
|
const Button = forwardRef(function Button2({
|
|
13
13
|
children,
|
|
14
14
|
className,
|
|
@@ -34,7 +34,7 @@ const Button = forwardRef(function Button2({
|
|
|
34
34
|
});
|
|
35
35
|
const [atomsProps, otherProps] = getAtomsAndProps(restProps);
|
|
36
36
|
return /* @__PURE__ */ jsxs(
|
|
37
|
-
|
|
37
|
+
Template,
|
|
38
38
|
{
|
|
39
39
|
ref,
|
|
40
40
|
asChild,
|
|
@@ -12,6 +12,22 @@ const Portal = ({ children, container }) => {
|
|
|
12
12
|
container || document.body
|
|
13
13
|
);
|
|
14
14
|
};
|
|
15
|
+
const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
|
|
16
|
+
react.useEffect(() => {
|
|
17
|
+
if (!enabled) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const listener = (event) => {
|
|
21
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
22
|
+
onClickOutside();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
document.addEventListener("click", listener);
|
|
26
|
+
return () => {
|
|
27
|
+
document.removeEventListener("click", listener);
|
|
28
|
+
};
|
|
29
|
+
}, [ref, onClickOutside, enabled]);
|
|
30
|
+
};
|
|
15
31
|
const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
16
32
|
const useKeyboard = (key, callback, { enabled = true, type = "keydown" } = {}) => {
|
|
17
33
|
react.useEffect(() => {
|
|
@@ -136,7 +152,6 @@ const Dialog = ({
|
|
|
136
152
|
const layer = useLayer();
|
|
137
153
|
const [visible, hide] = useVisibilityState(open);
|
|
138
154
|
const [enabled, setEnabled] = react.useState(true);
|
|
139
|
-
const lastAction = react.useRef(0);
|
|
140
155
|
useRestoreFocus(open);
|
|
141
156
|
const isNested = useNestedDialog(visible);
|
|
142
157
|
usePreventBodyScroll(visible && !isNested);
|
|
@@ -148,26 +163,7 @@ const Dialog = ({
|
|
|
148
163
|
[onRequestClose]
|
|
149
164
|
);
|
|
150
165
|
useKeyboard("Escape", onEscape, { enabled: open && enabled });
|
|
151
|
-
|
|
152
|
-
if (!open || !enabled) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
lastAction.current = Date.now();
|
|
156
|
-
const listener = (event) => {
|
|
157
|
-
var _a;
|
|
158
|
-
if (lastAction.current + 30 > Date.now()) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if ((_a = dialogRef.current) == null ? void 0 : _a.contains(event.target)) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
onRequestClose();
|
|
165
|
-
};
|
|
166
|
-
document.addEventListener("click", listener);
|
|
167
|
-
return () => {
|
|
168
|
-
document.removeEventListener("click", listener);
|
|
169
|
-
};
|
|
170
|
-
}, [enabled, onRequestClose, open]);
|
|
166
|
+
useClickOutside(dialogRef, onRequestClose, { enabled: open && enabled });
|
|
171
167
|
useIsomorphicLayoutEffect(() => {
|
|
172
168
|
var _a, _b;
|
|
173
169
|
if (!visible) {
|
|
@@ -222,6 +218,7 @@ const Dialog = ({
|
|
|
222
218
|
exports.Dialog = Dialog;
|
|
223
219
|
exports.Portal = Portal;
|
|
224
220
|
exports.hasAnimationDuration = hasAnimationDuration;
|
|
221
|
+
exports.useClickOutside = useClickOutside;
|
|
225
222
|
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
226
223
|
exports.useKeyboard = useKeyboard;
|
|
227
224
|
exports.useLayer = useLayer;
|
|
@@ -11,6 +11,22 @@ const Portal = ({ children, container }) => {
|
|
|
11
11
|
container || document.body
|
|
12
12
|
);
|
|
13
13
|
};
|
|
14
|
+
const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!enabled) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const listener = (event) => {
|
|
20
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
21
|
+
onClickOutside();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
document.addEventListener("click", listener);
|
|
25
|
+
return () => {
|
|
26
|
+
document.removeEventListener("click", listener);
|
|
27
|
+
};
|
|
28
|
+
}, [ref, onClickOutside, enabled]);
|
|
29
|
+
};
|
|
14
30
|
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
15
31
|
const useKeyboard = (key, callback, { enabled = true, type = "keydown" } = {}) => {
|
|
16
32
|
useEffect(() => {
|
|
@@ -135,7 +151,6 @@ const Dialog = ({
|
|
|
135
151
|
const layer = useLayer();
|
|
136
152
|
const [visible, hide] = useVisibilityState(open);
|
|
137
153
|
const [enabled, setEnabled] = useState(true);
|
|
138
|
-
const lastAction = useRef(0);
|
|
139
154
|
useRestoreFocus(open);
|
|
140
155
|
const isNested = useNestedDialog(visible);
|
|
141
156
|
usePreventBodyScroll(visible && !isNested);
|
|
@@ -147,26 +162,7 @@ const Dialog = ({
|
|
|
147
162
|
[onRequestClose]
|
|
148
163
|
);
|
|
149
164
|
useKeyboard("Escape", onEscape, { enabled: open && enabled });
|
|
150
|
-
|
|
151
|
-
if (!open || !enabled) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
lastAction.current = Date.now();
|
|
155
|
-
const listener = (event) => {
|
|
156
|
-
var _a;
|
|
157
|
-
if (lastAction.current + 30 > Date.now()) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if ((_a = dialogRef.current) == null ? void 0 : _a.contains(event.target)) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
onRequestClose();
|
|
164
|
-
};
|
|
165
|
-
document.addEventListener("click", listener);
|
|
166
|
-
return () => {
|
|
167
|
-
document.removeEventListener("click", listener);
|
|
168
|
-
};
|
|
169
|
-
}, [enabled, onRequestClose, open]);
|
|
165
|
+
useClickOutside(dialogRef, onRequestClose, { enabled: open && enabled });
|
|
170
166
|
useIsomorphicLayoutEffect(() => {
|
|
171
167
|
var _a, _b;
|
|
172
168
|
if (!visible) {
|
|
@@ -222,6 +218,7 @@ export {
|
|
|
222
218
|
Dialog,
|
|
223
219
|
Portal,
|
|
224
220
|
hasAnimationDuration,
|
|
221
|
+
useClickOutside,
|
|
225
222
|
useIsomorphicLayoutEffect,
|
|
226
223
|
useKeyboard,
|
|
227
224
|
useLayer,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
|
+
const css = require("@vanilla-extract/css");
|
|
3
4
|
const styles_lib_theme_makeComponentTheme_cjs = require("../../../lib/theme/makeComponentTheme.cjs");
|
|
4
5
|
fileScope.setFileScope("src/themes/momotaro/components/divider.css.ts", "@blockle/blocks");
|
|
5
6
|
const divider = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("divider", {
|
|
7
|
+
base: css.style({
|
|
8
|
+
blockSize: 1
|
|
9
|
+
}, "divider_base"),
|
|
6
10
|
defaultVariants: {
|
|
7
11
|
color: "textLight"
|
|
8
12
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
|
+
import { style } from "@vanilla-extract/css";
|
|
2
3
|
import { makeComponentTheme } from "../../../lib/theme/makeComponentTheme.mjs";
|
|
3
4
|
setFileScope("src/themes/momotaro/components/divider.css.ts", "@blockle/blocks");
|
|
4
5
|
const divider = makeComponentTheme("divider", {
|
|
6
|
+
base: style({
|
|
7
|
+
blockSize: 1
|
|
8
|
+
}, "divider_base"),
|
|
5
9
|
defaultVariants: {
|
|
6
10
|
color: "textLight"
|
|
7
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockle/blocks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Blocks design system",
|
|
5
5
|
"repository": "git@github.com:Blockle/blocks.git",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,7 +68,6 @@
|
|
|
68
68
|
"@storybook/addon-essentials": "^8.1.6",
|
|
69
69
|
"@storybook/addon-interactions": "^8.1.6",
|
|
70
70
|
"@storybook/addon-links": "^8.1.6",
|
|
71
|
-
"@storybook/addons": "^7.6.17",
|
|
72
71
|
"@storybook/blocks": "^8.1.6",
|
|
73
72
|
"@storybook/react": "^8.1.6",
|
|
74
73
|
"@storybook/react-vite": "^8.1.6",
|