@blockle/blocks 0.11.3 → 0.12.1
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 +52 -44
- package/dist/index.mjs +54 -46
- package/dist/momotaro.chunk.d.ts +15 -12
- package/dist/styles/components/overlay/Dialog/Dialog.cjs +41 -69
- package/dist/styles/components/overlay/Dialog/Dialog.mjs +44 -72
- package/dist/styles/components/overlay/Dialog/dialog.css.cjs +10 -12
- package/dist/styles/components/overlay/Dialog/dialog.css.mjs +10 -12
- package/dist/styles/themes/momotaro/components/dialog.css.cjs +13 -16
- package/dist/styles/themes/momotaro/components/dialog.css.mjs +13 -16
- package/dist/styles/themes/momotaro/components/index.cjs +5 -3
- package/dist/styles/themes/momotaro/components/index.mjs +5 -3
- package/dist/styles/themes/momotaro/components/{dropdown.css.cjs → popover.css.cjs} +6 -28
- package/dist/styles/themes/momotaro/components/{dropdown.css.mjs → popover.css.mjs} +6 -28
- package/dist/styles/themes/momotaro/components/progress.css.cjs +6 -6
- package/dist/styles/themes/momotaro/components/progress.css.mjs +6 -6
- package/dist/styles/themes/momotaro/components/tooltip.css.cjs +30 -0
- package/dist/styles/themes/momotaro/components/tooltip.css.mjs +31 -0
- package/package.json +38 -37
package/dist/index.cjs
CHANGED
|
@@ -152,19 +152,19 @@ const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
|
|
|
152
152
|
};
|
|
153
153
|
}, [ref, onClickOutside, enabled]);
|
|
154
154
|
};
|
|
155
|
-
function
|
|
156
|
-
if (!anchorRef.current || !
|
|
155
|
+
function getDopoverPosition(align, anchorRef, popoverRef) {
|
|
156
|
+
if (!anchorRef.current || !popoverRef.current) {
|
|
157
157
|
return [0, 0];
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
popoverRef.current.style.transform = "none";
|
|
160
|
+
popoverRef.current.style.transitionDuration = "0s";
|
|
161
161
|
const anchorRect = anchorRef.current.getBoundingClientRect();
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
const marginTop = Number.parseFloat(
|
|
165
|
-
const marginRight = Number.parseFloat(
|
|
166
|
-
const marginBottom = Number.parseFloat(
|
|
167
|
-
const marginLeft = Number.parseFloat(
|
|
162
|
+
const popoverRect = popoverRef.current.getBoundingClientRect();
|
|
163
|
+
const popoverStyles = getComputedStyle(popoverRef.current);
|
|
164
|
+
const marginTop = Number.parseFloat(popoverStyles.getPropertyValue("margin-top"));
|
|
165
|
+
const marginRight = Number.parseFloat(popoverStyles.getPropertyValue("margin-right"));
|
|
166
|
+
const marginBottom = Number.parseFloat(popoverStyles.getPropertyValue("margin-bottom"));
|
|
167
|
+
const marginLeft = Number.parseFloat(popoverStyles.getPropertyValue("margin-left"));
|
|
168
168
|
const marginY = marginTop + marginBottom;
|
|
169
169
|
const marginX = marginRight + marginLeft;
|
|
170
170
|
const docHeight = document.documentElement.clientHeight;
|
|
@@ -173,30 +173,30 @@ function getDropdownPosition(align, anchorRef, dropdownRef) {
|
|
|
173
173
|
const docScrollLeft = document.documentElement.scrollLeft;
|
|
174
174
|
const anchorLeft = anchorRect.left + docScrollLeft;
|
|
175
175
|
const anchorTop = anchorRect.top + docScrollTop;
|
|
176
|
-
const topPosition = anchorRect.top - (
|
|
177
|
-
const rightPosition = anchorRect.left + anchorRect.width +
|
|
178
|
-
const bottomPosition = anchorRect.top + anchorRect.height +
|
|
179
|
-
const leftPosition = anchorRect.left -
|
|
180
|
-
const offsetX = anchorLeft - (
|
|
181
|
-
const offsetY = anchorTop - (
|
|
182
|
-
|
|
183
|
-
|
|
176
|
+
const topPosition = anchorRect.top - (popoverRect.height + marginTop);
|
|
177
|
+
const rightPosition = anchorRect.left + anchorRect.width + popoverRect.width;
|
|
178
|
+
const bottomPosition = anchorRect.top + anchorRect.height + popoverRect.height;
|
|
179
|
+
const leftPosition = anchorRect.left - popoverRect.width;
|
|
180
|
+
const offsetX = anchorLeft - marginLeft - (popoverRect.width - anchorRect.width) / 2;
|
|
181
|
+
const offsetY = anchorTop - marginTop - (popoverRect.height - anchorRect.height) / 2;
|
|
182
|
+
popoverRef.current.style.transform = "";
|
|
183
|
+
popoverRef.current.style.transitionDuration = "";
|
|
184
184
|
switch (align) {
|
|
185
185
|
case "top": {
|
|
186
|
-
return topPosition > 0 ? [offsetX, anchorTop -
|
|
186
|
+
return topPosition > 0 ? [offsetX, anchorTop - popoverRect.height - marginY] : [offsetX, anchorTop + anchorRect.height];
|
|
187
187
|
}
|
|
188
188
|
case "bottom": {
|
|
189
|
-
return bottomPosition < docHeight || topPosition < 0 ? [offsetX, anchorTop + anchorRect.height] : [offsetX, anchorTop -
|
|
189
|
+
return bottomPosition < docHeight || topPosition < 0 ? [offsetX, anchorTop + anchorRect.height] : [offsetX, anchorTop - popoverRect.height - marginY];
|
|
190
190
|
}
|
|
191
191
|
case "left": {
|
|
192
|
-
return leftPosition > docWidth || leftPosition > 0 ? [anchorLeft -
|
|
192
|
+
return leftPosition > docWidth || leftPosition > 0 ? [anchorLeft - popoverRect.width - marginX, offsetY] : [anchorLeft + anchorRect.width, offsetY];
|
|
193
193
|
}
|
|
194
194
|
case "right": {
|
|
195
|
-
return rightPosition < docWidth || leftPosition < 0 ? [anchorLeft + anchorRect.width, offsetY] : [anchorLeft -
|
|
195
|
+
return rightPosition < docWidth || leftPosition < 0 ? [anchorLeft + anchorRect.width, offsetY] : [anchorLeft - popoverRect.width - marginX, offsetY];
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
-
const
|
|
199
|
+
const Popover = ({
|
|
200
200
|
align = "bottom",
|
|
201
201
|
anchorElement,
|
|
202
202
|
children,
|
|
@@ -205,23 +205,18 @@ const Dropdown = ({
|
|
|
205
205
|
open,
|
|
206
206
|
repositionOnScroll,
|
|
207
207
|
style,
|
|
208
|
-
variant,
|
|
209
208
|
...restProps
|
|
210
209
|
}) => {
|
|
211
210
|
const layer = styles_components_overlay_Dialog_Dialog_cjs.useLayer();
|
|
212
211
|
const [visible, hide] = styles_components_overlay_Dialog_Dialog_cjs.useVisibilityState(open);
|
|
213
212
|
const [position, setPosition] = react.useState({ x: 0, y: 0 });
|
|
214
|
-
const
|
|
215
|
-
const containerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles(
|
|
216
|
-
"dropdown",
|
|
217
|
-
{ base: true, variants: { variant } },
|
|
218
|
-
false
|
|
219
|
-
);
|
|
213
|
+
const popoverRef = react.useRef(null);
|
|
214
|
+
const containerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("popover", { base: true }, false);
|
|
220
215
|
react.useLayoutEffect(() => {
|
|
221
216
|
if (!visible) {
|
|
222
217
|
return;
|
|
223
218
|
}
|
|
224
|
-
const position2 =
|
|
219
|
+
const position2 = getDopoverPosition(align, anchorElement, popoverRef);
|
|
225
220
|
setPosition({ x: position2[0], y: position2[1] });
|
|
226
221
|
}, [align, anchorElement, visible]);
|
|
227
222
|
react.useEffect(() => {
|
|
@@ -229,7 +224,7 @@ const Dropdown = ({
|
|
|
229
224
|
return;
|
|
230
225
|
}
|
|
231
226
|
function handleResize() {
|
|
232
|
-
const position2 =
|
|
227
|
+
const position2 = getDopoverPosition(align, anchorElement, popoverRef);
|
|
233
228
|
setPosition({ x: position2[0], y: position2[1] });
|
|
234
229
|
}
|
|
235
230
|
window.addEventListener("resize", handleResize);
|
|
@@ -242,13 +237,13 @@ const Dropdown = ({
|
|
|
242
237
|
styles_components_overlay_Dialog_Dialog_cjs.useIsomorphicLayoutEffect(() => {
|
|
243
238
|
var _a;
|
|
244
239
|
if (!open) {
|
|
245
|
-
(_a =
|
|
240
|
+
(_a = popoverRef.current) == null ? void 0 : _a.removeAttribute("data-open");
|
|
246
241
|
return;
|
|
247
242
|
}
|
|
248
243
|
let timer = requestAnimationFrame(() => {
|
|
249
244
|
timer = requestAnimationFrame(() => {
|
|
250
245
|
var _a2;
|
|
251
|
-
(_a2 =
|
|
246
|
+
(_a2 = popoverRef.current) == null ? void 0 : _a2.setAttribute("data-open", "");
|
|
252
247
|
});
|
|
253
248
|
});
|
|
254
249
|
return () => {
|
|
@@ -264,12 +259,12 @@ const Dropdown = ({
|
|
|
264
259
|
if (open) {
|
|
265
260
|
return;
|
|
266
261
|
}
|
|
267
|
-
if (!styles_components_overlay_Dialog_Dialog_cjs.hasAnimationDuration(
|
|
262
|
+
if (!styles_components_overlay_Dialog_Dialog_cjs.hasAnimationDuration(popoverRef.current)) {
|
|
268
263
|
hide();
|
|
269
264
|
}
|
|
270
265
|
}, [hide, open]);
|
|
271
266
|
styles_components_overlay_Dialog_Dialog_cjs.useKeyboard("Escape", onRequestClose, { enabled: visible });
|
|
272
|
-
useClickOutside(
|
|
267
|
+
useClickOutside(popoverRef, onRequestClose, { enabled: visible });
|
|
273
268
|
if (!visible) {
|
|
274
269
|
return null;
|
|
275
270
|
}
|
|
@@ -277,7 +272,7 @@ const Dropdown = ({
|
|
|
277
272
|
return /* @__PURE__ */ jsxRuntime.jsx(styles_components_overlay_Dialog_Dialog_cjs.Portal, { container: layer(), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
278
273
|
styles_components_display_Divider_Divider_cjs.Box,
|
|
279
274
|
{
|
|
280
|
-
ref:
|
|
275
|
+
ref: popoverRef,
|
|
281
276
|
"data-open": dataOpen,
|
|
282
277
|
onAnimationEnd,
|
|
283
278
|
onTransitionEnd: onAnimationEnd,
|
|
@@ -285,10 +280,6 @@ const Dropdown = ({
|
|
|
285
280
|
position: "absolute",
|
|
286
281
|
style: {
|
|
287
282
|
...style,
|
|
288
|
-
// TODO Think about how to handle this, perhaps we could add a custom class to the dropdown
|
|
289
|
-
// Or we remove it from getDropdownPosition?
|
|
290
|
-
// "horizontal" ? "vertical"
|
|
291
|
-
margin: align === "bottom" || align === "top" ? "var(--spacing) 0" : "0 var(--spacing)",
|
|
292
283
|
left: position.x,
|
|
293
284
|
top: position.y
|
|
294
285
|
},
|
|
@@ -297,10 +288,19 @@ const Dropdown = ({
|
|
|
297
288
|
}
|
|
298
289
|
) });
|
|
299
290
|
};
|
|
300
|
-
const Tooltip = ({
|
|
291
|
+
const Tooltip = ({
|
|
292
|
+
align = "top",
|
|
293
|
+
children,
|
|
294
|
+
label,
|
|
295
|
+
colorScheme
|
|
296
|
+
}) => {
|
|
301
297
|
const id = react.useId();
|
|
302
298
|
const ref = react.useRef(null);
|
|
303
299
|
const [open, setOpen] = react.useState(false);
|
|
300
|
+
const tooltipClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("tooltip", {
|
|
301
|
+
base: true,
|
|
302
|
+
variants: { colorScheme }
|
|
303
|
+
});
|
|
304
304
|
react.useEffect(() => {
|
|
305
305
|
const element = ref.current;
|
|
306
306
|
if (!element) {
|
|
@@ -336,7 +336,7 @@ const Tooltip = ({ align = "top", children, label }) => {
|
|
|
336
336
|
["aria-describedby"]: open ? id : void 0
|
|
337
337
|
}),
|
|
338
338
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
339
|
-
|
|
339
|
+
Popover,
|
|
340
340
|
{
|
|
341
341
|
id,
|
|
342
342
|
role: "tooltip",
|
|
@@ -346,11 +346,19 @@ const Tooltip = ({ align = "top", children, label }) => {
|
|
|
346
346
|
setOpen(false);
|
|
347
347
|
},
|
|
348
348
|
align,
|
|
349
|
+
className: tooltipClassName,
|
|
349
350
|
children: label
|
|
350
351
|
}
|
|
351
352
|
)
|
|
352
353
|
] });
|
|
353
354
|
};
|
|
355
|
+
const useRootAriaHidden = (hidden) => {
|
|
356
|
+
const context = react.useContext(styles_components_display_Divider_Divider_cjs.BlocksProviderContext);
|
|
357
|
+
if (!context) {
|
|
358
|
+
throw new Error("useRootAriaHidden must be used within a BlocksProvider");
|
|
359
|
+
}
|
|
360
|
+
context.setAriaHidden(hidden);
|
|
361
|
+
};
|
|
354
362
|
exports.breakpointQuery = styles_lib_css_atoms_breakpoints_cjs.breakpointQuery;
|
|
355
363
|
exports.style = styles_lib_css_style_style_cjs.style;
|
|
356
364
|
exports.makeComponentTheme = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme;
|
|
@@ -379,7 +387,6 @@ exports.Portal = styles_components_overlay_Dialog_Dialog_cjs.Portal;
|
|
|
379
387
|
exports.useIsomorphicLayoutEffect = styles_components_overlay_Dialog_Dialog_cjs.useIsomorphicLayoutEffect;
|
|
380
388
|
exports.useKeyboard = styles_components_overlay_Dialog_Dialog_cjs.useKeyboard;
|
|
381
389
|
exports.usePreventBodyScroll = styles_components_overlay_Dialog_Dialog_cjs.usePreventBodyScroll;
|
|
382
|
-
exports.useRootAriaHidden = styles_components_overlay_Dialog_Dialog_cjs.useRootAriaHidden;
|
|
383
390
|
exports.Heading = styles_components_typography_Heading_Heading_cjs.Heading;
|
|
384
391
|
exports.Text = styles_components_typography_Text_Text_cjs.Text;
|
|
385
392
|
exports.Inline = Inline;
|
|
@@ -387,3 +394,4 @@ exports.Link = Link;
|
|
|
387
394
|
exports.Progress = Progress;
|
|
388
395
|
exports.Stack = Stack;
|
|
389
396
|
exports.Tooltip = Tooltip;
|
|
397
|
+
exports.useRootAriaHidden = useRootAriaHidden;
|
package/dist/index.mjs
CHANGED
|
@@ -5,11 +5,11 @@ import { style } from "./styles/lib/css/style/style.mjs";
|
|
|
5
5
|
import { makeComponentTheme } from "./styles/lib/theme/makeComponentTheme.mjs";
|
|
6
6
|
import { makeTheme } from "./styles/lib/theme/makeTheme.mjs";
|
|
7
7
|
import { vars } from "./styles/lib/theme/vars.css.mjs";
|
|
8
|
-
import { useComponentStyles, Box, classnames, createSlottable, composeRefs } from "./styles/components/display/Divider/Divider.mjs";
|
|
8
|
+
import { useComponentStyles, Box, classnames, createSlottable, composeRefs, BlocksProviderContext } from "./styles/components/display/Divider/Divider.mjs";
|
|
9
9
|
import { Divider, Slot, useComponentStyleDefaultProps } from "./styles/components/display/Divider/Divider.mjs";
|
|
10
10
|
import { atoms } from "./styles/lib/css/atoms/sprinkles.css.mjs";
|
|
11
11
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
12
|
-
import { forwardRef, useEffect, useState, useRef, useLayoutEffect, useCallback, useId, Children, isValidElement, cloneElement } from "react";
|
|
12
|
+
import { forwardRef, useEffect, useState, useRef, useLayoutEffect, useCallback, useId, Children, isValidElement, cloneElement, useContext } from "react";
|
|
13
13
|
import { Button, Spinner } from "./styles/components/form/Button/Button.mjs";
|
|
14
14
|
import { Checkbox, Label } from "./styles/components/form/Checkbox/Checkbox.mjs";
|
|
15
15
|
import { Input } from "./styles/components/form/Input/Input.mjs";
|
|
@@ -19,7 +19,7 @@ import { Slider } from "./styles/components/form/Slider/Slider.mjs";
|
|
|
19
19
|
import { Switch } from "./styles/components/form/Switch/Switch.mjs";
|
|
20
20
|
import { BlocksProvider } from "./styles/components/other/BlocksProvider/BlocksProvider.mjs";
|
|
21
21
|
import { useLayer, useVisibilityState, useIsomorphicLayoutEffect, hasAnimationDuration, useKeyboard, Portal } from "./styles/components/overlay/Dialog/Dialog.mjs";
|
|
22
|
-
import { Dialog, usePreventBodyScroll
|
|
22
|
+
import { Dialog, usePreventBodyScroll } from "./styles/components/overlay/Dialog/Dialog.mjs";
|
|
23
23
|
import { Heading } from "./styles/components/typography/Heading/Heading.mjs";
|
|
24
24
|
import { Text } from "./styles/components/typography/Text/Text.mjs";
|
|
25
25
|
const Progress = forwardRef(function Progress2({ value, max = 100, className, ...restProps }, ref) {
|
|
@@ -154,19 +154,19 @@ const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
|
|
|
154
154
|
};
|
|
155
155
|
}, [ref, onClickOutside, enabled]);
|
|
156
156
|
};
|
|
157
|
-
function
|
|
158
|
-
if (!anchorRef.current || !
|
|
157
|
+
function getDopoverPosition(align, anchorRef, popoverRef) {
|
|
158
|
+
if (!anchorRef.current || !popoverRef.current) {
|
|
159
159
|
return [0, 0];
|
|
160
160
|
}
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
popoverRef.current.style.transform = "none";
|
|
162
|
+
popoverRef.current.style.transitionDuration = "0s";
|
|
163
163
|
const anchorRect = anchorRef.current.getBoundingClientRect();
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const marginTop = Number.parseFloat(
|
|
167
|
-
const marginRight = Number.parseFloat(
|
|
168
|
-
const marginBottom = Number.parseFloat(
|
|
169
|
-
const marginLeft = Number.parseFloat(
|
|
164
|
+
const popoverRect = popoverRef.current.getBoundingClientRect();
|
|
165
|
+
const popoverStyles = getComputedStyle(popoverRef.current);
|
|
166
|
+
const marginTop = Number.parseFloat(popoverStyles.getPropertyValue("margin-top"));
|
|
167
|
+
const marginRight = Number.parseFloat(popoverStyles.getPropertyValue("margin-right"));
|
|
168
|
+
const marginBottom = Number.parseFloat(popoverStyles.getPropertyValue("margin-bottom"));
|
|
169
|
+
const marginLeft = Number.parseFloat(popoverStyles.getPropertyValue("margin-left"));
|
|
170
170
|
const marginY = marginTop + marginBottom;
|
|
171
171
|
const marginX = marginRight + marginLeft;
|
|
172
172
|
const docHeight = document.documentElement.clientHeight;
|
|
@@ -175,30 +175,30 @@ function getDropdownPosition(align, anchorRef, dropdownRef) {
|
|
|
175
175
|
const docScrollLeft = document.documentElement.scrollLeft;
|
|
176
176
|
const anchorLeft = anchorRect.left + docScrollLeft;
|
|
177
177
|
const anchorTop = anchorRect.top + docScrollTop;
|
|
178
|
-
const topPosition = anchorRect.top - (
|
|
179
|
-
const rightPosition = anchorRect.left + anchorRect.width +
|
|
180
|
-
const bottomPosition = anchorRect.top + anchorRect.height +
|
|
181
|
-
const leftPosition = anchorRect.left -
|
|
182
|
-
const offsetX = anchorLeft - (
|
|
183
|
-
const offsetY = anchorTop - (
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
const topPosition = anchorRect.top - (popoverRect.height + marginTop);
|
|
179
|
+
const rightPosition = anchorRect.left + anchorRect.width + popoverRect.width;
|
|
180
|
+
const bottomPosition = anchorRect.top + anchorRect.height + popoverRect.height;
|
|
181
|
+
const leftPosition = anchorRect.left - popoverRect.width;
|
|
182
|
+
const offsetX = anchorLeft - marginLeft - (popoverRect.width - anchorRect.width) / 2;
|
|
183
|
+
const offsetY = anchorTop - marginTop - (popoverRect.height - anchorRect.height) / 2;
|
|
184
|
+
popoverRef.current.style.transform = "";
|
|
185
|
+
popoverRef.current.style.transitionDuration = "";
|
|
186
186
|
switch (align) {
|
|
187
187
|
case "top": {
|
|
188
|
-
return topPosition > 0 ? [offsetX, anchorTop -
|
|
188
|
+
return topPosition > 0 ? [offsetX, anchorTop - popoverRect.height - marginY] : [offsetX, anchorTop + anchorRect.height];
|
|
189
189
|
}
|
|
190
190
|
case "bottom": {
|
|
191
|
-
return bottomPosition < docHeight || topPosition < 0 ? [offsetX, anchorTop + anchorRect.height] : [offsetX, anchorTop -
|
|
191
|
+
return bottomPosition < docHeight || topPosition < 0 ? [offsetX, anchorTop + anchorRect.height] : [offsetX, anchorTop - popoverRect.height - marginY];
|
|
192
192
|
}
|
|
193
193
|
case "left": {
|
|
194
|
-
return leftPosition > docWidth || leftPosition > 0 ? [anchorLeft -
|
|
194
|
+
return leftPosition > docWidth || leftPosition > 0 ? [anchorLeft - popoverRect.width - marginX, offsetY] : [anchorLeft + anchorRect.width, offsetY];
|
|
195
195
|
}
|
|
196
196
|
case "right": {
|
|
197
|
-
return rightPosition < docWidth || leftPosition < 0 ? [anchorLeft + anchorRect.width, offsetY] : [anchorLeft -
|
|
197
|
+
return rightPosition < docWidth || leftPosition < 0 ? [anchorLeft + anchorRect.width, offsetY] : [anchorLeft - popoverRect.width - marginX, offsetY];
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
const
|
|
201
|
+
const Popover = ({
|
|
202
202
|
align = "bottom",
|
|
203
203
|
anchorElement,
|
|
204
204
|
children,
|
|
@@ -207,23 +207,18 @@ const Dropdown = ({
|
|
|
207
207
|
open,
|
|
208
208
|
repositionOnScroll,
|
|
209
209
|
style: style2,
|
|
210
|
-
variant,
|
|
211
210
|
...restProps
|
|
212
211
|
}) => {
|
|
213
212
|
const layer = useLayer();
|
|
214
213
|
const [visible, hide] = useVisibilityState(open);
|
|
215
214
|
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
216
|
-
const
|
|
217
|
-
const containerClassName = useComponentStyles(
|
|
218
|
-
"dropdown",
|
|
219
|
-
{ base: true, variants: { variant } },
|
|
220
|
-
false
|
|
221
|
-
);
|
|
215
|
+
const popoverRef = useRef(null);
|
|
216
|
+
const containerClassName = useComponentStyles("popover", { base: true }, false);
|
|
222
217
|
useLayoutEffect(() => {
|
|
223
218
|
if (!visible) {
|
|
224
219
|
return;
|
|
225
220
|
}
|
|
226
|
-
const position2 =
|
|
221
|
+
const position2 = getDopoverPosition(align, anchorElement, popoverRef);
|
|
227
222
|
setPosition({ x: position2[0], y: position2[1] });
|
|
228
223
|
}, [align, anchorElement, visible]);
|
|
229
224
|
useEffect(() => {
|
|
@@ -231,7 +226,7 @@ const Dropdown = ({
|
|
|
231
226
|
return;
|
|
232
227
|
}
|
|
233
228
|
function handleResize() {
|
|
234
|
-
const position2 =
|
|
229
|
+
const position2 = getDopoverPosition(align, anchorElement, popoverRef);
|
|
235
230
|
setPosition({ x: position2[0], y: position2[1] });
|
|
236
231
|
}
|
|
237
232
|
window.addEventListener("resize", handleResize);
|
|
@@ -244,13 +239,13 @@ const Dropdown = ({
|
|
|
244
239
|
useIsomorphicLayoutEffect(() => {
|
|
245
240
|
var _a;
|
|
246
241
|
if (!open) {
|
|
247
|
-
(_a =
|
|
242
|
+
(_a = popoverRef.current) == null ? void 0 : _a.removeAttribute("data-open");
|
|
248
243
|
return;
|
|
249
244
|
}
|
|
250
245
|
let timer = requestAnimationFrame(() => {
|
|
251
246
|
timer = requestAnimationFrame(() => {
|
|
252
247
|
var _a2;
|
|
253
|
-
(_a2 =
|
|
248
|
+
(_a2 = popoverRef.current) == null ? void 0 : _a2.setAttribute("data-open", "");
|
|
254
249
|
});
|
|
255
250
|
});
|
|
256
251
|
return () => {
|
|
@@ -266,12 +261,12 @@ const Dropdown = ({
|
|
|
266
261
|
if (open) {
|
|
267
262
|
return;
|
|
268
263
|
}
|
|
269
|
-
if (!hasAnimationDuration(
|
|
264
|
+
if (!hasAnimationDuration(popoverRef.current)) {
|
|
270
265
|
hide();
|
|
271
266
|
}
|
|
272
267
|
}, [hide, open]);
|
|
273
268
|
useKeyboard("Escape", onRequestClose, { enabled: visible });
|
|
274
|
-
useClickOutside(
|
|
269
|
+
useClickOutside(popoverRef, onRequestClose, { enabled: visible });
|
|
275
270
|
if (!visible) {
|
|
276
271
|
return null;
|
|
277
272
|
}
|
|
@@ -279,7 +274,7 @@ const Dropdown = ({
|
|
|
279
274
|
return /* @__PURE__ */ jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsx(
|
|
280
275
|
Box,
|
|
281
276
|
{
|
|
282
|
-
ref:
|
|
277
|
+
ref: popoverRef,
|
|
283
278
|
"data-open": dataOpen,
|
|
284
279
|
onAnimationEnd,
|
|
285
280
|
onTransitionEnd: onAnimationEnd,
|
|
@@ -287,10 +282,6 @@ const Dropdown = ({
|
|
|
287
282
|
position: "absolute",
|
|
288
283
|
style: {
|
|
289
284
|
...style2,
|
|
290
|
-
// TODO Think about how to handle this, perhaps we could add a custom class to the dropdown
|
|
291
|
-
// Or we remove it from getDropdownPosition?
|
|
292
|
-
// "horizontal" ? "vertical"
|
|
293
|
-
margin: align === "bottom" || align === "top" ? "var(--spacing) 0" : "0 var(--spacing)",
|
|
294
285
|
left: position.x,
|
|
295
286
|
top: position.y
|
|
296
287
|
},
|
|
@@ -299,10 +290,19 @@ const Dropdown = ({
|
|
|
299
290
|
}
|
|
300
291
|
) });
|
|
301
292
|
};
|
|
302
|
-
const Tooltip = ({
|
|
293
|
+
const Tooltip = ({
|
|
294
|
+
align = "top",
|
|
295
|
+
children,
|
|
296
|
+
label,
|
|
297
|
+
colorScheme
|
|
298
|
+
}) => {
|
|
303
299
|
const id = useId();
|
|
304
300
|
const ref = useRef(null);
|
|
305
301
|
const [open, setOpen] = useState(false);
|
|
302
|
+
const tooltipClassName = useComponentStyles("tooltip", {
|
|
303
|
+
base: true,
|
|
304
|
+
variants: { colorScheme }
|
|
305
|
+
});
|
|
306
306
|
useEffect(() => {
|
|
307
307
|
const element = ref.current;
|
|
308
308
|
if (!element) {
|
|
@@ -338,7 +338,7 @@ const Tooltip = ({ align = "top", children, label }) => {
|
|
|
338
338
|
["aria-describedby"]: open ? id : void 0
|
|
339
339
|
}),
|
|
340
340
|
/* @__PURE__ */ jsx(
|
|
341
|
-
|
|
341
|
+
Popover,
|
|
342
342
|
{
|
|
343
343
|
id,
|
|
344
344
|
role: "tooltip",
|
|
@@ -348,11 +348,19 @@ const Tooltip = ({ align = "top", children, label }) => {
|
|
|
348
348
|
setOpen(false);
|
|
349
349
|
},
|
|
350
350
|
align,
|
|
351
|
+
className: tooltipClassName,
|
|
351
352
|
children: label
|
|
352
353
|
}
|
|
353
354
|
)
|
|
354
355
|
] });
|
|
355
356
|
};
|
|
357
|
+
const useRootAriaHidden = (hidden) => {
|
|
358
|
+
const context = useContext(BlocksProviderContext);
|
|
359
|
+
if (!context) {
|
|
360
|
+
throw new Error("useRootAriaHidden must be used within a BlocksProvider");
|
|
361
|
+
}
|
|
362
|
+
context.setAriaHidden(hidden);
|
|
363
|
+
};
|
|
356
364
|
export {
|
|
357
365
|
BlocksProvider,
|
|
358
366
|
Box,
|
package/dist/momotaro.chunk.d.ts
CHANGED
|
@@ -234,7 +234,7 @@ declare const atoms: ((props: {
|
|
|
234
234
|
wide?: "center" | "flex-start" | "flex-end" | undefined;
|
|
235
235
|
} | undefined) | _vanilla_extract_sprinkles.ResponsiveArray<4 | 1 | 2 | 3, "center" | "flex-start" | "flex-end" | null>;
|
|
236
236
|
}) => string) & {
|
|
237
|
-
properties: Set<"borderRadius" | "color" | "borderWidth" | "fontFamily" | "fontSize" | "fontWeight" | "lineHeight" | "transition" | "boxShadow" | "alignContent" | "alignItems" | "alignSelf" | "backgroundColor" | "blockSize" | "columnGap" | "cursor" | "display" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontStyle" | "inlineSize" | "insetBlockEnd" | "insetBlockStart" | "insetInlineEnd" | "insetInlineStart" | "justifyContent" | "marginBlockEnd" | "marginBlockStart" | "marginInlineEnd" | "marginInlineStart" | "maxBlockSize" | "maxInlineSize" | "opacity" | "overflowBlock" | "overflowInline" | "paddingBlockEnd" | "paddingBlockStart" | "paddingInlineEnd" | "paddingInlineStart" | "pointerEvents" | "position" | "rowGap" | "textAlign" | "textTransform" | "userSelect" | "whiteSpace" | "wordBreak" | "wordWrap" | "border" | "borderColor" | "flex" | "gap" | "inset" | "insetBlock" | "insetInline" | "margin" | "marginBlock" | "marginInline" | "outline" | "overflow" | "padding" | "paddingBlock" | "paddingInline" | "placeItems" | "textDecoration"
|
|
237
|
+
properties: Set<"borderRadius" | "color" | "borderWidth" | "fontFamily" | "fontSize" | "fontWeight" | "lineHeight" | "transition" | "boxShadow" | "alignContent" | "alignItems" | "alignSelf" | "backgroundColor" | "blockSize" | "columnGap" | "cursor" | "display" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontStyle" | "inlineSize" | "insetBlockEnd" | "insetBlockStart" | "insetInlineEnd" | "insetInlineStart" | "justifyContent" | "marginBlockEnd" | "marginBlockStart" | "marginInlineEnd" | "marginInlineStart" | "maxBlockSize" | "maxInlineSize" | "opacity" | "overflowBlock" | "overflowInline" | "paddingBlockEnd" | "paddingBlockStart" | "paddingInlineEnd" | "paddingInlineStart" | "pointerEvents" | "position" | "rowGap" | "textAlign" | "textTransform" | "textWrap" | "userSelect" | "whiteSpace" | "wordBreak" | "wordWrap" | "border" | "borderColor" | "flex" | "gap" | "inset" | "insetBlock" | "insetInline" | "margin" | "marginBlock" | "marginInline" | "outline" | "overflow" | "padding" | "paddingBlock" | "paddingInline" | "placeItems" | "textDecoration">;
|
|
238
238
|
};
|
|
239
239
|
|
|
240
240
|
declare const breakpoints: {
|
|
@@ -330,7 +330,6 @@ type DividerTheme = {
|
|
|
330
330
|
};
|
|
331
331
|
};
|
|
332
332
|
type DialogTheme = {
|
|
333
|
-
backdrop: string;
|
|
334
333
|
dialog: string;
|
|
335
334
|
variants: {
|
|
336
335
|
size: 'small' | 'medium' | 'large';
|
|
@@ -376,11 +375,8 @@ type SwitchTheme = {
|
|
|
376
375
|
base: string;
|
|
377
376
|
slider: string;
|
|
378
377
|
};
|
|
379
|
-
type
|
|
378
|
+
type PopoverTheme = {
|
|
380
379
|
base: string;
|
|
381
|
-
variants: {
|
|
382
|
-
variant: 'solid' | 'outline';
|
|
383
|
-
};
|
|
384
380
|
};
|
|
385
381
|
type SelectTheme = {
|
|
386
382
|
wrapper?: string;
|
|
@@ -400,21 +396,28 @@ type SliderTheme = {
|
|
|
400
396
|
colorScheme: 'primary' | 'secondary';
|
|
401
397
|
};
|
|
402
398
|
};
|
|
399
|
+
type TooltipTheme = {
|
|
400
|
+
base: string;
|
|
401
|
+
variants: {
|
|
402
|
+
colorScheme: 'primary' | 'secondary';
|
|
403
|
+
};
|
|
404
|
+
};
|
|
403
405
|
type ComponentThemes = {
|
|
404
406
|
button: ButtonTheme;
|
|
405
407
|
checkbox: CheckboxTheme;
|
|
406
408
|
dialog: DialogTheme;
|
|
407
409
|
divider: DividerTheme;
|
|
408
|
-
dropdown: DropdownTheme;
|
|
409
410
|
input: InputTheme;
|
|
410
411
|
label: LabelTheme;
|
|
411
412
|
link: LinkTheme;
|
|
413
|
+
popover: PopoverTheme;
|
|
412
414
|
progress: ProgressTheme;
|
|
413
415
|
radio: RadioTheme;
|
|
414
416
|
select: SelectTheme;
|
|
417
|
+
slider: SliderTheme;
|
|
415
418
|
spinner: SpinnerTheme;
|
|
416
419
|
switch: SwitchTheme;
|
|
417
|
-
|
|
420
|
+
tooltip: TooltipTheme;
|
|
418
421
|
};
|
|
419
422
|
/**
|
|
420
423
|
* ComponentThemeProps is a helper type to define the props passed to useComponentStyles.
|
|
@@ -1069,7 +1072,7 @@ type DialogProps = {
|
|
|
1069
1072
|
};
|
|
1070
1073
|
declare const Dialog: React.FC<DialogProps>;
|
|
1071
1074
|
|
|
1072
|
-
type
|
|
1075
|
+
type PopoverProps = {
|
|
1073
1076
|
align?: 'top' | 'bottom' | 'left' | 'right';
|
|
1074
1077
|
anchorElement: React.RefObject<HTMLElement>;
|
|
1075
1078
|
children: React.ReactNode;
|
|
@@ -1078,14 +1081,14 @@ type DropdownProps = {
|
|
|
1078
1081
|
open: boolean;
|
|
1079
1082
|
repositionOnScroll?: boolean;
|
|
1080
1083
|
style?: React.CSSProperties;
|
|
1081
|
-
variant?: DropdownTheme['variants']['variant'];
|
|
1082
1084
|
} & HTMLElementProps<HTMLDivElement>;
|
|
1083
1085
|
|
|
1084
1086
|
type ReactElement = React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
1085
1087
|
type TooltipProps = {
|
|
1086
|
-
align?:
|
|
1088
|
+
align?: PopoverProps['align'];
|
|
1087
1089
|
children: ReactElement;
|
|
1088
1090
|
label: React.ReactNode;
|
|
1091
|
+
colorScheme?: TooltipTheme['variants']['colorScheme'];
|
|
1089
1092
|
};
|
|
1090
1093
|
declare const Tooltip: React.FC<TooltipProps>;
|
|
1091
1094
|
|
|
@@ -1135,7 +1138,7 @@ type UseKeyboardOptions = {
|
|
|
1135
1138
|
enabled?: boolean;
|
|
1136
1139
|
type?: 'keydown' | 'keyup';
|
|
1137
1140
|
};
|
|
1138
|
-
declare const useKeyboard: (key: KeyboardEvent['key'], callback: () => void, { enabled, type }?: UseKeyboardOptions) => void;
|
|
1141
|
+
declare const useKeyboard: (key: KeyboardEvent['key'], callback: (event: KeyboardEvent) => void, { enabled, type }?: UseKeyboardOptions) => void;
|
|
1139
1142
|
|
|
1140
1143
|
declare const usePreventBodyScroll: (enabled?: boolean) => void;
|
|
1141
1144
|
|