@yakad/ui 1.3.109 → 1.3.110
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.
|
@@ -23,35 +23,43 @@ export const WithDropdawn = (_a) => {
|
|
|
23
23
|
const [showDropdawn, setShowDropdawn] = useState(false);
|
|
24
24
|
const [dropdawnOnTop, setDropdawnOnTop] = useState(false);
|
|
25
25
|
const [top, setTop] = useState(0);
|
|
26
|
-
const [
|
|
26
|
+
const [dropdawnX, setDropdawnX] = useState(0);
|
|
27
|
+
const [arrowTop, setArrowTop] = useState(0);
|
|
28
|
+
const [arrowX, setArrowX] = useState(0);
|
|
27
29
|
const toggleShowDropdawn = () => setShowDropdawn((prev) => !prev);
|
|
28
30
|
useEffect(() => {
|
|
29
31
|
if (toggleElementRef.current && dropdawnRef.current) {
|
|
30
32
|
const buttonRect = toggleElementRef.current.getBoundingClientRect();
|
|
31
33
|
const dropdawnRect = dropdawnRef.current.getBoundingClientRect();
|
|
32
34
|
const padding = 10;
|
|
33
|
-
let
|
|
34
|
-
let
|
|
35
|
+
let dTop = buttonRect.bottom + padding;
|
|
36
|
+
let dX = buttonRect.x + buttonRect.width / 2;
|
|
37
|
+
let aTop = top;
|
|
38
|
+
let aX = dX;
|
|
35
39
|
// Prevent overflow bottom
|
|
36
|
-
if (
|
|
37
|
-
|
|
40
|
+
if (dTop + dropdawnRect.height > window.innerHeight) {
|
|
41
|
+
dTop = buttonRect.top - dropdawnRect.height - padding;
|
|
42
|
+
aTop = buttonRect.top - padding;
|
|
38
43
|
setDropdawnOnTop(true);
|
|
39
44
|
}
|
|
40
45
|
else
|
|
41
46
|
setDropdawnOnTop(false);
|
|
42
47
|
// Prevent overflow right
|
|
43
|
-
if (
|
|
44
|
-
|
|
48
|
+
if (dX + dropdawnRect.width / 2 > window.innerWidth - padding) {
|
|
49
|
+
dX = window.innerWidth - dropdawnRect.width / 2 - padding;
|
|
45
50
|
}
|
|
46
51
|
// Prevent overflow left
|
|
47
|
-
if (
|
|
48
|
-
|
|
52
|
+
if (dX - dropdawnRect.width / 2 < padding) {
|
|
53
|
+
dX = dropdawnRect.width / 2 + padding;
|
|
49
54
|
}
|
|
50
|
-
setTop(
|
|
51
|
-
|
|
55
|
+
setTop(dTop);
|
|
56
|
+
setDropdawnX(dX);
|
|
57
|
+
// Arrow Placing
|
|
58
|
+
setArrowTop(aTop);
|
|
59
|
+
setArrowX(aX);
|
|
52
60
|
}
|
|
53
61
|
}, [showDropdawn, dropdawnChildren]);
|
|
54
|
-
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.dropdawnCard, { [styles.
|
|
62
|
+
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.dropdawnCard, { [styles.blur]: blur }, className);
|
|
55
63
|
return (_jsxs(_Fragment, { children: [_jsx(WithInteractions, { ref: toggleElementRef, onRightClick: () => trigger === "onRightClick" && setShowDropdawn(true), children: children &&
|
|
56
64
|
cloneElement(children, {
|
|
57
65
|
onClick: (e) => {
|
|
@@ -59,6 +67,12 @@ export const WithDropdawn = (_a) => {
|
|
|
59
67
|
(_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
60
68
|
trigger === "onClick" && toggleShowDropdawn();
|
|
61
69
|
},
|
|
62
|
-
}) }), _jsx(
|
|
70
|
+
}) }), _jsx("span", { className: classNames(styles.arrow, {
|
|
71
|
+
[styles.dropdawnOnTop]: dropdawnOnTop,
|
|
72
|
+
}, { [styles.blur]: blur }), style: {
|
|
73
|
+
top: arrowTop,
|
|
74
|
+
left: arrowX,
|
|
75
|
+
visibility: showDropdawn ? "visible" : "hidden",
|
|
76
|
+
} }), _jsx(WithInteractions, { onOutsideClick: () => setShowDropdawn(false), children: _jsx("div", Object.assign({ ref: dropdawnRef }, restProps, { className: joinedClassNames, style: Object.assign({ top: top, left: dropdawnX, visibility: showDropdawn ? "visible" : "hidden" }, style), children: dropdawnChildren })) })] }));
|
|
63
77
|
};
|
|
64
78
|
WithDropdawn.displayName = "WithDropdawn";
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
color: rgb(var(--onSurfaceColor, 28 27 31));
|
|
11
11
|
fill: rgb(var(--onSurfaceColor, 28 27 31));
|
|
12
12
|
z-index: 2;
|
|
13
|
+
transform: translate(-50%, 0);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
15
|
.dropdawnCard.blur {
|
|
16
16
|
background-color: color-mix(
|
|
17
17
|
in srgb,
|
|
@@ -21,28 +21,25 @@
|
|
|
21
21
|
backdrop-filter: blur(0.5rem);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
position:
|
|
27
|
-
top: -6px;
|
|
28
|
-
left: calc(50% - 6px);
|
|
24
|
+
/* Arrow */
|
|
25
|
+
.arrow {
|
|
26
|
+
position: fixed;
|
|
29
27
|
width: 0;
|
|
30
28
|
height: 0;
|
|
31
|
-
border-left:
|
|
32
|
-
border-right:
|
|
33
|
-
border-bottom:
|
|
29
|
+
border-left: 0.6rem solid transparent;
|
|
30
|
+
border-right: 0.6rem solid transparent;
|
|
31
|
+
border-bottom: 0.6rem solid
|
|
34
32
|
rgb(var(--surfaceContainerHighestColor, 230 224 233));
|
|
33
|
+
transform: translate(-50%, -100%);
|
|
35
34
|
}
|
|
36
|
-
.
|
|
37
|
-
border-bottom:
|
|
35
|
+
.arrow.blur {
|
|
36
|
+
border-bottom: 0.6rem solid
|
|
38
37
|
color-mix(
|
|
39
38
|
in srgb,
|
|
40
39
|
rgb(var(--surfaceContainerHighestColor, 230 224 233)) 85%,
|
|
41
40
|
transparent
|
|
42
41
|
);
|
|
43
42
|
}
|
|
44
|
-
.
|
|
45
|
-
|
|
46
|
-
bottom: -6px;
|
|
47
|
-
transform: scale(1, -1);
|
|
43
|
+
.arrow.dropdawnOnTop {
|
|
44
|
+
transform: translate(-50%, 0) rotate(180deg);
|
|
48
45
|
}
|