funda-ui 1.0.272

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.
Files changed (246) hide show
  1. package/BackToTop/index.css +34 -0
  2. package/BackToTop/index.d.ts +11 -0
  3. package/BackToTop/index.js +458 -0
  4. package/CascadingSelect/index.css +159 -0
  5. package/CascadingSelect/index.d.ts +56 -0
  6. package/CascadingSelect/index.js +958 -0
  7. package/CascadingSelectE2E/index.css +159 -0
  8. package/CascadingSelectE2E/index.d.ts +60 -0
  9. package/CascadingSelectE2E/index.js +1126 -0
  10. package/Checkbox/index.d.ts +30 -0
  11. package/Checkbox/index.js +226 -0
  12. package/ColorPicker/index.css +38 -0
  13. package/ColorPicker/index.d.ts +27 -0
  14. package/ColorPicker/index.js +246 -0
  15. package/DigitalClock/index.d.ts +7 -0
  16. package/DigitalClock/index.js +208 -0
  17. package/DropdownMenu/index.css +127 -0
  18. package/DropdownMenu/index.d.ts +37 -0
  19. package/DropdownMenu/index.js +237 -0
  20. package/DynamicFields/index.d.ts +26 -0
  21. package/DynamicFields/index.js +412 -0
  22. package/File/index.d.ts +36 -0
  23. package/File/index.js +473 -0
  24. package/Input/index.d.ts +42 -0
  25. package/Input/index.js +286 -0
  26. package/LiveSearch/index.d.ts +37 -0
  27. package/LiveSearch/index.js +1195 -0
  28. package/ModalDialog/index.d.ts +60 -0
  29. package/ModalDialog/index.js +725 -0
  30. package/ModeSwitch/index.d.ts +17 -0
  31. package/ModeSwitch/index.js +202 -0
  32. package/MultiFuncSelect/index.css +178 -0
  33. package/MultiFuncSelect/index.d.ts +67 -0
  34. package/MultiFuncSelect/index.js +1826 -0
  35. package/MultilevelDropdownMenu/index.css +35 -0
  36. package/MultilevelDropdownMenu/index.d.ts +25 -0
  37. package/MultilevelDropdownMenu/index.js +464 -0
  38. package/Pagination/index.d.ts +49 -0
  39. package/Pagination/index.js +341 -0
  40. package/README.md +108 -0
  41. package/Radio/index.d.ts +31 -0
  42. package/Radio/index.js +246 -0
  43. package/RangeSlider/index.css +149 -0
  44. package/RangeSlider/index.d.ts +21 -0
  45. package/RangeSlider/index.js +730 -0
  46. package/ScrollReveal/index.css +23 -0
  47. package/ScrollReveal/index.d.ts +21 -0
  48. package/ScrollReveal/index.js +216 -0
  49. package/Scrollbar/index.css +168 -0
  50. package/Scrollbar/index.d.ts +15 -0
  51. package/Scrollbar/index.js +605 -0
  52. package/SearchBar/index.d.ts +32 -0
  53. package/SearchBar/index.js +246 -0
  54. package/Select/index.d.ts +34 -0
  55. package/Select/index.js +331 -0
  56. package/ShowMoreLess/index.css +23 -0
  57. package/ShowMoreLess/index.d.ts +30 -0
  58. package/ShowMoreLess/index.js +202 -0
  59. package/Switch/index.d.ts +29 -0
  60. package/Switch/index.js +211 -0
  61. package/Table/index.css +533 -0
  62. package/Table/index.d.ts +25 -0
  63. package/Table/index.js +2113 -0
  64. package/Tabs/index.d.ts +3 -0
  65. package/Tabs/index.js +323 -0
  66. package/TagInput/index.css +90 -0
  67. package/TagInput/index.d.ts +28 -0
  68. package/TagInput/index.js +370 -0
  69. package/Textarea/index.d.ts +30 -0
  70. package/Textarea/index.js +242 -0
  71. package/Toast/index.css +95 -0
  72. package/Toast/index.d.ts +35 -0
  73. package/Toast/index.js +340 -0
  74. package/Tooltip/index.css +240 -0
  75. package/Tooltip/index.d.ts +19 -0
  76. package/Tooltip/index.js +200 -0
  77. package/Tree/index.css +225 -0
  78. package/Tree/index.d.ts +37 -0
  79. package/Tree/index.js +1406 -0
  80. package/all.d.ts +33 -0
  81. package/all.js +35 -0
  82. package/lib/cjs/BackToTop/index.d.ts +11 -0
  83. package/lib/cjs/BackToTop/index.js +458 -0
  84. package/lib/cjs/CascadingSelect/index.d.ts +56 -0
  85. package/lib/cjs/CascadingSelect/index.js +958 -0
  86. package/lib/cjs/CascadingSelectE2E/index.d.ts +60 -0
  87. package/lib/cjs/CascadingSelectE2E/index.js +1126 -0
  88. package/lib/cjs/Checkbox/index.d.ts +30 -0
  89. package/lib/cjs/Checkbox/index.js +226 -0
  90. package/lib/cjs/ColorPicker/index.d.ts +27 -0
  91. package/lib/cjs/ColorPicker/index.js +246 -0
  92. package/lib/cjs/DigitalClock/index.d.ts +7 -0
  93. package/lib/cjs/DigitalClock/index.js +208 -0
  94. package/lib/cjs/DropdownMenu/index.d.ts +37 -0
  95. package/lib/cjs/DropdownMenu/index.js +237 -0
  96. package/lib/cjs/DynamicFields/index.d.ts +26 -0
  97. package/lib/cjs/DynamicFields/index.js +412 -0
  98. package/lib/cjs/File/index.d.ts +36 -0
  99. package/lib/cjs/File/index.js +473 -0
  100. package/lib/cjs/Input/index.d.ts +42 -0
  101. package/lib/cjs/Input/index.js +286 -0
  102. package/lib/cjs/LiveSearch/index.d.ts +37 -0
  103. package/lib/cjs/LiveSearch/index.js +1195 -0
  104. package/lib/cjs/ModalDialog/index.d.ts +60 -0
  105. package/lib/cjs/ModalDialog/index.js +725 -0
  106. package/lib/cjs/ModeSwitch/index.d.ts +17 -0
  107. package/lib/cjs/ModeSwitch/index.js +202 -0
  108. package/lib/cjs/MultiFuncSelect/index.d.ts +67 -0
  109. package/lib/cjs/MultiFuncSelect/index.js +1826 -0
  110. package/lib/cjs/MultilevelDropdownMenu/index.d.ts +25 -0
  111. package/lib/cjs/MultilevelDropdownMenu/index.js +464 -0
  112. package/lib/cjs/Pagination/index.d.ts +49 -0
  113. package/lib/cjs/Pagination/index.js +341 -0
  114. package/lib/cjs/Radio/index.d.ts +31 -0
  115. package/lib/cjs/Radio/index.js +246 -0
  116. package/lib/cjs/RangeSlider/index.d.ts +21 -0
  117. package/lib/cjs/RangeSlider/index.js +730 -0
  118. package/lib/cjs/ScrollReveal/index.d.ts +21 -0
  119. package/lib/cjs/ScrollReveal/index.js +216 -0
  120. package/lib/cjs/Scrollbar/index.d.ts +15 -0
  121. package/lib/cjs/Scrollbar/index.js +605 -0
  122. package/lib/cjs/SearchBar/index.d.ts +32 -0
  123. package/lib/cjs/SearchBar/index.js +246 -0
  124. package/lib/cjs/Select/index.d.ts +34 -0
  125. package/lib/cjs/Select/index.js +331 -0
  126. package/lib/cjs/ShowMoreLess/index.d.ts +30 -0
  127. package/lib/cjs/ShowMoreLess/index.js +202 -0
  128. package/lib/cjs/Switch/index.d.ts +29 -0
  129. package/lib/cjs/Switch/index.js +211 -0
  130. package/lib/cjs/Table/index.d.ts +25 -0
  131. package/lib/cjs/Table/index.js +2113 -0
  132. package/lib/cjs/Tabs/index.d.ts +3 -0
  133. package/lib/cjs/Tabs/index.js +323 -0
  134. package/lib/cjs/TagInput/index.d.ts +28 -0
  135. package/lib/cjs/TagInput/index.js +370 -0
  136. package/lib/cjs/Textarea/index.d.ts +30 -0
  137. package/lib/cjs/Textarea/index.js +242 -0
  138. package/lib/cjs/Toast/index.d.ts +35 -0
  139. package/lib/cjs/Toast/index.js +340 -0
  140. package/lib/cjs/Tooltip/index.d.ts +19 -0
  141. package/lib/cjs/Tooltip/index.js +200 -0
  142. package/lib/cjs/Tree/index.d.ts +37 -0
  143. package/lib/cjs/Tree/index.js +1406 -0
  144. package/lib/cjs/index.d.ts +33 -0
  145. package/lib/cjs/index.js +35 -0
  146. package/lib/css/BackToTop/index.css +34 -0
  147. package/lib/css/CascadingSelect/index.css +159 -0
  148. package/lib/css/CascadingSelectE2E/index.css +159 -0
  149. package/lib/css/ColorPicker/index.css +38 -0
  150. package/lib/css/DropdownMenu/index.css +127 -0
  151. package/lib/css/MultiFuncSelect/index.css +178 -0
  152. package/lib/css/MultilevelDropdownMenu/index.css +35 -0
  153. package/lib/css/RangeSlider/index.css +149 -0
  154. package/lib/css/ScrollReveal/index.css +23 -0
  155. package/lib/css/Scrollbar/index.css +168 -0
  156. package/lib/css/ShowMoreLess/index.css +23 -0
  157. package/lib/css/Table/index.css +533 -0
  158. package/lib/css/TagInput/index.css +90 -0
  159. package/lib/css/Toast/index.css +95 -0
  160. package/lib/css/Tooltip/index.css +240 -0
  161. package/lib/css/Tree/index.css +225 -0
  162. package/lib/esm/BackToTop/index.scss +47 -0
  163. package/lib/esm/BackToTop/index.tsx +182 -0
  164. package/lib/esm/BackToTop/utils/easing.js +200 -0
  165. package/lib/esm/BackToTop/utils/performance.js +52 -0
  166. package/lib/esm/CascadingSelect/Group.tsx +39 -0
  167. package/lib/esm/CascadingSelect/index.scss +214 -0
  168. package/lib/esm/CascadingSelect/index.tsx +922 -0
  169. package/lib/esm/CascadingSelect/utils/performance.js +52 -0
  170. package/lib/esm/CascadingSelectE2E/Group.tsx +39 -0
  171. package/lib/esm/CascadingSelectE2E/index.scss +214 -0
  172. package/lib/esm/CascadingSelectE2E/index.tsx +1091 -0
  173. package/lib/esm/CascadingSelectE2E/utils/performance.js +52 -0
  174. package/lib/esm/Checkbox/index.tsx +160 -0
  175. package/lib/esm/ColorPicker/index.scss +48 -0
  176. package/lib/esm/ColorPicker/index.tsx +187 -0
  177. package/lib/esm/DigitalClock/index.tsx +72 -0
  178. package/lib/esm/DigitalClock/utils/useInterval.js +43 -0
  179. package/lib/esm/DropdownMenu/Option.tsx +27 -0
  180. package/lib/esm/DropdownMenu/index.scss +180 -0
  181. package/lib/esm/DropdownMenu/index.tsx +148 -0
  182. package/lib/esm/DynamicFields/index.tsx +386 -0
  183. package/lib/esm/File/index.tsx +302 -0
  184. package/lib/esm/Input/index.tsx +233 -0
  185. package/lib/esm/LiveSearch/index.tsx +582 -0
  186. package/lib/esm/LiveSearch/utils/performance.js +52 -0
  187. package/lib/esm/LiveSearch/utils/useThrottle.js +36 -0
  188. package/lib/esm/ModalDialog/index.tsx +479 -0
  189. package/lib/esm/ModalDialog/plugins/BSL/bodyScrollLock.es6.js +262 -0
  190. package/lib/esm/ModalDialog/plugins/BSL/index.ts +2 -0
  191. package/lib/esm/ModeSwitch/index.tsx +82 -0
  192. package/lib/esm/MultiFuncSelect/index.scss +269 -0
  193. package/lib/esm/MultiFuncSelect/index.tsx +1597 -0
  194. package/lib/esm/MultiFuncSelect/utils/performance.js +52 -0
  195. package/lib/esm/MultiFuncSelect/utils/tree.js +103 -0
  196. package/lib/esm/MultiFuncSelect/utils/useThrottle.js +36 -0
  197. package/lib/esm/MultilevelDropdownMenu/MenuList.tsx +230 -0
  198. package/lib/esm/MultilevelDropdownMenu/index.scss +75 -0
  199. package/lib/esm/MultilevelDropdownMenu/index.tsx +71 -0
  200. package/lib/esm/MultilevelDropdownMenu/utils/dom.js +81 -0
  201. package/lib/esm/Pagination/index.tsx +230 -0
  202. package/lib/esm/Pagination/pagination-navigators.tsx +60 -0
  203. package/lib/esm/Radio/index.tsx +201 -0
  204. package/lib/esm/RangeSlider/index.scss +184 -0
  205. package/lib/esm/RangeSlider/index.tsx +223 -0
  206. package/lib/esm/ScrollReveal/index.scss +27 -0
  207. package/lib/esm/ScrollReveal/index.tsx +146 -0
  208. package/lib/esm/Scrollbar/index.scss +217 -0
  209. package/lib/esm/Scrollbar/index.tsx +497 -0
  210. package/lib/esm/Scrollbar/utils/performance.js +52 -0
  211. package/lib/esm/SearchBar/index.tsx +181 -0
  212. package/lib/esm/Select/index.tsx +276 -0
  213. package/lib/esm/ShowMoreLess/index.scss +27 -0
  214. package/lib/esm/ShowMoreLess/index.tsx +144 -0
  215. package/lib/esm/Switch/index.tsx +143 -0
  216. package/lib/esm/Table/TableColgroup.tsx +29 -0
  217. package/lib/esm/Table/TableField.tsx +40 -0
  218. package/lib/esm/Table/TableFieldRow.tsx +212 -0
  219. package/lib/esm/Table/TableHeaders.tsx +146 -0
  220. package/lib/esm/Table/TableRow.tsx +127 -0
  221. package/lib/esm/Table/TableSummaries.tsx +36 -0
  222. package/lib/esm/Table/index.scss +364 -0
  223. package/lib/esm/Table/index.tsx +576 -0
  224. package/lib/esm/Table/table-utils.ts +65 -0
  225. package/lib/esm/Table/utils/dom.js +81 -0
  226. package/lib/esm/Table/utils/performance.js +52 -0
  227. package/lib/esm/Tabs/TabList.tsx +42 -0
  228. package/lib/esm/Tabs/TabPanel.tsx +34 -0
  229. package/lib/esm/Tabs/Tabs.tsx +232 -0
  230. package/lib/esm/Tabs/index.tsx +3 -0
  231. package/lib/esm/TagInput/index.scss +125 -0
  232. package/lib/esm/TagInput/index.tsx +314 -0
  233. package/lib/esm/Textarea/index.tsx +178 -0
  234. package/lib/esm/Toast/Item.tsx +75 -0
  235. package/lib/esm/Toast/index.scss +120 -0
  236. package/lib/esm/Toast/index.tsx +249 -0
  237. package/lib/esm/Tooltip/index.scss +327 -0
  238. package/lib/esm/Tooltip/index.tsx +142 -0
  239. package/lib/esm/Tree/TreeList.tsx +503 -0
  240. package/lib/esm/Tree/index.scss +375 -0
  241. package/lib/esm/Tree/index.tsx +301 -0
  242. package/lib/esm/Tree/init-height.tsx +27 -0
  243. package/lib/esm/Tree/utils/convert-tree.js +29 -0
  244. package/lib/esm/Tree/utils/dom.js +81 -0
  245. package/lib/esm/index.js +31 -0
  246. package/package.json +40 -0
@@ -0,0 +1,249 @@
1
+ import React, { useId, useEffect, useState, useRef } from 'react';
2
+
3
+ import Item from './Item';
4
+
5
+ declare global {
6
+ interface Window {
7
+ setCloseToast?: any;
8
+ }
9
+ }
10
+
11
+
12
+ type ToastProps = {
13
+ /** Specify data of toasts as a JSON string format. */
14
+ data: any[any];
15
+ /** Use asynchronous triggering */
16
+ async?: boolean;
17
+ /** The direction of the toast. */
18
+ direction?: string;
19
+ /** Set an automatic closing time, multiple items will be accumulated in order.
20
+ * Amount of time measured in milliseconds. If false or without this attribute, Auto-Close will be disabled.
21
+ */
22
+ autoCloseTime?: boolean | number;
23
+ /** Starts from the top position of the Array when we use the automatic close. */
24
+ autoCloseReverse?: boolean;
25
+ /** You can not close pop-win when it is enabled */
26
+ lock?: boolean;
27
+ /** Self-defined class name for body*/
28
+ schemeBody?: string;
29
+ /** Self-defined class name for header */
30
+ schemeHeader?: string;
31
+ /** Set the color of the close button */
32
+ closeBtnColor?: string;
33
+ /** Disable the close button. */
34
+ closeDisabled?: boolean;
35
+ /** -- */
36
+ id?: string;
37
+ onClose?: (e: any, data: any[]) => void;
38
+ };
39
+
40
+
41
+ const Toast = (props: ToastProps) => {
42
+ const {
43
+ async,
44
+ direction,
45
+ autoCloseTime,
46
+ autoCloseReverse,
47
+ lock,
48
+ data,
49
+ schemeBody,
50
+ schemeHeader,
51
+ closeBtnColor,
52
+ closeDisabled,
53
+ id,
54
+ onClose
55
+ } = props;
56
+
57
+
58
+ const uniqueID = useId().replace(/\:/g, "-");
59
+ const idRes = id || uniqueID;
60
+ const rootRef = useRef<any>(null);
61
+ let depth: number = data.length + 1;
62
+
63
+ function init() {
64
+
65
+
66
+ // Move HTML templates to tag end body </body>
67
+ // render() don't use "Fragment", in order to avoid error "Failed to execute 'insertBefore' on 'Node'"
68
+ // prevent "transform", "filter", "perspective" attribute destruction fixed viewport orientation
69
+ //------------------------------------------
70
+ if ( document.body !== null ) {
71
+ document.body.appendChild(rootRef.current);
72
+ [].slice.call(rootRef.current.querySelectorAll('[data-close]')).forEach( (node: HTMLElement) => {
73
+ node.addEventListener('pointerdown', (e: any) => {
74
+ const index = node.dataset.index;
75
+ handleClose(index as never);
76
+ });
77
+ });
78
+
79
+ }
80
+
81
+
82
+
83
+
84
+ // Initialize data
85
+ //--------------
86
+ const $toast = document.querySelector(`#${rootRef.current.id}`) as HTMLElement;
87
+ if ( $toast !== null ) {
88
+ if ( $toast.dataset.async == 'true' ) {
89
+
90
+ const _list = rootRef.current.querySelectorAll('.toast-container');
91
+ [].slice.call(_list).forEach((node: any, i: number) => {
92
+ node.classList.remove('hide-end');
93
+ // rearrange
94
+ node.style.transform = `perspective(100px) translateZ(-${2 * i}px) translateY(${35 * i}px)`;
95
+
96
+ });
97
+
98
+ }
99
+
100
+ }
101
+
102
+
103
+
104
+ // Auto hide
105
+ //--------------
106
+ const _autoCloseTime: any = typeof (autoCloseTime) === 'undefined' || autoCloseTime === false ? false : autoCloseTime;
107
+ if (_autoCloseTime !== false) {
108
+ const items = JSON.parse(JSON.stringify(data));
109
+ autoClose(0, items, _autoCloseTime);
110
+
111
+ }
112
+
113
+
114
+ }
115
+
116
+ function handleClose(index: number) {
117
+
118
+ const items = JSON.parse(JSON.stringify(data));
119
+ if (items[index] !== undefined) {
120
+ const _list = rootRef.current.querySelectorAll('.toast-container');
121
+ _list[index].classList.add('hide-start');
122
+
123
+ //Let the removed animation show
124
+ setTimeout(() => {
125
+
126
+ [].slice.call(_list).forEach((node: any, i: number) => {
127
+ node.classList.remove('hide-start');
128
+ });
129
+
130
+ // remove current
131
+ _list[index].classList.add('hide-end');
132
+
133
+ // rearrange
134
+ [].slice.call(_list).filter((node: any) => !node.classList.contains('hide-end')).forEach((node: any, index: number) => {
135
+ node.style.transform = `perspective(100px) translateZ(-${2 * index}px) translateY(${35 * index}px)`;
136
+ });
137
+
138
+ //
139
+ onClose?.(rootRef.current, items);
140
+
141
+ }, 300);
142
+ }
143
+ }
144
+
145
+ function autoClose(index: number, items: any[], delay: number = 3000) {
146
+ if ( items.length === index ) {
147
+
148
+ //
149
+ onClose?.(rootRef.current, items);
150
+
151
+ //
152
+ clearTimeout(window.setCloseToast);
153
+ return;
154
+ }
155
+
156
+ window.setCloseToast = setTimeout(() => {
157
+ const _list = rootRef.current.querySelectorAll('.toast-container');
158
+
159
+ if ( autoCloseReverse ) {
160
+ _list[items.length-index].classList.add('hide-start');
161
+ } else {
162
+ _list[index-1].classList.add('hide-start');
163
+ }
164
+
165
+
166
+ //Let the removed animation show
167
+ setTimeout(() => {
168
+
169
+ [].slice.call(_list).forEach((node: any) => {
170
+ node.classList.remove('hide-start');
171
+ });
172
+
173
+ // remove current
174
+ if ( autoCloseReverse ) {
175
+ _list[items.length-index].classList.add('hide-end');
176
+ } else {
177
+ _list[index-1].classList.add('hide-end');
178
+ }
179
+
180
+ // rearrange
181
+ [].slice.call(_list).filter((node: any) => !node.classList.contains('hide-end')).forEach((node: any, i: number) => {
182
+ node.style.transform = `perspective(100px) translateZ(-${2 * i}px) translateY(${35 * i}px)`;
183
+ });
184
+
185
+ autoClose(index, items, delay);
186
+
187
+ }, 300);
188
+ }, delay * (index + 1));
189
+
190
+ index++;
191
+ }
192
+
193
+
194
+
195
+ useEffect(() => {
196
+
197
+ // Initialize
198
+ //------------------------------------------
199
+ init();
200
+
201
+
202
+ // Remove the global list of events, especially as scroll and interval.
203
+ //--------------
204
+ return () => {
205
+
206
+ // Cancels a timeout previously established by calling setTimeout().
207
+ clearTimeout(window.setCloseToast);
208
+
209
+ // Remove all toasts
210
+ const _el = document.querySelector(`#toasts__wrapper-${idRes}`);
211
+ if ( _el !== null ) _el.remove();
212
+
213
+
214
+ }
215
+
216
+ }, [data]);
217
+
218
+ return (
219
+ <div>
220
+
221
+ <div id={`toasts__wrapper-${idRes}`} data-async={async ? async : false} className={`toasts__wrapper toasts__wrapper--${direction ? direction : 'bottom-center'}`} ref={rootRef}>
222
+ <div className="toasts">
223
+ {data.map((item: any, i: number) => {
224
+ return <Item
225
+ depth={depth - i}
226
+ key={i}
227
+ index={i}
228
+ title={item.title}
229
+ note={item.note}
230
+ lock={lock}
231
+ schemeBody={schemeBody}
232
+ schemeHeader={schemeHeader}
233
+ closeBtnColor={closeBtnColor}
234
+ closeDisabled={closeDisabled}
235
+ message={item.message}
236
+ closeEv={handleClose}
237
+ />
238
+
239
+ })}
240
+ </div>
241
+
242
+ </div>
243
+
244
+ </div>
245
+ )
246
+ };
247
+
248
+
249
+ export default Toast;
@@ -0,0 +1,327 @@
1
+ /* ======================================================
2
+ <!-- Tooltip -->
3
+ /* ====================================================== */
4
+
5
+
6
+ /*
7
+ * 1. Base Styles
8
+ * 2. Position Modifiers - Top
9
+ * 3. Position Modifiers - Top Left
10
+ * 4. Position Modifiers - Top Right
11
+ * 5. Position Modifiers - Bottom
12
+ * 6. Position Modifiers - Bottom Left
13
+ * 7. Position Modifiers - Bottom Right
14
+ * 8. Position Modifiers - Left
15
+ * 9. Position Modifiers - Right
16
+ * 10. Size
17
+ */
18
+
19
+ .tooltip__wrapper {
20
+
21
+ --tooltip-box-shadow: 0 5px 15px 0 rgba(0,0,0,.07), 0 15px 35px 0 rgba(50,50,93,.1);
22
+ --tooltip-content-bg: rgba(17, 17, 17, 0.9);
23
+ --tooltip-content-color: #fff;
24
+ --tooltip-content-font-size: 0.75em;
25
+ --tooltip-content-padding-x: 1em;
26
+ --tooltip-content-padding-y: .5em;
27
+ --tooltip-content-line-height: 1.5;
28
+ --tooltip-arrow-bg-top: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2236px%22%20height%3D%2212px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%280%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E") no-repeat;
29
+ --tooltip-arrow-bg-bottom: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2236px%22%20height%3D%2212px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%28180%2018%206%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E") no-repeat;
30
+ --tooltip-arrow-bg-left: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2212px%22%20height%3D%2236px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%28-90%2018%2018%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E") no-repeat;
31
+ --tooltip-arrow-bg-right: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2212px%22%20height%3D%2236px%22%3E%3Cpath%20fill%3D%22rgba%2817,%2017,%2017,%200.9%29%22%20transform%3D%22rotate%2890%206%206%29%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E") no-repeat;
32
+
33
+ --tooltip-arrow-width: 18px;
34
+ --tooltip-arrow-height: 6px;
35
+
36
+
37
+ position: relative;
38
+ display: inline-block;
39
+
40
+
41
+ &::before {
42
+ background-size: 100% auto !important;
43
+ content: "";
44
+ }
45
+
46
+ &.active {
47
+
48
+ &::before,
49
+ .tooltip__content {
50
+ opacity: 1;
51
+ pointer-events: auto;
52
+ }
53
+ }
54
+
55
+ &:focus {
56
+
57
+ &::before,
58
+ .tooltip__content {
59
+ opacity: 1;
60
+ pointer-events: auto;
61
+ }
62
+ }
63
+
64
+
65
+ &::before,
66
+ .tooltip__content {
67
+ backface-visibility: hidden;
68
+ will-change: transform;
69
+ opacity: 0;
70
+ pointer-events: none;
71
+
72
+ position: absolute;
73
+ box-sizing: border-box;
74
+ z-index: 10;
75
+ transform-origin: top;
76
+ box-shadow: var(--tooltip-box-shadow);
77
+ transition: .1s ease-in-out;
78
+ }
79
+
80
+
81
+
82
+ /*
83
+ ---------------------------
84
+ 1. Base Styles
85
+ ---------------------------
86
+ */
87
+
88
+ .tooltip__content {
89
+ background: var(--tooltip-content-bg);
90
+ border-radius: 4px;
91
+ color: var(--tooltip-content-color);
92
+ content: attr(aria-label);
93
+ font-size: var(--tooltip-content-font-size);
94
+ font-weight: normal;
95
+ text-transform: none;
96
+ padding: var(--tooltip-content-padding-y) var(--tooltip-content-padding-x);
97
+ white-space: nowrap;
98
+ box-sizing: content-box;
99
+ line-height: var(--tooltip-content-line-height);
100
+
101
+ img {
102
+ height: auto !important;
103
+ margin: .5rem 0;
104
+ }
105
+
106
+ }
107
+
108
+
109
+
110
+ /*
111
+ ---------------------------
112
+ 2. Position Modifiers - Top
113
+ ---------------------------
114
+ */
115
+
116
+ &[data-microtip-position|="top"] {
117
+ &::before {
118
+ background: var(--tooltip-arrow-bg-top);
119
+ height: var(--tooltip-arrow-height);
120
+ width: var(--tooltip-arrow-width);
121
+ }
122
+
123
+ .tooltip__content {
124
+ margin-bottom: var(--tooltip-arrow-height);
125
+ }
126
+
127
+ &::before {
128
+ bottom: calc(100% + var(--tooltip-arrow-height));
129
+ left: calc(50% - var(--tooltip-arrow-width)/2);
130
+ }
131
+
132
+ .tooltip__content {
133
+ bottom: calc(100% + var(--tooltip-arrow-height));
134
+ left: 50%;
135
+ transform: translateX(-50%);
136
+ }
137
+ }
138
+
139
+
140
+ /*
141
+ ---------------------------
142
+ 3. Position Modifiers - Top Left
143
+ ---------------------------
144
+ */
145
+
146
+ &[data-microtip-position="top-left"] {
147
+ .tooltip__content {
148
+ bottom: calc(100% + var(--tooltip-arrow-height));
149
+ left: 50%;
150
+ transform: translateX(calc(-100% + var(--tooltip-arrow-width)));
151
+ }
152
+
153
+ }
154
+
155
+
156
+
157
+ /*
158
+ ---------------------------
159
+ 4. Position Modifiers - Top Right
160
+ ---------------------------
161
+ */
162
+
163
+ &[data-microtip-position="top-right"] {
164
+ .tooltip__content {
165
+ bottom: calc(100% + var(--tooltip-arrow-height));
166
+ left: 50%;
167
+ transform: translateX(calc(0% - var(--tooltip-arrow-width)));
168
+ }
169
+ }
170
+
171
+ /*
172
+ ---------------------------
173
+ 5. Position Modifiers - Bottom
174
+ ---------------------------
175
+ */
176
+
177
+
178
+ &[data-microtip-position|="bottom"] {
179
+ &::before {
180
+ background: var(--tooltip-arrow-bg-bottom);
181
+ height: var(--tooltip-arrow-height);
182
+ width: var(--tooltip-arrow-width);
183
+ margin-top: 5px;
184
+ margin-bottom: 0;
185
+ }
186
+
187
+ .tooltip__content {
188
+ margin-top: var(--tooltip-arrow-height);
189
+ }
190
+
191
+ &::before {
192
+ bottom: auto;
193
+ top: calc(100% + 1px);
194
+ left: calc(50% - var(--tooltip-arrow-width)/2);
195
+ }
196
+
197
+ .tooltip__content {
198
+ bottom: auto;
199
+ top: calc(100% + var(--tooltip-arrow-height));
200
+ left: 50%;
201
+ transform: translateX(-50%);
202
+ }
203
+ }
204
+
205
+
206
+ /*
207
+ ---------------------------
208
+ 6. Position Modifiers - Bottom Left
209
+ ---------------------------
210
+ */
211
+
212
+
213
+ &[data-microtip-position="bottom-left"] {
214
+ .tooltip__content {
215
+ bottom: auto;
216
+ top: calc(100% + var(--tooltip-arrow-height));
217
+ left: 50%;
218
+ transform: translateX(calc(-100% + var(--tooltip-arrow-width)));
219
+ }
220
+ }
221
+
222
+ /*
223
+ ---------------------------
224
+ 7. Position Modifiers - Bottom Right
225
+ ---------------------------
226
+ */
227
+
228
+
229
+ &[data-microtip-position="bottom-right"] {
230
+ .tooltip__content {
231
+ bottom: auto;
232
+ top: calc(100% + var(--tooltip-arrow-height));
233
+ left: 50%;
234
+ transform: translateX(calc(0% - var(--tooltip-arrow-width)));
235
+ }
236
+ }
237
+
238
+
239
+ /*
240
+ ---------------------------
241
+ 8. Position Modifiers - Left
242
+ ---------------------------
243
+ */
244
+ &[data-microtip-position="left"] {
245
+
246
+ &::before,
247
+ .tooltip__content {
248
+ bottom: auto;
249
+ left: auto;
250
+ right: 100%;
251
+ top: 50%;
252
+ transform: translateY(-50%);
253
+ }
254
+
255
+ &::before {
256
+ background: var(--tooltip-arrow-bg-left);
257
+ height: var(--tooltip-arrow-width);
258
+ width: var(--tooltip-arrow-height);
259
+ margin-right: 5px;
260
+ margin-bottom: 0;
261
+ }
262
+
263
+ .tooltip__content {
264
+ margin-right: 10px;
265
+ }
266
+ }
267
+
268
+
269
+ /*
270
+ ---------------------------
271
+ 9. Position Modifiers - Right
272
+ ---------------------------
273
+ */
274
+
275
+ &[data-microtip-position="right"] {
276
+
277
+ &::before,
278
+ .tooltip__content {
279
+ bottom: auto;
280
+ left: 100%;
281
+ top: 50%;
282
+ transform: translateY(-50%);
283
+ }
284
+
285
+ &::before {
286
+ background: var(--tooltip-arrow-bg-right);
287
+ height: var(--tooltip-arrow-width);
288
+ width: var(--tooltip-arrow-height);
289
+ margin-bottom: 0;
290
+ margin-left: 5px;
291
+ }
292
+
293
+ .tooltip__content {
294
+ margin-left: 10px;
295
+ }
296
+ }
297
+
298
+
299
+ /*
300
+ ---------------------------
301
+ 10. Size
302
+ ---------------------------
303
+ */
304
+ &[data-microtip-size="auto"].tooltip__content {
305
+ white-space: nowrap;
306
+ width: auto;
307
+ max-width: 530px;
308
+ overflow: hidden;
309
+ text-overflow: ellipsis;
310
+ }
311
+
312
+ &[data-microtip-size="small"].tooltip__content {
313
+ white-space: initial;
314
+ width: 80px;
315
+ }
316
+
317
+ &[data-microtip-size="medium"].tooltip__content {
318
+ white-space: initial;
319
+ width: 150px;
320
+ }
321
+
322
+ &[data-microtip-size="large"].tooltip__content {
323
+ white-space: initial;
324
+ width: 260px;
325
+ }
326
+
327
+ }
@@ -0,0 +1,142 @@
1
+ import React, { useId, useState, useRef, useEffect } from 'react';
2
+
3
+
4
+ type TooltipProps = {
5
+ wrapperClassName?: string;
6
+ /** The direction of the tip. Defaults to `top`. Possible values are: `top`, `top-right`, `top-left`, `bottom`, `bottom-right`, `bottom-left` */
7
+ direction?: string;
8
+ /** The size of the content area. Defaults to `auto`. Possible values are: `auto`, `large`, `medium`, `small` */
9
+ size?: string;
10
+ /** The number of milliseconds to determine hover intent, defaults to 200 */
11
+ hoverDelay?: number;
12
+ /** The number of milliseconds to determine hover-end intent, defaults to the hoverDelay value */
13
+ mouseOutDelay?: number;
14
+ /** Set a piece of text or HTML code */
15
+ content?: React.ReactNode;
16
+ /** -- */
17
+ id?: string;
18
+ children: React.ReactNode;
19
+ };
20
+
21
+
22
+ const Tooltip = (props: TooltipProps) => {
23
+ const {
24
+ wrapperClassName,
25
+ direction,
26
+ size,
27
+ hoverDelay,
28
+ mouseOutDelay,
29
+ content,
30
+ id,
31
+ children
32
+ } = props;
33
+
34
+
35
+ const uniqueID = useId();
36
+ const idRes = id || uniqueID;
37
+ const rootRef = useRef<any>(null);
38
+ const HOVER_DELAY = hoverDelay ? hoverDelay : 200;
39
+ const MOUSE_OUT_DELAY = mouseOutDelay ? mouseOutDelay : HOVER_DELAY;
40
+
41
+ const [hasBeenShown, setHasBeenShown] = useState<boolean>(false);
42
+ const [isShow, setIsShow] = useState<boolean>(false);
43
+
44
+
45
+ //timer hover
46
+ const timeoutHoverIdRef = useRef<any>(null);
47
+ const startTimerHover = () => {
48
+ timeoutHoverIdRef.current = setTimeout(() => {
49
+
50
+ if (!hasBeenShown) {
51
+ // this will render once, then fire componentDidUpdate, which will show the tip
52
+ setHasBeenShown(true);
53
+ }
54
+
55
+ if (!isShow) setIsShow(true);
56
+
57
+ }, HOVER_DELAY);
58
+ };
59
+
60
+ const stopTimerHover = () => {
61
+ clearTimeout(timeoutHoverIdRef.current);
62
+ timeoutHoverIdRef.current = null;
63
+ };
64
+
65
+
66
+ //timer mouseout
67
+ const timeoutMouseoutIdRef = useRef<any>(null);
68
+ const startTimerMouseout = () => {
69
+ timeoutMouseoutIdRef.current = setTimeout(() => {
70
+ hideTip();
71
+ }, MOUSE_OUT_DELAY);
72
+ };
73
+
74
+ const stopTimerMouseout = () => {
75
+ clearTimeout(timeoutMouseoutIdRef.current);
76
+ timeoutMouseoutIdRef.current = null;
77
+ };
78
+
79
+
80
+ function handleMouseEnter() {
81
+ stopTimerHover();
82
+ stopTimerMouseout();
83
+ startTimerHover();
84
+ }
85
+
86
+ function handleMouseLeave() {
87
+ stopTimerHover();
88
+ stopTimerMouseout();
89
+ startTimerMouseout();
90
+ }
91
+
92
+
93
+ function hideTip() {
94
+ if (isShow) setIsShow(false);
95
+ }
96
+
97
+ function handleTouchStart(e: any) {
98
+ hideTip();
99
+ }
100
+
101
+
102
+ useEffect(() => {
103
+
104
+ window.removeEventListener('touchstart', handleTouchStart);
105
+ window.addEventListener( 'touchstart', handleTouchStart);
106
+
107
+ return () => {
108
+ stopTimerHover();
109
+ stopTimerMouseout();
110
+ window.removeEventListener('touchstart', handleTouchStart);
111
+ };
112
+
113
+
114
+ }, []);
115
+
116
+
117
+ return (
118
+ <>
119
+
120
+ <div
121
+ ref={rootRef}
122
+ id={idRes}
123
+ className={`${wrapperClassName || wrapperClassName === '' ? `tooltip__wrapper ${wrapperClassName}` : `tooltip__wrapper d-inline-block`} ${isShow ? 'active' : ''}`}
124
+ onMouseEnter={handleMouseEnter}
125
+ onMouseLeave={handleMouseLeave}
126
+ role="tooltip"
127
+ data-microtip-position={direction || 'top'}
128
+ data-microtip-size={size || 'auto'}
129
+ >
130
+ <div className="tooltip__content">{content}</div>
131
+
132
+ {children}
133
+ </div>
134
+
135
+
136
+
137
+ </>
138
+ )
139
+ };
140
+
141
+
142
+ export default Tooltip;