@superrb/react-addons 3.0.0-4 → 3.0.0-40
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/actions.d.ts +6 -0
- package/actions.d.ts.map +1 -0
- package/actions.js +18 -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 +1 -1
- 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 +23 -18
- package/components/cookie-banner.d.ts.map +1 -1
- package/components/cookie-banner.js +11 -12
- 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 +10 -3
- package/components/form/field.d.ts.map +1 -1
- package/components/form/field.js +17 -6
- 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 +23 -0
- package/components/form/submit-button.d.ts +3 -4
- package/components/form/submit-button.d.ts.map +1 -1
- package/components/form/submit-button.js +2 -3
- 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 +17 -4
- package/components/form.d.ts.map +1 -1
- package/components/form.js +68 -50
- 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 +8 -0
- package/components/slideshow-buttons.d.ts.map +1 -0
- package/components/slideshow-buttons.js +5 -0
- 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 +4 -1
- package/components.d.ts.map +1 -1
- package/components.js +4 -1
- package/context/cookies-context-provider.d.ts +13 -0
- package/context/cookies-context-provider.d.ts.map +1 -0
- package/context/cookies-context-provider.js +54 -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 +1 -1
- package/context/nav-context-provider.d.ts.map +1 -1
- package/context/nav-context-provider.js +26 -0
- package/context.d.ts +2 -1
- package/context.d.ts.map +1 -1
- package/context.js +2 -1
- 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 +18 -0
- package/hooks/use-slideshow.d.ts.map +1 -0
- package/hooks/use-slideshow.js +133 -0
- package/hooks.d.ts +3 -1
- package/hooks.d.ts.map +1 -1
- package/hooks.js +3 -1
- package/package.json +3 -3
- package/store/cookies.d.ts +3 -0
- package/store/cookies.d.ts.map +1 -1
- package/store/cookies.js +29 -22
- 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/utils.d.ts +2 -1
- package/utils.d.ts.map +1 -1
- package/utils.js +2 -1
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';
|
|
@@ -10,23 +10,11 @@ import ErrorMessage from './form/error-message';
|
|
|
10
10
|
import FormField from './form/field';
|
|
11
11
|
import SubmitButton from './form/submit-button';
|
|
12
12
|
import messages from './form/messages.json';
|
|
13
|
-
import { 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
|
-
function Form({ 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({});
|
|
13
|
+
import { GoogleReCaptchaProvider, useGoogleReCaptcha, } from 'react-google-recaptcha-v3';
|
|
14
|
+
const FormInner = forwardRef(function FormInner({ schema, name, action, className = '', initialData = {}, onSubmit, onChange = () => { }, method, onStatusChange = () => { }, renderSuccessMessage = (data) => (_jsx(SuccessMessage, { data: data })), renderErrorMessage = (error, fieldSchema) => (_jsx(ErrorMessage, { error: error, fieldSchema: fieldSchema })), renderSubmit = () => _jsx(SubmitButton, {}), 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,42 +22,56 @@ function Form({ schema, name, action, className, initialData, onSubmit, method =
|
|
|
34
22
|
field.oneOf(field?.spec?.meta?.options);
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
|
-
const { register, handleSubmit, formState: { errors }, } = useForm({
|
|
25
|
+
const { register, handleSubmit, formState: { errors }, getValues, setValue, reset, } = useForm({
|
|
38
26
|
resolver: yupResolver(schema),
|
|
39
27
|
defaultValues: initialData,
|
|
28
|
+
mode: 'onTouched',
|
|
40
29
|
});
|
|
30
|
+
useImperativeHandle(ref, () => ({
|
|
31
|
+
form: formRef.current,
|
|
32
|
+
submit() {
|
|
33
|
+
handleSubmit(execute)();
|
|
34
|
+
},
|
|
35
|
+
reset() {
|
|
36
|
+
setResponse({});
|
|
37
|
+
reset();
|
|
38
|
+
},
|
|
39
|
+
get values() {
|
|
40
|
+
return getValues();
|
|
41
|
+
},
|
|
42
|
+
fields: [...fieldRefs.current.entries()].reduce((refs, [key, value]) => ({
|
|
43
|
+
...refs,
|
|
44
|
+
[key]: value,
|
|
45
|
+
}), {}),
|
|
46
|
+
errors,
|
|
47
|
+
response,
|
|
48
|
+
}));
|
|
49
|
+
const typedRef = ref;
|
|
50
|
+
const handleInput = (event) => {
|
|
51
|
+
const element = event.target;
|
|
52
|
+
onChange({
|
|
53
|
+
...typedRef.current?.values,
|
|
54
|
+
[element.name]: element.value,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
41
57
|
const onSubmitHandler = useCallback(async (data) => {
|
|
42
58
|
if (onSubmit) {
|
|
43
59
|
return onSubmit(data);
|
|
44
60
|
}
|
|
45
|
-
if (typeof action === 'function') {
|
|
46
|
-
const formData = new FormData();
|
|
47
|
-
for (const [key, value] of Object.entries(data)) {
|
|
48
|
-
formData.append(key, value);
|
|
49
|
-
}
|
|
50
|
-
return action(formData);
|
|
51
|
-
}
|
|
52
|
-
for (const [key, value] of Object.entries(data)) {
|
|
53
|
-
if (value instanceof FileList) {
|
|
54
|
-
data[`file_${key}`] = [];
|
|
55
|
-
for (const [fileKey, fileValue] of Object.entries(value)) {
|
|
56
|
-
if (fileValue instanceof File && fileValue.size > 0) {
|
|
57
|
-
const insertFile = {
|
|
58
|
-
base64: await toBase64(fileValue),
|
|
59
|
-
name: fileValue.name,
|
|
60
|
-
type: fileValue.type,
|
|
61
|
-
size: fileValue.size,
|
|
62
|
-
};
|
|
63
|
-
data[`file_${key}`][fileKey] = insertFile;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
61
|
// if recaptcha is enabled generate a token and add to the data
|
|
69
62
|
if (useRecaptcha && executeRecaptcha) {
|
|
70
63
|
const token = await executeRecaptcha();
|
|
71
64
|
data['recaptchaToken'] = token;
|
|
72
65
|
}
|
|
66
|
+
// Intercept submissions for Next server actions
|
|
67
|
+
if (typeof action === 'function') {
|
|
68
|
+
if (!formRef.current) {
|
|
69
|
+
throw new Error('Something went wrong while submitting the form');
|
|
70
|
+
}
|
|
71
|
+
const formData = new FormData(formRef.current);
|
|
72
|
+
formData.set('recaptchaToken', data.recaptchaToken);
|
|
73
|
+
return action(formData);
|
|
74
|
+
}
|
|
73
75
|
const response = await fetch(action, {
|
|
74
76
|
method: 'post',
|
|
75
77
|
headers: {
|
|
@@ -84,7 +86,7 @@ function Form({ schema, name, action, className, initialData, onSubmit, method =
|
|
|
84
86
|
}
|
|
85
87
|
throw new Error(messages.form.error.endpoint_failure);
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
setResponse(responseData);
|
|
88
90
|
return responseData;
|
|
89
91
|
}, [action, onSubmit, useRecaptcha, executeRecaptcha]);
|
|
90
92
|
const { execute, status, error } = useAsync(onSubmitHandler, false, [
|
|
@@ -101,18 +103,34 @@ function Form({ schema, name, action, className, initialData, onSubmit, method =
|
|
|
101
103
|
field.spec.label = sentenceCase(fieldName);
|
|
102
104
|
}
|
|
103
105
|
});
|
|
104
|
-
return (_jsx(_Fragment, { children: status === 'success' && renderSuccessMessage !== false ? (_jsx(_Fragment, { children: renderSuccessMessage(
|
|
106
|
+
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) => {
|
|
105
107
|
const field = schema.fields[fieldName];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
const onInput = (event) => {
|
|
109
|
+
const field = fieldRefs.current.get(fieldName);
|
|
110
|
+
const group = field?.closest('.form__group');
|
|
111
|
+
const fn = (field?.value?.length || 0) > 0 ? 'add' : 'remove';
|
|
112
|
+
group?.classList[fn]('form__group--filled');
|
|
113
|
+
setValue(fieldName, field?.value);
|
|
114
|
+
handleInput(event);
|
|
115
|
+
};
|
|
116
|
+
return (_jsx(Fragment, { children: field?.spec?.meta?.hidden === true ? (_jsx(FormField, { register: register(fieldName), schema: field, onInput: onInput, 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", dangerouslySetInnerHTML: {
|
|
109
117
|
__html: `${field?.spec?.label} ${!field?.spec?.optional
|
|
110
118
|
? '<span class="form__required-indicator">*</span>'
|
|
111
119
|
: ''}`,
|
|
112
|
-
} }), 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: (
|
|
113
|
-
fieldRefs.current
|
|
120
|
+
} }), 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, ref: (ref) => {
|
|
121
|
+
fieldRefs.current.set(fieldName, ref);
|
|
114
122
|
} }), fieldName in errors &&
|
|
115
|
-
renderErrorMessage(errors[fieldName], field)] }))] }) })) }, key));
|
|
123
|
+
renderErrorMessage(errors[fieldName], field), field.spec?.meta?.help && (_jsx("p", { className: "form__help", children: field.spec.meta.help }))] }))] }) })) }, key));
|
|
116
124
|
}), 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."] }))] })) }));
|
|
125
|
+
});
|
|
126
|
+
function Form(props, ref) {
|
|
127
|
+
if (props.useRecaptcha === false) {
|
|
128
|
+
return _jsx(FormInner, { ...props, ref: ref });
|
|
129
|
+
}
|
|
130
|
+
const key = process.env.NEXT_PUBLIC_RECAPTCHA_KEY;
|
|
131
|
+
if (!key) {
|
|
132
|
+
throw new Error('Env var NEXT_PUBLIC_RECAPTCHA_KEY is not set');
|
|
133
|
+
}
|
|
134
|
+
return (_jsx(GoogleReCaptchaProvider, { reCaptchaKey: process.env.NEXT_PUBLIC_RECAPTCHA_KEY, children: _jsx(FormInner, { ...props, ref: ref }) }));
|
|
117
135
|
}
|
|
118
136
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ButtonProps } from './button';
|
|
3
|
+
import { Slideshow } from '@/hooks/use-slideshow';
|
|
4
|
+
export default function SlideshowButtons({ slideshow: { currentSlide, goTo, slideshowRef, atStart, atEnd }, ButtonComponent, }: {
|
|
5
|
+
slideshow: Slideshow;
|
|
6
|
+
ButtonComponent?: FC<ButtonProps>;
|
|
7
|
+
}): JSX.Element;
|
|
8
|
+
//# sourceMappingURL=slideshow-buttons.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Button from './button';
|
|
3
|
+
export default function SlideshowButtons({ slideshow: { currentSlide, goTo, slideshowRef, atStart, atEnd }, ButtonComponent = Button, }) {
|
|
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
|
+
}
|
|
@@ -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';
|
|
@@ -8,5 +9,7 @@ import Form from './components/form';
|
|
|
8
9
|
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';
|
|
13
|
+
import SlideshowPagination from './components/slideshow-pagination';
|
|
14
|
+
export { Accordion, AccordionItem, BackToTop, Button, CookieBanner, Form, MenuToggle, Modal, SkipTo, SlideshowButtons, SlideshowPagination, };
|
|
12
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;
|
|
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';
|
|
@@ -8,4 +9,6 @@ import Form from './components/form';
|
|
|
8
9
|
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';
|
|
13
|
+
import SlideshowPagination from './components/slideshow-pagination';
|
|
14
|
+
export { Accordion, AccordionItem, BackToTop, Button, CookieBanner, Form, MenuToggle, Modal, SkipTo, SlideshowButtons, SlideshowPagination, };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
export declare const CookiesContext: import("react").Context<{
|
|
3
|
+
cookiesAccepted: boolean;
|
|
4
|
+
setCookiesAccepted: (accepted: boolean) => void;
|
|
5
|
+
trackingCookiesAccepted: boolean;
|
|
6
|
+
setTrackingCookiesAccepted: (accepted: boolean) => void;
|
|
7
|
+
popupOpen: boolean;
|
|
8
|
+
openPopup: () => void;
|
|
9
|
+
closePopup: () => void;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const CookiesContextProvider: ({ children }: PropsWithChildren<{}>) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default CookiesContextProvider;
|
|
13
|
+
//# sourceMappingURL=cookies-context-provider.d.ts.map
|
|
@@ -0,0 +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,iBAAiB,CAAC,EAAE,CAAC,4CA2DzE,CAAA;AAED,eAAe,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useCallback, useEffect, useState, } from 'react';
|
|
4
|
+
import Cookies from 'js-cookie';
|
|
5
|
+
export const CookiesContext = createContext({
|
|
6
|
+
cookiesAccepted: false,
|
|
7
|
+
setCookiesAccepted: (accepted) => { },
|
|
8
|
+
trackingCookiesAccepted: false,
|
|
9
|
+
setTrackingCookiesAccepted: (accepted) => { },
|
|
10
|
+
popupOpen: false,
|
|
11
|
+
openPopup: () => { },
|
|
12
|
+
closePopup: () => { },
|
|
13
|
+
});
|
|
14
|
+
export const CookiesContextProvider = ({ children }) => {
|
|
15
|
+
const [cookiesAccepted, setCookiesAcceptedStorage] = useState(false);
|
|
16
|
+
const [popupOpen, setPopupOpenStorage] = useState(false);
|
|
17
|
+
const [trackingCookiesAccepted, setTrackingCookiesAcceptedStorage] = useState(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const accepted = Cookies.get('accepted-cookies') || false;
|
|
20
|
+
setCookiesAcceptedStorage(!!accepted);
|
|
21
|
+
}, [setCookiesAcceptedStorage]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const accepted = Cookies.get('accepted-tracking-cookies') || false;
|
|
24
|
+
setTrackingCookiesAcceptedStorage(!!accepted);
|
|
25
|
+
}, [setTrackingCookiesAcceptedStorage]);
|
|
26
|
+
const setCookiesAccepted = useCallback((accepted) => {
|
|
27
|
+
Cookies.set('accepted-cookies', accepted.toString(), {
|
|
28
|
+
expires: 30,
|
|
29
|
+
});
|
|
30
|
+
setCookiesAcceptedStorage(accepted);
|
|
31
|
+
}, [setCookiesAcceptedStorage]);
|
|
32
|
+
const setTrackingCookiesAccepted = useCallback((accepted) => {
|
|
33
|
+
Cookies.set('accepted-tracking-cookies', accepted.toString(), {
|
|
34
|
+
expires: 30,
|
|
35
|
+
});
|
|
36
|
+
setTrackingCookiesAcceptedStorage(accepted);
|
|
37
|
+
}, [setTrackingCookiesAcceptedStorage]);
|
|
38
|
+
const openPopup = useCallback(() => {
|
|
39
|
+
setPopupOpenStorage(true);
|
|
40
|
+
}, [setPopupOpenStorage]);
|
|
41
|
+
const closePopup = useCallback(() => {
|
|
42
|
+
setPopupOpenStorage(false);
|
|
43
|
+
}, [setPopupOpenStorage]);
|
|
44
|
+
return (_jsx(CookiesContext.Provider, { value: {
|
|
45
|
+
cookiesAccepted,
|
|
46
|
+
setCookiesAccepted,
|
|
47
|
+
trackingCookiesAccepted,
|
|
48
|
+
setTrackingCookiesAccepted,
|
|
49
|
+
popupOpen,
|
|
50
|
+
openPopup,
|
|
51
|
+
closePopup,
|
|
52
|
+
}, children: children }));
|
|
53
|
+
};
|
|
54
|
+
export default CookiesContextProvider;
|
|
@@ -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 function 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;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"}
|
|
@@ -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 function 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;
|
|
@@ -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"}
|
|
@@ -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 function 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
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Context
|
|
3
3
|
*/
|
|
4
|
+
import { CookiesContext, CookiesContextProvider } from './context/cookies-context-provider';
|
|
4
5
|
import { ModalContext, ModalContextProvider } from './context/modal-context-provider';
|
|
5
6
|
import { NavContext, NavContextProvider } from './context/nav-context-provider';
|
|
6
|
-
export { ModalContext, ModalContextProvider, NavContext, NavContextProvider, };
|
|
7
|
+
export { CookiesContext, CookiesContextProvider, ModalContext, ModalContextProvider, NavContext, NavContextProvider, };
|
|
7
8
|
//# sourceMappingURL=context.d.ts.map
|
package/context.d.ts.map
CHANGED
|
@@ -1 +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,EACL,YAAY,EACZ,oBAAoB,EACpB,UAAU,EACV,kBAAkB,GACnB,CAAA"}
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,cAAc,EACd,sBAAsB,EACvB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACL,YAAY,EACZ,oBAAoB,EACrB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAE/E,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,YAAY,EACZ,oBAAoB,EACpB,UAAU,EACV,kBAAkB,GACnB,CAAA"}
|
package/context.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Context
|
|
3
3
|
*/
|
|
4
|
+
import { CookiesContext, CookiesContextProvider, } from './context/cookies-context-provider';
|
|
4
5
|
import { ModalContext, ModalContextProvider, } from './context/modal-context-provider';
|
|
5
6
|
import { NavContext, NavContextProvider } from './context/nav-context-provider';
|
|
6
|
-
export { ModalContext, ModalContextProvider, NavContext, NavContextProvider, };
|
|
7
|
+
export { CookiesContext, CookiesContextProvider, ModalContext, ModalContextProvider, NavContext, 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
|
+
}
|