@blockle/blocks 0.12.2 → 0.14.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.
@@ -1,16 +1,7 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { useEffect, useLayoutEffect, useRef, useState, useCallback, createContext, useContext } from "react";
3
- import { useTheme, useComponentStyles, classnames } from "../../display/Divider/Divider.mjs";
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useRef, createContext, useContext, useState, useCallback } from "react";
3
+ import { useComponentStyles, classnames } from "../../display/Divider/Divider.mjs";
4
4
  import { dialog } from "./dialog.css.mjs";
5
- import { createPortal } from "react-dom";
6
- import { BlocksProvider } from "../../other/BlocksProvider/BlocksProvider.mjs";
7
- const Portal = ({ children, container }) => {
8
- const context = useTheme();
9
- return createPortal(
10
- /* @__PURE__ */ jsx(BlocksProvider, { theme: context, children }),
11
- container || document.body
12
- );
13
- };
14
5
  const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
15
6
  useEffect(() => {
16
7
  if (!enabled) {
@@ -21,8 +12,11 @@ const useClickOutside = (ref, onClickOutside, { enabled = true } = {}) => {
21
12
  onClickOutside();
22
13
  }
23
14
  };
24
- document.addEventListener("click", listener);
15
+ const rafId = requestAnimationFrame(() => {
16
+ document.addEventListener("click", listener);
17
+ });
25
18
  return () => {
19
+ cancelAnimationFrame(rafId);
26
20
  document.removeEventListener("click", listener);
27
21
  };
28
22
  }, [ref, onClickOutside, enabled]);
@@ -44,27 +38,6 @@ const useKeyboard = (key, callback, { enabled = true, type = "keydown" } = {}) =
44
38
  };
45
39
  }, [callback, enabled, key, type]);
46
40
  };
47
- const useLayer = () => {
48
- const layerRef = useRef();
49
- useEffect(
50
- () => () => {
51
- if (layerRef.current) {
52
- layerRef.current.remove();
53
- layerRef.current = void 0;
54
- }
55
- },
56
- []
57
- );
58
- return () => {
59
- if (!layerRef.current) {
60
- const div = document.createElement("div");
61
- div.dataset.layer = "blocks";
62
- layerRef.current = div;
63
- document.body.append(layerRef.current);
64
- }
65
- return layerRef.current;
66
- };
67
- };
68
41
  const usePreventBodyScroll = (enabled = true) => {
69
42
  useIsomorphicLayoutEffect(() => {
70
43
  if (!enabled) {
@@ -105,24 +78,15 @@ const useRestoreFocus = (active) => {
105
78
  }
106
79
  }, [active]);
107
80
  };
108
- const useVisibilityState = (open) => {
109
- const [visible, setVisible] = useState(open);
110
- const hide = useCallback(() => {
111
- setVisible(false);
112
- }, []);
113
- useEffect(() => {
114
- if (open) {
115
- setVisible(true);
116
- }
117
- }, [open]);
118
- return [visible, hide];
119
- };
120
81
  function hasAnimationDuration(element) {
121
82
  if (!element) {
122
83
  return false;
123
84
  }
124
85
  const style = window.getComputedStyle(element);
125
- return style.transitionDuration !== "0s" || style.animationDuration !== "0s";
86
+ return hasDuration(style.transitionDuration) || hasDuration(style.animationDuration);
87
+ }
88
+ function hasDuration(duration) {
89
+ return duration.split(",").map((part) => Number.parseFloat(part.trim())).some((part) => part > 0);
126
90
  }
127
91
  const DialogContext = createContext(void 0);
128
92
  const useNestedDialog = (open) => {
@@ -148,12 +112,11 @@ const Dialog = ({
148
112
  }) => {
149
113
  const dialogClassName = useComponentStyles("dialog", { dialog: true, variants: { size } });
150
114
  const dialogRef = useRef(null);
151
- const layer = useLayer();
152
- const [visible, hide] = useVisibilityState(open);
153
115
  const [enabled, setEnabled] = useState(true);
116
+ const [visible, setVisible] = useState(open);
154
117
  useRestoreFocus(open);
155
- const isNested = useNestedDialog(visible);
156
- usePreventBodyScroll(visible && !isNested);
118
+ const isNested = useNestedDialog(open);
119
+ usePreventBodyScroll(open && !isNested);
157
120
  const onEscape = useCallback(
158
121
  (event) => {
159
122
  event.preventDefault();
@@ -165,47 +128,32 @@ const Dialog = ({
165
128
  useClickOutside(dialogRef, onRequestClose, { enabled: open && enabled });
166
129
  useIsomorphicLayoutEffect(() => {
167
130
  var _a, _b;
168
- if (!visible) {
169
- (_a = dialogRef.current) == null ? void 0 : _a.close();
170
- }
171
- if (!open) {
172
- (_b = dialogRef.current) == null ? void 0 : _b.removeAttribute("data-open");
173
- return;
131
+ if (open && visible) {
132
+ (_a = dialogRef.current) == null ? void 0 : _a.showModal();
133
+ } else if (open) {
134
+ setVisible(true);
135
+ } else {
136
+ if (!hasAnimationDuration(dialogRef.current)) {
137
+ setVisible(false);
138
+ }
139
+ (_b = dialogRef.current) == null ? void 0 : _b.close();
174
140
  }
175
- let timer = requestAnimationFrame(() => {
176
- timer = requestAnimationFrame(() => {
177
- var _a2, _b2;
178
- (_a2 = dialogRef.current) == null ? void 0 : _a2.showModal();
179
- (_b2 = dialogRef.current) == null ? void 0 : _b2.setAttribute("data-open", "");
180
- });
181
- });
182
- return () => {
183
- cancelAnimationFrame(timer);
184
- };
185
141
  }, [open, visible]);
186
142
  const onAnimationEnd = useCallback(() => {
187
143
  if (!open) {
188
- hide();
189
- }
190
- }, [hide, open]);
191
- useEffect(() => {
192
- if (open) {
193
- return;
194
- }
195
- if (!hasAnimationDuration(dialogRef.current)) {
196
- hide();
144
+ setVisible(false);
197
145
  }
198
- }, [hide, open]);
146
+ }, [setVisible, open]);
199
147
  if (!visible) {
200
148
  return null;
201
149
  }
202
- const dataOpen = typeof window === "undefined" && open ? "" : void 0;
203
- return /* @__PURE__ */ jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsx(
150
+ const dataOpen = typeof window === "undefined" && open ? true : void 0;
151
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(DialogContext.Provider, { value: { setEnabled }, children: /* @__PURE__ */ jsx(
204
152
  "dialog",
205
153
  {
206
154
  ref: dialogRef,
207
155
  "aria-modal": "true",
208
- "data-open": dataOpen,
156
+ open: dataOpen,
209
157
  className: classnames(dialog, dialogClassName, className),
210
158
  onAnimationEnd,
211
159
  onTransitionEnd: onAnimationEnd,
@@ -216,12 +164,9 @@ const Dialog = ({
216
164
  };
217
165
  export {
218
166
  Dialog,
219
- Portal,
220
167
  hasAnimationDuration,
221
168
  useClickOutside,
222
169
  useIsomorphicLayoutEffect,
223
170
  useKeyboard,
224
- useLayer,
225
- usePreventBodyScroll,
226
- useVisibilityState
171
+ usePreventBodyScroll
227
172
  };
@@ -20,23 +20,36 @@ const dialog = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("dialo
20
20
  backgroundColor: "rgba(0, 0, 0, 0.5)"
21
21
  },
22
22
  selectors: {
23
- "&[data-open]": {
23
+ "&[open]": {
24
24
  transform: "translate(0, 0)",
25
25
  opacity: 1
26
26
  },
27
- "&[data-open]::backdrop": {
27
+ "&[open]::backdrop": {
28
28
  opacity: 1
29
29
  }
30
30
  },
31
31
  // Apply the animation only if the user has not requested reduced motion
32
32
  "@media": {
33
33
  "(prefers-reduced-motion: no-preference)": {
34
+ // Ending style
34
35
  transform: "translate(0, -120px)",
35
36
  opacity: 0,
36
- transition: "transform 240ms, opacity 160ms",
37
+ transitionBehavior: "allow-discrete",
38
+ transitionProperty: "opacity, transform, overlay, display",
39
+ transitionDuration: "240ms, 160ms, 240ms, 240ms",
40
+ // @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
41
+ "@starting-style": {
42
+ transform: "translate(0, -120px)",
43
+ opacity: 0
44
+ },
37
45
  "::backdrop": {
38
46
  opacity: 0,
39
- transition: "opacity 160ms"
47
+ transitionBehavior: "allow-discrete",
48
+ transitionProperty: "opacity, overlay, display",
49
+ transitionDuration: "160ms, 240ms, 240ms",
50
+ "@starting-style": {
51
+ opacity: 0
52
+ }
40
53
  }
41
54
  }
42
55
  }
@@ -19,23 +19,36 @@ const dialog = makeComponentTheme("dialog", {
19
19
  backgroundColor: "rgba(0, 0, 0, 0.5)"
20
20
  },
21
21
  selectors: {
22
- "&[data-open]": {
22
+ "&[open]": {
23
23
  transform: "translate(0, 0)",
24
24
  opacity: 1
25
25
  },
26
- "&[data-open]::backdrop": {
26
+ "&[open]::backdrop": {
27
27
  opacity: 1
28
28
  }
29
29
  },
30
30
  // Apply the animation only if the user has not requested reduced motion
31
31
  "@media": {
32
32
  "(prefers-reduced-motion: no-preference)": {
33
+ // Ending style
33
34
  transform: "translate(0, -120px)",
34
35
  opacity: 0,
35
- transition: "transform 240ms, opacity 160ms",
36
+ transitionBehavior: "allow-discrete",
37
+ transitionProperty: "opacity, transform, overlay, display",
38
+ transitionDuration: "240ms, 160ms, 240ms, 240ms",
39
+ // @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
40
+ "@starting-style": {
41
+ transform: "translate(0, -120px)",
42
+ opacity: 0
43
+ },
36
44
  "::backdrop": {
37
45
  opacity: 0,
38
- transition: "opacity 160ms"
46
+ transitionBehavior: "allow-discrete",
47
+ transitionProperty: "opacity, overlay, display",
48
+ transitionDuration: "160ms, 240ms, 240ms",
49
+ "@starting-style": {
50
+ opacity: 0
51
+ }
39
52
  }
40
53
  }
41
54
  }
@@ -19,6 +19,12 @@ const link = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("link",
19
19
  textDecoration: "underline"
20
20
  },
21
21
  cursor: "pointer"
22
+ // selectors: {
23
+ // '&[target="_blank"]::after': {
24
+ // content: '"\\2197"',
25
+ // marginLeft: 4,
26
+ // },
27
+ // },
22
28
  }, styles_themes_momotaro_components_helpers_css_cjs.focusable], "link_base"),
23
29
  variants: {
24
30
  variant: {
@@ -18,6 +18,12 @@ const link = makeComponentTheme("link", {
18
18
  textDecoration: "underline"
19
19
  },
20
20
  cursor: "pointer"
21
+ // selectors: {
22
+ // '&[target="_blank"]::after': {
23
+ // content: '"\\2197"',
24
+ // marginLeft: 4,
25
+ // },
26
+ // },
21
27
  }, focusable], "link_base"),
22
28
  variants: {
23
29
  variant: {
@@ -11,6 +11,7 @@ const popover = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("popo
11
11
  padding: "medium",
12
12
  margin: "small",
13
13
  // Space between the popover and the anchor element
14
+ width: "max-content",
14
15
  selectors: {
15
16
  "&[data-open]": {
16
17
  transform: "scale(1)",
@@ -10,6 +10,7 @@ const popover = makeComponentTheme("popover", {
10
10
  padding: "medium",
11
11
  margin: "small",
12
12
  // Space between the popover and the anchor element
13
+ width: "max-content",
13
14
  selectors: {
14
15
  "&[data-open]": {
15
16
  transform: "scale(1)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockle/blocks",
3
- "version": "0.12.2",
3
+ "version": "0.14.0",
4
4
  "description": "Blocks design system",
5
5
  "repository": "git@github.com:Blockle/blocks.git",
6
6
  "license": "MIT",
@@ -34,7 +34,6 @@
34
34
  "import": "./dist/themes/momotaro.mjs",
35
35
  "require": "./dist/themes/momotaro.cjs"
36
36
  },
37
- "./dist/style.css": "./dist/style.css",
38
37
  "./package.json": "./package.json"
39
38
  },
40
39
  "main": "./dist/index.cjs",
@@ -59,6 +58,10 @@
59
58
  "resolutions": {
60
59
  "string-width": "^4.2.2"
61
60
  },
61
+ "dependencies": {
62
+ "npm": "^10.8.1",
63
+ "update": "^0.4.2"
64
+ },
62
65
  "devDependencies": {
63
66
  "@changesets/cli": "^2.27.5",
64
67
  "@crackle/cli": "^0.15.4",