@superrb/react-addons 1.2.2 → 1.2.3
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/.eslintrc.json +24 -0
- package/components/button.d.ts +1 -1
- package/components/button.d.ts.map +1 -1
- package/components/button.js +6 -6
- package/components/context-wrapper.d.ts +1 -1
- package/components/context-wrapper.js +1 -1
- package/components/cookie-banner.js +23 -23
- package/components/form/error-message.d.ts +2 -2
- package/components/form/error-message.js +1 -1
- package/components/form/field.d.ts +3 -3
- package/components/form/field.d.ts.map +1 -1
- package/components/form/field.js +4 -4
- package/components/form/submit-button.js +2 -2
- package/components/form/types.d.ts +3 -3
- package/components/form.d.ts +5 -5
- package/components/form.d.ts.map +1 -1
- package/components/form.js +21 -21
- package/components/menu-toggle.d.ts +2 -2
- package/components/menu-toggle.js +10 -10
- package/components/modal.d.ts +1 -1
- package/components/modal.js +6 -6
- package/components.d.ts +8 -8
- package/components.js +8 -8
- package/context/cookies-context-provider.d.ts +1 -1
- package/context/cookies-context-provider.js +7 -7
- package/context/modal-context-provider.d.ts +1 -1
- package/context/modal-context-provider.js +4 -4
- package/context/nav-context-provider.d.ts +1 -1
- package/context/nav-context-provider.js +4 -4
- package/context.d.ts +3 -3
- package/context.js +3 -3
- package/hooks/use-async.d.ts +1 -1
- package/hooks/use-async.js +7 -8
- package/hooks/use-draggable-scroll.d.ts +1 -1
- package/hooks/use-draggable-scroll.js +7 -7
- package/hooks/use-event-listener.js +3 -4
- package/hooks/use-hide-on-scroll.js +6 -6
- package/hooks/use-is-in-viewport.js +2 -2
- package/hooks/use-is-overflowing.d.ts +4 -0
- package/hooks/use-is-overflowing.d.ts.map +1 -0
- package/hooks/use-is-overflowing.js +4 -0
- package/hooks/use-modal.js +2 -2
- package/hooks/use-parallax.js +3 -3
- package/hooks.d.ts +13 -12
- package/hooks.d.ts.map +1 -1
- package/hooks.js +13 -12
- package/index.d.ts +5 -5
- package/index.js +5 -5
- package/package.json +10 -3
- package/storage.js +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/utils/animate.d.ts +1 -1
- package/utils/animate.js +2 -2
- package/utils/animator.js +2 -2
- package/utils/easing-functions.d.ts.map +1 -1
- package/utils/easing-functions.js +14 -14
- package/utils/extend-class.js +1 -1
- package/utils/scroll-to-hash.js +2 -2
- package/utils.d.ts +7 -7
- package/utils.js +7 -7
package/context.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Context
|
|
3
3
|
*/
|
|
4
|
-
import { CookiesContext, CookiesContextProvider, } from
|
|
5
|
-
import { ModalContext, ModalContextProvider, } from
|
|
6
|
-
import { NavContext, NavContextProvider } from
|
|
4
|
+
import { CookiesContext, CookiesContextProvider, } from './context/cookies-context-provider';
|
|
5
|
+
import { ModalContext, ModalContextProvider, } from './context/modal-context-provider';
|
|
6
|
+
import { NavContext, NavContextProvider } from './context/nav-context-provider';
|
|
7
7
|
export { CookiesContext, CookiesContextProvider, ModalContext, ModalContextProvider, NavContext, NavContextProvider, };
|
package/hooks/use-async.d.ts
CHANGED
package/hooks/use-async.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
// Hook
|
|
3
3
|
const useAsync = (asyncFunction, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
4
|
-
immediate = false, dependencies = []
|
|
5
|
-
|
|
6
|
-
const [status, setStatus] = useState("idle");
|
|
4
|
+
immediate = false, dependencies = []) => {
|
|
5
|
+
const [status, setStatus] = useState('idle');
|
|
7
6
|
const [value, setValue] = useState(null);
|
|
8
7
|
const [error, setError] = useState(null);
|
|
9
8
|
useEffect(() => {
|
|
10
|
-
setStatus(
|
|
9
|
+
setStatus('idle');
|
|
11
10
|
setValue(null);
|
|
12
11
|
setError(null);
|
|
13
12
|
}, dependencies);
|
|
@@ -16,17 +15,17 @@ immediate = false, dependencies = [] // eslint-disable-line @typescript-eslint/n
|
|
|
16
15
|
// useCallback ensures the below useEffect is not called
|
|
17
16
|
// on every render, but only if asyncFunction changes.
|
|
18
17
|
const execute = useCallback(async (...args) => {
|
|
19
|
-
setStatus(
|
|
18
|
+
setStatus('pending');
|
|
20
19
|
setValue(null);
|
|
21
20
|
setError(null);
|
|
22
21
|
try {
|
|
23
22
|
const response = await asyncFunction(...args);
|
|
24
23
|
setValue(response);
|
|
25
|
-
setStatus(
|
|
24
|
+
setStatus('success');
|
|
26
25
|
}
|
|
27
26
|
catch (err) {
|
|
28
27
|
setError(err.message);
|
|
29
|
-
setStatus(
|
|
28
|
+
setStatus('error');
|
|
30
29
|
}
|
|
31
30
|
}, [asyncFunction]);
|
|
32
31
|
// Call execute if we want to fire it right away.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useEffect, useRef, useState, } from
|
|
2
|
-
import { useDraggable } from
|
|
3
|
-
import { useEventListener, useIsInViewport } from
|
|
1
|
+
import { useEffect, useRef, useState, } from 'react';
|
|
2
|
+
import { useDraggable } from 'react-use-draggable-scroll';
|
|
3
|
+
import { useEventListener, useIsInViewport } from '../hooks';
|
|
4
4
|
const useDraggableScroll = (ref, { className, ...opts }) => {
|
|
5
5
|
const { isInViewport, setRef } = useIsInViewport(false);
|
|
6
6
|
const { events } = useDraggable(ref, {
|
|
@@ -16,7 +16,7 @@ const useDraggableScroll = (ref, { className, ...opts }) => {
|
|
|
16
16
|
const shouldScroll = ref.current?.scrollWidth > ref.current?.clientWidth ||
|
|
17
17
|
ref.current?.scrollHeight > ref.current?.clientHeight;
|
|
18
18
|
setShouldScroll(shouldScroll);
|
|
19
|
-
const fn = shouldScroll ?
|
|
19
|
+
const fn = shouldScroll ? 'add' : 'remove';
|
|
20
20
|
ref.current?.classList[fn](`${className}--draggable`);
|
|
21
21
|
}, [ref.current]);
|
|
22
22
|
const onDragStart = () => {
|
|
@@ -34,8 +34,8 @@ const useDraggableScroll = (ref, { className, ...opts }) => {
|
|
|
34
34
|
ref.current?.classList.remove(`${className}--dragging`);
|
|
35
35
|
}, 100);
|
|
36
36
|
};
|
|
37
|
-
useEventListener(
|
|
38
|
-
useEventListener(
|
|
37
|
+
useEventListener('mousemove', onDragMove, undefined, undefined, isInViewport && shouldScroll);
|
|
38
|
+
useEventListener('mouseup', onDragEnd, undefined, undefined, isInViewport && shouldScroll);
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
if (!shouldScroll) {
|
|
41
41
|
setModifiedEvents({
|
|
@@ -45,7 +45,7 @@ const useDraggableScroll = (ref, { className, ...opts }) => {
|
|
|
45
45
|
}
|
|
46
46
|
const originalOnMouseDown = events.onMouseDown;
|
|
47
47
|
setModifiedEvents({
|
|
48
|
-
onMouseDown: event => {
|
|
48
|
+
onMouseDown: (event) => {
|
|
49
49
|
onDragStart();
|
|
50
50
|
originalOnMouseDown(event);
|
|
51
51
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
2
|
// Hook
|
|
3
3
|
const useEventListener = (eventName, handler, options = {}, element, flag = true) => {
|
|
4
4
|
// Create a ref that stores handler
|
|
@@ -21,7 +21,7 @@ const useEventListener = (eventName, handler, options = {}, element, flag = true
|
|
|
21
21
|
if (!isSupported)
|
|
22
22
|
return;
|
|
23
23
|
// Create event listener that calls handler function stored in ref
|
|
24
|
-
const eventListener = event => savedHandler.current(event);
|
|
24
|
+
const eventListener = (event) => savedHandler.current(event);
|
|
25
25
|
if (flag) {
|
|
26
26
|
// Add event listener
|
|
27
27
|
elementRef.current.addEventListener(eventName, eventListener, options);
|
|
@@ -40,7 +40,6 @@ const useEventListener = (eventName, handler, options = {}, element, flag = true
|
|
|
40
40
|
element,
|
|
41
41
|
elementRef.current,
|
|
42
42
|
flag,
|
|
43
|
-
]
|
|
44
|
-
);
|
|
43
|
+
]);
|
|
45
44
|
};
|
|
46
45
|
export default useEventListener;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEventListener } from
|
|
2
|
-
import { useCallback, useEffect, useState } from
|
|
1
|
+
import { useEventListener } from '../hooks';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
3
|
const useHideOnScroll = (hiddenOnLoad = false) => {
|
|
4
4
|
const [hidden, setHidden] = useState(hiddenOnLoad);
|
|
5
5
|
const handleScroll = useCallback(() => {
|
|
@@ -26,10 +26,10 @@ const useHideOnScroll = (hiddenOnLoad = false) => {
|
|
|
26
26
|
useEffect(() => {
|
|
27
27
|
handleScroll();
|
|
28
28
|
}, []);
|
|
29
|
-
useEventListener(
|
|
30
|
-
useEventListener(
|
|
31
|
-
useEventListener(
|
|
32
|
-
useEventListener(
|
|
29
|
+
useEventListener('scroll', handleScroll, { passive: true }, typeof window !== 'undefined' ? window : undefined);
|
|
30
|
+
useEventListener('resize', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
|
|
31
|
+
useEventListener('popstate', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
|
|
32
|
+
useEventListener('pageshow', handleLoad, { passive: true }, typeof window !== 'undefined' ? window : undefined);
|
|
33
33
|
return hidden;
|
|
34
34
|
};
|
|
35
35
|
export default useHideOnScroll;
|
|
@@ -5,8 +5,8 @@ const useIsInViewport = (initial = false, rootMargin = '0px 0px', threshold = [0
|
|
|
5
5
|
const observer = useRef();
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
if (!observer.current) {
|
|
8
|
-
observer.current = new IntersectionObserver(entries => {
|
|
9
|
-
entries.forEach(entry => {
|
|
8
|
+
observer.current = new IntersectionObserver((entries) => {
|
|
9
|
+
entries.forEach((entry) => {
|
|
10
10
|
setIsInViewport(entry.isIntersecting && entry.intersectionRatio > 0);
|
|
11
11
|
});
|
|
12
12
|
}, {
|
|
@@ -0,0 +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,QAAA,MAAM,gBAAgB,gBAAiB,iBAAiB,WAAW,CAAC,YAGpB,CAAA;AAEhD,eAAe,gBAAgB,CAAA"}
|
package/hooks/use-modal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useContext, useEffect, useState } from
|
|
2
|
-
import { ModalContext } from
|
|
1
|
+
import { useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { ModalContext } from '../context';
|
|
3
3
|
const useModal = (name) => {
|
|
4
4
|
const [open, setOpen] = useState(false);
|
|
5
5
|
const { openState, openModal, closeModal } = useContext(ModalContext);
|
package/hooks/use-parallax.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEventListener, useMotionAllowed } from
|
|
2
|
-
import { useCallback } from
|
|
1
|
+
import { useEventListener, useMotionAllowed } from '../hooks';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
3
|
const useParallax = (items, flag = true) => {
|
|
4
4
|
const isMotionAllowed = useMotionAllowed();
|
|
5
5
|
const onScroll = useCallback((event) => {
|
|
@@ -13,6 +13,6 @@ const useParallax = (items, flag = true) => {
|
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
}, [items]);
|
|
16
|
-
useEventListener(
|
|
16
|
+
useEventListener('scroll', onScroll, { passive: true }, undefined, flag && isMotionAllowed);
|
|
17
17
|
};
|
|
18
18
|
export default useParallax;
|
package/hooks.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hooks
|
|
3
3
|
*/
|
|
4
|
-
import useAsync from
|
|
5
|
-
import useDraggableScroll from
|
|
6
|
-
import useEventListener from
|
|
7
|
-
import useHideOnScroll from
|
|
8
|
-
import useId from
|
|
9
|
-
import useIsInViewport from
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
4
|
+
import useAsync from './hooks/use-async';
|
|
5
|
+
import useDraggableScroll from './hooks/use-draggable-scroll';
|
|
6
|
+
import useEventListener from './hooks/use-event-listener';
|
|
7
|
+
import useHideOnScroll from './hooks/use-hide-on-scroll';
|
|
8
|
+
import useId from './hooks/use-id';
|
|
9
|
+
import useIsInViewport from './hooks/use-is-in-viewport';
|
|
10
|
+
import useIsOverflowing from './hooks/use-is-overflowing';
|
|
11
|
+
import useIsMobile from './hooks/use-is-mobile';
|
|
12
|
+
import useLockBodyScroll from './hooks/use-lock-body-scroll';
|
|
13
|
+
import useModal from './hooks/use-modal';
|
|
14
|
+
import useMotionAllowed from './hooks/use-motion-allowed';
|
|
15
|
+
import useParallax from './hooks/use-parallax';
|
|
16
|
+
export { useAsync, useDraggableScroll, useEventListener, useHideOnScroll, useId, useIsOverflowing, useIsInViewport, useIsMobile, useLockBodyScroll, useModal, useMotionAllowed, useParallax, };
|
|
16
17
|
//# 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,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;AAE9C,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,KAAK,EACL,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAChB,WAAW,GACZ,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,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;AAE9C,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,GACZ,CAAA"}
|
package/hooks.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hooks
|
|
3
3
|
*/
|
|
4
|
-
import useAsync from
|
|
5
|
-
import useDraggableScroll from
|
|
6
|
-
import useEventListener from
|
|
7
|
-
import useHideOnScroll from
|
|
8
|
-
import useId from
|
|
9
|
-
import useIsInViewport from
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
4
|
+
import useAsync from './hooks/use-async';
|
|
5
|
+
import useDraggableScroll from './hooks/use-draggable-scroll';
|
|
6
|
+
import useEventListener from './hooks/use-event-listener';
|
|
7
|
+
import useHideOnScroll from './hooks/use-hide-on-scroll';
|
|
8
|
+
import useId from './hooks/use-id';
|
|
9
|
+
import useIsInViewport from './hooks/use-is-in-viewport';
|
|
10
|
+
import useIsOverflowing from './hooks/use-is-overflowing';
|
|
11
|
+
import useIsMobile from './hooks/use-is-mobile';
|
|
12
|
+
import useLockBodyScroll from './hooks/use-lock-body-scroll';
|
|
13
|
+
import useModal from './hooks/use-modal';
|
|
14
|
+
import useMotionAllowed from './hooks/use-motion-allowed';
|
|
15
|
+
import useParallax from './hooks/use-parallax';
|
|
16
|
+
export { useAsync, useDraggableScroll, useEventListener, useHideOnScroll, useId, useIsOverflowing, useIsInViewport, useIsMobile, useLockBodyScroll, useModal, useMotionAllowed, useParallax, };
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as Components from
|
|
2
|
-
import * as Context from
|
|
3
|
-
import * as Hooks from
|
|
4
|
-
import * as Storage from
|
|
5
|
-
import * as Utils from
|
|
1
|
+
import * as Components from './components';
|
|
2
|
+
import * as Context from './context';
|
|
3
|
+
import * as Hooks from './hooks';
|
|
4
|
+
import * as Storage from './storage';
|
|
5
|
+
import * as Utils from './utils';
|
|
6
6
|
export { Components, Context, Hooks, Storage, Utils };
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as Components from
|
|
2
|
-
import * as Context from
|
|
3
|
-
import * as Hooks from
|
|
4
|
-
import * as Storage from
|
|
1
|
+
import * as Components from './components';
|
|
2
|
+
import * as Context from './context';
|
|
3
|
+
import * as Hooks from './hooks';
|
|
4
|
+
import * as Storage from './storage';
|
|
5
5
|
// import * as Types from './types'
|
|
6
|
-
import * as Utils from
|
|
6
|
+
import * as Utils from './utils';
|
|
7
7
|
export { Components, Context, Hooks, Storage, Utils };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superrb/react-addons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "https://github.com/superrbstudio/react-addons",
|
|
7
7
|
"author": "@molovo",
|
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@superrb/react-addons": "^1.0.0",
|
|
21
|
-
"@types/node": "^20.5.7",
|
|
22
|
-
"@types/react": "^18.2.21",
|
|
23
21
|
"react": "^18.2.0",
|
|
24
22
|
"typescript": "^5.2.2"
|
|
25
23
|
},
|
|
@@ -31,6 +29,15 @@
|
|
|
31
29
|
},
|
|
32
30
|
"devDependencies": {
|
|
33
31
|
"@types/js-cookie": "^3.0.3",
|
|
32
|
+
"@types/node": "^20.5.7",
|
|
33
|
+
"@types/react": "^18.2.21",
|
|
34
|
+
"eslint": "^8.50.0",
|
|
35
|
+
"eslint-config-next": "^13.5.3",
|
|
36
|
+
"eslint-config-prettier": "^9.0.0",
|
|
37
|
+
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
38
|
+
"eslint-plugin-react": "^7.33.2",
|
|
39
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
40
|
+
"typescript-eslint": "^0.0.1-alpha.0",
|
|
34
41
|
"watch": "^1.0.2"
|
|
35
42
|
}
|
|
36
43
|
}
|
package/storage.js
CHANGED