@superrb/react-addons 3.0.0-9 → 4.0.0-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/components/accordion.d.ts +9 -0
- package/components/accordion.d.ts.map +1 -0
- package/components/accordion.js +44 -0
- package/components/back-to-top.d.ts +1 -2
- package/components/back-to-top.d.ts.map +1 -1
- package/components/back-to-top.js +2 -3
- package/components/button.d.ts.map +1 -1
- package/components/button.js +3 -3
- package/components/context-wrapper.d.ts +1 -2
- package/components/context-wrapper.d.ts.map +1 -1
- package/components/context-wrapper.js +3 -2
- package/components/cookie-banner.d.ts +8 -3
- package/components/cookie-banner.d.ts.map +1 -1
- package/components/cookie-banner.js +6 -7
- package/components/form/error-message.d.ts +1 -2
- package/components/form/error-message.d.ts.map +1 -1
- package/components/form/error-message.js +2 -3
- package/components/form/field.d.ts +11 -3
- package/components/form/field.d.ts.map +1 -1
- package/components/form/field.js +18 -7
- package/components/form/file-field.d.ts +15 -0
- package/components/form/file-field.d.ts.map +1 -0
- package/components/form/file-field.js +24 -0
- package/components/form/submit-button.d.ts +3 -3
- package/components/form/submit-button.d.ts.map +1 -1
- package/components/form/submit-button.js +3 -4
- package/components/form/success-message.d.ts +3 -2
- package/components/form/success-message.d.ts.map +1 -1
- package/components/form/success-message.js +9 -2
- package/components/form.d.ts +22 -6
- package/components/form.d.ts.map +1 -1
- package/components/form.js +72 -55
- package/components/menu-toggle.d.ts +4 -4
- package/components/menu-toggle.d.ts.map +1 -1
- package/components/menu-toggle.js +4 -13
- package/components/modal.d.ts +3 -2
- package/components/modal.d.ts.map +1 -1
- package/components/modal.js +10 -6
- package/components/skip-to.d.ts +1 -2
- package/components/skip-to.d.ts.map +1 -1
- package/components/skip-to.js +2 -3
- package/components/slideshow-buttons.d.ts +2 -3
- package/components/slideshow-buttons.d.ts.map +1 -1
- package/components/slideshow-buttons.js +2 -3
- package/components/slideshow-pagination.d.ts +5 -0
- package/components/slideshow-pagination.d.ts.map +1 -0
- package/components/slideshow-pagination.js +4 -0
- package/components.d.ts +3 -1
- package/components.d.ts.map +1 -1
- package/components.js +3 -1
- package/context/cookies-context-provider.d.ts.map +1 -1
- package/context/modal-context-provider.d.ts +1 -1
- package/context/modal-context-provider.d.ts.map +1 -1
- package/context/modal-context-provider.js +2 -2
- package/context/nav-context-provider.d.ts +1 -1
- package/context/nav-context-provider.d.ts.map +1 -1
- package/context/nav-context-provider.js +2 -2
- package/hooks/use-async.d.ts +3 -2
- package/hooks/use-async.d.ts.map +1 -1
- package/hooks/use-async.js +3 -4
- package/hooks/use-draggable-scroll.d.ts +3 -3
- package/hooks/use-draggable-scroll.d.ts.map +1 -1
- package/hooks/use-draggable-scroll.js +2 -3
- package/hooks/use-escape.d.ts +3 -0
- package/hooks/use-escape.d.ts.map +1 -0
- package/hooks/use-escape.js +11 -0
- package/hooks/use-event-listener.d.ts +2 -2
- package/hooks/use-event-listener.d.ts.map +1 -1
- package/hooks/use-event-listener.js +4 -12
- package/hooks/use-hide-on-scroll.d.ts +1 -2
- package/hooks/use-hide-on-scroll.d.ts.map +1 -1
- package/hooks/use-hide-on-scroll.js +2 -3
- package/hooks/use-id.d.ts +1 -2
- package/hooks/use-id.d.ts.map +1 -1
- package/hooks/use-id.js +2 -3
- package/hooks/use-is-in-viewport.d.ts +2 -3
- package/hooks/use-is-in-viewport.d.ts.map +1 -1
- package/hooks/use-is-in-viewport.js +17 -15
- package/hooks/use-is-mobile.d.ts +1 -2
- package/hooks/use-is-mobile.d.ts.map +1 -1
- package/hooks/use-is-mobile.js +2 -3
- package/hooks/use-is-overflowing.d.ts +1 -2
- package/hooks/use-is-overflowing.d.ts.map +1 -1
- package/hooks/use-is-overflowing.js +5 -4
- package/hooks/use-lock-body-scroll.d.ts +1 -2
- package/hooks/use-lock-body-scroll.d.ts.map +1 -1
- package/hooks/use-lock-body-scroll.js +1 -2
- package/hooks/use-modal.d.ts +1 -2
- package/hooks/use-modal.d.ts.map +1 -1
- package/hooks/use-modal.js +2 -3
- package/hooks/use-motion-allowed.d.ts +1 -2
- package/hooks/use-motion-allowed.d.ts.map +1 -1
- package/hooks/use-motion-allowed.js +2 -3
- package/hooks/use-parallax.d.ts +1 -2
- package/hooks/use-parallax.d.ts.map +1 -1
- package/hooks/use-parallax.js +2 -3
- package/hooks/use-slideshow.d.ts +5 -4
- package/hooks/use-slideshow.d.ts.map +1 -1
- package/hooks/use-slideshow.js +86 -41
- package/hooks.d.ts +2 -1
- package/hooks.d.ts.map +1 -1
- package/hooks.js +2 -1
- package/package.json +18 -11
- package/store/cookies.d.ts.map +1 -1
- package/store/cookies.js +7 -3
- package/store/modal.d.ts.map +1 -1
- package/store/modal.js +4 -0
- package/store/nav.d.ts.map +1 -1
- package/store/nav.js +4 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/utils/animate.d.ts +1 -2
- package/utils/animate.d.ts.map +1 -1
- package/utils/animate.js +24 -23
- package/utils/extend-class.d.ts +1 -2
- package/utils/extend-class.d.ts.map +1 -1
- package/utils/extend-class.js +8 -7
- package/utils/get-y-pos.d.ts +1 -2
- package/utils/get-y-pos.d.ts.map +1 -1
- package/utils/get-y-pos.js +2 -3
- package/utils/get.d.ts +2 -2
- package/utils/get.d.ts.map +1 -1
- package/utils/get.js +1 -2
- package/utils/is-external-link.d.ts +1 -2
- package/utils/is-external-link.d.ts.map +1 -1
- package/utils/is-external-link.js +6 -7
- package/utils/scroll-to-hash.d.ts +1 -2
- package/utils/scroll-to-hash.d.ts.map +1 -1
- package/utils/scroll-to-hash.js +2 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
// Hook
|
|
3
|
-
|
|
3
|
+
export default function useEventListener(eventName, handler, options = {}, element, flag = true) {
|
|
4
4
|
// Create a ref that stores handler
|
|
5
5
|
const savedHandler = useRef();
|
|
6
6
|
const elementRef = useRef();
|
|
@@ -13,7 +13,7 @@ const useEventListener = (eventName, handler, options = {}, element, flag = true
|
|
|
13
13
|
// ... and potentially cause effect to re-run every render.
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
savedHandler.current = handler;
|
|
16
|
-
}, [handler
|
|
16
|
+
}, [handler]);
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
// Make sure element supports addEventListener
|
|
19
19
|
// On
|
|
@@ -33,13 +33,5 @@ const useEventListener = (eventName, handler, options = {}, element, flag = true
|
|
|
33
33
|
return () => {
|
|
34
34
|
elementRef.current.removeEventListener(eventName, eventListener);
|
|
35
35
|
};
|
|
36
|
-
}, [
|
|
37
|
-
|
|
38
|
-
handler,
|
|
39
|
-
savedHandler.current,
|
|
40
|
-
element,
|
|
41
|
-
elementRef.current,
|
|
42
|
-
flag,
|
|
43
|
-
]);
|
|
44
|
-
};
|
|
45
|
-
export default useEventListener;
|
|
36
|
+
}, [eventName, handler, options, element, flag]);
|
|
37
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hide-on-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-hide-on-scroll.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"use-hide-on-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-hide-on-scroll.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,YAAY,GAAE,OAAe,GAC5B,OAAO,CA+DT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEventListener } from '../hooks';
|
|
2
2
|
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
-
|
|
3
|
+
export default function useHideOnScroll(hiddenOnLoad = false) {
|
|
4
4
|
const [hidden, setHidden] = useState(hiddenOnLoad);
|
|
5
5
|
const handleScroll = useCallback(() => {
|
|
6
6
|
const previousY = window.scrollY;
|
|
@@ -31,5 +31,4 @@ const useHideOnScroll = (hiddenOnLoad = false) => {
|
|
|
31
31
|
useEventListener('popstate', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
|
|
32
32
|
useEventListener('pageshow', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
|
|
33
33
|
return hidden;
|
|
34
|
-
}
|
|
35
|
-
export default useHideOnScroll;
|
|
34
|
+
}
|
package/hooks/use-id.d.ts
CHANGED
package/hooks/use-id.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-id.d.ts","sourceRoot":"","sources":["../src/hooks/use-id.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"use-id.d.ts","sourceRoot":"","sources":["../src/hooks/use-id.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,MAAM,EAAE,MAAM,UAU3C"}
|
package/hooks/use-id.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
2
|
+
export default function useId(prefix) {
|
|
3
3
|
const [id, setId] = useState(`${prefix}-${Math.random().toString(36).substring(2, 9)}`);
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
setId(`${prefix}-${Math.random().toString(36).substring(2, 9)}`);
|
|
6
6
|
}, [prefix]);
|
|
7
7
|
return id;
|
|
8
|
-
}
|
|
9
|
-
export default useId;
|
|
8
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export default function useIsInViewport(initial?: boolean, rootMargin?: string, threshold?: number[]): {
|
|
2
2
|
isInViewport: boolean;
|
|
3
|
-
setRef: (ref: HTMLElement | null) =>
|
|
3
|
+
setRef: (ref: HTMLElement | null) => void;
|
|
4
4
|
};
|
|
5
|
-
export default useIsInViewport;
|
|
6
5
|
//# sourceMappingURL=use-is-in-viewport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-in-viewport.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-in-viewport.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"use-is-in-viewport.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-in-viewport.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,OAAO,UAAQ,EACf,UAAU,SAAY,EACtB,SAAS,WAA0B;;kBA6Dd,WAAW,GAAG,IAAI;EAiBxC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
|
|
2
|
+
export default function useIsInViewport(initial = false, rootMargin = '0px 0px', threshold = [0, 0.25, 0.5, 0.75, 1]) {
|
|
3
3
|
const [isInViewport, setIsInViewport] = useState(initial);
|
|
4
4
|
const element = useRef();
|
|
5
5
|
const observer = useRef();
|
|
@@ -45,20 +45,22 @@ const useIsInViewport = (initial = false, rootMargin = '0px 0px', threshold = [0
|
|
|
45
45
|
wait();
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
-
const setRef =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
const setRef = (ref) => {
|
|
49
|
+
;
|
|
50
|
+
(async () => {
|
|
51
|
+
element.current = ref;
|
|
52
|
+
if (ref) {
|
|
53
|
+
try {
|
|
54
|
+
const observer = await waitForObserver();
|
|
55
|
+
observer.observe(ref);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
// If IntersectionObserver fails, just set isInViewport to true
|
|
59
|
+
console.error(error);
|
|
60
|
+
setIsInViewport(true);
|
|
61
|
+
}
|
|
59
62
|
}
|
|
60
|
-
}
|
|
63
|
+
})();
|
|
61
64
|
};
|
|
62
65
|
return { isInViewport, setRef };
|
|
63
|
-
}
|
|
64
|
-
export default useIsInViewport;
|
|
66
|
+
}
|
package/hooks/use-is-mobile.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-mobile.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-mobile.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"use-is-mobile.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-mobile.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAAO,UAAO,EAAE,IAAI,SAAY,WAiBnE"}
|
package/hooks/use-is-mobile.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
|
|
2
|
+
export default function useIsMobile(initial = true, size = '63.75em') {
|
|
3
3
|
const [isMobile, setIsMobile] = useState(initial);
|
|
4
4
|
const setScreenSize = useCallback(() => {
|
|
5
5
|
setIsMobile(!window.matchMedia(`(min-width: ${size})`).matches);
|
|
@@ -12,5 +12,4 @@ const useIsMobile = (initial = true, size = '63.75em') => {
|
|
|
12
12
|
};
|
|
13
13
|
}, [setScreenSize]);
|
|
14
14
|
return isMobile;
|
|
15
|
-
}
|
|
16
|
-
export default useIsMobile;
|
|
15
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { MutableRefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
export default useIsOverflowing;
|
|
2
|
+
export default function useIsOverflowing({ current, }: MutableRefObject<HTMLElement>): boolean;
|
|
4
3
|
//# sourceMappingURL=use-is-overflowing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-overflowing.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-overflowing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAExC,
|
|
1
|
+
{"version":3,"file":"use-is-overflowing.d.ts","sourceRoot":"","sources":["../src/hooks/use-is-overflowing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAExC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,OAAO,GACR,EAAE,gBAAgB,CAAC,WAAW,CAAC,WAM/B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
(current
|
|
3
|
-
current.
|
|
4
|
-
|
|
1
|
+
export default function useIsOverflowing({ current, }) {
|
|
2
|
+
return (current &&
|
|
3
|
+
(current.scrollWidth > current.clientWidth ||
|
|
4
|
+
current.scrollHeight > current.clientHeight));
|
|
5
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-lock-body-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-lock-body-scroll.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"use-lock-body-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-lock-body-scroll.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAO/D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
function useLockBodyScroll(toggle) {
|
|
2
|
+
export default function useLockBodyScroll(toggle) {
|
|
3
3
|
useEffect(() => {
|
|
4
4
|
document.body.style.overflow = toggle ? 'hidden' : 'unset';
|
|
5
5
|
return () => {
|
|
@@ -7,4 +7,3 @@ function useLockBodyScroll(toggle) {
|
|
|
7
7
|
};
|
|
8
8
|
}, [toggle]);
|
|
9
9
|
}
|
|
10
|
-
export default useLockBodyScroll;
|
package/hooks/use-modal.d.ts
CHANGED
package/hooks/use-modal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-modal.d.ts","sourceRoot":"","sources":["../src/hooks/use-modal.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"use-modal.d.ts","sourceRoot":"","sources":["../src/hooks/use-modal.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,IAAI,EAAE,MAAM;;;;EAU5C"}
|
package/hooks/use-modal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import useModalStore from '../store/modal';
|
|
2
|
-
|
|
2
|
+
export default function useModal(name) {
|
|
3
3
|
const isOpen = useModalStore((state) => state.openState[name]);
|
|
4
4
|
const openModal = useModalStore((state) => state.openModal);
|
|
5
5
|
const closeModal = useModalStore((state) => state.closeModal);
|
|
@@ -8,5 +8,4 @@ const useModal = (name) => {
|
|
|
8
8
|
openModal: () => openModal(name),
|
|
9
9
|
closeModal: () => closeModal(name),
|
|
10
10
|
};
|
|
11
|
-
}
|
|
12
|
-
export default useModal;
|
|
11
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-motion-allowed.d.ts","sourceRoot":"","sources":["../src/hooks/use-motion-allowed.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"use-motion-allowed.d.ts","sourceRoot":"","sources":["../src/hooks/use-motion-allowed.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,gBAAgB,YAUvC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
2
|
+
export default function useMotionAllowed() {
|
|
3
3
|
const [motionAllowed, setMotionAllowed] = useState(true);
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
setMotionAllowed(!window.matchMedia('(prefers-reduced-motion: reduce)').matches);
|
|
6
6
|
}, [setMotionAllowed]);
|
|
7
7
|
return motionAllowed;
|
|
8
|
-
}
|
|
9
|
-
export default useMotionAllowed;
|
|
8
|
+
}
|
package/hooks/use-parallax.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-parallax.d.ts","sourceRoot":"","sources":["../src/hooks/use-parallax.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"use-parallax.d.ts","sourceRoot":"","sources":["../src/hooks/use-parallax.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,KAAK,EAAE,WAAW,EAAE,EACpB,IAAI,GAAE,OAAc,QA4BrB"}
|
package/hooks/use-parallax.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEventListener, useMotionAllowed } from '../hooks';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
|
-
|
|
3
|
+
export default function useParallax(items, flag = true) {
|
|
4
4
|
const isMotionAllowed = useMotionAllowed();
|
|
5
5
|
const onScroll = useCallback((event) => {
|
|
6
6
|
items.forEach((item, index) => {
|
|
@@ -14,5 +14,4 @@ const useParallax = (items, flag = true) => {
|
|
|
14
14
|
});
|
|
15
15
|
}, [items]);
|
|
16
16
|
useEventListener('scroll', onScroll, { passive: true }, undefined, flag && isMotionAllowed);
|
|
17
|
-
}
|
|
18
|
-
export default useParallax;
|
|
17
|
+
}
|
package/hooks/use-slideshow.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ export type Slideshow = {
|
|
|
10
10
|
atStart: boolean;
|
|
11
11
|
atEnd: boolean;
|
|
12
12
|
};
|
|
13
|
-
export declare
|
|
14
|
-
export declare
|
|
15
|
-
declare
|
|
16
|
-
export
|
|
13
|
+
export declare function isHorizontal(element: SlideshowElement): boolean;
|
|
14
|
+
export declare function isCentered(element: SlideshowElement): boolean;
|
|
15
|
+
export declare function getScrollProgress(target: SlideshowElement): number;
|
|
16
|
+
export declare function getCurrentSlideIndex(element: SlideshowElement, currentIndex: number): number;
|
|
17
|
+
export default function useSlideshow(slideshow: MutableRefObject<SlideshowElement>): Slideshow;
|
|
17
18
|
//# sourceMappingURL=use-slideshow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-slideshow.d.ts","sourceRoot":"","sources":["../src/hooks/use-slideshow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAuB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"use-slideshow.d.ts","sourceRoot":"","sources":["../src/hooks/use-slideshow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAuB,MAAM,OAAO,CAAA;AAG7D,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,YAAY,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;IAChD,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAE/D;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAK7D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,UAMzD;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,GACnB,MAAM,CAkER;AAED,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAAS,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,GAC5C,SAAS,CAqGX"}
|
package/hooks/use-slideshow.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
2
|
+
import useEventListener from './use-event-listener';
|
|
3
|
+
export function isHorizontal(element) {
|
|
4
|
+
return window.getComputedStyle(element).scrollSnapType.startsWith('x');
|
|
5
|
+
}
|
|
6
|
+
export function isCentered(element) {
|
|
7
|
+
return (window.getComputedStyle(element.firstElementChild)
|
|
8
|
+
?.scrollSnapAlign === 'center');
|
|
9
|
+
}
|
|
10
|
+
export function getScrollProgress(target) {
|
|
3
11
|
if (!target || target.scrollWidth === target.clientWidth) {
|
|
4
12
|
return -1;
|
|
5
13
|
}
|
|
6
14
|
return target.scrollLeft / (target.scrollWidth - target.clientWidth);
|
|
7
|
-
}
|
|
8
|
-
export
|
|
15
|
+
}
|
|
16
|
+
export function getCurrentSlideIndex(element, currentIndex) {
|
|
9
17
|
if (!element) {
|
|
10
18
|
return currentIndex;
|
|
11
19
|
}
|
|
@@ -13,76 +21,113 @@ export const getCurrentSlideIndex = (element, currentIndex) => {
|
|
|
13
21
|
element.previousScroll = element.scrollLeft;
|
|
14
22
|
return currentIndex;
|
|
15
23
|
}
|
|
16
|
-
const
|
|
24
|
+
const centered = isCentered(element);
|
|
25
|
+
const horizontal = isHorizontal(element);
|
|
26
|
+
const direction = element.scrollLeft > (element.previousScroll || 0) ? 'right' : 'left';
|
|
27
|
+
const offset = 25;
|
|
17
28
|
let gap = parseFloat(window.getComputedStyle(element).gap) || 0;
|
|
18
29
|
if (isNaN(gap)) {
|
|
19
30
|
gap = 0;
|
|
20
31
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const containerEdge = element.getBoundingClientRect()[horizontal ? 'left' : 'top'];
|
|
32
|
+
let padding = parseFloat(window.getComputedStyle(element)[horizontal ? 'paddingLeft' : 'paddingTop']) || 0;
|
|
33
|
+
if (isNaN(padding)) {
|
|
34
|
+
padding = 0;
|
|
35
|
+
}
|
|
36
|
+
const containerEdge = element.getBoundingClientRect()[horizontal ? 'left' : 'top'] + padding;
|
|
27
37
|
let newIndex = currentIndex;
|
|
28
38
|
let i = 0;
|
|
29
39
|
for (const child of element.children) {
|
|
30
40
|
const edge = child.getBoundingClientRect()[horizontal ? 'left' : 'top'] - containerEdge;
|
|
31
41
|
if (centered) {
|
|
42
|
+
const centeredEdge = edge - child.clientWidth / 2;
|
|
32
43
|
const threshold = horizontal
|
|
33
44
|
? element.clientWidth / 2
|
|
34
45
|
: element.clientHeight / 2;
|
|
35
|
-
if (
|
|
36
|
-
|
|
46
|
+
if (centeredEdge >= 0 && centeredEdge < threshold) {
|
|
47
|
+
newIndex = i;
|
|
48
|
+
break;
|
|
37
49
|
}
|
|
38
50
|
}
|
|
39
51
|
else {
|
|
40
52
|
const threshold = direction === 'right'
|
|
41
|
-
? (horizontal ? child.clientWidth : child.clientHeight) - gap
|
|
42
|
-
: 0 + gap;
|
|
53
|
+
? (horizontal ? child.clientWidth : child.clientHeight) - gap - offset
|
|
54
|
+
: 0 + gap + offset;
|
|
43
55
|
if (edge >= 0 - threshold) {
|
|
44
|
-
|
|
56
|
+
newIndex = i;
|
|
57
|
+
break;
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
i++;
|
|
48
61
|
}
|
|
49
62
|
element.previousScroll = element.scrollLeft;
|
|
50
63
|
return newIndex;
|
|
51
|
-
}
|
|
52
|
-
|
|
64
|
+
}
|
|
65
|
+
export default function useSlideshow(slideshow) {
|
|
53
66
|
const [currentSlide, setCurrentSlide] = useState(0);
|
|
67
|
+
const [progress, setProgress] = useState(-1);
|
|
68
|
+
const [ready, setReady] = useState(false);
|
|
69
|
+
const update = () => {
|
|
70
|
+
if (!slideshow.current) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
setCurrentSlide((current) => getCurrentSlideIndex(slideshow.current, current));
|
|
74
|
+
setProgress(getScrollProgress(slideshow.current));
|
|
75
|
+
};
|
|
76
|
+
useEventListener('scroll', update, { passive: true }, slideshow.current, !!slideshow.current && ready);
|
|
77
|
+
useEventListener('resize', update, { passive: true }, slideshow.current, !!slideshow.current && ready);
|
|
54
78
|
useEffect(() => {
|
|
79
|
+
setReady(true);
|
|
55
80
|
if (slideshow.current) {
|
|
56
|
-
|
|
57
|
-
slideshow.current.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
slideshow.current.addEventListener('resize', () => setCurrentSlide((current) => getCurrentSlideIndex(slideshow.current, current)));
|
|
81
|
+
update();
|
|
82
|
+
slideshow.current.setAttribute('role', 'region');
|
|
83
|
+
slideshow.current.setAttribute('aria-label', 'carousel');
|
|
84
|
+
slideshow.current.setAttribute('aria-live', 'polite');
|
|
61
85
|
}
|
|
62
|
-
}, [slideshow]);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
goTo: () => { },
|
|
69
|
-
atStart: true,
|
|
70
|
-
atEnd: true,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
86
|
+
}, [slideshow]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
;
|
|
89
|
+
[...slideshow.current?.children].forEach((child) => child.setAttribute('aria-hidden', 'true'));
|
|
90
|
+
slideshow.current?.children[currentSlide].setAttribute('aria-hidden', 'false');
|
|
91
|
+
}, [currentSlide, slideshow]);
|
|
73
92
|
return {
|
|
74
93
|
slideshowRef: slideshow,
|
|
75
94
|
currentSlide,
|
|
76
95
|
slideCount: slideshow.current?.children.length || 0,
|
|
77
|
-
goTo
|
|
78
|
-
slideshow.current?.children
|
|
96
|
+
goTo(index) {
|
|
97
|
+
index = Math.min(slideshow.current?.children.length - 1, Math.max(0, index));
|
|
98
|
+
const newElement = slideshow.current?.children[index];
|
|
99
|
+
newElement.scrollIntoView({
|
|
79
100
|
behavior: 'smooth',
|
|
80
|
-
block:
|
|
81
|
-
|
|
101
|
+
block: isHorizontal(slideshow.current)
|
|
102
|
+
? 'nearest'
|
|
103
|
+
: isCentered(slideshow.current)
|
|
104
|
+
? 'center'
|
|
105
|
+
: 'start',
|
|
106
|
+
inline: isHorizontal(slideshow.current)
|
|
107
|
+
? isCentered(slideshow.current)
|
|
108
|
+
? 'center'
|
|
109
|
+
: 'start'
|
|
110
|
+
: 'nearest',
|
|
82
111
|
});
|
|
112
|
+
// const scrollOpts: ScrollToOptions = {
|
|
113
|
+
// behavior: 'smooth',
|
|
114
|
+
// }
|
|
115
|
+
// if (isHorizontal(slideshow.current)) {
|
|
116
|
+
// if (isCentered(slideshow.current)) {
|
|
117
|
+
// scrollOpts.left = newElement?.offsetLeft + newElement?.clientWidth / 2
|
|
118
|
+
// } else {
|
|
119
|
+
// scrollOpts.left = newElement?.offsetLeft
|
|
120
|
+
// }
|
|
121
|
+
// } else {
|
|
122
|
+
// if (isCentered(slideshow.current)) {
|
|
123
|
+
// scrollOpts.top = newElement?.offsetTop + newElement?.clientHeight / 2
|
|
124
|
+
// } else {
|
|
125
|
+
// scrollOpts.top = newElement?.offsetTop
|
|
126
|
+
// }
|
|
127
|
+
// }
|
|
128
|
+
// slideshow.current?.scrollTo(scrollOpts)
|
|
83
129
|
},
|
|
84
|
-
atStart:
|
|
85
|
-
atEnd:
|
|
130
|
+
atStart: progress <= 0 || progress === -1,
|
|
131
|
+
atEnd: progress >= 1 || progress === -1,
|
|
86
132
|
};
|
|
87
|
-
}
|
|
88
|
-
export default useSlideshow;
|
|
133
|
+
}
|
package/hooks.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import useAsync from './hooks/use-async';
|
|
5
5
|
import useDraggableScroll from './hooks/use-draggable-scroll';
|
|
6
|
+
import useEscape from './hooks/use-escape';
|
|
6
7
|
import useEventListener from './hooks/use-event-listener';
|
|
7
8
|
import useHideOnScroll from './hooks/use-hide-on-scroll';
|
|
8
9
|
import useId from './hooks/use-id';
|
|
@@ -14,5 +15,5 @@ import useModal from './hooks/use-modal';
|
|
|
14
15
|
import useMotionAllowed from './hooks/use-motion-allowed';
|
|
15
16
|
import useParallax from './hooks/use-parallax';
|
|
16
17
|
import useSlideshow from './hooks/use-slideshow';
|
|
17
|
-
export { useAsync, useDraggableScroll, useEventListener, useHideOnScroll, useId, useIsOverflowing, useIsInViewport, useIsMobile, useLockBodyScroll, useModal, useMotionAllowed, useParallax, useSlideshow, };
|
|
18
|
+
export { useAsync, useDraggableScroll, useEscape, useEventListener, useHideOnScroll, useId, useIsOverflowing, useIsInViewport, useIsMobile, useLockBodyScroll, useModal, useMotionAllowed, useParallax, useSlideshow, };
|
|
18
19
|
//# sourceMappingURL=hooks.d.ts.map
|
package/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["src/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,QAAQ,MAAM,mBAAmB,CAAA;AACxC,OAAO,kBAAkB,MAAM,8BAA8B,CAAA;AAC7D,OAAO,gBAAgB,MAAM,4BAA4B,CAAA;AACzD,OAAO,eAAe,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,MAAM,gBAAgB,CAAA;AAClC,OAAO,eAAe,MAAM,4BAA4B,CAAA;AACxD,OAAO,gBAAgB,MAAM,4BAA4B,CAAA;AACzD,OAAO,WAAW,MAAM,uBAAuB,CAAA;AAC/C,OAAO,iBAAiB,MAAM,8BAA8B,CAAA;AAC5D,OAAO,QAAQ,MAAM,mBAAmB,CAAA;AACxC,OAAO,gBAAgB,MAAM,4BAA4B,CAAA;AACzD,OAAO,WAAW,MAAM,sBAAsB,CAAA;AAC9C,OAAO,YAAY,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,KAAK,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,YAAY,GACb,CAAA"}
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["src/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,QAAQ,MAAM,mBAAmB,CAAA;AACxC,OAAO,kBAAkB,MAAM,8BAA8B,CAAA;AAC7D,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAC1C,OAAO,gBAAgB,MAAM,4BAA4B,CAAA;AACzD,OAAO,eAAe,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,MAAM,gBAAgB,CAAA;AAClC,OAAO,eAAe,MAAM,4BAA4B,CAAA;AACxD,OAAO,gBAAgB,MAAM,4BAA4B,CAAA;AACzD,OAAO,WAAW,MAAM,uBAAuB,CAAA;AAC/C,OAAO,iBAAiB,MAAM,8BAA8B,CAAA;AAC5D,OAAO,QAAQ,MAAM,mBAAmB,CAAA;AACxC,OAAO,gBAAgB,MAAM,4BAA4B,CAAA;AACzD,OAAO,WAAW,MAAM,sBAAsB,CAAA;AAC9C,OAAO,YAAY,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,KAAK,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,YAAY,GACb,CAAA"}
|
package/hooks.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import useAsync from './hooks/use-async';
|
|
5
5
|
import useDraggableScroll from './hooks/use-draggable-scroll';
|
|
6
|
+
import useEscape from './hooks/use-escape';
|
|
6
7
|
import useEventListener from './hooks/use-event-listener';
|
|
7
8
|
import useHideOnScroll from './hooks/use-hide-on-scroll';
|
|
8
9
|
import useId from './hooks/use-id';
|
|
@@ -14,4 +15,4 @@ import useModal from './hooks/use-modal';
|
|
|
14
15
|
import useMotionAllowed from './hooks/use-motion-allowed';
|
|
15
16
|
import useParallax from './hooks/use-parallax';
|
|
16
17
|
import useSlideshow from './hooks/use-slideshow';
|
|
17
|
-
export { useAsync, useDraggableScroll, useEventListener, useHideOnScroll, useId, useIsOverflowing, useIsInViewport, useIsMobile, useLockBodyScroll, useModal, useMotionAllowed, useParallax, useSlideshow, };
|
|
18
|
+
export { useAsync, useDraggableScroll, useEscape, useEventListener, useHideOnScroll, useId, useIsOverflowing, useIsInViewport, useIsMobile, useLockBodyScroll, useModal, useMotionAllowed, useParallax, useSlideshow, };
|
package/package.json
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superrb/react-addons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-0",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"module": "index.js",
|
|
6
7
|
"repository": "https://github.com/superrbstudio/react-addons",
|
|
7
8
|
"author": "@molovo",
|
|
8
9
|
"license": "MIT",
|
|
9
|
-
"private": false,
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@hookform/resolvers": "^3.3.1",
|
|
12
|
-
"change-case": "^
|
|
12
|
+
"change-case": "^5.0.0",
|
|
13
13
|
"install-peers-cli": "^2.2.0",
|
|
14
14
|
"js-cookie": "^3.0.5",
|
|
15
15
|
"react-google-recaptcha-v3": "^1.10.1",
|
|
16
16
|
"react-hook-form": "^7.46.1",
|
|
17
|
-
"react-use-draggable-scroll": "^0.4.7"
|
|
17
|
+
"react-use-draggable-scroll": "^0.4.7",
|
|
18
|
+
"simple-zustand-devtools": "^1.1.0"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
20
|
-
"react": "^
|
|
21
|
+
"react": "^19.1.0",
|
|
21
22
|
"typescript": "^5.2.2",
|
|
22
|
-
"yup": "^1.
|
|
23
|
+
"yup": "^1.4.0",
|
|
23
24
|
"zustand": "^4.4.7"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "tsc",
|
|
27
28
|
"prepublishOnly": "yarn build",
|
|
28
|
-
"
|
|
29
|
+
"install-peers": "install-peers",
|
|
29
30
|
"dev": "watch 'yarn build' ./src"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/js-cookie": "^3.0.3",
|
|
33
34
|
"@types/node": "^20.5.7",
|
|
34
|
-
"@types/react": "^
|
|
35
|
+
"@types/react": "^19.1.0",
|
|
35
36
|
"eslint": "^8.50.0",
|
|
36
37
|
"eslint-config-next": "^13.5.3",
|
|
37
38
|
"eslint-config-prettier": "^9.0.0",
|
|
@@ -39,7 +40,13 @@
|
|
|
39
40
|
"eslint-plugin-react": "^7.33.2",
|
|
40
41
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
41
42
|
"prettier": "^3.2.2",
|
|
43
|
+
"react": "^19.1.0",
|
|
44
|
+
"typescript": "^5.2.2",
|
|
42
45
|
"typescript-eslint": "^0.0.1-alpha.0",
|
|
43
|
-
"watch": "^1.0.2"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
"watch": "^1.0.2",
|
|
47
|
+
"yup": "^1.4.0",
|
|
48
|
+
"zustand": "^4.4.7"
|
|
49
|
+
},
|
|
50
|
+
"packageManager": "yarn@4.9.1",
|
|
51
|
+
"stableVersion": "3.0.0"
|
|
52
|
+
}
|
package/store/cookies.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../src/store/cookies.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../src/store/cookies.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,eAAe,EAAE,OAAO,CAAA;IACxB,uBAAuB,EAAE,OAAO,CAAA;IAChC,kBAAkB,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;IAC/C,0BAA0B,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;IACvD,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB;AAED,QAAA,MAAM,cAAc,0EAyBlB,CAAA;AAMF,eAAe,cAAc,CAAA"}
|