next-helios-fe 1.8.52 → 1.8.53
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.
- package/dist/components/button/index.d.ts +1 -3
- package/dist/components/tooltip/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +0 -7
- package/package.json +1 -2
- package/src/components/button/index.tsx +34 -9
- package/src/components/form/input/checkbox.tsx +9 -6
- package/src/components/form/input/color.tsx +9 -6
- package/src/components/form/input/date.tsx +9 -7
- package/src/components/form/input/email.tsx +7 -3
- package/src/components/form/input/file.tsx +7 -6
- package/src/components/form/input/number.tsx +7 -3
- package/src/components/form/input/password.tsx +7 -3
- package/src/components/form/input/radio.tsx +9 -6
- package/src/components/form/input/range.tsx +7 -3
- package/src/components/form/input/text.tsx +7 -3
- package/src/components/form/input/time.tsx +9 -7
- package/src/components/form/other/autocomplete.tsx +9 -6
- package/src/components/form/other/multipleSelect.tsx +9 -7
- package/src/components/form/other/phoneNumber.tsx +9 -7
- package/src/components/form/other/pin.tsx +9 -6
- package/src/components/form/other/rating.tsx +9 -6
- package/src/components/form/other/secret.tsx +9 -6
- package/src/components/form/other/select.tsx +9 -7
- package/src/components/form/other/textarea.tsx +7 -3
- package/src/components/tooltip/index.tsx +212 -16
@@ -1,24 +1,220 @@
|
|
1
1
|
"use client";
|
2
|
-
import React from "react";
|
3
|
-
import {
|
2
|
+
import React, { useState, useRef, useEffect } from "react";
|
3
|
+
import { createPortal } from "react-dom";
|
4
4
|
|
5
5
|
interface TooltipProps {
|
6
|
-
|
7
|
-
content: React.ReactNode;
|
6
|
+
children: React.ReactNode;
|
7
|
+
content: string | React.ReactNode;
|
8
|
+
options?: {
|
9
|
+
position?: "left" | "right" | "top" | "bottom";
|
10
|
+
};
|
8
11
|
}
|
9
12
|
|
10
|
-
export const Tooltip: React.FC<TooltipProps> = ({
|
13
|
+
export const Tooltip: React.FC<TooltipProps> = ({ children, content, options }) => {
|
14
|
+
const [visible, setVisible] = useState(false);
|
15
|
+
const [position, setPosition] = useState(options?.position ?? "right");
|
16
|
+
const tooltipRef = useRef<HTMLDivElement | null>(null);
|
17
|
+
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
18
|
+
const [wrapperComponent, setWrapperComponent] = useState<DOMRect | null>(
|
19
|
+
null
|
20
|
+
);
|
21
|
+
const [tooltipComponent, setTooltipComponent] = useState<DOMRect | null>(
|
22
|
+
null
|
23
|
+
);
|
24
|
+
|
25
|
+
useEffect(() => {
|
26
|
+
setPosition(options?.position ?? "right");
|
27
|
+
}, [options?.position]);
|
28
|
+
|
29
|
+
useEffect(() => {
|
30
|
+
const handlePosition = () => {
|
31
|
+
if (!wrapperRef.current || !tooltipRef.current) return;
|
32
|
+
|
33
|
+
const tooltipRect = tooltipRef.current.getBoundingClientRect();
|
34
|
+
|
35
|
+
if (tooltipRect.right > window.innerWidth) {
|
36
|
+
setPosition("left");
|
37
|
+
} else if (tooltipRect.left < 0) {
|
38
|
+
setPosition("right");
|
39
|
+
} else if (tooltipRect.bottom > window.innerHeight) {
|
40
|
+
setPosition("top");
|
41
|
+
} else if (tooltipRect.top < 0) {
|
42
|
+
setPosition("bottom");
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
if (visible) {
|
47
|
+
handlePosition();
|
48
|
+
window.addEventListener("resize", handlePosition);
|
49
|
+
}
|
50
|
+
|
51
|
+
return () => {
|
52
|
+
window.removeEventListener("resize", handlePosition);
|
53
|
+
};
|
54
|
+
}, [visible, content]);
|
55
|
+
|
56
|
+
useEffect(() => {
|
57
|
+
let animationFrameId: number;
|
58
|
+
|
59
|
+
const updatePosition = () => {
|
60
|
+
if (!wrapperRef.current || !tooltipRef.current) return;
|
61
|
+
|
62
|
+
setWrapperComponent(wrapperRef.current.getBoundingClientRect());
|
63
|
+
setTooltipComponent(tooltipRef.current.getBoundingClientRect());
|
64
|
+
|
65
|
+
animationFrameId = requestAnimationFrame(updatePosition);
|
66
|
+
};
|
67
|
+
|
68
|
+
animationFrameId = requestAnimationFrame(updatePosition);
|
69
|
+
|
70
|
+
return () => {
|
71
|
+
cancelAnimationFrame(animationFrameId);
|
72
|
+
};
|
73
|
+
}, [visible]);
|
74
|
+
|
75
|
+
const getTooltipPosition = () => {
|
76
|
+
if (wrapperComponent && tooltipComponent) {
|
77
|
+
switch (position) {
|
78
|
+
case "left":
|
79
|
+
return {
|
80
|
+
top:
|
81
|
+
wrapperComponent.top +
|
82
|
+
wrapperComponent.height / 2 -
|
83
|
+
tooltipComponent.height / 2,
|
84
|
+
left: wrapperComponent.left - tooltipComponent.width,
|
85
|
+
};
|
86
|
+
case "right":
|
87
|
+
return {
|
88
|
+
top:
|
89
|
+
wrapperComponent.top +
|
90
|
+
wrapperComponent.height / 2 -
|
91
|
+
tooltipComponent.height / 2,
|
92
|
+
left: wrapperComponent.right,
|
93
|
+
};
|
94
|
+
case "top":
|
95
|
+
return {
|
96
|
+
top: wrapperComponent.top - tooltipComponent.height,
|
97
|
+
left:
|
98
|
+
wrapperComponent.left +
|
99
|
+
wrapperComponent.width / 2 -
|
100
|
+
tooltipComponent.width / 2,
|
101
|
+
};
|
102
|
+
case "bottom":
|
103
|
+
return {
|
104
|
+
top: wrapperComponent.bottom,
|
105
|
+
left:
|
106
|
+
wrapperComponent.left +
|
107
|
+
wrapperComponent.width / 2 -
|
108
|
+
tooltipComponent.width / 2,
|
109
|
+
};
|
110
|
+
default:
|
111
|
+
return {
|
112
|
+
top:
|
113
|
+
wrapperComponent.top +
|
114
|
+
wrapperComponent.height / 2 -
|
115
|
+
tooltipComponent.height / 2,
|
116
|
+
left: wrapperComponent.right,
|
117
|
+
};
|
118
|
+
}
|
119
|
+
}
|
120
|
+
};
|
121
|
+
|
122
|
+
const getTooltipArrowPosition = () => {
|
123
|
+
if (wrapperComponent && tooltipComponent) {
|
124
|
+
switch (position) {
|
125
|
+
case "left":
|
126
|
+
return {
|
127
|
+
width: "0px",
|
128
|
+
height: "0px",
|
129
|
+
borderStyle: "solid",
|
130
|
+
borderWidth: "6px",
|
131
|
+
borderColor: "transparent transparent transparent black",
|
132
|
+
opacity: "0.75",
|
133
|
+
};
|
134
|
+
case "right":
|
135
|
+
return {
|
136
|
+
width: "0px",
|
137
|
+
height: "0px",
|
138
|
+
borderStyle: "solid",
|
139
|
+
borderWidth: "6px",
|
140
|
+
borderColor: "transparent black transparent transparent",
|
141
|
+
opacity: "0.75",
|
142
|
+
};
|
143
|
+
case "top":
|
144
|
+
return {
|
145
|
+
width: "0px",
|
146
|
+
height: "0px",
|
147
|
+
borderStyle: "solid",
|
148
|
+
borderWidth: "6px",
|
149
|
+
borderColor: "black transparent transparent transparent",
|
150
|
+
opacity: "0.75",
|
151
|
+
};
|
152
|
+
case "bottom":
|
153
|
+
return {
|
154
|
+
width: "0px",
|
155
|
+
height: "0px",
|
156
|
+
borderStyle: "solid",
|
157
|
+
borderWidth: "6px",
|
158
|
+
borderColor: "transparent transparent black transparent",
|
159
|
+
opacity: "0.75",
|
160
|
+
};
|
161
|
+
default:
|
162
|
+
return {
|
163
|
+
width: "0px",
|
164
|
+
height: "0px",
|
165
|
+
borderStyle: "solid",
|
166
|
+
borderWidth: "6px",
|
167
|
+
borderColor: "transparent black transparent transparent",
|
168
|
+
opacity: "0.75",
|
169
|
+
};
|
170
|
+
}
|
171
|
+
}
|
172
|
+
};
|
173
|
+
|
11
174
|
return (
|
12
|
-
<
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
175
|
+
<div
|
176
|
+
className="relative inline-block"
|
177
|
+
ref={wrapperRef}
|
178
|
+
onMouseEnter={() => setVisible(true)}
|
179
|
+
onMouseLeave={() => setVisible(false)}
|
180
|
+
>
|
181
|
+
{children}
|
182
|
+
{createPortal(
|
183
|
+
<div
|
184
|
+
ref={tooltipRef}
|
185
|
+
className={`absolute z-50 duration-200 transition-opacity ${
|
186
|
+
visible ? "opacity-100" : "opacity-0 pointer-events-none"
|
187
|
+
}`}
|
188
|
+
style={getTooltipPosition()}
|
189
|
+
>
|
190
|
+
{position === "bottom" && (
|
191
|
+
<div className="flex justify-center">
|
192
|
+
<div style={getTooltipArrowPosition()}></div>
|
193
|
+
</div>
|
194
|
+
)}
|
195
|
+
<div className="flex items-center">
|
196
|
+
{position === "right" && (
|
197
|
+
<div className="flex justify-center">
|
198
|
+
<div style={getTooltipArrowPosition()}></div>
|
199
|
+
</div>
|
200
|
+
)}
|
201
|
+
<div className="max-w-96 w-fit px-3 py-1.5 rounded-md bg-black/75 text-sm text-white">
|
202
|
+
{content}
|
203
|
+
</div>
|
204
|
+
{position === "left" && (
|
205
|
+
<div className="flex justify-center">
|
206
|
+
<div style={getTooltipArrowPosition()}></div>
|
207
|
+
</div>
|
208
|
+
)}
|
209
|
+
</div>
|
210
|
+
{position === "top" && (
|
211
|
+
<div className="flex justify-center">
|
212
|
+
<div style={getTooltipArrowPosition()}></div>
|
213
|
+
</div>
|
214
|
+
)}
|
215
|
+
</div>,
|
216
|
+
document.body
|
217
|
+
)}
|
218
|
+
</div>
|
23
219
|
);
|
24
220
|
};
|