@superrb/react-addons 3.0.0-9 → 3.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/.pnp.cjs +11252 -0
- package/.pnp.loader.mjs +2126 -0
- package/.yarn/install-state.gz +0 -0
- 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 +5 -3
- 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
package/components/form.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useState, useEffect, Fragment, forwardRef, useRef, useCallback, } from 'react';
|
|
3
|
+
import { useState, useEffect, Fragment, forwardRef, useRef, useCallback, useImperativeHandle, } from 'react';
|
|
4
4
|
import { paramCase, sentenceCase } from 'change-case';
|
|
5
5
|
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
@@ -11,22 +11,10 @@ import FormField from './form/field';
|
|
|
11
11
|
import SubmitButton from './form/submit-button';
|
|
12
12
|
import messages from './form/messages.json';
|
|
13
13
|
import { GoogleReCaptchaProvider, useGoogleReCaptcha, } from 'react-google-recaptcha-v3';
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const base64String = reader.result
|
|
19
|
-
?.toString()
|
|
20
|
-
.replace('data:', '')
|
|
21
|
-
.replace(/^.+,/, '');
|
|
22
|
-
resolve(base64String);
|
|
23
|
-
};
|
|
24
|
-
reader.readAsDataURL(file);
|
|
25
|
-
reader.onerror = reject;
|
|
26
|
-
});
|
|
27
|
-
const FormInner = forwardRef(function FormInner({ schema, name, action, className, initialData, onSubmit, method = 'POST', onStatusChange = () => { }, renderSuccessMessage = (data) => _jsx(SuccessMessage, {}), renderErrorMessage = (error, fieldSchema) => (_jsx(ErrorMessage, { error: error, fieldSchema: fieldSchema })), renderSubmit = () => _jsx(SubmitButton, {}), renderers = {}, useRecaptcha = true, ...props }, ref) {
|
|
28
|
-
const [data, setData] = useState({});
|
|
29
|
-
const fieldRefs = useRef({});
|
|
14
|
+
const FormInner = forwardRef(function FormInner({ schema, name, action, disabled = false, className = '', initialData = {}, onSubmit, onChange = () => { }, method, onStatusChange = () => { }, renderSuccessMessage = (data) => (_jsx(SuccessMessage, { data: data })), renderErrorMessage = (error, fieldSchema) => (_jsx(ErrorMessage, { error: error, fieldSchema: fieldSchema })), renderSubmit = (props) => _jsx(SubmitButton, { ...props }), renderers = {}, useRecaptcha = true, ...props }, ref) {
|
|
15
|
+
const [response, setResponse] = useState();
|
|
16
|
+
const formRef = useRef();
|
|
17
|
+
const fieldRefs = useRef(new Map());
|
|
30
18
|
const { executeRecaptcha } = useGoogleReCaptcha();
|
|
31
19
|
for (const name of Object.keys(schema.fields)) {
|
|
32
20
|
const field = schema.fields[name];
|
|
@@ -34,10 +22,14 @@ const FormInner = forwardRef(function FormInner({ schema, name, action, classNam
|
|
|
34
22
|
field.oneOf(field?.spec?.meta?.options);
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
const typedRef = ref;
|
|
26
|
+
const handleInput = (event) => {
|
|
27
|
+
const element = event.target;
|
|
28
|
+
onChange({
|
|
29
|
+
...typedRef?.current?.values,
|
|
30
|
+
[element.name]: element.value,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
41
33
|
const onSubmitHandler = useCallback(async (data) => {
|
|
42
34
|
if (onSubmit) {
|
|
43
35
|
return onSubmit(data);
|
|
@@ -49,24 +41,17 @@ const FormInner = forwardRef(function FormInner({ schema, name, action, classNam
|
|
|
49
41
|
}
|
|
50
42
|
// Intercept submissions for Next server actions
|
|
51
43
|
if (typeof action === 'function') {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
base64: await toBase64(fileValue),
|
|
62
|
-
name: fileValue.name,
|
|
63
|
-
type: fileValue.type,
|
|
64
|
-
size: fileValue.size,
|
|
65
|
-
};
|
|
66
|
-
data[`file_${key}`][fileKey] = insertFile;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
44
|
+
if (!formRef.current) {
|
|
45
|
+
throw new Error('Something went wrong while submitting the form');
|
|
46
|
+
}
|
|
47
|
+
const formData = new FormData(formRef.current);
|
|
48
|
+
formData.set('recaptchaToken', data.recaptchaToken);
|
|
49
|
+
const response = await action(formData);
|
|
50
|
+
if (response.statusCode === 200) {
|
|
51
|
+
setResponse(response.body);
|
|
52
|
+
return response.body;
|
|
69
53
|
}
|
|
54
|
+
throw new Error(response.body?.message);
|
|
70
55
|
}
|
|
71
56
|
const response = await fetch(action, {
|
|
72
57
|
method: 'post',
|
|
@@ -82,12 +67,36 @@ const FormInner = forwardRef(function FormInner({ schema, name, action, classNam
|
|
|
82
67
|
}
|
|
83
68
|
throw new Error(messages.form.error.endpoint_failure);
|
|
84
69
|
}
|
|
85
|
-
|
|
70
|
+
setResponse(responseData);
|
|
86
71
|
return responseData;
|
|
87
72
|
}, [action, onSubmit, useRecaptcha, executeRecaptcha]);
|
|
88
73
|
const { execute, status, error } = useAsync(onSubmitHandler, false, [
|
|
89
74
|
onSubmitHandler,
|
|
90
75
|
]);
|
|
76
|
+
const { register, handleSubmit, formState: { errors }, getValues, setValue, reset, } = useForm({
|
|
77
|
+
resolver: yupResolver(schema),
|
|
78
|
+
defaultValues: initialData,
|
|
79
|
+
mode: 'onTouched',
|
|
80
|
+
});
|
|
81
|
+
useImperativeHandle(ref, () => ({
|
|
82
|
+
form: formRef.current,
|
|
83
|
+
submit() {
|
|
84
|
+
handleSubmit(execute)();
|
|
85
|
+
},
|
|
86
|
+
reset() {
|
|
87
|
+
setResponse({});
|
|
88
|
+
reset();
|
|
89
|
+
},
|
|
90
|
+
get values() {
|
|
91
|
+
return getValues();
|
|
92
|
+
},
|
|
93
|
+
fields: [...fieldRefs.current.entries()].reduce((refs, [key, value]) => ({
|
|
94
|
+
...refs,
|
|
95
|
+
[key]: value,
|
|
96
|
+
}), {}),
|
|
97
|
+
errors,
|
|
98
|
+
response,
|
|
99
|
+
}));
|
|
91
100
|
useEffect(() => {
|
|
92
101
|
if (onStatusChange) {
|
|
93
102
|
onStatusChange(status);
|
|
@@ -99,28 +108,36 @@ const FormInner = forwardRef(function FormInner({ schema, name, action, classNam
|
|
|
99
108
|
field.spec.label = sentenceCase(fieldName);
|
|
100
109
|
}
|
|
101
110
|
});
|
|
102
|
-
return (_jsx(_Fragment, { children: status === 'success' && renderSuccessMessage !== false ? (_jsx(_Fragment, { children: renderSuccessMessage(
|
|
111
|
+
return (_jsx(_Fragment, { children: status === 'success' && renderSuccessMessage !== false ? (_jsx(_Fragment, { children: renderSuccessMessage(typedRef.current?.values) })) : (_jsxs("form", { className: `form ${className}`, action: action, ...(method ? { method } : {}), onSubmit: handleSubmit(execute), noValidate: true, ref: formRef, ...props, children: [error && renderErrorMessage({ message: error }), Object.keys(schema.fields).map((fieldName, key) => {
|
|
103
112
|
const field = schema.fields[fieldName];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
const onInput = (event) => {
|
|
114
|
+
const field = fieldRefs.current.get(fieldName);
|
|
115
|
+
const group = field?.closest('.form__group');
|
|
116
|
+
const fn = (field?.value?.length || 0) > 0 ? 'add' : 'remove';
|
|
117
|
+
group?.classList[fn]('form__group--filled');
|
|
118
|
+
setValue(fieldName, field?.value);
|
|
119
|
+
handleInput(event);
|
|
120
|
+
};
|
|
121
|
+
return (_jsx(Fragment, { children: field?.spec?.meta?.hidden === true ? (_jsx(FormField, { register: register(fieldName), schema: field, onInput: onInput, disabled: disabled, ref: (ref) => fieldRefs.current.set(fieldName, ref) })) : (_jsx("div", { className: `form__group form__group--${paramCase(fieldName)} ${fieldName in errors ? 'form__group--error' : ''} ${field?.type === 'boolean' ? 'form__group--checkbox' : ''} ${field?.type === 'date' ? 'form__group--date' : ''}`, children: _jsxs("label", { className: "form__label", htmlFor: `${name}__${paramCase(fieldName)}`, children: [_jsx("span", { className: "form__label-text", "data-label": `${field?.spec?.meta?.buttonLabel ? field?.spec?.meta?.buttonLabel : field?.spec?.label}`, dangerouslySetInnerHTML: {
|
|
107
122
|
__html: `${field?.spec?.label} ${!field?.spec?.optional
|
|
108
123
|
? '<span class="form__required-indicator">*</span>'
|
|
109
124
|
: ''}`,
|
|
110
|
-
} }), fieldName in renderers ? (renderers[fieldName](register(fieldName), errors[fieldName], field)) : (_jsxs(_Fragment, { children: [_jsx(FormField, { register: register(fieldName), id: `${name}__${paramCase(fieldName)}`, schema: field, onInput: (
|
|
111
|
-
fieldRefs.current
|
|
125
|
+
} }), fieldName in renderers ? (renderers[fieldName](register(fieldName), errors[fieldName], field)) : (_jsxs(_Fragment, { children: [_jsx(FormField, { register: register(fieldName), id: `${name}__${paramCase(fieldName)}`, schema: field, onInput: onInput, onChange: onInput, disabled: disabled, ref: (ref) => {
|
|
126
|
+
fieldRefs.current.set(fieldName, ref);
|
|
112
127
|
} }), fieldName in errors &&
|
|
113
|
-
renderErrorMessage(errors[fieldName], field)] }))] }) })) }, key));
|
|
114
|
-
}), renderSubmit(), useRecaptcha && (_jsxs("p", { className: "form__recaptcha-message", children: ["This site is protected by reCAPTCHA and the Google", ' ', _jsx("a", { href: "https://policies.google.com/privacy", target: "_blank", rel: "noopener", children: "Privacy Policy" }), ' ', "and", ' ', _jsx("a", { href: "https://policies.google.com/terms", target: "_blank", rel: "noopener", children: "Terms of Service" }), ' ', "apply."] }))] })) }));
|
|
128
|
+
renderErrorMessage(errors[fieldName], field), field.spec?.meta?.help && (_jsx("p", { className: "form__help", children: field.spec.meta.help }))] }))] }) })) }, key));
|
|
129
|
+
}), renderSubmit({ disabled }), useRecaptcha && (_jsxs("p", { className: "form__recaptcha-message", children: ["This site is protected by reCAPTCHA and the Google", ' ', _jsx("a", { href: "https://policies.google.com/privacy", target: "_blank", rel: "noopener", children: "Privacy Policy" }), ' ', "and", ' ', _jsx("a", { href: "https://policies.google.com/terms", target: "_blank", rel: "noopener", children: "Terms of Service" }), ' ', "apply."] }))] })) }));
|
|
115
130
|
});
|
|
116
|
-
|
|
117
|
-
if (props.useRecaptcha === false) {
|
|
118
|
-
return _jsx(FormInner, { ...props, ref: ref });
|
|
119
|
-
}
|
|
131
|
+
function Form(props, ref) {
|
|
120
132
|
const key = process.env.NEXT_PUBLIC_RECAPTCHA_KEY;
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
let { useRecaptcha } = props;
|
|
134
|
+
if (useRecaptcha === true && !key) {
|
|
135
|
+
console.error('Env var NEXT_PUBLIC_RECAPTCHA_KEY is not set. Recaptcha is disabled.');
|
|
136
|
+
useRecaptcha = false;
|
|
137
|
+
}
|
|
138
|
+
if (useRecaptcha === false) {
|
|
139
|
+
return _jsx(FormInner, { ...props, ref: ref, useRecaptcha: false });
|
|
123
140
|
}
|
|
124
|
-
return (_jsx(GoogleReCaptchaProvider, { reCaptchaKey: process.env.NEXT_PUBLIC_RECAPTCHA_KEY, children: _jsx(FormInner, { ...props, ref: ref }) }));
|
|
125
|
-
}
|
|
141
|
+
return (_jsx(GoogleReCaptchaProvider, { reCaptchaKey: process.env.NEXT_PUBLIC_RECAPTCHA_KEY, children: _jsx(FormInner, { ...props, ref: ref, useRecaptcha: true }) }));
|
|
142
|
+
}
|
|
126
143
|
export default forwardRef(Form);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ButtonHTMLAttributes, PropsWithChildren,
|
|
1
|
+
import { ButtonHTMLAttributes, PropsWithChildren, ReactNode } from 'react';
|
|
2
2
|
interface Props extends PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>> {
|
|
3
3
|
'aria-controls': string;
|
|
4
4
|
className?: string;
|
|
5
5
|
label?: string;
|
|
6
6
|
closeLabel?: string;
|
|
7
|
-
renderIcon?: (navOpen: boolean) =>
|
|
7
|
+
renderIcon?: (navOpen: boolean) => ReactNode;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
export
|
|
9
|
+
export default function MenuToggle({ 'aria-controls': ariaControls, className, label, closeLabel, renderIcon, ...props }: Props): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
11
11
|
//# sourceMappingURL=menu-toggle.d.ts.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"menu-toggle.d.ts","sourceRoot":"","sources":["../src/components/menu-toggle.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,EAEV,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,SAAS,CAAA;CAC7C;AAED,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,eAAe,EAAE,YAAY,EAC7B,SAAc,EACd,KAAkB,EAClB,UAAwB,EACxB,UAA+C,EAC/C,GAAG,KAAK,EACT,EAAE,KAAK,2CA6BP"}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback,
|
|
3
|
+
import { useCallback, } from 'react';
|
|
4
4
|
import { Button } from '../components';
|
|
5
5
|
import { extendClass } from '../utils';
|
|
6
6
|
import useNavStore from '../store/nav';
|
|
7
|
-
|
|
7
|
+
export default function MenuToggle({ 'aria-controls': ariaControls, className = '', label = 'Open Nav', closeLabel = 'Close Nav', renderIcon = (navOpen) => (navOpen ? '×' : '☰'), ...props }) {
|
|
8
8
|
const { navOpen, toggleNav } = useNavStore();
|
|
9
|
-
const [icon, setIcon] = useState(navOpen ? '×' : '꠵');
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (renderIcon) {
|
|
12
|
-
setIcon(renderIcon(navOpen));
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
setIcon(navOpen ? '×' : '꠵');
|
|
16
|
-
}, [navOpen, renderIcon]);
|
|
17
9
|
const handleClick = useCallback(() => {
|
|
18
10
|
if (document &&
|
|
19
11
|
document?.activeElement instanceof Element &&
|
|
@@ -23,6 +15,5 @@ const MenuToggle = ({ 'aria-controls': ariaControls, className = '', label = 'Op
|
|
|
23
15
|
}
|
|
24
16
|
toggleNav();
|
|
25
17
|
}, [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:
|
|
27
|
-
}
|
|
28
|
-
export default MenuToggle;
|
|
18
|
+
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: renderIcon(navOpen) }) }));
|
|
19
|
+
}
|
package/components/modal.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ interface Props {
|
|
|
4
4
|
className?: string;
|
|
5
5
|
openAfter?: number;
|
|
6
6
|
dismissable?: boolean;
|
|
7
|
+
preventScroll?: boolean;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
export
|
|
9
|
+
export default function Modal({ name, className, openAfter, dismissable, preventScroll, children, }: PropsWithChildren<Props>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
10
11
|
//# sourceMappingURL=modal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/components/modal.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/components/modal.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAA;AASd,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;IACrB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,IAAI,EACJ,SAAS,EACT,SAAS,EACT,WAAmB,EACnB,aAAoB,EACpB,QAAQ,GACT,EAAE,iBAAiB,CAAC,KAAK,CAAC,2CAkE1B"}
|
package/components/modal.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect, useRef, useCallback, } from 'react';
|
|
4
4
|
import { local } from '../storage';
|
|
5
|
-
import { useLockBodyScroll, useModal } from '../hooks';
|
|
6
|
-
|
|
5
|
+
import { useEscape, useEventListener, useLockBodyScroll, useModal, } from '../hooks';
|
|
6
|
+
export default function Modal({ name, className, openAfter, dismissable = false, preventScroll = true, children, }) {
|
|
7
7
|
const [dismissed, setDismissed] = useState(false);
|
|
8
8
|
const openTimer = useRef();
|
|
9
|
+
const ref = useRef();
|
|
10
|
+
const innerRef = useRef();
|
|
9
11
|
const { isOpen, openModal, closeModal } = useModal(name);
|
|
10
|
-
useLockBodyScroll(isOpen);
|
|
12
|
+
useLockBodyScroll(isOpen && preventScroll);
|
|
11
13
|
useEffect(() => {
|
|
12
14
|
if (dismissable) {
|
|
13
15
|
setDismissed(local.getItem(`${name}-popup-dismissed`) === 'true');
|
|
@@ -21,6 +23,9 @@ const Modal = ({ name, className, openAfter, dismissable = false, children, }) =
|
|
|
21
23
|
}, openAfter);
|
|
22
24
|
}
|
|
23
25
|
}, [dismissed, openAfter, openModal]);
|
|
26
|
+
useEscape(ref, closeModal);
|
|
27
|
+
useEventListener('click', closeModal, undefined, typeof document !== 'undefined' ? document : undefined);
|
|
28
|
+
useEventListener('click', (event) => event.stopPropagation(), undefined, innerRef.current);
|
|
24
29
|
const close = useCallback(() => {
|
|
25
30
|
closeModal();
|
|
26
31
|
if (dismissable) {
|
|
@@ -28,6 +33,5 @@ const Modal = ({ name, className, openAfter, dismissable = false, children, }) =
|
|
|
28
33
|
setDismissed(true);
|
|
29
34
|
}
|
|
30
35
|
}, [dismissable, 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;
|
|
36
|
+
return (_jsxs("aside", { id: name, className: `modal ${className}`, "aria-hidden": !isOpen, ref: ref, children: [_jsxs("button", { className: 'modal__close', onClick: close, children: [_jsx("span", { className: "screenreader-text", children: "Close Modal" }), "\u00D7"] }), _jsx("div", { className: 'modal__inner', ref: innerRef, children: children })] }));
|
|
37
|
+
}
|
package/components/skip-to.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip-to.d.ts","sourceRoot":"","sources":["../src/components/skip-to.tsx"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"skip-to.d.ts","sourceRoot":"","sources":["../src/components/skip-to.tsx"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,MAAM,4CAO7B"}
|
package/components/skip-to.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
2
|
+
export default function SkipTo() {
|
|
3
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;
|
|
4
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { ButtonProps } from './button';
|
|
3
3
|
import { Slideshow } from '@/hooks/use-slideshow';
|
|
4
|
-
|
|
4
|
+
export default function SlideshowButtons({ slideshow: { currentSlide, goTo, slideshowRef, atStart, atEnd }, ButtonComponent, }: {
|
|
5
5
|
slideshow: Slideshow;
|
|
6
6
|
ButtonComponent?: FC<ButtonProps>;
|
|
7
|
-
})
|
|
8
|
-
export default SlideshowButtons;
|
|
7
|
+
}): JSX.Element;
|
|
9
8
|
//# sourceMappingURL=slideshow-buttons.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slideshow-buttons.d.ts","sourceRoot":"","sources":["../src/components/slideshow-buttons.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,
|
|
1
|
+
{"version":3,"file":"slideshow-buttons.d.ts","sourceRoot":"","sources":["../src/components/slideshow-buttons.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,SAAS,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,EAC/D,eAAwB,GACzB,EAAE;IACD,SAAS,EAAE,SAAS,CAAA;IACpB,eAAe,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAA;CAClC,GAAG,GAAG,CAAC,OAAO,CAqBd"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import Button from './button';
|
|
3
|
-
|
|
3
|
+
export default function SlideshowButtons({ slideshow: { currentSlide, goTo, slideshowRef, atStart, atEnd }, ButtonComponent = Button, }) {
|
|
4
4
|
return (_jsxs("nav", { className: "slideshow-buttons", children: [_jsx(ButtonComponent, { label: "Previous slide", onClick: () => goTo(currentSlide - 1), disabled: atStart, "aria-controls": slideshowRef.current?.getAttribute('id') }), _jsx(ButtonComponent, { label: "Next slide", onClick: () => goTo(currentSlide + 1), disabled: atEnd, "aria-controls": slideshowRef.current?.getAttribute('id') })] }));
|
|
5
|
-
}
|
|
6
|
-
export default SlideshowButtons;
|
|
5
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Slideshow } from '@/hooks/use-slideshow';
|
|
2
|
+
export default function SlideshowPagination({ slideshow: { currentSlide, slideCount, goTo }, }: {
|
|
3
|
+
slideshow: Slideshow;
|
|
4
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
//# sourceMappingURL=slideshow-pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slideshow-pagination.d.ts","sourceRoot":"","sources":["../src/components/slideshow-pagination.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,SAAS,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,GAC9C,EAAE;IACD,SAAS,EAAE,SAAS,CAAA;CACrB,2CAeA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export default function SlideshowPagination({ slideshow: { currentSlide, slideCount, goTo }, }) {
|
|
3
|
+
return (_jsx("nav", { className: "slideshow-pagination", children: Array.from({ length: slideCount }, (_, i) => (_jsx("button", { className: "slideshow-pagination__button", "aria-current": currentSlide === i ? 'true' : 'false', onClick: () => goTo(i), children: _jsxs("span", { children: ["Slide ", i + 1] }) }, i))) }));
|
|
4
|
+
}
|
package/components.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Components
|
|
3
3
|
*/
|
|
4
|
+
import { Accordion, AccordionItem } from './components/accordion';
|
|
4
5
|
import BackToTop from './components/back-to-top';
|
|
5
6
|
import Button from './components/button';
|
|
6
7
|
import CookieBanner from './components/cookie-banner';
|
|
@@ -9,5 +10,6 @@ import MenuToggle from './components/menu-toggle';
|
|
|
9
10
|
import Modal from './components/modal';
|
|
10
11
|
import SkipTo from './components/skip-to';
|
|
11
12
|
import SlideshowButtons from './components/slideshow-buttons';
|
|
12
|
-
|
|
13
|
+
import SlideshowPagination from './components/slideshow-pagination';
|
|
14
|
+
export { Accordion, AccordionItem, BackToTop, Button, CookieBanner, Form, MenuToggle, Modal, SkipTo, SlideshowButtons, SlideshowPagination, };
|
|
13
15
|
//# sourceMappingURL=components.d.ts.map
|
package/components.d.ts.map
CHANGED
|
@@ -1 +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,YAAY,MAAM,4BAA4B,CAAA;AACrD,OAAO,IAAI,MAAM,mBAAmB,CAAA;AACpC,OAAO,UAAU,MAAM,0BAA0B,CAAA;AACjD,OAAO,KAAK,MAAM,oBAAoB,CAAA;AACtC,OAAO,MAAM,MAAM,sBAAsB,CAAA;AACzC,OAAO,gBAAgB,MAAM,gCAAgC,CAAA;
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["src/components.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,SAAS,MAAM,0BAA0B,CAAA;AAChD,OAAO,MAAM,MAAM,qBAAqB,CAAA;AACxC,OAAO,YAAY,MAAM,4BAA4B,CAAA;AACrD,OAAO,IAAI,MAAM,mBAAmB,CAAA;AACpC,OAAO,UAAU,MAAM,0BAA0B,CAAA;AACjD,OAAO,KAAK,MAAM,oBAAoB,CAAA;AACtC,OAAO,MAAM,MAAM,sBAAsB,CAAA;AACzC,OAAO,gBAAgB,MAAM,gCAAgC,CAAA;AAC7D,OAAO,mBAAmB,MAAM,mCAAmC,CAAA;AAEnE,OAAO,EACL,SAAS,EACT,aAAa,EACb,SAAS,EACT,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,KAAK,EACL,MAAM,EACN,gBAAgB,EAChB,mBAAmB,GACpB,CAAA"}
|
package/components.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Components
|
|
3
3
|
*/
|
|
4
|
+
import { Accordion, AccordionItem } from './components/accordion';
|
|
4
5
|
import BackToTop from './components/back-to-top';
|
|
5
6
|
import Button from './components/button';
|
|
6
7
|
import CookieBanner from './components/cookie-banner';
|
|
@@ -9,4 +10,5 @@ import MenuToggle from './components/menu-toggle';
|
|
|
9
10
|
import Modal from './components/modal';
|
|
10
11
|
import SkipTo from './components/skip-to';
|
|
11
12
|
import SlideshowButtons from './components/slideshow-buttons';
|
|
12
|
-
|
|
13
|
+
import SlideshowPagination from './components/slideshow-pagination';
|
|
14
|
+
export { Accordion, AccordionItem, BackToTop, Button, CookieBanner, Form, MenuToggle, Modal, SkipTo, SlideshowButtons, SlideshowPagination, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies-context-provider.d.ts","sourceRoot":"","sources":["../src/context/cookies-context-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EAKlB,MAAM,OAAO,CAAA;AAGd,eAAO,MAAM,cAAc;;mCAEM,OAAO;;2CAEC,OAAO;;;;EAI9C,CAAA;AAEF,eAAO,MAAM,sBAAsB,iBAAkB,
|
|
1
|
+
{"version":3,"file":"cookies-context-provider.d.ts","sourceRoot":"","sources":["../src/context/cookies-context-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EAKlB,MAAM,OAAO,CAAA;AAGd,eAAO,MAAM,cAAc;;mCAEM,OAAO;;2CAEC,OAAO;;;;EAI9C,CAAA;AAEF,eAAO,MAAM,sBAAsB,iBAAkB,iBAAiB,CAAC,EAAE,CAAC,4CA2DzE,CAAA;AAED,eAAe,sBAAsB,CAAA"}
|
|
@@ -8,6 +8,6 @@ export declare const ModalContext: import("react").Context<{
|
|
|
8
8
|
interface OpenState {
|
|
9
9
|
[key: string]: boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare
|
|
11
|
+
export declare function ModalContextProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
export default ModalContextProvider;
|
|
13
13
|
//# sourceMappingURL=modal-context-provider.d.ts.map
|
|
@@ -1 +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
|
|
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;eACN,SAAS;mBACX,MAAM,KAAc,OAAO;sBACxB,MAAM;uBACL,MAAM;EACzB,CAAA;AAEF,UAAU,SAAS;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CA8BnE;AAED,eAAe,oBAAoB,CAAA"}
|
|
@@ -7,7 +7,7 @@ export const ModalContext = createContext({
|
|
|
7
7
|
openModal: (name) => { },
|
|
8
8
|
closeModal: (name) => { },
|
|
9
9
|
});
|
|
10
|
-
export
|
|
10
|
+
export function ModalContextProvider({ children }) {
|
|
11
11
|
const [openState, setOpenState] = useState({});
|
|
12
12
|
const isOpen = (name) => {
|
|
13
13
|
return openState[name] || false;
|
|
@@ -27,5 +27,5 @@ export const ModalContextProvider = ({ children }) => {
|
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
return (_jsx(ModalContext.Provider, { value: { openState, isOpen, openModal, closeModal }, children: children }));
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
31
|
export default ModalContextProvider;
|
|
@@ -5,6 +5,6 @@ export declare const NavContext: import("react").Context<{
|
|
|
5
5
|
openNav: () => void;
|
|
6
6
|
closeNav: () => void;
|
|
7
7
|
}>;
|
|
8
|
-
export declare
|
|
8
|
+
export declare function NavContextProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
export default NavContextProvider;
|
|
10
10
|
//# sourceMappingURL=nav-context-provider.d.ts.map
|
|
@@ -1 +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,
|
|
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,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CAsBjE;AAED,eAAe,kBAAkB,CAAA"}
|
|
@@ -8,7 +8,7 @@ export const NavContext = createContext({
|
|
|
8
8
|
openNav: () => { },
|
|
9
9
|
closeNav: () => { },
|
|
10
10
|
});
|
|
11
|
-
export
|
|
11
|
+
export function NavContextProvider({ children }) {
|
|
12
12
|
const [navOpen, setNavOpen] = useState(false);
|
|
13
13
|
useLockBodyScroll(navOpen);
|
|
14
14
|
const toggleNav = useCallback(() => {
|
|
@@ -22,5 +22,5 @@ export const NavContextProvider = ({ children }) => {
|
|
|
22
22
|
document.activeElement?.blur();
|
|
23
23
|
}, [setNavOpen]);
|
|
24
24
|
return (_jsx(NavContext.Provider, { value: { navOpen, toggleNav, openNav, closeNav }, children: children }));
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
export default NavContextProvider;
|
package/hooks/use-async.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ interface ReturnType<T, E = string> {
|
|
|
5
5
|
value: T | null;
|
|
6
6
|
error: E | null;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export default function useAsync<T, E = string>(asyncFunction: (...args: any[]) => Promise<T>, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
9
|
+
immediate?: boolean, dependencies?: any[]): ReturnType<T, E>;
|
|
10
|
+
export {};
|
|
10
11
|
//# sourceMappingURL=use-async.d.ts.map
|
package/hooks/use-async.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,EAC5C,aAAa,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,yDAAyD;AACxG,SAAS,UAAQ,EACjB,YAAY,GAAE,GAAG,EAAO,GACvB,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CA2ClB"}
|
package/hooks/use-async.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
// Hook
|
|
3
|
-
|
|
4
|
-
immediate = false, dependencies = [])
|
|
3
|
+
export default function useAsync(asyncFunction, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
4
|
+
immediate = false, dependencies = []) {
|
|
5
5
|
const [status, setStatus] = useState('idle');
|
|
6
6
|
const [value, setValue] = useState(null);
|
|
7
7
|
const [error, setError] = useState(null);
|
|
@@ -37,5 +37,4 @@ immediate = false, dependencies = []) => {
|
|
|
37
37
|
}
|
|
38
38
|
}, [execute, immediate]);
|
|
39
39
|
return { execute, status, value, error };
|
|
40
|
-
}
|
|
41
|
-
export default useAsync;
|
|
40
|
+
}
|
|
@@ -2,10 +2,10 @@ import { MouseEventHandler, MutableRefObject } from 'react';
|
|
|
2
2
|
interface Events {
|
|
3
3
|
onMouseDown: MouseEventHandler<HTMLElement>;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
export default function useDraggableScroll(ref: MutableRefObject<HTMLElement>, { className, ...opts }: {
|
|
6
6
|
className: string;
|
|
7
|
-
})
|
|
7
|
+
}): {
|
|
8
8
|
events: Events;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export {};
|
|
11
11
|
//# sourceMappingURL=use-draggable-scroll.d.ts.map
|
|
@@ -1 +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,
|
|
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,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,GAAG,EAAE,gBAAgB,CAAC,WAAW,CAAC,EAClC,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE;;EA8E9C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef, useState, } from 'react';
|
|
2
2
|
import { useDraggable } from 'react-use-draggable-scroll';
|
|
3
3
|
import { useEventListener, useIsInViewport } from '../hooks';
|
|
4
|
-
|
|
4
|
+
export default function useDraggableScroll(ref, { className, ...opts }) {
|
|
5
5
|
const { isInViewport, setRef } = useIsInViewport(false);
|
|
6
6
|
const { events } = useDraggable(ref, {
|
|
7
7
|
...opts,
|
|
@@ -52,5 +52,4 @@ const useDraggableScroll = (ref, { className, ...opts }) => {
|
|
|
52
52
|
});
|
|
53
53
|
}, [ref, ref.current, setModifiedEvents, shouldScroll]);
|
|
54
54
|
return { events: modifiedEvents };
|
|
55
|
-
}
|
|
56
|
-
export default useDraggableScroll;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-escape.d.ts","sourceRoot":"","sources":["../src/hooks/use-escape.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,SAAS,GAAI,KAAK,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,UAAU,MAAM,IAAI,SAgBzE,CAAA;AAED,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEventListener } from '../hooks';
|
|
2
|
+
const useEscape = (ref, callback) => {
|
|
3
|
+
useEventListener('keydown', (event) => {
|
|
4
|
+
if (ref.current?.contains(document.activeElement) &&
|
|
5
|
+
event.key === 'Escape') {
|
|
6
|
+
event.preventDefault();
|
|
7
|
+
callback();
|
|
8
|
+
}
|
|
9
|
+
}, {}, typeof document !== 'undefined' ? document : undefined, ref.current !== undefined && document !== undefined);
|
|
10
|
+
};
|
|
11
|
+
export default useEscape;
|
|
@@ -2,6 +2,6 @@ type Target = Document | Window | Element;
|
|
|
2
2
|
type EventMap<T extends Target> = T extends Window ? WindowEventHandlersEventMap & GlobalEventHandlersEventMap : T extends Document ? DocumentEventMap : GlobalEventHandlersEventMap;
|
|
3
3
|
type EventName<T extends Target> = keyof EventMap<T>;
|
|
4
4
|
type EventListener<T extends Target, E extends EventName<T>> = (event: EventMap<T>[E]) => void | boolean;
|
|
5
|
-
|
|
6
|
-
export
|
|
5
|
+
export default function useEventListener<T extends Target, E extends EventName<T>>(eventName: E, handler: EventListener<T, E>, options?: boolean | AddEventListenerOptions, element?: T, flag?: boolean): void;
|
|
6
|
+
export {};
|
|
7
7
|
//# sourceMappingURL=use-event-listener.d.ts.map
|
|
@@ -1 +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,
|
|
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,GAChB,gBAAgB,GAChB,2BAA2B,CAAA;AAEjC,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,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAEtB,SAAS,EAAE,CAAC,EACZ,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,OAAO,GAAE,OAAO,GAAG,uBAA4B,EAC/C,OAAO,CAAC,EAAE,CAAC,EACX,IAAI,GAAE,OAAc,QAqDrB"}
|