@thecb/components 9.2.0-beta.10 → 9.2.0-beta.11

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/index.d.ts CHANGED
@@ -298,6 +298,57 @@ declare namespace index_d {
298
298
  };
299
299
  }
300
300
 
301
+ /*
302
+ Hook that assigns a click event listener to the main document element
303
+ Returns a ref to attach to another element (like an icon/button that triggers a popover)
304
+ If a click event gets captured by the document and the assigned element isn't the target
305
+ hook will run whatever handler is passed (eg a function that closes a popover)
306
+
307
+ See popover component for implementation
308
+
309
+ */
310
+
311
+ declare const useOutsideClickHook = handler => {
312
+ const ref = useRef();
313
+
314
+ useEffect(() => {
315
+ const handleOutsideClick = e => {
316
+ if (ref.current && !ref.current.contains(e.target)) {
317
+ handler();
318
+ }
319
+
320
+ document.addEventListener("click", handleOutsideClick, true);
321
+
322
+ return () => {
323
+ document.removeEventListener("click", handleOutsideClick, true);
324
+ };
325
+ };
326
+ }, [ref]);
327
+
328
+ return ref;
329
+ };
330
+
331
+ /*
332
+ Hook that takes an ID selector for an element on the screen
333
+ And optionally values for top position, left position, smooth behavior
334
+ Finds element on screen and scrolls it to the provided coordinates
335
+
336
+ (string, number, number, string, number) => undefined;
337
+ */
338
+
339
+ declare const useScrollTo = (id, top = 0, left = 0, behavior = "auto", delay) => {
340
+ let scrollItem;
341
+ if (delay) {
342
+ setTimeout(() => {
343
+ scrollItem = document.getElementById(id);
344
+ scrollItem?.scrollTo({ top, left, behavior });
345
+ }, delay);
346
+ } else {
347
+ scrollItem = document.getElementById(id);
348
+ scrollItem?.scrollTo({ top, left, behavior });
349
+ }
350
+ };
351
+
301
352
  interface Field {
302
353
  hasErrors: boolean;
303
354
  dirty: boolean;
@@ -386,9 +437,12 @@ declare function useToastNotification(
386
437
 
387
438
 
388
439
 
440
+ declare const index_useScrollTo: typeof useScrollTo;
389
441
  declare const index_useToastNotification: typeof useToastNotification;
390
442
  declare namespace index {
391
443
  export {
444
+ useOutsideClickHook as useOutsideClick,
445
+ index_useScrollTo as useScrollTo,
392
446
  index_useToastNotification as useToastNotification,
393
447
  };
394
448
  }