reshaped 3.2.0-canary.5 → 3.2.0-canary.6

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.
@@ -9,7 +9,7 @@ export default {
9
9
  component: Overlay,
10
10
  parameters: {
11
11
  iframe: {
12
- url: "https://reshaped.so/docs/components/overlay",
12
+ url: "https://reshaped.so/docs/utilities/overlay",
13
13
  },
14
14
  },
15
15
  };
@@ -8,6 +8,6 @@ const Tooltip = (props) => {
8
8
  const { id, text, children, onOpen, onClose, position = "bottom", containerRef, active, disabled, disableContentHover, } = props;
9
9
  if (!text)
10
10
  return _jsx(_Fragment, { children: children({}) });
11
- return (_jsxs(Flyout, { id: id, active: active, position: position, disabled: disabled, onOpen: onOpen, onClose: onClose, disableContentHover: disableContentHover, containerRef: containerRef, triggerType: "hover", children: [_jsx(Flyout.Trigger, { children: children }), _jsx(Flyout.Content, { children: _jsx(Theme, { colorMode: "inverted", children: _jsx(Text, { variant: "caption-1", className: s.root, children: text }) }) })] }));
11
+ return (_jsxs(Flyout, { id: id, active: active, position: position, disabled: disabled, onOpen: onOpen, onClose: onClose, disableContentHover: disableContentHover, containerRef: containerRef, triggerType: "hover", groupTimeouts: true, children: [_jsx(Flyout.Trigger, { children: children }), _jsx(Flyout.Content, { children: _jsx(Theme, { colorMode: "inverted", children: _jsx(Text, { variant: "caption-1", className: s.root, children: text }) }) })] }));
12
12
  };
13
13
  export default Tooltip;
@@ -26,16 +26,20 @@ const Expandable = (props) => {
26
26
  const rootEl = rootRef.current;
27
27
  if (!rootEl || !mountedRef.current)
28
28
  return;
29
- let targetHeight = 0;
30
29
  if (active) {
31
30
  rootEl.style.height = "auto";
32
- targetHeight = rootEl.clientHeight;
33
- rootEl.style.height = "0";
31
+ requestAnimationFrame(() => {
32
+ const targetHeight = rootEl.clientHeight;
33
+ rootEl.style.height = "0";
34
+ setAnimatedHeight(targetHeight);
35
+ });
34
36
  }
35
- if (!active) {
37
+ else {
36
38
  rootEl.style.height = `${rootEl.clientHeight}px`;
39
+ requestAnimationFrame(() => {
40
+ setAnimatedHeight(0);
41
+ });
37
42
  }
38
- setAnimatedHeight(targetHeight);
39
43
  }, [active]);
40
44
  return (_jsx("div", { ...attributes, className: contentClassNames, ref: rootRef, style: animatedHeight !== null
41
45
  ? { height: animatedHeight, overflow: animatedHeight === "auto" ? "visible" : undefined }
@@ -64,6 +64,7 @@ export type TriggerAttributes = {
64
64
  type BaseProps = {
65
65
  id?: string;
66
66
  triggerType?: "hover" | "click" | "focus";
67
+ groupTimeouts?: boolean;
67
68
  position?: Position;
68
69
  forcePosition?: boolean;
69
70
  trapFocusMode?: TrapMode;
@@ -16,7 +16,7 @@ import cooldown from "./utilities/cooldown.js";
16
16
  import { Provider, useFlyoutTriggerContext, useFlyoutContext, useFlyoutContentContext, } from "./Flyout.context.js";
17
17
  import useHandlerRef from "../../../hooks/useHandlerRef.js";
18
18
  const FlyoutRoot = (props) => {
19
- const { triggerType = "click", onOpen, onClose, children, disabled, forcePosition, trapFocusMode, width, disableHideAnimation, disableContentHover, disableCloseOnOutsideClick, contentGap, contentClassName, contentAttributes, position: passedPosition, active: passedActive, id: passedId, instanceRef, containerRef, } = props;
19
+ const { triggerType = "click", groupTimeouts, onOpen, onClose, children, disabled, forcePosition, trapFocusMode, width, disableHideAnimation, disableContentHover, disableCloseOnOutsideClick, contentGap, contentClassName, contentAttributes, position: passedPosition, active: passedActive, id: passedId, instanceRef, containerRef, } = props;
20
20
  const onOpenRef = useHandlerRef(onOpen);
21
21
  const onCloseRef = useHandlerRef(onClose);
22
22
  const resolvedActive = disabled === true ? false : passedActive;
@@ -113,17 +113,20 @@ const FlyoutRoot = (props) => {
113
113
  }, [triggerType]);
114
114
  const handleMouseEnter = React.useCallback(() => {
115
115
  clearTimer();
116
- console.log("enter");
117
116
  if (hoverTriggeredWithTouchEventRef.current) {
118
117
  handleOpen();
119
118
  hoverTriggeredWithTouchEventRef.current = false;
120
119
  }
121
120
  else {
122
- timerRef.current = setTimeout(handleOpen, cooldown.timer || isSubmenu ? timeouts.mouseEnterShort : timeouts.mouseEnter);
123
- if (!isSubmenu && triggerType === "hover")
121
+ if (groupTimeouts)
124
122
  cooldown.warm();
123
+ timerRef.current = setTimeout(() => {
124
+ handleOpen();
125
+ }, groupTimeouts && cooldown.status === "warming"
126
+ ? timeouts.mouseEnter
127
+ : timeouts.mouseEnterShort);
125
128
  }
126
- }, [clearTimer, timerRef, handleOpen, isSubmenu, triggerType]);
129
+ }, [clearTimer, timerRef, handleOpen, groupTimeouts]);
127
130
  const handleMouseLeave = React.useCallback(() => {
128
131
  cooldown.cool();
129
132
  clearTimer();
@@ -181,14 +184,14 @@ const FlyoutRoot = (props) => {
181
184
  if (checkTransitions() &&
182
185
  !disableHideAnimation &&
183
186
  transitionStartedRef.current &&
184
- (cooldown.status !== "warm" || triggerType !== "hover")) {
187
+ (cooldown.status === "cooling" || !groupTimeouts)) {
185
188
  hide();
186
189
  }
187
190
  else {
188
191
  // In case transitions are disabled globally - remove from the DOM immediately
189
192
  remove();
190
193
  }
191
- }, [resolvedActive, render, hide, remove, disableHideAnimation, disabled]);
194
+ }, [resolvedActive, render, hide, remove, disableHideAnimation, disabled, groupTimeouts]);
192
195
  React.useEffect(() => {
193
196
  // Wait after positioning before show is triggered to animate flyout from the right side
194
197
  if (status === "positioned")
@@ -1,5 +1,5 @@
1
1
  declare class Cooldown {
2
- status: "cold" | "warm" | "cooling";
2
+ status: "warming" | "warm" | "cooling" | "cold";
3
3
  timer?: ReturnType<typeof setTimeout>;
4
4
  warm: () => void;
5
5
  cool: () => void;
@@ -1,18 +1,30 @@
1
+ import * as timeouts from "../Flyout.constants.js";
1
2
  class Cooldown {
2
3
  status = "cold";
3
4
  timer;
4
5
  warm = () => {
5
6
  clearTimeout(this.timer);
6
- this.status = "warm";
7
+ if (this.status === "cooling") {
8
+ this.status = "warm";
9
+ return;
10
+ }
11
+ this.status = "warming";
12
+ this.timer = setTimeout(() => {
13
+ this.status = "warm";
14
+ this.timer = undefined;
15
+ }, timeouts.mouseEnterShort);
7
16
  };
8
17
  cool = () => {
18
+ clearTimeout(this.timer);
19
+ if (this.status === "warming") {
20
+ this.status = "cold";
21
+ return;
22
+ }
9
23
  this.status = "cooling";
10
- const currentTimer = setTimeout(() => {
24
+ this.timer = setTimeout(() => {
11
25
  this.status = "cold";
12
- if (currentTimer === this.timer)
13
- this.timer = undefined;
26
+ this.timer = undefined;
14
27
  }, 500);
15
- this.timer = currentTimer;
16
28
  };
17
29
  }
18
30
  export default new Cooldown();
@@ -3,7 +3,6 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import React from "react";
4
4
  import ReactDOM from "react-dom";
5
5
  import Theme from "../../Theme/index.js";
6
- import { getShadowRoot } from "../../../utilities/dom.js";
7
6
  import s from "./Portal.module.css";
8
7
  const PortalScopeContext = React.createContext({});
9
8
  export const usePortalScope = () => {
@@ -16,8 +15,9 @@ export const usePortalScope = () => {
16
15
  const Portal = (props) => {
17
16
  const { children, targetRef } = props;
18
17
  const rootRef = React.useRef(null);
19
- const shadowRoot = getShadowRoot(rootRef.current);
20
- const defaultTargetEl = shadowRoot ?? document.body;
18
+ const rootNode = rootRef.current?.getRootNode();
19
+ const isShadowDom = rootNode instanceof ShadowRoot;
20
+ const defaultTargetEl = isShadowDom ? rootNode : document.body;
21
21
  /**
22
22
  * Check for parent portal to render inside it
23
23
  * To avoid z-iondex issues
@@ -70,10 +70,12 @@ export class HotkeyStore {
70
70
  const hotkeyData = this.hotkeyMap[pressedId];
71
71
  /**
72
72
  * Support for `mod` that represents both Mac and Win keyboards
73
+ * We create the hotkeyId again to sort the mod key correctly
73
74
  */
74
- const hotkeyControlModData = pressedFormattedKeys.includes("control") &&
75
- this.hotkeyMap[pressedId.replace("control", "mod")];
76
- const hotkeyMetaModData = pressedFormattedKeys.includes("meta") && this.hotkeyMap[pressedId.replace("meta", "mod")];
75
+ const controlToModPressedId = getHotkeyId(pressedId.replace("control", "mod"));
76
+ const metaToModPressedId = getHotkeyId(pressedId.replace("meta", "mod"));
77
+ const hotkeyControlModData = pressedFormattedKeys.includes("control") && this.hotkeyMap[controlToModPressedId];
78
+ const hotkeyMetaModData = pressedFormattedKeys.includes("meta") && this.hotkeyMap[metaToModPressedId];
77
79
  [hotkeyData, hotkeyControlModData, hotkeyMetaModData].forEach((hotkeyData) => {
78
80
  if (!hotkeyData)
79
81
  return;
@@ -6,6 +6,9 @@ function Example() {
6
6
  "shift + b + n": () => console.log("pressed"),
7
7
  "c + v": () => console.log(111),
8
8
  "Meta + v": () => console.log(222),
9
+ "control + enter": () => console.log("control + enter"),
10
+ "meta + enter": () => console.log("meta + enter"),
11
+ "mod + enter": () => console.log("mod + enter"),
9
12
  "mod + ArrowRight": () => console.log("right"),
10
13
  "mod + ArrowUp": () => console.log("top"),
11
14
  "shift + ArrowRight": () => console.log("right"),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reshaped",
3
3
  "description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
4
- "version": "3.2.0-canary.5",
4
+ "version": "3.2.0-canary.6",
5
5
  "license": "MIT",
6
6
  "email": "hello@reshaped.so",
7
7
  "homepage": "https://reshaped.so",
@@ -138,8 +138,8 @@
138
138
  "postcss-each": "1.1.0",
139
139
  "postcss-nested": "6.2.0",
140
140
  "prettier": "3.3.3",
141
- "react": "19.0.0-rc-e4953922-20240919",
142
- "react-dom": "19.0.0-rc-e4953922-20240919",
141
+ "react": "18.3.1",
142
+ "react-dom": "18.3.1",
143
143
  "react-shadow": "^20.5.0",
144
144
  "resolve-tspaths": "0.8.19",
145
145
  "size-limit": "11.1.4",