@thecb/components 9.2.0-beta.9 → 9.2.0

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;
@@ -359,36 +410,39 @@ interface ErrorMessageDictionary {
359
410
 
360
411
  enum ToastVariants {
361
412
  ERROR = "error",
362
- SUCCESS = "success",
413
+ SUCCESS = "success"
363
414
  }
364
415
 
365
- interface UseToastProps {
416
+ interface UseToastOptions {
366
417
  timeout?: number;
367
418
  }
368
419
 
369
420
  interface UseToastResult {
370
421
  isToastOpen: boolean;
371
- toastVariant: "" | ToastVariants;
422
+ toastVariant: string | ToastVariants;
372
423
  toastMessage: string;
373
424
  showToast: ({
374
425
  message,
375
- variant,
426
+ variant
376
427
  }: {
377
428
  message: string;
378
- variant: ToastVariants;
429
+ variant: string | ToastVariants;
379
430
  }) => void;
380
431
  hideToast: () => void;
381
432
  }
382
433
 
383
434
  declare function useToastNotification(
384
- props: UseToastProps
435
+ options?: UseToastOptions
385
436
  ): UseToastResult;
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
  }