@cfx-dev/ui-components 5.0.26 → 5.0.28

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.
@@ -0,0 +1,5 @@
1
+ export declare function useKeyboardArrows<T extends (direction: 'left' | 'right') => void>(callback: T): void;
2
+ export declare namespace useKeyboardArrows {
3
+ var isArrowLeft: (event: KeyboardEvent) => boolean;
4
+ var isArrowRight: (event: KeyboardEvent) => boolean;
5
+ }
@@ -0,0 +1,13 @@
1
+ import { useDynamicRef as t } from "./useDynamicRef.js";
2
+ import { useGlobalKeyboardEvent as f } from "./useGlobalKeyboardEvent.js";
3
+ function o(r) {
4
+ const e = t((i) => {
5
+ o.isArrowLeft(i) && r("left"), o.isArrowRight(i) && r("right");
6
+ });
7
+ f(e);
8
+ }
9
+ o.isArrowLeft = (r) => r.key === "ArrowLeft";
10
+ o.isArrowRight = (r) => r.key === "ArrowRight";
11
+ export {
12
+ o as useKeyboardArrows
13
+ };
@@ -0,0 +1,21 @@
1
+ import { default as React } from 'react';
2
+ import { MediaItem, UseLightboxOptions } from '../../components/Lightbox/types';
3
+
4
+ export declare function useLightboxOpener(initialIndex?: number): {
5
+ isOpen: boolean;
6
+ openLightbox: (idx: number) => void;
7
+ closeLightbox: () => void;
8
+ currentIndex: number;
9
+ handleIndexChange: (idx: number) => void;
10
+ };
11
+ export declare function useLightbox({ currentIndex, isOpen, onClose, onIndexChange, initialIndex, }: UseLightboxOptions & {
12
+ initialIndex?: number;
13
+ }): {
14
+ emblaRef: import('embla-carousel-react').EmblaViewportRefType;
15
+ getSelectedIndex: () => number;
16
+ handlePrevious: () => void;
17
+ handleNext: () => void;
18
+ handleOverlayClick: (e: React.MouseEvent) => void;
19
+ handleOverlayKeyDown: (e: React.KeyboardEvent) => void;
20
+ };
21
+ export declare const usePreloadMedia: (items: MediaItem[], open: boolean) => void;
@@ -0,0 +1,80 @@
1
+ import { u as b } from "../../embla-carousel-react.esm-BE464U1q.js";
2
+ import { useCallback as c, useEffect as i, useState as g } from "react";
3
+ import { useBodyScrollLock as y } from "./useBodyScrollLock.js";
4
+ function L(o = 0) {
5
+ const [s, t] = g(!1), [l, n] = g(o), f = c((a) => {
6
+ n(a), t(!0);
7
+ }, []), e = c(() => {
8
+ t(!1);
9
+ }, []), u = c((a) => {
10
+ n(a);
11
+ }, []);
12
+ return {
13
+ isOpen: s,
14
+ openLightbox: f,
15
+ closeLightbox: e,
16
+ currentIndex: l,
17
+ handleIndexChange: u
18
+ };
19
+ }
20
+ function v({
21
+ currentIndex: o,
22
+ isOpen: s,
23
+ onClose: t,
24
+ onIndexChange: l,
25
+ initialIndex: n
26
+ }) {
27
+ const [f, e] = b({
28
+ loop: !1,
29
+ startIndex: typeof n == "number" ? n : o
30
+ }), u = c(() => {
31
+ e && e.scrollPrev();
32
+ }, [e]), a = c(() => {
33
+ e && e.scrollNext();
34
+ }, [e]), d = c(
35
+ (r) => {
36
+ r.target === r.currentTarget && t();
37
+ },
38
+ [t]
39
+ ), p = c(
40
+ (r) => {
41
+ (r.key === "Enter" || r.key === " ") && r.target === r.currentTarget && t();
42
+ },
43
+ [t]
44
+ ), h = c(() => e ? e.selectedScrollSnap() : o, [e, o]);
45
+ return i(() => {
46
+ e && s && e.scrollTo(o);
47
+ }, [e, o, s]), i(() => {
48
+ if (!e)
49
+ return;
50
+ const r = () => {
51
+ const m = e.selectedScrollSnap();
52
+ l(m);
53
+ };
54
+ return e.on("select", r), () => {
55
+ e.off("select", r);
56
+ };
57
+ }, [e, l]), y(s), {
58
+ emblaRef: f,
59
+ getSelectedIndex: h,
60
+ handlePrevious: u,
61
+ handleNext: a,
62
+ handleOverlayClick: d,
63
+ handleOverlayKeyDown: p
64
+ };
65
+ }
66
+ const w = (o, s) => {
67
+ i(() => {
68
+ s && o.forEach((t) => {
69
+ if (t.type === "image" && t.src) {
70
+ const l = new window.Image();
71
+ l.src = t.src;
72
+ }
73
+ });
74
+ }, [s, o]);
75
+ };
76
+ export {
77
+ v as useLightbox,
78
+ L as useLightboxOpener,
79
+ w as usePreloadMedia
80
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfx-dev/ui-components",
3
- "version": "5.0.26",
3
+ "version": "5.0.28",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "dist/main.js",