@blockle/blocks 0.10.0 → 0.11.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.
Files changed (161) hide show
  1. package/dist/index.cjs +256 -8
  2. package/dist/index.d.mts +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.mjs +257 -8
  5. package/dist/momotaro.chunk.d.ts +289 -271
  6. package/dist/reset.css.cjs +2 -0
  7. package/dist/reset.css.mjs +2 -0
  8. package/dist/style.css +2851 -0
  9. package/dist/styles/components/display/Divider/Divider.cjs +1 -0
  10. package/dist/styles/components/display/Divider/Divider.mjs +1 -0
  11. package/dist/styles/components/display/Divider/divider.css.cjs +3 -10
  12. package/dist/styles/components/display/Divider/divider.css.mjs +3 -10
  13. package/dist/styles/components/form/Button/Button.css.cjs +3 -10
  14. package/dist/styles/components/form/Button/Button.css.mjs +3 -10
  15. package/dist/styles/components/form/Button/Button.css.ts.vanilla.cjs +1 -0
  16. package/dist/styles/components/form/Button/Button.css.ts.vanilla.mjs +1 -0
  17. package/dist/styles/components/form/Checkbox/checkbox.css.cjs +5 -24
  18. package/dist/styles/components/form/Checkbox/checkbox.css.mjs +5 -24
  19. package/dist/styles/components/form/Checkbox/checkbox.css.ts.vanilla.cjs +1 -0
  20. package/dist/styles/components/form/Checkbox/checkbox.css.ts.vanilla.mjs +1 -0
  21. package/dist/styles/components/form/Input/input.css.cjs +3 -14
  22. package/dist/styles/components/form/Input/input.css.mjs +3 -14
  23. package/dist/styles/components/form/Input/input.css.ts.vanilla.cjs +1 -0
  24. package/dist/styles/components/form/Input/input.css.ts.vanilla.mjs +1 -0
  25. package/dist/styles/components/form/Radio/radio.css.cjs +5 -24
  26. package/dist/styles/components/form/Radio/radio.css.mjs +5 -24
  27. package/dist/styles/components/form/Radio/radio.css.ts.vanilla.cjs +1 -0
  28. package/dist/styles/components/form/Radio/radio.css.ts.vanilla.mjs +1 -0
  29. package/dist/styles/components/form/Select/Select.cjs +2 -2
  30. package/dist/styles/components/form/Select/Select.mjs +2 -2
  31. package/dist/styles/components/form/Select/select.css.cjs +5 -30
  32. package/dist/styles/components/form/Select/select.css.mjs +5 -30
  33. package/dist/styles/components/form/Select/select.css.ts.vanilla.cjs +1 -0
  34. package/dist/styles/components/form/Select/select.css.ts.vanilla.mjs +1 -0
  35. package/dist/styles/components/form/Slider/slider.css.cjs +7 -64
  36. package/dist/styles/components/form/Slider/slider.css.mjs +7 -64
  37. package/dist/styles/components/form/Slider/slider.css.ts.vanilla.cjs +1 -0
  38. package/dist/styles/components/form/Slider/slider.css.ts.vanilla.mjs +1 -0
  39. package/dist/styles/components/form/Switch/switch.css.cjs +4 -20
  40. package/dist/styles/components/form/Switch/switch.css.mjs +4 -20
  41. package/dist/styles/components/form/Switch/switch.css.ts.vanilla.cjs +1 -0
  42. package/dist/styles/components/form/Switch/switch.css.ts.vanilla.mjs +1 -0
  43. package/dist/styles/components/overlay/Dialog/Dialog.cjs +3 -0
  44. package/dist/styles/components/overlay/Dialog/Dialog.mjs +4 -1
  45. package/dist/styles/components/overlay/Dialog/dialog.css.cjs +3 -18
  46. package/dist/styles/components/overlay/Dialog/dialog.css.mjs +3 -18
  47. package/dist/styles/components/overlay/Dialog/dialog.css.ts.vanilla.cjs +1 -0
  48. package/dist/styles/components/overlay/Dialog/dialog.css.ts.vanilla.mjs +1 -0
  49. package/dist/styles/components/typography/Heading/heading.css.cjs +3 -10
  50. package/dist/styles/components/typography/Heading/heading.css.mjs +3 -10
  51. package/dist/styles/components/typography/Heading/heading.css.ts.vanilla.cjs +1 -0
  52. package/dist/styles/components/typography/Heading/heading.css.ts.vanilla.mjs +1 -0
  53. package/dist/styles/components/typography/Text/text.css.cjs +3 -10
  54. package/dist/styles/components/typography/Text/text.css.mjs +3 -10
  55. package/dist/styles/components/typography/Text/text.css.ts.vanilla.cjs +1 -0
  56. package/dist/styles/components/typography/Text/text.css.ts.vanilla.mjs +1 -0
  57. package/dist/styles/entries/reset.css.ts.vanilla.cjs +1 -0
  58. package/dist/styles/entries/reset.css.ts.vanilla.mjs +1 -0
  59. package/dist/styles/lib/css/atoms/sprinkles.css.cjs +2088 -31
  60. package/dist/styles/lib/css/atoms/sprinkles.css.mjs +2088 -31
  61. package/dist/styles/lib/css/atoms/sprinkles.css.ts.vanilla.cjs +1 -0
  62. package/dist/styles/lib/css/atoms/sprinkles.css.ts.vanilla.mjs +1 -0
  63. package/dist/styles/lib/css/layers/layers.css.ts.vanilla.cjs +1 -0
  64. package/dist/styles/lib/css/layers/layers.css.ts.vanilla.mjs +1 -0
  65. package/dist/styles/lib/css/reset/reset.css.ts.vanilla.cjs +1 -0
  66. package/dist/styles/lib/css/reset/reset.css.ts.vanilla.mjs +1 -0
  67. package/dist/styles/lib/theme/makeTheme.cjs +18 -2
  68. package/dist/styles/lib/theme/makeTheme.mjs +17 -1
  69. package/dist/styles/lib/theme/vars.css.cjs +76 -4
  70. package/dist/styles/lib/theme/vars.css.mjs +76 -4
  71. package/dist/styles/lib/theme/vars.css.ts.vanilla.cjs +1 -0
  72. package/dist/styles/lib/theme/vars.css.ts.vanilla.mjs +1 -0
  73. package/dist/styles/themes/momotaro/components/button.css.ts.vanilla.cjs +1 -0
  74. package/dist/styles/themes/momotaro/components/button.css.ts.vanilla.mjs +1 -0
  75. package/dist/styles/themes/momotaro/components/checkbox.css.ts.vanilla.cjs +1 -0
  76. package/dist/styles/themes/momotaro/components/checkbox.css.ts.vanilla.mjs +1 -0
  77. package/dist/styles/themes/momotaro/components/dialog.css.ts.vanilla.cjs +1 -0
  78. package/dist/styles/themes/momotaro/components/dialog.css.ts.vanilla.mjs +1 -0
  79. package/dist/styles/themes/momotaro/components/divider.css.ts.vanilla.cjs +1 -0
  80. package/dist/styles/themes/momotaro/components/divider.css.ts.vanilla.mjs +1 -0
  81. package/dist/styles/themes/momotaro/components/dropdown.css.ts.vanilla.cjs +1 -0
  82. package/dist/styles/themes/momotaro/components/dropdown.css.ts.vanilla.mjs +1 -0
  83. package/dist/styles/themes/momotaro/components/helpers.css.ts.vanilla.cjs +1 -0
  84. package/dist/styles/themes/momotaro/components/helpers.css.ts.vanilla.mjs +1 -0
  85. package/dist/styles/themes/momotaro/components/input.css.ts.vanilla.cjs +1 -0
  86. package/dist/styles/themes/momotaro/components/input.css.ts.vanilla.mjs +1 -0
  87. package/dist/styles/themes/momotaro/components/label.css.ts.vanilla.cjs +1 -0
  88. package/dist/styles/themes/momotaro/components/label.css.ts.vanilla.mjs +1 -0
  89. package/dist/styles/themes/momotaro/components/link.css.ts.vanilla.cjs +1 -0
  90. package/dist/styles/themes/momotaro/components/link.css.ts.vanilla.mjs +1 -0
  91. package/dist/styles/themes/momotaro/components/progress.css.ts.vanilla.cjs +1 -0
  92. package/dist/styles/themes/momotaro/components/progress.css.ts.vanilla.mjs +1 -0
  93. package/dist/styles/themes/momotaro/components/radio.css.ts.vanilla.cjs +1 -0
  94. package/dist/styles/themes/momotaro/components/radio.css.ts.vanilla.mjs +1 -0
  95. package/dist/styles/themes/momotaro/components/select.css.ts.vanilla.cjs +1 -0
  96. package/dist/styles/themes/momotaro/components/select.css.ts.vanilla.mjs +1 -0
  97. package/dist/styles/themes/momotaro/components/slider.css.ts.vanilla.cjs +1 -0
  98. package/dist/styles/themes/momotaro/components/slider.css.ts.vanilla.mjs +1 -0
  99. package/dist/styles/themes/momotaro/components/spinner.css.ts.vanilla.cjs +1 -0
  100. package/dist/styles/themes/momotaro/components/spinner.css.ts.vanilla.mjs +1 -0
  101. package/dist/styles/themes/momotaro/components/switch.css.ts.vanilla.cjs +1 -0
  102. package/dist/styles/themes/momotaro/components/switch.css.ts.vanilla.mjs +1 -0
  103. package/dist/styles/themes/momotaro/momotaro.css.cjs +191 -7
  104. package/dist/styles/themes/momotaro/momotaro.css.mjs +191 -7
  105. package/dist/styles/themes/momotaro/momotaro.css.ts.vanilla.cjs +1 -0
  106. package/dist/styles/themes/momotaro/momotaro.css.ts.vanilla.mjs +1 -0
  107. package/dist/styles/themes/momotaro/tokens.css.ts.vanilla.cjs +1 -0
  108. package/dist/styles/themes/momotaro/tokens.css.ts.vanilla.mjs +1 -0
  109. package/package.json +22 -22
  110. package/dist/styles/lib/css/atoms/atomicProperties.cjs +0 -83
  111. package/dist/styles/lib/css/atoms/atomicProperties.mjs +0 -84
  112. package/dist/styles/lib/css/atoms/breakpoints.cjs +0 -11
  113. package/dist/styles/lib/css/atoms/breakpoints.mjs +0 -12
  114. package/dist/styles/lib/css/layers/layers.css.cjs +0 -7
  115. package/dist/styles/lib/css/layers/layers.css.mjs +0 -8
  116. package/dist/styles/lib/css/style/style.cjs +0 -28
  117. package/dist/styles/lib/css/style/style.mjs +0 -29
  118. package/dist/styles/lib/theme/makeComponentTheme.cjs +0 -5
  119. package/dist/styles/lib/theme/makeComponentTheme.mjs +0 -6
  120. package/dist/styles/lib/theme/makeVanillaTheme.cjs +0 -19
  121. package/dist/styles/lib/theme/makeVanillaTheme.mjs +0 -20
  122. package/dist/styles/lib/theme/tokens.cjs +0 -81
  123. package/dist/styles/lib/theme/tokens.mjs +0 -82
  124. package/dist/styles/themes/momotaro/components/button.css.cjs +0 -103
  125. package/dist/styles/themes/momotaro/components/button.css.mjs +0 -104
  126. package/dist/styles/themes/momotaro/components/checkbox.css.cjs +0 -59
  127. package/dist/styles/themes/momotaro/components/checkbox.css.mjs +0 -60
  128. package/dist/styles/themes/momotaro/components/dialog.css.cjs +0 -68
  129. package/dist/styles/themes/momotaro/components/dialog.css.mjs +0 -69
  130. package/dist/styles/themes/momotaro/components/divider.css.cjs +0 -11
  131. package/dist/styles/themes/momotaro/components/divider.css.mjs +0 -12
  132. package/dist/styles/themes/momotaro/components/dropdown.css.cjs +0 -54
  133. package/dist/styles/themes/momotaro/components/dropdown.css.mjs +0 -55
  134. package/dist/styles/themes/momotaro/components/helpers.css.cjs +0 -43
  135. package/dist/styles/themes/momotaro/components/helpers.css.mjs +0 -44
  136. package/dist/styles/themes/momotaro/components/index.cjs +0 -32
  137. package/dist/styles/themes/momotaro/components/index.mjs +0 -33
  138. package/dist/styles/themes/momotaro/components/input.css.cjs +0 -41
  139. package/dist/styles/themes/momotaro/components/input.css.mjs +0 -42
  140. package/dist/styles/themes/momotaro/components/label.css.cjs +0 -33
  141. package/dist/styles/themes/momotaro/components/label.css.mjs +0 -34
  142. package/dist/styles/themes/momotaro/components/link.css.cjs +0 -47
  143. package/dist/styles/themes/momotaro/components/link.css.mjs +0 -48
  144. package/dist/styles/themes/momotaro/components/progress.css.cjs +0 -55
  145. package/dist/styles/themes/momotaro/components/progress.css.mjs +0 -56
  146. package/dist/styles/themes/momotaro/components/radio.css.cjs +0 -60
  147. package/dist/styles/themes/momotaro/components/radio.css.mjs +0 -61
  148. package/dist/styles/themes/momotaro/components/select.css.cjs +0 -35
  149. package/dist/styles/themes/momotaro/components/select.css.mjs +0 -36
  150. package/dist/styles/themes/momotaro/components/slider.css.cjs +0 -65
  151. package/dist/styles/themes/momotaro/components/slider.css.mjs +0 -66
  152. package/dist/styles/themes/momotaro/components/spinner.css.cjs +0 -43
  153. package/dist/styles/themes/momotaro/components/spinner.css.mjs +0 -44
  154. package/dist/styles/themes/momotaro/components/switch.css.cjs +0 -58
  155. package/dist/styles/themes/momotaro/components/switch.css.mjs +0 -59
  156. package/dist/styles/themes/momotaro/components/transitions.cjs +0 -3
  157. package/dist/styles/themes/momotaro/components/transitions.mjs +0 -4
  158. package/dist/styles/themes/momotaro/tokens.css.cjs +0 -84
  159. package/dist/styles/themes/momotaro/tokens.css.mjs +0 -85
  160. /package/dist/styles/{lib/css/reset/reset.css.cjs → components/display/Divider/divider.css.ts.vanilla.cjs} +0 -0
  161. /package/dist/styles/{lib/css/reset/reset.css.mjs → components/display/Divider/divider.css.ts.vanilla.mjs} +0 -0
package/dist/index.cjs CHANGED
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const styles_lib_css_atoms_breakpoints_cjs = require("./styles/lib/css/atoms/breakpoints.cjs");
4
- const styles_lib_css_style_style_cjs = require("./styles/lib/css/style/style.cjs");
5
- const styles_lib_theme_makeComponentTheme_cjs = require("./styles/lib/theme/makeComponentTheme.cjs");
3
+ const css = require("@vanilla-extract/css");
4
+ const styles_lib_css_atoms_sprinkles_css_cjs = require("./styles/lib/css/atoms/sprinkles.css.cjs");
6
5
  const styles_lib_theme_makeTheme_cjs = require("./styles/lib/theme/makeTheme.cjs");
7
6
  const styles_lib_theme_vars_css_cjs = require("./styles/lib/theme/vars.css.cjs");
8
7
  const styles_components_display_Divider_Divider_cjs = require("./styles/components/display/Divider/Divider.cjs");
9
- const styles_lib_css_atoms_sprinkles_css_cjs = require("./styles/lib/css/atoms/sprinkles.css.cjs");
10
8
  const jsxRuntime = require("react/jsx-runtime");
11
9
  const react = require("react");
12
10
  const styles_components_form_Button_Button_cjs = require("./styles/components/form/Button/Button.cjs");
@@ -20,6 +18,40 @@ const styles_components_other_BlocksProvider_BlocksProvider_cjs = require("./sty
20
18
  const styles_components_overlay_Dialog_Dialog_cjs = require("./styles/components/overlay/Dialog/Dialog.cjs");
21
19
  const styles_components_typography_Heading_Heading_cjs = require("./styles/components/typography/Heading/Heading.cjs");
22
20
  const styles_components_typography_Text_Text_cjs = require("./styles/components/typography/Text/Text.cjs");
21
+ const breakpoints = {
22
+ mobile: 0,
23
+ tablet: 740,
24
+ desktop: 992,
25
+ wide: 1200
26
+ };
27
+ const breakpointQuery = (key) => `screen and (min-width: ${breakpoints[key]}px)`;
28
+ function style(props) {
29
+ const styleRule = {};
30
+ const atomClassNames = [];
31
+ if (Array.isArray(props)) {
32
+ return props.map((rule) => {
33
+ if (typeof rule === "string") {
34
+ return rule;
35
+ }
36
+ return style(rule);
37
+ }).join(" ");
38
+ }
39
+ for (const [name, value] of Object.entries(props)) {
40
+ if (styles_lib_css_atoms_sprinkles_css_cjs.atoms.properties.has(name)) {
41
+ try {
42
+ atomClassNames.push(styles_lib_css_atoms_sprinkles_css_cjs.atoms({ [name]: value }));
43
+ } catch {
44
+ styleRule[name] = value;
45
+ }
46
+ } else {
47
+ styleRule[name] = value;
48
+ }
49
+ }
50
+ return css.style([styleRule, ...atomClassNames]);
51
+ }
52
+ function makeComponentTheme(component, componentTheme) {
53
+ return componentTheme;
54
+ }
23
55
  const Progress = react.forwardRef(function Progress2({ value, max = 100, className, ...restProps }, ref) {
24
56
  const containerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles(
25
57
  "progress",
@@ -136,9 +168,222 @@ const Link = react.forwardRef(function Link2({ asChild, className, children, var
136
168
  }
137
169
  );
138
170
  });
139
- exports.breakpointQuery = styles_lib_css_atoms_breakpoints_cjs.breakpointQuery;
140
- exports.style = styles_lib_css_style_style_cjs.style;
141
- exports.makeComponentTheme = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme;
171
+ const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
172
+ react.useEffect(() => {
173
+ if (!enabled) {
174
+ return;
175
+ }
176
+ const listener = (event) => {
177
+ if (ref.current && !ref.current.contains(event.target)) {
178
+ onClickOutside();
179
+ }
180
+ };
181
+ document.addEventListener("click", listener);
182
+ return () => {
183
+ document.removeEventListener("click", listener);
184
+ };
185
+ }, [ref, onClickOutside, enabled]);
186
+ };
187
+ function getDropdownPosition(align, anchorRef, dropdownRef) {
188
+ if (!anchorRef.current || !dropdownRef.current) {
189
+ return [0, 0];
190
+ }
191
+ dropdownRef.current.style.transform = "none";
192
+ dropdownRef.current.style.transitionDuration = "0s";
193
+ const anchorRect = anchorRef.current.getBoundingClientRect();
194
+ const dropdownRect = dropdownRef.current.getBoundingClientRect();
195
+ const dropdownStyles = getComputedStyle(dropdownRef.current);
196
+ const marginTop = Number.parseFloat(dropdownStyles.getPropertyValue("margin-top"));
197
+ const marginRight = Number.parseFloat(dropdownStyles.getPropertyValue("margin-right"));
198
+ const marginBottom = Number.parseFloat(dropdownStyles.getPropertyValue("margin-bottom"));
199
+ const marginLeft = Number.parseFloat(dropdownStyles.getPropertyValue("margin-left"));
200
+ const marginY = marginTop + marginBottom;
201
+ const marginX = marginRight + marginLeft;
202
+ const docHeight = document.documentElement.clientHeight;
203
+ const docWidth = document.documentElement.clientWidth;
204
+ const docScrollTop = document.documentElement.scrollTop;
205
+ const docScrollLeft = document.documentElement.scrollLeft;
206
+ const anchorLeft = anchorRect.left + docScrollLeft;
207
+ const anchorTop = anchorRect.top + docScrollTop;
208
+ const topPosition = anchorRect.top - (dropdownRect.height + marginTop);
209
+ const rightPosition = anchorRect.left + anchorRect.width + dropdownRect.width;
210
+ const bottomPosition = anchorRect.top + anchorRect.height + dropdownRect.height;
211
+ const leftPosition = anchorRect.left - dropdownRect.width;
212
+ const offsetX = anchorLeft - (dropdownRect.width - anchorRect.width) / 2;
213
+ const offsetY = anchorTop - (dropdownRect.height - anchorRect.height) / 2;
214
+ dropdownRef.current.style.transform = "";
215
+ dropdownRef.current.style.transitionDuration = "";
216
+ switch (align) {
217
+ case "top": {
218
+ return topPosition > 0 ? [offsetX, anchorTop - dropdownRect.height - marginY] : [offsetX, anchorTop + anchorRect.height];
219
+ }
220
+ case "bottom": {
221
+ return bottomPosition < docHeight || topPosition < 0 ? [offsetX, anchorTop + anchorRect.height] : [offsetX, anchorTop - dropdownRect.height - marginY];
222
+ }
223
+ case "left": {
224
+ return leftPosition > docWidth || leftPosition > 0 ? [anchorLeft - dropdownRect.width - marginX, offsetY] : [anchorLeft + anchorRect.width, offsetY];
225
+ }
226
+ case "right": {
227
+ return rightPosition < docWidth || leftPosition < 0 ? [anchorLeft + anchorRect.width, offsetY] : [anchorLeft - dropdownRect.width - marginX, offsetY];
228
+ }
229
+ }
230
+ }
231
+ const Dropdown = ({
232
+ align = "bottom",
233
+ anchorElement,
234
+ children,
235
+ className,
236
+ onRequestClose,
237
+ open,
238
+ repositionOnScroll,
239
+ style: style2,
240
+ variant,
241
+ ...restProps
242
+ }) => {
243
+ const layer = styles_components_overlay_Dialog_Dialog_cjs.useLayer();
244
+ const [visible, hide] = styles_components_overlay_Dialog_Dialog_cjs.useVisibilityState(open);
245
+ const [position, setPosition] = react.useState({ x: 0, y: 0 });
246
+ const dropdownRef = react.useRef(null);
247
+ const containerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles(
248
+ "dropdown",
249
+ { base: true, variants: { variant } },
250
+ false
251
+ );
252
+ react.useLayoutEffect(() => {
253
+ if (!visible) {
254
+ return;
255
+ }
256
+ const position2 = getDropdownPosition(align, anchorElement, dropdownRef);
257
+ setPosition({ x: position2[0], y: position2[1] });
258
+ }, [align, anchorElement, visible]);
259
+ react.useEffect(() => {
260
+ if (!open || !repositionOnScroll) {
261
+ return;
262
+ }
263
+ function handleResize() {
264
+ const position2 = getDropdownPosition(align, anchorElement, dropdownRef);
265
+ setPosition({ x: position2[0], y: position2[1] });
266
+ }
267
+ window.addEventListener("resize", handleResize);
268
+ window.addEventListener("scroll", handleResize);
269
+ return () => {
270
+ window.removeEventListener("resize", handleResize);
271
+ window.removeEventListener("scroll", handleResize);
272
+ };
273
+ }, [align, anchorElement, open, repositionOnScroll]);
274
+ styles_components_overlay_Dialog_Dialog_cjs.useIsomorphicLayoutEffect(() => {
275
+ var _a;
276
+ if (!open) {
277
+ (_a = dropdownRef.current) == null ? void 0 : _a.removeAttribute("data-open");
278
+ return;
279
+ }
280
+ let timer = requestAnimationFrame(() => {
281
+ timer = requestAnimationFrame(() => {
282
+ var _a2;
283
+ (_a2 = dropdownRef.current) == null ? void 0 : _a2.setAttribute("data-open", "");
284
+ });
285
+ });
286
+ return () => {
287
+ cancelAnimationFrame(timer);
288
+ };
289
+ }, [open, visible]);
290
+ const onAnimationEnd = react.useCallback(() => {
291
+ if (!open) {
292
+ hide();
293
+ }
294
+ }, [hide, open]);
295
+ react.useEffect(() => {
296
+ if (open) {
297
+ return;
298
+ }
299
+ if (!styles_components_overlay_Dialog_Dialog_cjs.hasAnimationDuration(dropdownRef.current)) {
300
+ hide();
301
+ }
302
+ }, [hide, open]);
303
+ styles_components_overlay_Dialog_Dialog_cjs.useKeyboard("Escape", onRequestClose, { enabled: visible });
304
+ useClickOutside(dropdownRef, onRequestClose, { enabled: visible });
305
+ if (!visible) {
306
+ return null;
307
+ }
308
+ const dataOpen = typeof window === "undefined" && open ? "" : void 0;
309
+ return /* @__PURE__ */ jsxRuntime.jsx(styles_components_overlay_Dialog_Dialog_cjs.Portal, { container: layer(), children: /* @__PURE__ */ jsxRuntime.jsx(
310
+ styles_components_display_Divider_Divider_cjs.Box,
311
+ {
312
+ ref: dropdownRef,
313
+ "data-open": dataOpen,
314
+ onAnimationEnd,
315
+ onTransitionEnd: onAnimationEnd,
316
+ className: styles_components_display_Divider_Divider_cjs.classnames(containerClassName, className),
317
+ position: "absolute",
318
+ style: {
319
+ ...style2,
320
+ // TODO Think about how to handle this, perhaps we could add a custom class to the dropdown
321
+ // Or we remove it from getDropdownPosition?
322
+ // "horizontal" ? "vertical"
323
+ margin: align === "bottom" || align === "top" ? "var(--spacing) 0" : "0 var(--spacing)",
324
+ left: position.x,
325
+ top: position.y
326
+ },
327
+ ...restProps,
328
+ children
329
+ }
330
+ ) });
331
+ };
332
+ const Tooltip = ({ align = "top", children, label }) => {
333
+ const id = react.useId();
334
+ const ref = react.useRef(null);
335
+ const [open, setOpen] = react.useState(false);
336
+ react.useEffect(() => {
337
+ const element = ref.current;
338
+ if (!element) {
339
+ return;
340
+ }
341
+ function onEnter() {
342
+ setOpen(true);
343
+ }
344
+ function onLeave() {
345
+ setOpen(false);
346
+ }
347
+ element.addEventListener("mouseenter", onEnter);
348
+ element.addEventListener("mouseleave", onLeave);
349
+ element.addEventListener("focusin", onEnter);
350
+ element.addEventListener("focusout", onLeave);
351
+ return () => {
352
+ element.removeEventListener("mouseenter", onEnter);
353
+ element.removeEventListener("mouseleave", onLeave);
354
+ element.removeEventListener("focusin", onEnter);
355
+ element.removeEventListener("focusout", onLeave);
356
+ };
357
+ }, [ref, setOpen]);
358
+ if (react.Children.count(children) !== 1) {
359
+ throw new Error("Tooltip component can only have one child");
360
+ }
361
+ const child = react.Children.toArray(children)[0];
362
+ if (!react.isValidElement(child)) {
363
+ return null;
364
+ }
365
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
366
+ react.cloneElement(child, {
367
+ ref: styles_components_display_Divider_Divider_cjs.composeRefs(ref, child.ref),
368
+ ["aria-describedby"]: open ? id : void 0
369
+ }),
370
+ /* @__PURE__ */ jsxRuntime.jsx(
371
+ Dropdown,
372
+ {
373
+ id,
374
+ role: "tooltip",
375
+ anchorElement: ref,
376
+ open,
377
+ onRequestClose: () => {
378
+ setOpen(false);
379
+ },
380
+ align,
381
+ children: label
382
+ }
383
+ )
384
+ ] });
385
+ };
386
+ exports.atoms = styles_lib_css_atoms_sprinkles_css_cjs.atoms;
142
387
  exports.makeTheme = styles_lib_theme_makeTheme_cjs.makeTheme;
143
388
  exports.vars = styles_lib_theme_vars_css_cjs.vars;
144
389
  exports.Box = styles_components_display_Divider_Divider_cjs.Box;
@@ -148,7 +393,6 @@ exports.classnames = styles_components_display_Divider_Divider_cjs.classnames;
148
393
  exports.createSlottable = styles_components_display_Divider_Divider_cjs.createSlottable;
149
394
  exports.useComponentStyleDefaultProps = styles_components_display_Divider_Divider_cjs.useComponentStyleDefaultProps;
150
395
  exports.useComponentStyles = styles_components_display_Divider_Divider_cjs.useComponentStyles;
151
- exports.atoms = styles_lib_css_atoms_sprinkles_css_cjs.atoms;
152
396
  exports.Button = styles_components_form_Button_Button_cjs.Button;
153
397
  exports.Spinner = styles_components_form_Button_Button_cjs.Spinner;
154
398
  exports.Checkbox = styles_components_form_Checkbox_Checkbox_cjs.Checkbox;
@@ -171,3 +415,7 @@ exports.Inline = Inline;
171
415
  exports.Link = Link;
172
416
  exports.Progress = Progress;
173
417
  exports.Stack = Stack;
418
+ exports.Tooltip = Tooltip;
419
+ exports.breakpointQuery = breakpointQuery;
420
+ exports.makeComponentTheme = makeComponentTheme;
421
+ exports.style = style;
package/dist/index.d.mts CHANGED
@@ -1 +1 @@
1
- export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Button, ButtonProps, Checkbox, CheckboxProps, Dialog, DialogProps, Divider, DividerProps, Heading, HeadingProps, Inline, InlineProps, Input, InputProps, Label, LabelProps, Link, LinkProps, Portal, PortalProps, Progress, ProgressProps, Radio, RadioProps, Select, SelectProps, Slider, SliderProps, Slot, Spinner, SpinnerProps, Stack, StackProps, Switch, SwitchProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, atoms, breakpointQuery, classnames, createSlottable, makeComponentTheme, makeTheme, style, useComponentStyleDefaultProps, useComponentStyles, useIsomorphicLayoutEffect, useKeyboard, usePreventBodyScroll, useRootAriaHidden, vars } from './momotaro.chunk.js';
1
+ export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Button, ButtonProps, Checkbox, CheckboxProps, Dialog, DialogProps, Divider, DividerProps, Heading, HeadingProps, Inline, InlineProps, Input, InputProps, Label, LabelProps, Link, LinkProps, Portal, PortalProps, Progress, ProgressProps, Radio, RadioProps, Select, SelectProps, Slider, SliderProps, Slot, Spinner, SpinnerProps, Stack, StackProps, Switch, SwitchProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, Tooltip, TooltipProps, atoms, breakpointQuery, classnames, createSlottable, makeComponentTheme, makeTheme, style, useComponentStyleDefaultProps, useComponentStyles, useIsomorphicLayoutEffect, useKeyboard, usePreventBodyScroll, useRootAriaHidden, vars } from './momotaro.chunk.js';
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Button, ButtonProps, Checkbox, CheckboxProps, Dialog, DialogProps, Divider, DividerProps, Heading, HeadingProps, Inline, InlineProps, Input, InputProps, Label, LabelProps, Link, LinkProps, Portal, PortalProps, Progress, ProgressProps, Radio, RadioProps, Select, SelectProps, Slider, SliderProps, Slot, Spinner, SpinnerProps, Stack, StackProps, Switch, SwitchProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, atoms, breakpointQuery, classnames, createSlottable, makeComponentTheme, makeTheme, style, useComponentStyleDefaultProps, useComponentStyles, useIsomorphicLayoutEffect, useKeyboard, usePreventBodyScroll, useRootAriaHidden, vars } from './momotaro.chunk.js';
1
+ export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Button, ButtonProps, Checkbox, CheckboxProps, Dialog, DialogProps, Divider, DividerProps, Heading, HeadingProps, Inline, InlineProps, Input, InputProps, Label, LabelProps, Link, LinkProps, Portal, PortalProps, Progress, ProgressProps, Radio, RadioProps, Select, SelectProps, Slider, SliderProps, Slot, Spinner, SpinnerProps, Stack, StackProps, Switch, SwitchProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, Tooltip, TooltipProps, atoms, breakpointQuery, classnames, createSlottable, makeComponentTheme, makeTheme, style, useComponentStyleDefaultProps, useComponentStyles, useIsomorphicLayoutEffect, useKeyboard, usePreventBodyScroll, useRootAriaHidden, vars } from './momotaro.chunk.js';
package/dist/index.mjs CHANGED
@@ -1,15 +1,13 @@
1
1
  'use client';
2
2
 
3
- import { breakpointQuery } from "./styles/lib/css/atoms/breakpoints.mjs";
4
- import { style } from "./styles/lib/css/style/style.mjs";
5
- import { makeComponentTheme } from "./styles/lib/theme/makeComponentTheme.mjs";
3
+ import { style as style$1 } from "@vanilla-extract/css";
4
+ import { atoms } from "./styles/lib/css/atoms/sprinkles.css.mjs";
6
5
  import { makeTheme } from "./styles/lib/theme/makeTheme.mjs";
7
6
  import { vars } from "./styles/lib/theme/vars.css.mjs";
8
- import { useComponentStyles, Box, classnames, createSlottable } from "./styles/components/display/Divider/Divider.mjs";
7
+ import { useComponentStyles, Box, classnames, createSlottable, composeRefs } from "./styles/components/display/Divider/Divider.mjs";
9
8
  import { Divider, Slot, useComponentStyleDefaultProps } from "./styles/components/display/Divider/Divider.mjs";
10
- import { atoms } from "./styles/lib/css/atoms/sprinkles.css.mjs";
11
- import { jsx } from "react/jsx-runtime";
12
- import { forwardRef } from "react";
9
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
10
+ import { forwardRef, useEffect, useState, useRef, useLayoutEffect, useCallback, useId, Children, isValidElement, cloneElement } from "react";
13
11
  import { Button, Spinner } from "./styles/components/form/Button/Button.mjs";
14
12
  import { Checkbox, Label } from "./styles/components/form/Checkbox/Checkbox.mjs";
15
13
  import { Input } from "./styles/components/form/Input/Input.mjs";
@@ -18,9 +16,44 @@ import { Select } from "./styles/components/form/Select/Select.mjs";
18
16
  import { Slider } from "./styles/components/form/Slider/Slider.mjs";
19
17
  import { Switch } from "./styles/components/form/Switch/Switch.mjs";
20
18
  import { BlocksProvider } from "./styles/components/other/BlocksProvider/BlocksProvider.mjs";
21
- import { Dialog, Portal, useIsomorphicLayoutEffect, useKeyboard, usePreventBodyScroll, useRootAriaHidden } from "./styles/components/overlay/Dialog/Dialog.mjs";
19
+ import { useLayer, useVisibilityState, useIsomorphicLayoutEffect, hasAnimationDuration, useKeyboard, Portal } from "./styles/components/overlay/Dialog/Dialog.mjs";
20
+ import { Dialog, usePreventBodyScroll, useRootAriaHidden } from "./styles/components/overlay/Dialog/Dialog.mjs";
22
21
  import { Heading } from "./styles/components/typography/Heading/Heading.mjs";
23
22
  import { Text } from "./styles/components/typography/Text/Text.mjs";
23
+ const breakpoints = {
24
+ mobile: 0,
25
+ tablet: 740,
26
+ desktop: 992,
27
+ wide: 1200
28
+ };
29
+ const breakpointQuery = (key) => `screen and (min-width: ${breakpoints[key]}px)`;
30
+ function style(props) {
31
+ const styleRule = {};
32
+ const atomClassNames = [];
33
+ if (Array.isArray(props)) {
34
+ return props.map((rule) => {
35
+ if (typeof rule === "string") {
36
+ return rule;
37
+ }
38
+ return style(rule);
39
+ }).join(" ");
40
+ }
41
+ for (const [name, value] of Object.entries(props)) {
42
+ if (atoms.properties.has(name)) {
43
+ try {
44
+ atomClassNames.push(atoms({ [name]: value }));
45
+ } catch {
46
+ styleRule[name] = value;
47
+ }
48
+ } else {
49
+ styleRule[name] = value;
50
+ }
51
+ }
52
+ return style$1([styleRule, ...atomClassNames]);
53
+ }
54
+ function makeComponentTheme(component, componentTheme) {
55
+ return componentTheme;
56
+ }
24
57
  const Progress = forwardRef(function Progress2({ value, max = 100, className, ...restProps }, ref) {
25
58
  const containerClassName = useComponentStyles(
26
59
  "progress",
@@ -137,6 +170,221 @@ const Link = forwardRef(function Link2({ asChild, className, children, variant,
137
170
  }
138
171
  );
139
172
  });
173
+ const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
174
+ useEffect(() => {
175
+ if (!enabled) {
176
+ return;
177
+ }
178
+ const listener = (event) => {
179
+ if (ref.current && !ref.current.contains(event.target)) {
180
+ onClickOutside();
181
+ }
182
+ };
183
+ document.addEventListener("click", listener);
184
+ return () => {
185
+ document.removeEventListener("click", listener);
186
+ };
187
+ }, [ref, onClickOutside, enabled]);
188
+ };
189
+ function getDropdownPosition(align, anchorRef, dropdownRef) {
190
+ if (!anchorRef.current || !dropdownRef.current) {
191
+ return [0, 0];
192
+ }
193
+ dropdownRef.current.style.transform = "none";
194
+ dropdownRef.current.style.transitionDuration = "0s";
195
+ const anchorRect = anchorRef.current.getBoundingClientRect();
196
+ const dropdownRect = dropdownRef.current.getBoundingClientRect();
197
+ const dropdownStyles = getComputedStyle(dropdownRef.current);
198
+ const marginTop = Number.parseFloat(dropdownStyles.getPropertyValue("margin-top"));
199
+ const marginRight = Number.parseFloat(dropdownStyles.getPropertyValue("margin-right"));
200
+ const marginBottom = Number.parseFloat(dropdownStyles.getPropertyValue("margin-bottom"));
201
+ const marginLeft = Number.parseFloat(dropdownStyles.getPropertyValue("margin-left"));
202
+ const marginY = marginTop + marginBottom;
203
+ const marginX = marginRight + marginLeft;
204
+ const docHeight = document.documentElement.clientHeight;
205
+ const docWidth = document.documentElement.clientWidth;
206
+ const docScrollTop = document.documentElement.scrollTop;
207
+ const docScrollLeft = document.documentElement.scrollLeft;
208
+ const anchorLeft = anchorRect.left + docScrollLeft;
209
+ const anchorTop = anchorRect.top + docScrollTop;
210
+ const topPosition = anchorRect.top - (dropdownRect.height + marginTop);
211
+ const rightPosition = anchorRect.left + anchorRect.width + dropdownRect.width;
212
+ const bottomPosition = anchorRect.top + anchorRect.height + dropdownRect.height;
213
+ const leftPosition = anchorRect.left - dropdownRect.width;
214
+ const offsetX = anchorLeft - (dropdownRect.width - anchorRect.width) / 2;
215
+ const offsetY = anchorTop - (dropdownRect.height - anchorRect.height) / 2;
216
+ dropdownRef.current.style.transform = "";
217
+ dropdownRef.current.style.transitionDuration = "";
218
+ switch (align) {
219
+ case "top": {
220
+ return topPosition > 0 ? [offsetX, anchorTop - dropdownRect.height - marginY] : [offsetX, anchorTop + anchorRect.height];
221
+ }
222
+ case "bottom": {
223
+ return bottomPosition < docHeight || topPosition < 0 ? [offsetX, anchorTop + anchorRect.height] : [offsetX, anchorTop - dropdownRect.height - marginY];
224
+ }
225
+ case "left": {
226
+ return leftPosition > docWidth || leftPosition > 0 ? [anchorLeft - dropdownRect.width - marginX, offsetY] : [anchorLeft + anchorRect.width, offsetY];
227
+ }
228
+ case "right": {
229
+ return rightPosition < docWidth || leftPosition < 0 ? [anchorLeft + anchorRect.width, offsetY] : [anchorLeft - dropdownRect.width - marginX, offsetY];
230
+ }
231
+ }
232
+ }
233
+ const Dropdown = ({
234
+ align = "bottom",
235
+ anchorElement,
236
+ children,
237
+ className,
238
+ onRequestClose,
239
+ open,
240
+ repositionOnScroll,
241
+ style: style2,
242
+ variant,
243
+ ...restProps
244
+ }) => {
245
+ const layer = useLayer();
246
+ const [visible, hide] = useVisibilityState(open);
247
+ const [position, setPosition] = useState({ x: 0, y: 0 });
248
+ const dropdownRef = useRef(null);
249
+ const containerClassName = useComponentStyles(
250
+ "dropdown",
251
+ { base: true, variants: { variant } },
252
+ false
253
+ );
254
+ useLayoutEffect(() => {
255
+ if (!visible) {
256
+ return;
257
+ }
258
+ const position2 = getDropdownPosition(align, anchorElement, dropdownRef);
259
+ setPosition({ x: position2[0], y: position2[1] });
260
+ }, [align, anchorElement, visible]);
261
+ useEffect(() => {
262
+ if (!open || !repositionOnScroll) {
263
+ return;
264
+ }
265
+ function handleResize() {
266
+ const position2 = getDropdownPosition(align, anchorElement, dropdownRef);
267
+ setPosition({ x: position2[0], y: position2[1] });
268
+ }
269
+ window.addEventListener("resize", handleResize);
270
+ window.addEventListener("scroll", handleResize);
271
+ return () => {
272
+ window.removeEventListener("resize", handleResize);
273
+ window.removeEventListener("scroll", handleResize);
274
+ };
275
+ }, [align, anchorElement, open, repositionOnScroll]);
276
+ useIsomorphicLayoutEffect(() => {
277
+ var _a;
278
+ if (!open) {
279
+ (_a = dropdownRef.current) == null ? void 0 : _a.removeAttribute("data-open");
280
+ return;
281
+ }
282
+ let timer = requestAnimationFrame(() => {
283
+ timer = requestAnimationFrame(() => {
284
+ var _a2;
285
+ (_a2 = dropdownRef.current) == null ? void 0 : _a2.setAttribute("data-open", "");
286
+ });
287
+ });
288
+ return () => {
289
+ cancelAnimationFrame(timer);
290
+ };
291
+ }, [open, visible]);
292
+ const onAnimationEnd = useCallback(() => {
293
+ if (!open) {
294
+ hide();
295
+ }
296
+ }, [hide, open]);
297
+ useEffect(() => {
298
+ if (open) {
299
+ return;
300
+ }
301
+ if (!hasAnimationDuration(dropdownRef.current)) {
302
+ hide();
303
+ }
304
+ }, [hide, open]);
305
+ useKeyboard("Escape", onRequestClose, { enabled: visible });
306
+ useClickOutside(dropdownRef, onRequestClose, { enabled: visible });
307
+ if (!visible) {
308
+ return null;
309
+ }
310
+ const dataOpen = typeof window === "undefined" && open ? "" : void 0;
311
+ return /* @__PURE__ */ jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsx(
312
+ Box,
313
+ {
314
+ ref: dropdownRef,
315
+ "data-open": dataOpen,
316
+ onAnimationEnd,
317
+ onTransitionEnd: onAnimationEnd,
318
+ className: classnames(containerClassName, className),
319
+ position: "absolute",
320
+ style: {
321
+ ...style2,
322
+ // TODO Think about how to handle this, perhaps we could add a custom class to the dropdown
323
+ // Or we remove it from getDropdownPosition?
324
+ // "horizontal" ? "vertical"
325
+ margin: align === "bottom" || align === "top" ? "var(--spacing) 0" : "0 var(--spacing)",
326
+ left: position.x,
327
+ top: position.y
328
+ },
329
+ ...restProps,
330
+ children
331
+ }
332
+ ) });
333
+ };
334
+ const Tooltip = ({ align = "top", children, label }) => {
335
+ const id = useId();
336
+ const ref = useRef(null);
337
+ const [open, setOpen] = useState(false);
338
+ useEffect(() => {
339
+ const element = ref.current;
340
+ if (!element) {
341
+ return;
342
+ }
343
+ function onEnter() {
344
+ setOpen(true);
345
+ }
346
+ function onLeave() {
347
+ setOpen(false);
348
+ }
349
+ element.addEventListener("mouseenter", onEnter);
350
+ element.addEventListener("mouseleave", onLeave);
351
+ element.addEventListener("focusin", onEnter);
352
+ element.addEventListener("focusout", onLeave);
353
+ return () => {
354
+ element.removeEventListener("mouseenter", onEnter);
355
+ element.removeEventListener("mouseleave", onLeave);
356
+ element.removeEventListener("focusin", onEnter);
357
+ element.removeEventListener("focusout", onLeave);
358
+ };
359
+ }, [ref, setOpen]);
360
+ if (Children.count(children) !== 1) {
361
+ throw new Error("Tooltip component can only have one child");
362
+ }
363
+ const child = Children.toArray(children)[0];
364
+ if (!isValidElement(child)) {
365
+ return null;
366
+ }
367
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
368
+ cloneElement(child, {
369
+ ref: composeRefs(ref, child.ref),
370
+ ["aria-describedby"]: open ? id : void 0
371
+ }),
372
+ /* @__PURE__ */ jsx(
373
+ Dropdown,
374
+ {
375
+ id,
376
+ role: "tooltip",
377
+ anchorElement: ref,
378
+ open,
379
+ onRequestClose: () => {
380
+ setOpen(false);
381
+ },
382
+ align,
383
+ children: label
384
+ }
385
+ )
386
+ ] });
387
+ };
140
388
  export {
141
389
  BlocksProvider,
142
390
  Box,
@@ -159,6 +407,7 @@ export {
159
407
  Stack,
160
408
  Switch,
161
409
  Text,
410
+ Tooltip,
162
411
  atoms,
163
412
  breakpointQuery,
164
413
  classnames,