x-ui-design 0.9.21 → 0.9.23

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.
@@ -201,7 +201,7 @@ function MenuInner({
201
201
  }: DropdownMenuInnerProps) {
202
202
  return (
203
203
  <ul className={`${prefixCls}-menu`} ref={menuRef} role='menu'>
204
- {items.map((it) => (
204
+ {items?.map((it) => (
205
205
  <li
206
206
  key={it.key}
207
207
  role='menuitem'
@@ -11,7 +11,7 @@ import {
11
11
  import { Placement } from "../types";
12
12
  import { getElementParentDetails } from "../helpers";
13
13
 
14
- const OFFSET = 12;
14
+ const OFFSET = 11;
15
15
 
16
16
  type TPopupPosition = {
17
17
  open: boolean;
@@ -37,6 +37,7 @@ export const usePopupPosition = ({
37
37
  const [popupPosition, setPopupPosition] = useState<CSSProperties>({});
38
38
 
39
39
  const inBody = useMemo(() => popupContainer?.tagName === 'BODY', [popupContainer]);
40
+ const popupRect = useMemo(() => popupRef.current?.getBoundingClientRect(), [popupRef.current]);
40
41
 
41
42
  const calculatePosition = useCallback((e?: Event) => {
42
43
  const container = targetRef.current?.getBoundingClientRect();
@@ -75,9 +76,7 @@ export const usePopupPosition = ({
75
76
  return
76
77
  }
77
78
 
78
- if (popupRef.current) {
79
- const popupRect = popupRef.current?.getBoundingClientRect();
80
-
79
+ if (popupRect) {
81
80
  const availableSpace = {
82
81
  top: container.top - (popupRect.height + OFFSET),
83
82
  bottom: (inBody ? window.innerHeight : (scrollableParents?.clientHeight || 0)) - (container.bottom + popupRect.height + OFFSET),
@@ -122,7 +121,7 @@ export const usePopupPosition = ({
122
121
  case "bottom":
123
122
  setPopupPosition({
124
123
  top: positions.top + container.height,
125
- left: positions.left + ((container.width || 0) / 2) - ((popupRef.current?.offsetWidth || 0) / 2)
124
+ left: positions.left + ((container.width || 0) / 2) - ((popupRect?.width || 0) / 2)
126
125
  });
127
126
  break;
128
127
  case "bottomLeft":
@@ -134,32 +133,32 @@ export const usePopupPosition = ({
134
133
  case "bottomRight":
135
134
  setPopupPosition({
136
135
  top: positions.top + container.height,
137
- left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
136
+ left: positions.left + (container.width || 0) - (popupRect?.width || 0)
138
137
  });
139
138
  break;
140
139
  case "top":
141
140
  setPopupPosition({
142
- top: positions.top - (popupRef.current?.clientHeight || 0) - (OFFSET * 2),
143
- left: positions.left + ((container.width || 0) / 2) - ((popupRef.current?.offsetWidth || 0) / 2)
141
+ top: positions.top - (popupRect?.height || 0) - (OFFSET * 2),
142
+ left: positions.left + ((container.width || 0) / 2) - ((popupRect?.width || 0) / 2)
144
143
  });
145
144
  break;
146
145
  case "topLeft":
147
146
  setPopupPosition({
148
- top: positions.top - (popupRef.current?.clientHeight || 0) - (OFFSET * 2),
147
+ top: positions.top - (popupRect?.height || 0) - (OFFSET * 2),
149
148
  left: positions.left
150
149
  });
151
150
  break;
152
151
  case "topRight":
153
152
  setPopupPosition({
154
- top: positions.top - (popupRef.current?.clientHeight || 0) - (OFFSET * 2),
155
- left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
153
+ top: positions.top - (popupRect?.height || 0) - (OFFSET * 2),
154
+ left: positions.left + (container.width || 0) - (popupRect?.width || 0)
156
155
  });
157
156
  break;
158
157
  }
159
158
  }
160
159
 
161
160
  _calculation()
162
- }, [targetRef, popupContainer, popupRef, inBody, _placement, setOpen]);
161
+ }, [targetRef, popupContainer, popupRect, inBody, _placement, setOpen]);
163
162
 
164
163
  useEffect(() => {
165
164
  if (!open) {
@@ -172,8 +171,6 @@ export const usePopupPosition = ({
172
171
  const { scrollableParents } = getElementParentDetails(targetRef.current, true);
173
172
  scrollableParents?.addEventListener("scroll", calculatePosition, options);
174
173
 
175
- // setPositionRelative('relative');
176
-
177
174
  calculatePosition();
178
175
 
179
176
  document.body.addEventListener("scroll", calculatePosition, options);
@@ -184,14 +181,20 @@ export const usePopupPosition = ({
184
181
 
185
182
  setPopupPosition({});
186
183
  };
187
- }, [open, calculatePosition]);
184
+ }, [open, targetRef, calculatePosition]);
185
+
186
+ const opacity = useMemo(() => {
187
+ console.log(popupRect?.width, popupPosition);
188
+
189
+ return Object.keys(popupPosition).length && popupRect?.width ? 1 : 0
190
+ }, [popupPosition, popupRect?.width])
188
191
 
189
192
  return {
190
193
  _placement,
191
194
  popupStyle: {
192
195
  zIndex: 10000,
193
196
  position: "absolute",
194
- opacity: Object.keys(popupPosition).length ? 1 : 0,
197
+ opacity: opacity,
195
198
  ...popupPosition
196
199
  }
197
200
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "0.9.21",
3
+ "version": "0.9.23",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
package/src/app/page.tsx CHANGED
@@ -10,6 +10,7 @@ import { Menu } from '../../lib/components/Menu';
10
10
  import { ArrowIcon, ClearIcon } from "../../lib/components/Icons/Icons";
11
11
  import { ItemType } from "../../lib/types/menu";
12
12
  import { lazy, Suspense } from "react";
13
+ import MenuItem from '../../lib/components/Menu/Item/Item';
13
14
 
14
15
  const Result = lazy(() => import('../../lib/components/Result/Result'))
15
16
 
@@ -155,7 +156,7 @@ export default function Home() {
155
156
  <Popover
156
157
  placement='bottomLeft'
157
158
  content={
158
- <Suspense>
159
+ <Suspense fallback={<div style={{ width: 12, height: 12 }}></div>}>
159
160
  <Result
160
161
  status="success"
161
162
  title="Success"
@@ -173,6 +174,15 @@ export default function Home() {
173
174
  Menu
174
175
  </Popover>
175
176
  {/* <DatePicker getPopupContainer={() => document.body} /> */}
177
+ {/* <Dropdown overlay={() => {
178
+ return <Menu>
179
+ {items.map((item) => {
180
+ return <MenuItem key={item.key} itemKey={item.key} label={item.label} />
181
+ })}
182
+ </Menu>
183
+ }}>
184
+ DropDown
185
+ </Dropdown> */}
176
186
  </div>
177
187
  <div style={{ minWidth: 1500 }} />
178
188
  </div>