next-helios-fe 1.8.78 → 1.8.79

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-helios-fe",
3
- "version": "1.8.78",
3
+ "version": "1.8.79",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -493,13 +493,13 @@ export const Table: TableComponentProps = ({
493
493
  return (
494
494
  <td
495
495
  key={headerItem.key}
496
- className="max-w-60 bg-secondary-bg truncate whitespace-nowrap"
496
+ className="max-w-60 px-4 py-1.5 bg-secondary-bg truncate whitespace-nowrap"
497
497
  >
498
498
  <Tooltip
499
499
  content={item[headerItem.key as keyof typeof item] || "-"}
500
500
  options={{ position: "top" }}
501
501
  >
502
- <span className="px-4 py-1.5">
502
+ <span>
503
503
  {item[headerItem.key as keyof typeof item] || "-"}
504
504
  </span>
505
505
  </Tooltip>
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- import React, { useState, useRef, useEffect } from "react";
2
+ import React from "react";
3
+ import { Tooltip as Tp } from "flowbite-react";
3
4
 
4
5
  interface TooltipProps {
5
6
  children: React.ReactNode;
@@ -15,217 +16,23 @@ export const Tooltip: React.FC<TooltipProps> = ({
15
16
  content,
16
17
  options,
17
18
  }) => {
18
- const [isRendered, setIsRendered] = useState(false);
19
- const [visible, setVisible] = useState(false);
20
- const [position, setPosition] = useState(options?.position ?? "right");
21
- const tooltipRef = useRef<HTMLDivElement | null>(null);
22
- const wrapperRef = useRef<HTMLDivElement | null>(null);
23
- const [wrapperComponent, setWrapperComponent] = useState<DOMRect | null>(
24
- null
25
- );
26
- const [tooltipComponent, setTooltipComponent] = useState<DOMRect | null>(
27
- null
28
- );
29
-
30
- useEffect(() => {
31
- setIsRendered(true);
32
- }, []);
33
-
34
- useEffect(() => {
35
- setPosition(options?.position ?? "right");
36
- }, [options?.position]);
37
-
38
- useEffect(() => {
39
- const handlePosition = () => {
40
- if (!wrapperRef.current || !tooltipRef.current) return;
41
-
42
- const tooltipRect = tooltipRef.current.getBoundingClientRect();
43
-
44
- if (tooltipRect.right > window.innerWidth) {
45
- setPosition("left");
46
- } else if (tooltipRect.left < 0) {
47
- setPosition("right");
48
- } else if (tooltipRect.bottom > window.innerHeight) {
49
- setPosition("top");
50
- } else if (tooltipRect.top < 0) {
51
- setPosition("bottom");
52
- }
53
- };
54
-
55
- if (visible) {
56
- handlePosition();
57
- window.addEventListener("resize", handlePosition);
58
- }
59
-
60
- return () => {
61
- window.removeEventListener("resize", handlePosition);
62
- };
63
- }, [visible, content]);
64
-
65
- useEffect(() => {
66
- let animationFrameId: number;
67
-
68
- const updatePosition = () => {
69
- if (!wrapperRef.current || !tooltipRef.current) return;
70
-
71
- setWrapperComponent(wrapperRef.current.getBoundingClientRect());
72
- setTooltipComponent(tooltipRef.current.getBoundingClientRect());
73
-
74
- animationFrameId = requestAnimationFrame(updatePosition);
75
- };
76
-
77
- animationFrameId = requestAnimationFrame(updatePosition);
78
-
79
- return () => {
80
- cancelAnimationFrame(animationFrameId);
81
- };
82
- }, [visible]);
83
-
84
- const getTooltipPosition = () => {
85
- if (wrapperComponent && tooltipComponent) {
86
- switch (position) {
87
- case "left":
88
- return {
89
- top:
90
- wrapperComponent.top +
91
- wrapperComponent.height / 2 -
92
- tooltipComponent.height / 2,
93
- left: wrapperComponent.left - tooltipComponent.width,
94
- };
95
- case "right":
96
- return {
97
- top:
98
- wrapperComponent.top +
99
- wrapperComponent.height / 2 -
100
- tooltipComponent.height / 2,
101
- left: wrapperComponent.right,
102
- };
103
- case "top":
104
- return {
105
- top: wrapperComponent.top - tooltipComponent.height,
106
- left:
107
- wrapperComponent.left +
108
- wrapperComponent.width / 2 -
109
- tooltipComponent.width / 2,
110
- };
111
- case "bottom":
112
- return {
113
- top: wrapperComponent.bottom,
114
- left:
115
- wrapperComponent.left +
116
- wrapperComponent.width / 2 -
117
- tooltipComponent.width / 2,
118
- };
119
- default:
120
- return {
121
- top:
122
- wrapperComponent.top +
123
- wrapperComponent.height / 2 -
124
- tooltipComponent.height / 2,
125
- left: wrapperComponent.right,
126
- };
127
- }
128
- }
129
- };
130
-
131
- const getTooltipArrowPosition = () => {
132
- if (wrapperComponent && tooltipComponent) {
133
- switch (position) {
134
- case "left":
135
- return {
136
- width: "0px",
137
- height: "0px",
138
- borderStyle: "solid",
139
- borderWidth: "6px",
140
- borderColor: "transparent transparent transparent black",
141
- opacity: "0.75",
142
- };
143
- case "right":
144
- return {
145
- width: "0px",
146
- height: "0px",
147
- borderStyle: "solid",
148
- borderWidth: "6px",
149
- borderColor: "transparent black transparent transparent",
150
- opacity: "0.75",
151
- };
152
- case "top":
153
- return {
154
- width: "0px",
155
- height: "0px",
156
- borderStyle: "solid",
157
- borderWidth: "6px",
158
- borderColor: "black transparent transparent transparent",
159
- opacity: "0.75",
160
- };
161
- case "bottom":
162
- return {
163
- width: "0px",
164
- height: "0px",
165
- borderStyle: "solid",
166
- borderWidth: "6px",
167
- borderColor: "transparent transparent black transparent",
168
- opacity: "0.75",
169
- };
170
- default:
171
- return {
172
- width: "0px",
173
- height: "0px",
174
- borderStyle: "solid",
175
- borderWidth: "6px",
176
- borderColor: "transparent black transparent transparent",
177
- opacity: "0.75",
178
- };
179
- }
180
- }
181
- };
182
-
183
19
  return (
184
- <div
185
- ref={wrapperRef}
186
- className="group/tooltip"
187
- onMouseEnter={() => setVisible(true)}
188
- onMouseLeave={() => setVisible(false)}
20
+ <Tp
21
+ content={content}
22
+ className={`z-50 max-w-[75dvw] md:max-w-96 px-3 py-1.5 rounded-md bg-black/85 text-sm text-wrap font-normal ${
23
+ !options?.enableHover && "pointer-events-none"
24
+ }`}
25
+ style="dark"
26
+ placement={options?.position || "right"}
27
+ theme={{
28
+ arrow: {
29
+ base: "absolute z-10 h-2 w-2 rotate-45",
30
+ style: { dark: "bg-black/85" },
31
+ },
32
+ }}
33
+ animation="duration-200"
189
34
  >
190
35
  {children}
191
- {isRendered && (
192
- <div
193
- ref={tooltipRef}
194
- className={`absolute z-50 duration-200 transition-opacity hidden group-hover/tooltip:block ${
195
- options?.enableHover ? "" : "pointer-events-none"
196
- }`}
197
- style={getTooltipPosition()}
198
- >
199
- {position === "bottom" && (
200
- <div className="flex justify-center">
201
- <div style={getTooltipArrowPosition()}></div>
202
- </div>
203
- )}
204
- <div className="flex items-center">
205
- {position === "right" && (
206
- <div className="flex justify-center">
207
- <div style={getTooltipArrowPosition()}></div>
208
- </div>
209
- )}
210
- <div
211
- className="w-fit px-3 py-1.5 rounded-md bg-black/75 text-sm text-white text-wrap"
212
- style={{ maxWidth: "50dvw" }}
213
- >
214
- {content}
215
- </div>
216
- {position === "left" && (
217
- <div className="flex justify-center">
218
- <div style={getTooltipArrowPosition()}></div>
219
- </div>
220
- )}
221
- </div>
222
- {position === "top" && (
223
- <div className="flex justify-center">
224
- <div style={getTooltipArrowPosition()}></div>
225
- </div>
226
- )}
227
- </div>
228
- )}
229
- </div>
36
+ </Tp>
230
37
  );
231
38
  };