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,479 @@
1
+ import React, { useId, useState, useRef, useEffect } from 'react';
2
+ //Destroys body scroll locking
3
+ import { clearAllBodyScrollLocks, disableBodyScroll, enableBodyScroll } from './plugins/BSL';
4
+
5
+
6
+ declare module 'react' {
7
+ interface ReactI18NextChildren<T> {
8
+ children?: any;
9
+ }
10
+ }
11
+
12
+ declare global {
13
+ interface Window {
14
+ curVideo?: any;
15
+ setCloseModalDialog?: any;
16
+ }
17
+ }
18
+
19
+
20
+
21
+ type ModalDialogProps = {
22
+ /** Whether the modal dialog is visible or not, you can use it with the `autoClose` property at the same time */
23
+ show: boolean;
24
+ /** Prevent "transform", "filter", "perspective" attribute destruction fixed viewport orientation. Enabled by default, after enabling the default JS event will be invalid, you need to use the `onOpen` attribute to add some new events to elements. Please refer to the example. */
25
+ protectFixedViewport?: boolean;
26
+ /** Custom modal max-width whick need a unit string. */
27
+ maxWidth?: number | string;
28
+ /** Custom modal max-height whick need a unit string. */
29
+ minHeight?: number | string;
30
+ /** Adapt the video to the window */
31
+ enableVideo?: boolean;
32
+ /** Set a window title */
33
+ heading?: React.ReactNode;
34
+ /** Specify a class for this Node. */
35
+ triggerClassName?: string;
36
+ /** Set a piece of text or HTML code for the trigger */
37
+ triggerContent?: React.ReactNode;
38
+ /** set close button */
39
+ closeBtnClassName?: string;
40
+ closeBtnLabel?: string | React.ReactNode;
41
+ /** set submit button */
42
+ submitBtnClassName?: string;
43
+ submitBtnLabel?: string | React.ReactNode;
44
+ /** Specify auto-close time. This function is not enabled when this value is false. If the value is 2000, it will automatically close after 2 seconds. */
45
+ autoClose?: number | boolean;
46
+ /** Disable mask */
47
+ maskDisabled?: boolean;
48
+ /** Mask opacity */
49
+ maskOpacity?: string;
50
+ /** Disable mask to close the window */
51
+ closeOnlyBtn?: boolean;
52
+ /** Disable the close button. */
53
+ closeDisabled?: boolean;
54
+ /** Incoming data, you can set the third parameter of `onSubmit` */
55
+ data?: any;
56
+ /** -- */
57
+ id?: string;
58
+ children: React.ReactNode;
59
+ /** This function is called whenever the data is updated.
60
+ * Exposes the JSON format data about the option as an argument.
61
+ */
62
+ onLoad?: (openFunc: any, closeFunc: any) => void;
63
+ onOpen?: (e: any, callback: any) => void;
64
+ onClose?: (e: any) => void;
65
+ onSubmit?: (e: any, callback: any, incomingData: string | null | undefined) => void;
66
+ };
67
+
68
+ const ModalDialog = (props: ModalDialogProps) => {
69
+ const {
70
+ show,
71
+ protectFixedViewport,
72
+ maxWidth,
73
+ minHeight,
74
+ enableVideo,
75
+ heading,
76
+ triggerClassName,
77
+ triggerContent,
78
+ closeBtnClassName,
79
+ closeBtnLabel,
80
+ submitBtnClassName,
81
+ submitBtnLabel,
82
+ autoClose,
83
+ maskDisabled,
84
+ maskOpacity,
85
+ closeOnlyBtn,
86
+ closeDisabled,
87
+ data,
88
+ onLoad,
89
+ onOpen,
90
+ onClose,
91
+ onSubmit,
92
+ id,
93
+ children
94
+ } = props;
95
+
96
+
97
+ const uniqueID = useId().replace(/\:/g, "-");
98
+ const modalRef = useRef<any>(null);
99
+ const triggerRef = useRef<any>(null);
100
+ const idRes = id || uniqueID;
101
+ const PROTECT_FIXED_VIEWPORT = typeof protectFixedViewport === 'undefined' ? true : protectFixedViewport;
102
+
103
+ const [winShow, setWinShow] = useState<boolean>(false);
104
+ const [incomingData, setIncomingData] = useState<string | null | undefined>(null);
105
+
106
+
107
+ function handleCloseWin(e: any) {
108
+ if (typeof e !== 'undefined' && e !== null) e.preventDefault();
109
+
110
+ closeAction();
111
+
112
+ //
113
+ onClose?.(e);
114
+ }
115
+
116
+
117
+ function handleOpenWin(e: any) {
118
+ if (typeof e !== 'undefined' && e !== null) e.preventDefault();
119
+
120
+ openAction();
121
+
122
+ //
123
+ const callback = (e: any) => {
124
+ return () => {
125
+ handleCloseWin(e);
126
+ }
127
+ };
128
+ onOpen?.(e, callback(e));
129
+ }
130
+
131
+ function closeAction() {
132
+ // pause video without controls
133
+ //------------------------------------------
134
+ if (window.curVideo !== null && typeof window.curVideo !== 'undefined') window.curVideo.pause();
135
+
136
+
137
+ // close Modal Dialog
138
+ //------------------------------------------
139
+ const $mask: HTMLElement | null = document.querySelector(`#mask-${idRes} > .modal-backdrop`);
140
+ setWinShow(false);
141
+ if ($mask !== null) $mask.classList.remove('show');
142
+
143
+ setTimeout(() => {
144
+ if (modalRef.current !== null) modalRef.current.style.display = 'none';
145
+ if ($mask !== null) $mask.style.display = 'none';
146
+ }, 300);
147
+
148
+
149
+
150
+ // Unlocks the page
151
+ //------------------------------------------
152
+ enableBodyScroll(document.querySelector('body'));
153
+
154
+
155
+ // Cancels a timeout previously established by calling setTimeout().
156
+ //------------------------------------------
157
+ clearTimeout(window.setCloseModalDialog);
158
+
159
+
160
+ }
161
+
162
+
163
+ function openAction() {
164
+
165
+
166
+ // Video PopUp Interaction
167
+ //------------------------------------------
168
+ const hasVideo = modalRef.current.classList.contains('is-video') ? true : false;
169
+
170
+ if (hasVideo) {
171
+
172
+ const windowWidth = window.innerWidth;
173
+ const windowHeight = window.innerHeight;
174
+ const $videoWrapper = modalRef.current.querySelector('.modal-dialog__video');
175
+ const isIframe = $videoWrapper.getElementsByTagName('iframe').length > 0 ? true : false;
176
+ let $video: any = isIframe ? $videoWrapper.getElementsByTagName('iframe')[0] : $videoWrapper.getElementsByTagName('video')[0];
177
+
178
+ //
179
+ const setVideo = function (currentWidth: number, currentHeight: number, obj: any) {
180
+
181
+ const newMaxW = windowWidth - 80,
182
+ newMaxH = windowHeight - 80;
183
+
184
+ let newW = currentWidth,
185
+ newH = currentHeight;
186
+
187
+
188
+ if (currentHeight > newMaxH) {
189
+ newH = newMaxH;
190
+
191
+ //Scaled/Proportional Content
192
+ newW = currentWidth * (newH / currentHeight);
193
+
194
+ }
195
+
196
+ if (newW > newMaxW) {
197
+ newW = newMaxW;
198
+
199
+ //Scaled/Proportional Content
200
+ newH = currentHeight * (newW / currentWidth);
201
+ }
202
+
203
+ obj.height = newH + 'px';
204
+ obj.width = newW + 'px';
205
+
206
+ //
207
+ modalRef.current.querySelector('.modal-dialog').style.width = newW + 'px';
208
+
209
+ };
210
+
211
+
212
+ if (isIframe) {
213
+ let _w = parseFloat(modalRef.current.querySelector('.modal-dialog').style.maxWidth);
214
+ if (isNaN(_w)) _w = 500;
215
+ const _h = _w * 0.5625;
216
+
217
+ setVideo(_w, _h, $video);
218
+ } else {
219
+
220
+ const _sources = $video.getElementsByTagName('source');
221
+ const _src = _sources.length > 0 ? _sources[0].src : $video.src;
222
+
223
+ getVideoDimensions(_src).then(function (res: any): void {
224
+ setVideo(res.width, res.height, $video);
225
+ });
226
+ }
227
+
228
+ //Set current video when the tag is <video>
229
+ window.curVideo = $video.tagName === 'VIDEO' ? $video : null;
230
+
231
+ }
232
+
233
+
234
+ // fire Modal Dialog
235
+ //------------------------------------------
236
+ const $mask: HTMLElement | null = document.querySelector(`#mask-${idRes} > .modal-backdrop`);
237
+ modalRef.current.style.display = 'block';
238
+ if ($mask !== null) $mask.style.display = 'block';
239
+ setTimeout(() => {
240
+ setWinShow(true);
241
+ if ($mask !== null) $mask.classList.add('show');
242
+ }, 0);
243
+
244
+
245
+
246
+ // Locks the page
247
+ //------------------------------------------
248
+ //
249
+ // Get a target element that you want to persist scrolling for (such as a modal/lightbox/flyout/nav).
250
+ // Specifically, the target element is the one we would like to allow scroll on (NOT a parent of that element).
251
+ // This is also the element to apply the CSS '-webkit-overflow-scrolling: touch;' if desired.
252
+ disableBodyScroll(document.querySelector('body'));
253
+
254
+
255
+
256
+ //auto close
257
+ //------------------------------------------
258
+ if (autoClose && !isNaN(autoClose as number)) {
259
+ window.setCloseModalDialog = setTimeout(function () {
260
+ closeAction();
261
+
262
+ //
263
+ onClose?.(null);
264
+ }, autoClose as number);
265
+ }
266
+
267
+ }
268
+
269
+
270
+
271
+
272
+ //Returns the dimensions of a video asynchrounsly.
273
+ function getVideoDimensions(url: string) {
274
+ return new Promise(function (resolve) {
275
+ // create the video element
276
+ let video = document.createElement('video');
277
+
278
+ // place a listener on it
279
+ video.addEventListener("loadedmetadata", function () {
280
+ // retrieve dimensions
281
+ let height = this.videoHeight;
282
+ let width = this.videoWidth;
283
+ // send back result
284
+ resolve({
285
+ height: height,
286
+ width: width
287
+ });
288
+ }, false);
289
+
290
+ // start download meta-datas
291
+ video.src = url;
292
+ });
293
+ }
294
+
295
+
296
+ useEffect(() => {
297
+
298
+
299
+
300
+ // update incoming data
301
+ //--------------
302
+ setIncomingData(data);
303
+
304
+
305
+ // Move HTML templates to tag end body </body>
306
+ // render() don't use "Fragment", in order to avoid error "Failed to execute 'insertBefore' on 'Node'"
307
+ // prevent "transform", "filter", "perspective" attribute destruction fixed viewport orientation
308
+ //--------------
309
+ if ( PROTECT_FIXED_VIEWPORT ) {
310
+ if ( document.body !== null ) {
311
+
312
+ document.body.appendChild(modalRef.current);
313
+
314
+ [].slice.call(modalRef.current.querySelectorAll('[data-close]')).forEach((node: HTMLElement) => {
315
+ if ( typeof node.dataset.ev === 'undefined' ) {
316
+ node.dataset.ev = 'true';
317
+ node.addEventListener('pointerdown', (e: any) => {
318
+ handleCloseWin(e);
319
+ });
320
+ }
321
+
322
+ });
323
+ [].slice.call(modalRef.current.querySelectorAll('[data-confirm]')).forEach((node: HTMLElement) => {
324
+ if ( typeof node.dataset.ev === 'undefined' ) {
325
+ node.dataset.ev = 'true';
326
+ node.addEventListener('pointerdown', (e: any) => {
327
+ const callback = (e: any) => {
328
+ return () => {
329
+ handleCloseWin(e);
330
+ }
331
+ };
332
+
333
+ const _incomingData = node.dataset.incomingData;
334
+ onSubmit?.(e, callback(e), _incomingData);
335
+ });
336
+ }
337
+
338
+ });
339
+ }
340
+
341
+
342
+ }
343
+
344
+
345
+ // add mask
346
+ //--------------
347
+ if (document.getElementById(`mask-${idRes}`) === null && !maskDisabled && document.body !== null) {
348
+ const maskDiv = document.createElement('div');
349
+ maskDiv.id = `mask-${idRes}`;
350
+ maskDiv.innerHTML = `<div class="${winShow ? 'modal-backdrop fade show' : 'modal-backdrop fade'}" style="display:none;${maskOpacity ? `opacity:${maskOpacity};` : ''}"></div>`;
351
+ document.body.appendChild(maskDiv);
352
+
353
+ if (!closeOnlyBtn) {
354
+ const $mask: HTMLElement | null = document.querySelector(`#mask-${idRes} > .modal-backdrop`);
355
+ if ($mask !== null) $mask.addEventListener('pointerdown', (e: any) => {
356
+ handleCloseWin(e);
357
+ });
358
+ }
359
+
360
+ }
361
+
362
+
363
+ // show
364
+ //--------------
365
+ if (show) {
366
+ openAction();
367
+
368
+
369
+ //
370
+ const callback = (e: any) => {
371
+ return () => {
372
+ handleCloseWin(e);
373
+ }
374
+ };
375
+ onOpen?.(null, callback(null));
376
+
377
+ } else {
378
+ handleCloseWin(null);
379
+ }
380
+
381
+
382
+ // Pass the function to be called
383
+ //--------------
384
+ onLoad?.(() => handleOpenWin, () => handleCloseWin);
385
+
386
+
387
+ // Remove the global list of events, especially as scroll and interval.
388
+ //--------------
389
+ return () => {
390
+
391
+ clearAllBodyScrollLocks();
392
+
393
+ // Cancels a timeout previously established by calling setTimeout().
394
+ clearTimeout(window.setCloseModalDialog);
395
+
396
+ // Remove all masks and modals
397
+ Array.prototype.forEach.call(document.querySelectorAll('.modal'), (node: any) => {
398
+
399
+ if ( PROTECT_FIXED_VIEWPORT ) {
400
+ // for current actived modal
401
+ if (node.classList.contains('protect-fixed-viewport') && node.classList.contains('show')) {
402
+ node.remove();
403
+ }
404
+ }
405
+
406
+ });
407
+
408
+
409
+ // If there is no active modal, hide all masks
410
+ const existingModal = [].slice.call(document.querySelectorAll('.modal')).filter((node: any) => node.classList.contains('show')).length > 0;
411
+ if ( !existingModal ) {
412
+ Array.prototype.forEach.call(document.querySelectorAll('.modal-backdrop'), (mask: any) => {
413
+ mask.classList.remove('show');
414
+ mask.style.display = 'none';
415
+ });
416
+ }
417
+
418
+ }
419
+
420
+
421
+ }, [show, data]);
422
+
423
+ return (
424
+ <div>
425
+ {triggerContent ? <>
426
+ <div className={triggerClassName ? triggerClassName : 'd-inline w-auto'} ref={triggerRef} onClick={handleOpenWin}>{triggerContent}</div>
427
+ </> : null}
428
+
429
+ {/* Modal */}
430
+ <div ref={modalRef} className={enableVideo ? `modal ${PROTECT_FIXED_VIEWPORT ? 'protect-fixed-viewport' : ''} fade is-video ${winShow ? 'show' : ''}` : `modal ${PROTECT_FIXED_VIEWPORT ? 'protect-fixed-viewport' : ''} fade ${winShow ? 'show' : ''}`} tabIndex={-1} aria-hidden="true" style={{ pointerEvents: 'none' }} data-mask={`mask-${idRes}`}>
431
+ <div className="modal-dialog modal-dialog-centered modal-dialog-scrollable" style={maxWidth ? { maxWidth: `${maxWidth}` } : {}}>
432
+ <div className={enableVideo ? 'modal-content bg-transparent shadow-none border-0' : 'modal-content'} style={{overflow: 'inherit',minHeight: minHeight ? minHeight : 'auto'}}>
433
+ {(!heading || heading === '') && closeDisabled ? null : <>
434
+
435
+ <div className={enableVideo ? 'modal-header border-0 px-0' : 'modal-header'}>
436
+ <h5 className="modal-title">{heading || ''}</h5>
437
+ {!closeDisabled ? <button type="button" className={enableVideo ? 'btn-close btn-close-white' : 'btn-close'} data-close="1" onClick={handleCloseWin}></button> : null}
438
+
439
+ </div>
440
+ </>}
441
+
442
+ <div className={enableVideo ? 'modal-body m-0 p-0' : 'modal-body'}>
443
+ {/*<!-- //////// content begin //////// -->*/}
444
+ {enableVideo ? <>
445
+ <div className="modal-dialog__video">
446
+ <div className="ratio ratio-16x9">
447
+ {children}
448
+ </div>
449
+ </div>
450
+ </> : children}
451
+ {/*<!-- //////// content end //////// -->*/}
452
+ </div>
453
+
454
+ {closeBtnLabel || submitBtnLabel ? <>
455
+ <div className="modal-footer">
456
+
457
+ {!closeDisabled ? <>{closeBtnLabel ? <button data-close="1" onClick={handleCloseWin} type="button" className={closeBtnClassName ? closeBtnClassName : 'btn btn-secondary'}>{closeBtnLabel}</button> : null}</> : null}
458
+
459
+ {submitBtnLabel ? <button data-confirm="1" data-incoming-data={`${incomingData}`} onClick={(e: any) => {
460
+ const callback = (e: any) => {
461
+ return () => {
462
+ handleCloseWin(e);
463
+ }
464
+ };
465
+ onSubmit?.(e, callback(e), incomingData);
466
+ }} type="button" className={submitBtnClassName ? submitBtnClassName : 'btn btn-primary'}>{submitBtnLabel}</button> : null}
467
+ </div>
468
+ </> : null}
469
+
470
+ </div>
471
+ </div>
472
+ </div>
473
+
474
+
475
+ </div>
476
+ )
477
+ };
478
+
479
+ export default ModalDialog;