@x-plat/design-system 0.5.10 → 0.5.12

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,31 +1,28 @@
1
1
  /* src/components/PopOver/popOver.scss */
2
2
  .lib-xplat-pop-over {
3
3
  position: relative;
4
- z-index: 10;
5
4
  width: fit-content;
6
5
  cursor: pointer;
7
6
  user-select: none;
8
7
  }
9
- .lib-xplat-pop-over > .content-wrap {
10
- position: absolute;
8
+ .lib-xplat-pop-over-content {
9
+ position: fixed;
10
+ z-index: 1000;
11
11
  cursor: default;
12
12
  transition: transform 0.2s ease, opacity 0.2s ease;
13
- background: white;
13
+ background: var(--semantic-surface-neutral-default);
14
14
  border-radius: var(--spacing-radius-md);
15
15
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
16
- z-index: 10;
17
16
  opacity: 0;
18
17
  transform: scale(0.8);
19
18
  }
20
- .lib-xplat-pop-over > .content-wrap.top {
19
+ .lib-xplat-pop-over-content.top {
21
20
  transform-origin: bottom;
22
- margin-bottom: var(--spacing-space-2);
23
21
  }
24
- .lib-xplat-pop-over > .content-wrap.bottom {
22
+ .lib-xplat-pop-over-content.bottom {
25
23
  transform-origin: top;
26
- margin-top: var(--spacing-space-2);
27
24
  }
28
- .lib-xplat-pop-over > .content-wrap.visible {
25
+ .lib-xplat-pop-over-content.visible {
29
26
  opacity: 1;
30
27
  transform: scale(1);
31
28
  }
@@ -1,5 +1,5 @@
1
1
  // src/components/PopOver/PopOver.tsx
2
- import React3 from "react";
2
+ import React4 from "react";
3
3
 
4
4
  // src/tokens/hooks/useAutoPosition.ts
5
5
  import React from "react";
@@ -12,28 +12,38 @@ var useAutoPosition = (triggerRef, popRef, enabled = true) => {
12
12
  if (!triggerRef.current || !popRef.current) return;
13
13
  const triggerRect = triggerRef.current.getBoundingClientRect();
14
14
  const popRect = popRef.current.getBoundingClientRect();
15
- const viewportWidth = window.innerWidth;
16
15
  const viewportHeight = window.innerHeight;
17
- const position2 = {};
16
+ const viewportWidth = window.innerWidth;
18
17
  let direction = "bottom";
19
- if (triggerRect.bottom + popRect.height > viewportHeight) {
18
+ let top;
19
+ let left = triggerRect.left;
20
+ if (triggerRect.bottom + popRect.height > viewportHeight && triggerRect.top - popRect.height > 0) {
20
21
  direction = "top";
22
+ top = triggerRect.top - popRect.height;
23
+ } else {
24
+ top = triggerRect.bottom;
21
25
  }
22
- if (triggerRect.left + popRect.width > viewportWidth) {
23
- position2["right"] = 10;
24
- }
25
- if (triggerRect.left < 0) {
26
- position2["left"] = 10;
26
+ if (left + popRect.width > viewportWidth) {
27
+ left = viewportWidth - popRect.width - 8;
27
28
  }
29
+ if (left < 8) left = 8;
28
30
  setPosition({
29
- position: position2,
31
+ position: { top, left, width: triggerRect.width },
30
32
  direction
31
33
  });
32
34
  }, [triggerRef, popRef]);
33
35
  React.useEffect(() => {
34
- calculatePosition();
36
+ if (!enabled) return;
37
+ const raf = requestAnimationFrame(() => {
38
+ calculatePosition();
39
+ });
35
40
  window.addEventListener("resize", calculatePosition);
36
- return () => window.removeEventListener("resize", calculatePosition);
41
+ window.addEventListener("scroll", calculatePosition, true);
42
+ return () => {
43
+ cancelAnimationFrame(raf);
44
+ window.removeEventListener("resize", calculatePosition);
45
+ window.removeEventListener("scroll", calculatePosition, true);
46
+ };
37
47
  }, [calculatePosition, enabled]);
38
48
  return position;
39
49
  };
@@ -64,6 +74,24 @@ var useClickOutside = (refs, handler, enabled = true) => {
64
74
  };
65
75
  var useClickOutside_default = useClickOutside;
66
76
 
77
+ // src/tokens/hooks/Portal.tsx
78
+ import React3 from "react";
79
+ import ReactDOM from "react-dom";
80
+ import { jsx } from "react/jsx-runtime";
81
+ var PortalContainerContext = React3.createContext(null);
82
+ var Portal = ({ children }) => {
83
+ const contextContainer = React3.useContext(PortalContainerContext);
84
+ const [fallback, setFallback] = React3.useState(null);
85
+ React3.useEffect(() => {
86
+ if (!contextContainer) setFallback(document.body);
87
+ }, [contextContainer]);
88
+ const container = contextContainer ?? fallback;
89
+ if (!container) return null;
90
+ return ReactDOM.createPortal(children, container);
91
+ };
92
+ Portal.displayName = "Portal";
93
+ var Portal_default = Portal;
94
+
67
95
  // ../../node_modules/clsx/dist/clsx.mjs
68
96
  function r(e) {
69
97
  var t, f, n = "";
@@ -81,16 +109,16 @@ function clsx() {
81
109
  var clsx_default = clsx;
82
110
 
83
111
  // src/components/PopOver/PopOver.tsx
84
- import { jsx, jsxs } from "react/jsx-runtime";
112
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
85
113
  var PopOver = (props) => {
86
114
  const { children, isOpen, onClose, PopOverEl } = props;
87
- const popRef = React3.useRef(null);
88
- const triggerRef = React3.useRef(null);
89
- const [localOpen, setLocalOpen] = React3.useState(false);
90
- const [eventTrigger, setEventTrigger] = React3.useState(false);
115
+ const popRef = React4.useRef(null);
116
+ const triggerRef = React4.useRef(null);
117
+ const [localOpen, setLocalOpen] = React4.useState(false);
118
+ const [eventTrigger, setEventTrigger] = React4.useState(false);
91
119
  useClickOutside_default([popRef, triggerRef], onClose, isOpen);
92
120
  const position = useAutoPosition_default(triggerRef, popRef, localOpen);
93
- React3.useEffect(() => {
121
+ React4.useEffect(() => {
94
122
  if (isOpen) {
95
123
  setLocalOpen(isOpen);
96
124
  setTimeout(() => {
@@ -113,11 +141,11 @@ var PopOver = (props) => {
113
141
  },
114
142
  children: [
115
143
  children,
116
- localOpen && /* @__PURE__ */ jsx(
144
+ localOpen && /* @__PURE__ */ jsx2(Portal_default, { children: /* @__PURE__ */ jsx2(
117
145
  "div",
118
146
  {
119
147
  className: clsx_default(
120
- "content-wrap",
148
+ "lib-xplat-pop-over-content",
121
149
  position.direction,
122
150
  eventTrigger && "visible"
123
151
  ),
@@ -127,7 +155,7 @@ var PopOver = (props) => {
127
155
  },
128
156
  children: PopOverEl
129
157
  }
130
- )
158
+ ) })
131
159
  ]
132
160
  }
133
161
  );