@superrb/react-addons 1.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/back-to-top.d.ts +3 -0
- package/components/back-to-top.d.ts.map +1 -0
- package/components/back-to-top.js +5 -0
- package/components/button.d.ts +14 -0
- package/components/button.d.ts.map +1 -0
- package/components/button.js +31 -0
- package/components/context-wrapper.d.ts +4 -0
- package/components/context-wrapper.d.ts.map +1 -0
- package/components/context-wrapper.js +4 -0
- package/components/image.d.ts +11 -0
- package/components/image.d.ts.map +1 -0
- package/components/image.js +7 -0
- package/components/link.d.ts +49 -0
- package/components/link.d.ts.map +1 -0
- package/components/link.js +11 -0
- package/components/menu-toggle.d.ts +11 -0
- package/components/menu-toggle.d.ts.map +1 -0
- package/components/menu-toggle.js +28 -0
- package/components/modal.d.ts +10 -0
- package/components/modal.d.ts.map +1 -0
- package/components/modal.js +33 -0
- package/components/skip-to.d.ts +3 -0
- package/components/skip-to.d.ts.map +1 -0
- package/components/skip-to.js +5 -0
- package/components.d.ts +11 -0
- package/components.d.ts.map +1 -0
- package/components.js +10 -0
- package/context/modal-context-provider.d.ts +13 -0
- package/context/modal-context-provider.d.ts.map +1 -0
- package/context/modal-context-provider.js +31 -0
- package/context/nav-context-provider.d.ts +10 -0
- package/context/nav-context-provider.d.ts.map +1 -0
- package/context/nav-context-provider.js +26 -0
- package/context.d.ts +7 -0
- package/context.d.ts.map +1 -0
- package/context.js +6 -0
- package/hooks/use-async.d.ts +10 -0
- package/hooks/use-async.d.ts.map +1 -0
- package/hooks/use-async.js +42 -0
- package/hooks/use-draggable-scroll.d.ts +11 -0
- package/hooks/use-draggable-scroll.d.ts.map +1 -0
- package/hooks/use-draggable-scroll.js +56 -0
- package/hooks/use-event-listener.d.ts +7 -0
- package/hooks/use-event-listener.d.ts.map +1 -0
- package/hooks/use-event-listener.js +46 -0
- package/hooks/use-hide-on-scroll.d.ts +3 -0
- package/hooks/use-hide-on-scroll.d.ts.map +1 -0
- package/hooks/use-hide-on-scroll.js +35 -0
- package/hooks/use-id.d.ts +3 -0
- package/hooks/use-id.d.ts.map +1 -0
- package/hooks/use-id.js +9 -0
- package/hooks/use-is-in-viewport.d.ts +6 -0
- package/hooks/use-is-in-viewport.d.ts.map +1 -0
- package/hooks/use-is-in-viewport.js +64 -0
- package/hooks/use-is-mobile.d.ts +3 -0
- package/hooks/use-is-mobile.d.ts.map +1 -0
- package/hooks/use-is-mobile.js +16 -0
- package/hooks/use-lock-body-scroll.d.ts +3 -0
- package/hooks/use-lock-body-scroll.d.ts.map +1 -0
- package/hooks/use-lock-body-scroll.js +10 -0
- package/hooks/use-modal.d.ts +7 -0
- package/hooks/use-modal.d.ts.map +1 -0
- package/hooks/use-modal.js +15 -0
- package/hooks/use-motion-allowed.d.ts +3 -0
- package/hooks/use-motion-allowed.d.ts.map +1 -0
- package/hooks/use-motion-allowed.js +9 -0
- package/hooks/use-parallax.d.ts +3 -0
- package/hooks/use-parallax.d.ts.map +1 -0
- package/hooks/use-parallax.js +18 -0
- package/hooks.d.ts +16 -0
- package/hooks.d.ts.map +1 -0
- package/hooks.js +15 -0
- package/index.d.ts +7 -0
- package/index.d.ts.map +1 -0
- package/index.js +7 -0
- package/package.json +33 -0
- package/storage.d.ts +3 -0
- package/storage.d.ts.map +1 -0
- package/storage.js +3 -0
- package/tsconfig.json +43 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/utils/animate.d.ts +4 -0
- package/utils/animate.d.ts.map +1 -0
- package/utils/animate.js +27 -0
- package/utils/animator.d.ts +3 -0
- package/utils/animator.d.ts.map +1 -0
- package/utils/animator.js +24 -0
- package/utils/easing-functions.d.ts +20 -0
- package/utils/easing-functions.d.ts.map +1 -0
- package/utils/easing-functions.js +28 -0
- package/utils/extend-class.d.ts +3 -0
- package/utils/extend-class.d.ts.map +1 -0
- package/utils/extend-class.js +7 -0
- package/utils/get-y-pos.d.ts +3 -0
- package/utils/get-y-pos.d.ts.map +1 -0
- package/utils/get-y-pos.js +9 -0
- package/utils/get.d.ts +7 -0
- package/utils/get.d.ts.map +1 -0
- package/utils/get.js +8 -0
- package/utils/is-external-link.d.ts +3 -0
- package/utils/is-external-link.d.ts.map +1 -0
- package/utils/is-external-link.js +22 -0
- package/utils/scroll-to-hash.d.ts +3 -0
- package/utils/scroll-to-hash.d.ts.map +1 -0
- package/utils/scroll-to-hash.js +10 -0
- package/utils/storage-factory.d.ts +2 -0
- package/utils/storage-factory.d.ts.map +1 -0
- package/utils/storage-factory.js +73 -0
- package/utils.d.ts +9 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"back-to-top.d.ts","sourceRoot":"","sources":["../src/components/back-to-top.tsx"],"names":[],"mappings":"AAAA,QAAA,MAAM,SAAS,+CAMd,CAAA;AAED,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnchorHTMLAttributes, ButtonHTMLAttributes, HTMLAttributes, MouseEventHandler, PropsWithChildren } from "react";
|
|
2
|
+
import { PrismicNextLinkProps } from "@prismicio/next";
|
|
3
|
+
type Props = (PropsWithChildren<HTMLAttributes<HTMLButtonElement | HTMLAnchorElement>> | ButtonHTMLAttributes<HTMLButtonElement> | AnchorHTMLAttributes<HTMLAnchorElement>) & {
|
|
4
|
+
label?: string;
|
|
5
|
+
label_a11y?: string;
|
|
6
|
+
onClick?: MouseEventHandler;
|
|
7
|
+
className?: string;
|
|
8
|
+
href?: string;
|
|
9
|
+
field?: PrismicNextLinkProps["field"];
|
|
10
|
+
};
|
|
11
|
+
declare const _default: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<HTMLButtonElement | HTMLAnchorElement>>>;
|
|
12
|
+
export default _default;
|
|
13
|
+
export type { Props as ButtonProps };
|
|
14
|
+
//# sourceMappingURL=button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../src/components/button.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EAEpB,cAAc,EACd,iBAAiB,EAEjB,iBAAiB,EAGlB,MAAM,OAAO,CAAA;AAGd,OAAO,EAAmB,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEvE,KAAK,KAAK,GAAG,CACT,iBAAiB,CAAC,cAAc,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,CAAC,GACxE,oBAAoB,CAAC,iBAAiB,CAAC,GACvC,oBAAoB,CAAC,iBAAiB,CAAC,CAC1C,GAAG;IACF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAA;CACtC,CAAA;;AAkFD,wBAA2B;AAC3B,YAAY,EAAE,KAAK,IAAI,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, memo, } from "react";
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import { extendClass } from "../utils";
|
|
5
|
+
import { PrismicNextLink } from "@prismicio/next";
|
|
6
|
+
const Button = forwardRef(({ children, label, label_a11y, onClick, className = "", href, field, ...props }, ref) => {
|
|
7
|
+
className = `button ${className}`;
|
|
8
|
+
const renderedChildren = (_jsxs(_Fragment, { children: [label_a11y && _jsx("span", { className: "screenreader-text", children: label_a11y }), label && (_jsx("span", { className: `${extendClass("button", "label")} ${extendClass(className, "label")}`, "aria-hidden": label_a11y !== undefined, "data-text": label, children: label })), children] }));
|
|
9
|
+
const linkProps = {
|
|
10
|
+
...props,
|
|
11
|
+
onClick,
|
|
12
|
+
className,
|
|
13
|
+
"aria-label": label_a11y || label,
|
|
14
|
+
ref,
|
|
15
|
+
};
|
|
16
|
+
if (href) {
|
|
17
|
+
return (_jsx(Link, { ...linkProps, href, children: renderedChildren }));
|
|
18
|
+
}
|
|
19
|
+
if (field) {
|
|
20
|
+
return (_jsx(PrismicNextLink, { ...linkProps, field, children: renderedChildren }));
|
|
21
|
+
}
|
|
22
|
+
const buttonProps = {
|
|
23
|
+
...props,
|
|
24
|
+
onClick,
|
|
25
|
+
className,
|
|
26
|
+
"aria-label": label_a11y || label,
|
|
27
|
+
ref,
|
|
28
|
+
};
|
|
29
|
+
return _jsx("button", { ...buttonProps, children: renderedChildren });
|
|
30
|
+
});
|
|
31
|
+
export default memo(Button);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-wrapper.d.ts","sourceRoot":"","sources":["../src/components/context-wrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAGzC,QAAA,MAAM,cAAc,iBAAkB,kBAAkB,EAAE,CAAC,4CAI1D,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ModalContextProvider, NavContextProvider } from "../context";
|
|
3
|
+
const ContextWrapper = ({ children }) => (_jsx(ModalContextProvider, { children: _jsx(NavContextProvider, { children: children }) }));
|
|
4
|
+
export default ContextWrapper;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ImageFieldImage } from "@prismicio/client";
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
declare const Image: ({ image, sizes, className, style, imgStyle, }: {
|
|
4
|
+
image: ImageFieldImage;
|
|
5
|
+
sizes?: string | undefined;
|
|
6
|
+
className?: string | undefined;
|
|
7
|
+
style?: Partial<CSSProperties> | undefined;
|
|
8
|
+
imgStyle?: Partial<CSSProperties> | undefined;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default Image;
|
|
11
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../src/components/image.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,QAAA,MAAM,KAAK;WAOF,eAAe;;;;;6CAmBvB,CAAA;AAED,eAAe,KAAK,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PrismicNextImage } from "@prismicio/next";
|
|
3
|
+
import { extendClass } from "../utils";
|
|
4
|
+
const Image = ({ image, sizes = "100vw", className = "", style = {}, imgStyle = {}, }) => {
|
|
5
|
+
return (_jsx("figure", { className: `image ${className}`, style: style, children: _jsx(PrismicNextImage, { className: `${extendClass(className, "image")} ${extendClass("image", "image")}`, field: image, sizes: sizes, style: imgStyle }) }));
|
|
6
|
+
};
|
|
7
|
+
export default Image;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
import { PrismicNextLinkProps } from "@prismicio/next";
|
|
3
|
+
interface Props {
|
|
4
|
+
to: PrismicNextLinkProps["field"] | PrismicNextLinkProps["href"] | PrismicNextLinkProps["document"];
|
|
5
|
+
}
|
|
6
|
+
declare const Link: import("react").ForwardRefExoticComponent<((Props & HTMLAttributes<HTMLAnchorElement> & {
|
|
7
|
+
children?: import("react").ReactNode;
|
|
8
|
+
}) | Omit<Props & Omit<any, "field" | "document" | "href" | "rel"> & {
|
|
9
|
+
linkResolver?: import("@prismicio/client").LinkResolverFunction | undefined;
|
|
10
|
+
rel?: string | ((args: {
|
|
11
|
+
href: string | undefined;
|
|
12
|
+
isExternal: boolean;
|
|
13
|
+
target?: string | undefined;
|
|
14
|
+
}) => string | void | undefined) | undefined;
|
|
15
|
+
} & {
|
|
16
|
+
field: import("@prismicio/client").LinkField | null | undefined;
|
|
17
|
+
document?: undefined;
|
|
18
|
+
href?: undefined;
|
|
19
|
+
} & {
|
|
20
|
+
children?: import("react").ReactNode;
|
|
21
|
+
}, "ref"> | Omit<Props & Omit<any, "field" | "document" | "href" | "rel"> & {
|
|
22
|
+
linkResolver?: import("@prismicio/client").LinkResolverFunction | undefined;
|
|
23
|
+
rel?: string | ((args: {
|
|
24
|
+
href: string | undefined;
|
|
25
|
+
isExternal: boolean;
|
|
26
|
+
target?: string | undefined;
|
|
27
|
+
}) => string | void | undefined) | undefined;
|
|
28
|
+
} & {
|
|
29
|
+
field?: undefined;
|
|
30
|
+
document: import("@prismicio/client").PrismicDocument<Record<string, any>, string, string> | null | undefined;
|
|
31
|
+
href?: undefined;
|
|
32
|
+
} & {
|
|
33
|
+
children?: import("react").ReactNode;
|
|
34
|
+
}, "ref"> | Omit<Props & Omit<any, "field" | "document" | "href" | "rel"> & {
|
|
35
|
+
linkResolver?: import("@prismicio/client").LinkResolverFunction | undefined;
|
|
36
|
+
rel?: string | ((args: {
|
|
37
|
+
href: string | undefined;
|
|
38
|
+
isExternal: boolean;
|
|
39
|
+
target?: string | undefined;
|
|
40
|
+
}) => string | void | undefined) | undefined;
|
|
41
|
+
} & {
|
|
42
|
+
field?: undefined;
|
|
43
|
+
document?: undefined;
|
|
44
|
+
href: any;
|
|
45
|
+
} & {
|
|
46
|
+
children?: import("react").ReactNode;
|
|
47
|
+
}, "ref">) & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
48
|
+
export default Link;
|
|
49
|
+
//# sourceMappingURL=link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/components/link.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAGf,MAAM,OAAO,CAAA;AACd,OAAO,EAAmB,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAGvE,UAAU,KAAK;IACb,EAAE,EACE,oBAAoB,CAAC,OAAO,CAAC,GAC7B,oBAAoB,CAAC,MAAM,CAAC,GAC5B,oBAAoB,CAAC,UAAU,CAAC,CAAA;CACrC;AAED,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8DAiCT,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, } from "react";
|
|
3
|
+
import { PrismicNextLink } from "@prismicio/next";
|
|
4
|
+
import isExternalLink from "../utils/is-external-link";
|
|
5
|
+
const Link = forwardRef(({ to, children, ...props }, ref) => {
|
|
6
|
+
if (typeof to === "string" && isExternalLink(to)) {
|
|
7
|
+
return (_jsx("a", { href: to, ...props, ref: ref, children: children }));
|
|
8
|
+
}
|
|
9
|
+
return (_jsx(PrismicNextLink, { ...("url" in to ? { field: to } : { document: to }), ...props, ref: ref, children: children }));
|
|
10
|
+
});
|
|
11
|
+
export default Link;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ButtonHTMLAttributes, PropsWithChildren, ReactElement } from "react";
|
|
2
|
+
interface Props extends PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>> {
|
|
3
|
+
"aria-controls": string;
|
|
4
|
+
className?: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
closeLabel?: string;
|
|
7
|
+
renderIcon?: (navOpen: boolean) => ReactElement;
|
|
8
|
+
}
|
|
9
|
+
declare const MenuToggle: ({ "aria-controls": ariaControls, className, label, closeLabel, renderIcon, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default MenuToggle;
|
|
11
|
+
//# sourceMappingURL=menu-toggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-toggle.d.ts","sourceRoot":"","sources":["../src/components/menu-toggle.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EAKb,MAAM,OAAO,CAAA;AAKd,UAAU,KACR,SAAQ,iBAAiB,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;IAClE,eAAe,EAAE,MAAM,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,CAAA;CAChD;AAED,QAAA,MAAM,UAAU,0FAOb,KAAK,4CAwCP,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useContext, useEffect, useState, } from "react";
|
|
4
|
+
import { NavContext } from "../context";
|
|
5
|
+
import { Button } from "../components";
|
|
6
|
+
import { extendClass } from "../utils";
|
|
7
|
+
const MenuToggle = ({ "aria-controls": ariaControls, className = "", label = "Open Nav", closeLabel = "Close Nav", renderIcon = undefined, ...props }) => {
|
|
8
|
+
const { navOpen, toggleNav } = useContext(NavContext);
|
|
9
|
+
const [icon, setIcon] = useState(navOpen ? "×" : "꠵");
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (renderIcon) {
|
|
12
|
+
setIcon(renderIcon(navOpen));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
setIcon(navOpen ? "×" : "꠵");
|
|
16
|
+
}, [navOpen]);
|
|
17
|
+
const handleClick = useCallback(() => {
|
|
18
|
+
if (document &&
|
|
19
|
+
document?.activeElement instanceof Element &&
|
|
20
|
+
"blur" in document?.activeElement) {
|
|
21
|
+
;
|
|
22
|
+
document.activeElement?.blur();
|
|
23
|
+
}
|
|
24
|
+
toggleNav();
|
|
25
|
+
}, [toggleNav]);
|
|
26
|
+
return (_jsx(Button, { className: `menu-toggle ${className}`, onClick: handleClick, "aria-expanded": navOpen, "aria-controls": ariaControls, label_a11y: navOpen ? closeLabel : label, ...props, children: _jsx("span", { className: `menu-toggle__icon ${extendClass(className, "icon")}`, children: icon }) }));
|
|
27
|
+
};
|
|
28
|
+
export default MenuToggle;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
name: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
openAfter?: number;
|
|
6
|
+
dismissable?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const Modal: ({ name, className, openAfter, dismissable, children, }: PropsWithChildren<Props>) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default Modal;
|
|
10
|
+
//# sourceMappingURL=modal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/components/modal.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAA;AAId,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,QAAA,MAAM,KAAK,2DAMR,kBAAkB,KAAK,CAAC,4CAyC1B,CAAA;AAED,eAAe,KAAK,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useEffect, useRef, useCallback, } from "react";
|
|
4
|
+
import { local } from "../storage";
|
|
5
|
+
import { useLockBodyScroll, useModal } from "../hooks";
|
|
6
|
+
const Modal = ({ name, className, openAfter, dismissable = false, children, }) => {
|
|
7
|
+
const [dismissed, setDismissed] = useState(false);
|
|
8
|
+
const openTimer = useRef();
|
|
9
|
+
const { isOpen, openModal, closeModal } = useModal(name);
|
|
10
|
+
useLockBodyScroll(isOpen);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (dismissable) {
|
|
13
|
+
setDismissed(local.getItem(`${name}-popup-dismissed`) === "true");
|
|
14
|
+
}
|
|
15
|
+
}, []);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
clearTimeout(openTimer.current);
|
|
18
|
+
if (!dismissed && openAfter) {
|
|
19
|
+
openTimer.current = setTimeout(() => {
|
|
20
|
+
openModal();
|
|
21
|
+
}, openAfter);
|
|
22
|
+
}
|
|
23
|
+
}, [dismissed, openAfter, openModal]);
|
|
24
|
+
const close = useCallback(() => {
|
|
25
|
+
closeModal();
|
|
26
|
+
if (dismissable) {
|
|
27
|
+
local.setItem(`${name}-popup-dismissed`, "true");
|
|
28
|
+
setDismissed(true);
|
|
29
|
+
}
|
|
30
|
+
}, [name, closeModal]);
|
|
31
|
+
return (_jsxs("aside", { id: name, className: `modal ${className}`, "aria-hidden": !isOpen, children: [_jsxs("button", { className: `modal__close`, onClick: close, children: [_jsx("span", { className: "screenreader-text", children: "Close Modal" }), "\u00D7"] }), _jsx("div", { className: `modal__inner`, children: children })] }));
|
|
32
|
+
};
|
|
33
|
+
export default Modal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-to.d.ts","sourceRoot":"","sources":["../src/components/skip-to.tsx"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM,+CAOX,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
const SkipTo = () => {
|
|
3
|
+
return (_jsxs("div", { className: "skip-to", id: "skip-to", children: [_jsx("a", { href: "#content", children: "Skip to Content" }), _jsx("a", { href: "#nav", children: "Skip to Navigation" })] }));
|
|
4
|
+
};
|
|
5
|
+
export default SkipTo;
|
package/components.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Components
|
|
3
|
+
*/
|
|
4
|
+
import BackToTop from "./components/back-to-top";
|
|
5
|
+
import Button from "./components/button";
|
|
6
|
+
import ContextWrapper from "./components/context-wrapper";
|
|
7
|
+
import MenuToggle from "./components/menu-toggle";
|
|
8
|
+
import Modal from "./components/modal";
|
|
9
|
+
import SkipTo from "./components/skip-to";
|
|
10
|
+
export { BackToTop, Button, ContextWrapper, MenuToggle, Modal, SkipTo };
|
|
11
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["src/components.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,SAAS,MAAM,0BAA0B,CAAA;AAChD,OAAO,MAAM,MAAM,qBAAqB,CAAA;AACxC,OAAO,cAAc,MAAM,8BAA8B,CAAA;AACzD,OAAO,UAAU,MAAM,0BAA0B,CAAA;AACjD,OAAO,KAAK,MAAM,oBAAoB,CAAA;AACtC,OAAO,MAAM,MAAM,sBAAsB,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
|
package/components.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Components
|
|
3
|
+
*/
|
|
4
|
+
import BackToTop from "./components/back-to-top";
|
|
5
|
+
import Button from "./components/button";
|
|
6
|
+
import ContextWrapper from "./components/context-wrapper";
|
|
7
|
+
import MenuToggle from "./components/menu-toggle";
|
|
8
|
+
import Modal from "./components/modal";
|
|
9
|
+
import SkipTo from "./components/skip-to";
|
|
10
|
+
export { BackToTop, Button, ContextWrapper, MenuToggle, Modal, SkipTo };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
export declare const ModalContext: import("react").Context<{
|
|
3
|
+
openState: OpenState;
|
|
4
|
+
isOpen: (name: string) => boolean;
|
|
5
|
+
openModal: (name: string) => void;
|
|
6
|
+
closeModal: (name: string) => void;
|
|
7
|
+
}>;
|
|
8
|
+
interface OpenState {
|
|
9
|
+
[key: string]: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const ModalContextProvider: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default ModalContextProvider;
|
|
13
|
+
//# sourceMappingURL=modal-context-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-context-provider.d.ts","sourceRoot":"","sources":["../src/context/modal-context-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,iBAAiB,EAAY,MAAM,OAAO,CAAA;AAElE,eAAO,MAAM,YAAY;;mBAER,MAAM;sBACH,MAAM;uBACL,MAAM;EACzB,CAAA;AAEF,UAAU,SAAS;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,eAAO,MAAM,oBAAoB,iBAAkB,iBAAiB,4CA8BnE,CAAA;AAED,eAAe,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useState } from "react";
|
|
4
|
+
export const ModalContext = createContext({
|
|
5
|
+
openState: {},
|
|
6
|
+
isOpen: (name) => false,
|
|
7
|
+
openModal: (name) => { },
|
|
8
|
+
closeModal: (name) => { },
|
|
9
|
+
});
|
|
10
|
+
export const ModalContextProvider = ({ children }) => {
|
|
11
|
+
const [openState, setOpenState] = useState({});
|
|
12
|
+
const isOpen = (name) => {
|
|
13
|
+
return openState[name] || false;
|
|
14
|
+
};
|
|
15
|
+
const openModal = (name) => {
|
|
16
|
+
setOpenState(state => {
|
|
17
|
+
const newState = { ...state };
|
|
18
|
+
newState[name] = true;
|
|
19
|
+
return newState;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const closeModal = (name) => {
|
|
23
|
+
setOpenState(state => {
|
|
24
|
+
const newState = { ...state };
|
|
25
|
+
newState[name] = false;
|
|
26
|
+
return newState;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
return (_jsx(ModalContext.Provider, { value: { openState, isOpen, openModal, closeModal }, children: children }));
|
|
30
|
+
};
|
|
31
|
+
export default ModalContextProvider;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
export declare const NavContext: import("react").Context<{
|
|
3
|
+
navOpen: boolean;
|
|
4
|
+
toggleNav: () => void;
|
|
5
|
+
openNav: () => void;
|
|
6
|
+
closeNav: () => void;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const NavContextProvider: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default NavContextProvider;
|
|
10
|
+
//# sourceMappingURL=nav-context-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nav-context-provider.d.ts","sourceRoot":"","sources":["../src/context/nav-context-provider.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAiB,iBAAiB,EAAyB,MAAM,OAAO,CAAA;AAE/E,eAAO,MAAM,UAAU;;;;;EAKrB,CAAA;AAEF,eAAO,MAAM,kBAAkB,iBAAkB,iBAAiB,4CAsBjE,CAAA;AAED,eAAe,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useLockBodyScroll } from "../hooks";
|
|
4
|
+
import { createContext, useCallback, useState } from "react";
|
|
5
|
+
export const NavContext = createContext({
|
|
6
|
+
navOpen: false,
|
|
7
|
+
toggleNav: () => { },
|
|
8
|
+
openNav: () => { },
|
|
9
|
+
closeNav: () => { },
|
|
10
|
+
});
|
|
11
|
+
export const NavContextProvider = ({ children }) => {
|
|
12
|
+
const [navOpen, setNavOpen] = useState(false);
|
|
13
|
+
useLockBodyScroll(navOpen);
|
|
14
|
+
const toggleNav = useCallback(() => {
|
|
15
|
+
setNavOpen(navOpen => !navOpen);
|
|
16
|
+
}, [setNavOpen]);
|
|
17
|
+
const openNav = useCallback(() => {
|
|
18
|
+
setNavOpen(true);
|
|
19
|
+
}, [setNavOpen]);
|
|
20
|
+
const closeNav = useCallback(() => {
|
|
21
|
+
setNavOpen(false);
|
|
22
|
+
document.activeElement?.blur();
|
|
23
|
+
}, [setNavOpen]);
|
|
24
|
+
return (_jsx(NavContext.Provider, { value: { navOpen, toggleNav, openNav, closeNav }, children: children }));
|
|
25
|
+
};
|
|
26
|
+
export default NavContextProvider;
|
package/context.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context
|
|
3
|
+
*/
|
|
4
|
+
import { ModalContext, ModalContextProvider } from "./context/modal-context-provider";
|
|
5
|
+
import { NavContext, NavContextProvider } from "./context/nav-context-provider";
|
|
6
|
+
export { ModalContext, ModalContextProvider, NavContext, NavContextProvider };
|
|
7
|
+
//# sourceMappingURL=context.d.ts.map
|
package/context.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,YAAY,EACZ,oBAAoB,EACrB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAE/E,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAA"}
|
package/context.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context
|
|
3
|
+
*/
|
|
4
|
+
import { ModalContext, ModalContextProvider, } from "./context/modal-context-provider";
|
|
5
|
+
import { NavContext, NavContextProvider } from "./context/nav-context-provider";
|
|
6
|
+
export { ModalContext, ModalContextProvider, NavContext, NavContextProvider };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type Status = "idle" | "pending" | "success" | "error";
|
|
2
|
+
interface ReturnType<T, E = string> {
|
|
3
|
+
execute: (...args: any) => Promise<void>;
|
|
4
|
+
status: Status;
|
|
5
|
+
value: T | null;
|
|
6
|
+
error: E | null;
|
|
7
|
+
}
|
|
8
|
+
declare const useAsync: <T, E = string>(asyncFunction: (...args: any[]) => Promise<T>, immediate?: boolean, dependencies?: any[]) => ReturnType<T, E>;
|
|
9
|
+
export default useAsync;
|
|
10
|
+
//# sourceMappingURL=use-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-async.d.ts","sourceRoot":"","sources":["../src/hooks/use-async.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;AAE7D,UAAU,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM;IAChC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;CAChB;AAGD,QAAA,MAAM,QAAQ,2CACa,GAAG,EAAE,qDAEhB,GAAG,EAAE,qBA4CpB,CAAA;AAED,eAAe,QAAQ,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
// Hook
|
|
3
|
+
const useAsync = (asyncFunction, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
4
|
+
immediate = false, dependencies = [] // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
5
|
+
) => {
|
|
6
|
+
const [status, setStatus] = useState("idle");
|
|
7
|
+
const [value, setValue] = useState(null);
|
|
8
|
+
const [error, setError] = useState(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setStatus("idle");
|
|
11
|
+
setValue(null);
|
|
12
|
+
setError(null);
|
|
13
|
+
}, dependencies);
|
|
14
|
+
// The execute function wraps asyncFunction and
|
|
15
|
+
// handles setting state for pending, value, and error.
|
|
16
|
+
// useCallback ensures the below useEffect is not called
|
|
17
|
+
// on every render, but only if asyncFunction changes.
|
|
18
|
+
const execute = useCallback(async (...args) => {
|
|
19
|
+
setStatus("pending");
|
|
20
|
+
setValue(null);
|
|
21
|
+
setError(null);
|
|
22
|
+
try {
|
|
23
|
+
const response = await asyncFunction(...args);
|
|
24
|
+
setValue(response);
|
|
25
|
+
setStatus("success");
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
setError(err.message);
|
|
29
|
+
setStatus("error");
|
|
30
|
+
}
|
|
31
|
+
}, [asyncFunction]);
|
|
32
|
+
// Call execute if we want to fire it right away.
|
|
33
|
+
// Otherwise execute can be called later, such as
|
|
34
|
+
// in an onClick handler.
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (immediate) {
|
|
37
|
+
void execute();
|
|
38
|
+
}
|
|
39
|
+
}, [execute, immediate]);
|
|
40
|
+
return { execute, status, value, error };
|
|
41
|
+
};
|
|
42
|
+
export default useAsync;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MouseEventHandler, MutableRefObject } from "react";
|
|
2
|
+
interface Events {
|
|
3
|
+
onMouseDown: MouseEventHandler<HTMLElement>;
|
|
4
|
+
}
|
|
5
|
+
declare const useDraggableScroll: (ref: MutableRefObject<HTMLElement>, { className, ...opts }: {
|
|
6
|
+
className: string;
|
|
7
|
+
}) => {
|
|
8
|
+
events: Events;
|
|
9
|
+
};
|
|
10
|
+
export default useDraggableScroll;
|
|
11
|
+
//# sourceMappingURL=use-draggable-scroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-draggable-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-draggable-scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,EAIjB,MAAM,OAAO,CAAA;AAId,UAAU,MAAM;IACd,WAAW,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAA;CAC5C;AAED,QAAA,MAAM,kBAAkB,QACjB,iBAAiB,WAAW,CAAC;eACG,MAAM;;;CA8E5C,CAAA;AAED,eAAe,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, } from "react";
|
|
2
|
+
import { useDraggable } from "react-use-draggable-scroll";
|
|
3
|
+
import { useEventListener, useIsInViewport } from "../hooks";
|
|
4
|
+
const useDraggableScroll = (ref, { className, ...opts }) => {
|
|
5
|
+
const { isInViewport, setRef } = useIsInViewport(false);
|
|
6
|
+
const { events } = useDraggable(ref, {
|
|
7
|
+
...opts,
|
|
8
|
+
isMounted: ref.current !== undefined,
|
|
9
|
+
});
|
|
10
|
+
const [modifiedEvents, setModifiedEvents] = useState(events);
|
|
11
|
+
const timer = useRef();
|
|
12
|
+
const [dragging, setDragging] = useState(false);
|
|
13
|
+
const [shouldScroll, setShouldScroll] = useState(false);
|
|
14
|
+
setRef(ref.current);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const shouldScroll = ref.current?.scrollWidth > ref.current?.clientWidth ||
|
|
17
|
+
ref.current?.scrollHeight > ref.current?.clientHeight;
|
|
18
|
+
setShouldScroll(shouldScroll);
|
|
19
|
+
const fn = shouldScroll ? "add" : "remove";
|
|
20
|
+
ref.current?.classList[fn](`${className}--draggable`);
|
|
21
|
+
}, [ref.current]);
|
|
22
|
+
const onDragStart = () => {
|
|
23
|
+
setDragging(true);
|
|
24
|
+
ref.current?.classList.add(`${className}--dragging`);
|
|
25
|
+
};
|
|
26
|
+
const onDragMove = () => {
|
|
27
|
+
if (timer.current && dragging) {
|
|
28
|
+
clearTimeout(timer.current);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const onDragEnd = () => {
|
|
32
|
+
setDragging(false);
|
|
33
|
+
timer.current = setTimeout(() => {
|
|
34
|
+
ref.current?.classList.remove(`${className}--dragging`);
|
|
35
|
+
}, 100);
|
|
36
|
+
};
|
|
37
|
+
useEventListener("mousemove", onDragMove, undefined, undefined, isInViewport && shouldScroll);
|
|
38
|
+
useEventListener("mouseup", onDragEnd, undefined, undefined, isInViewport && shouldScroll);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!shouldScroll) {
|
|
41
|
+
setModifiedEvents({
|
|
42
|
+
onMouseDown: (event) => event,
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const originalOnMouseDown = events.onMouseDown;
|
|
47
|
+
setModifiedEvents({
|
|
48
|
+
onMouseDown: event => {
|
|
49
|
+
onDragStart();
|
|
50
|
+
originalOnMouseDown(event);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}, [ref, ref.current, setModifiedEvents, shouldScroll]);
|
|
54
|
+
return { events: modifiedEvents };
|
|
55
|
+
};
|
|
56
|
+
export default useDraggableScroll;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Target = Document | Window | Element;
|
|
2
|
+
type EventMap<T extends Target> = T extends Window ? WindowEventHandlersEventMap & GlobalEventHandlersEventMap : T extends Document ? DocumentEventMap : GlobalEventHandlersEventMap;
|
|
3
|
+
type EventName<T extends Target> = keyof EventMap<T>;
|
|
4
|
+
type EventListener<T extends Target, E extends EventName<T>> = (event: EventMap<T>[E]) => void | boolean;
|
|
5
|
+
declare const useEventListener: <T extends Target, E extends keyof EventMap<T>>(eventName: E, handler: EventListener<T, E>, options?: boolean | AddEventListenerOptions, element?: T | undefined, flag?: boolean) => void;
|
|
6
|
+
export default useEventListener;
|
|
7
|
+
//# sourceMappingURL=use-event-listener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-event-listener.d.ts","sourceRoot":"","sources":["../src/hooks/use-event-listener.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAEzC,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,GAC9C,2BAA2B,GAAG,2BAA2B,GACzD,CAAC,SAAS,QAAQ,GAClB,gBAAgB,GAChB,2BAA2B,CAAA;AAE/B,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAA;AAEpD,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IAAI,CAC7D,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAClB,IAAI,GAAG,OAAO,CAAA;AAGnB,QAAA,MAAM,gBAAgB,wGAGX,OAAO,GAAG,uBAAuB,kCAEpC,OAAO,SA+Dd,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
// Hook
|
|
3
|
+
const useEventListener = (eventName, handler, options = {}, element, flag = true) => {
|
|
4
|
+
// Create a ref that stores handler
|
|
5
|
+
const savedHandler = useRef();
|
|
6
|
+
const elementRef = useRef();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
elementRef.current = element || window;
|
|
9
|
+
}, [element]);
|
|
10
|
+
// Update ref.current value if handler changes.
|
|
11
|
+
// This allows our effect below to always get latest handler ...
|
|
12
|
+
// ... without us needing to pass it in effect deps array ...
|
|
13
|
+
// ... and potentially cause effect to re-run every render.
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
savedHandler.current = handler;
|
|
16
|
+
}, [handler, elementRef.current]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
// Make sure element supports addEventListener
|
|
19
|
+
// On
|
|
20
|
+
const isSupported = elementRef.current && elementRef.current.addEventListener;
|
|
21
|
+
if (!isSupported)
|
|
22
|
+
return;
|
|
23
|
+
// Create event listener that calls handler function stored in ref
|
|
24
|
+
const eventListener = event => savedHandler.current(event);
|
|
25
|
+
if (flag) {
|
|
26
|
+
// Add event listener
|
|
27
|
+
elementRef.current.addEventListener(eventName, eventListener, options);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
elementRef.current.removeEventListener(eventName, eventListener);
|
|
31
|
+
}
|
|
32
|
+
// Remove event listener on cleanup
|
|
33
|
+
return () => {
|
|
34
|
+
elementRef.current.removeEventListener(eventName, eventListener);
|
|
35
|
+
};
|
|
36
|
+
}, [
|
|
37
|
+
eventName,
|
|
38
|
+
handler,
|
|
39
|
+
savedHandler.current,
|
|
40
|
+
element,
|
|
41
|
+
elementRef.current,
|
|
42
|
+
flag,
|
|
43
|
+
] // Re-run if eventName or element changes
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
export default useEventListener;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-hide-on-scroll.d.ts","sourceRoot":"","sources":["../src/hooks/use-hide-on-scroll.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,eAAe,kBAAkB,OAAO,KAAW,OA+DxD,CAAA;AAED,eAAe,eAAe,CAAA"}
|