@tpzdsp/next-toolkit 1.0.1
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/README.md +594 -0
- package/package.json +133 -0
- package/src/assets/fonts/gds-bold-w-v2.woff +0 -0
- package/src/assets/fonts/gds-bold-w2-v2.woff2 +0 -0
- package/src/assets/fonts/gds-light-w-v2.woff +0 -0
- package/src/assets/fonts/gds-light-w2-v2.woff2 +0 -0
- package/src/assets/images/defra-logo.svg +51 -0
- package/src/assets/images/ea-logo.svg +58 -0
- package/src/assets/images/ogl.svg +1 -0
- package/src/assets/styles/globals.css +68 -0
- package/src/assets/styles/index.ts +7 -0
- package/src/components/Button/Button.stories.tsx +41 -0
- package/src/components/Button/Button.test.tsx +55 -0
- package/src/components/Button/Button.tsx +44 -0
- package/src/components/Card/Card.stories.tsx +35 -0
- package/src/components/Card/Card.test.tsx +12 -0
- package/src/components/Card/Card.tsx +19 -0
- package/src/components/ErrorText/ErrorText.stories.tsx +34 -0
- package/src/components/ErrorText/ErrorText.test.tsx +35 -0
- package/src/components/ErrorText/ErrorText.tsx +17 -0
- package/src/components/Heading/Heading.stories.tsx +21 -0
- package/src/components/Heading/Heading.test.tsx +24 -0
- package/src/components/Heading/Heading.tsx +21 -0
- package/src/components/Hint/Hint.stories.tsx +40 -0
- package/src/components/Hint/Hint.test.tsx +35 -0
- package/src/components/Hint/Hint.tsx +13 -0
- package/src/components/Paragraph/Paragraph.stories.tsx +30 -0
- package/src/components/Paragraph/Paragraph.test.tsx +12 -0
- package/src/components/Paragraph/Paragraph.tsx +7 -0
- package/src/components/container/Container.tsx +38 -0
- package/src/components/dropdown/DropdownMenu.test.tsx +213 -0
- package/src/components/dropdown/DropdownMenu.tsx +106 -0
- package/src/components/dropdown/useDropdownMenu.ts +245 -0
- package/src/components/images/DefraLogo.tsx +64 -0
- package/src/components/images/EaLogo.tsx +81 -0
- package/src/components/images/OglLogo.tsx +18 -0
- package/src/components/index.ts +36 -0
- package/src/components/layout/footer/Copyright.tsx +14 -0
- package/src/components/layout/footer/Footer.tsx +26 -0
- package/src/components/layout/footer/Licence.tsx +19 -0
- package/src/components/layout/footer/MetaLinks.tsx +36 -0
- package/src/components/layout/header/Header.tsx +89 -0
- package/src/components/layout/header/HeaderAuthClient.tsx +32 -0
- package/src/components/layout/header/HeaderNavClient.tsx +64 -0
- package/src/components/link/ExternalLink.tsx +29 -0
- package/src/components/link/Link.tsx +26 -0
- package/src/components/link/NextLinkWrapper.tsx +66 -0
- package/src/components/theme/ThemeProvider.tsx +30 -0
- package/src/contexts/ThemeContext.tsx +72 -0
- package/src/contexts/index.ts +5 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useDebounce.ts +18 -0
- package/src/hooks/useLocalStorage.ts +57 -0
- package/src/index.ts +8 -0
- package/src/types.ts +99 -0
- package/src/utils/auth.ts +19 -0
- package/src/utils/constants.ts +3 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/renderers.tsx +68 -0
- package/src/utils/utils.ts +63 -0
- package/src/vite-env.d.ts +17 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type RenderHookOptions,
|
|
5
|
+
type RenderHookResult,
|
|
6
|
+
render,
|
|
7
|
+
renderHook,
|
|
8
|
+
} from '@testing-library/react';
|
|
9
|
+
|
|
10
|
+
type WrapperParams = {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type Options = {
|
|
15
|
+
initialEntries?: string[];
|
|
16
|
+
renderHookOptions?: RenderHookOptions<unknown>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A custom testing-library component renderer that wraps the component being
|
|
21
|
+
* rendered with any Providers used in the app. Any test can pre-configure the
|
|
22
|
+
* Providers, to be in any state they wish.
|
|
23
|
+
*
|
|
24
|
+
* @param ui The component to render.
|
|
25
|
+
* @param options The options to configure any providers.
|
|
26
|
+
*
|
|
27
|
+
* @returns The rendered component.
|
|
28
|
+
*/
|
|
29
|
+
const customRender = (ui: ReactElement, options?: Options) => {
|
|
30
|
+
const { renderHookOptions } = options ?? {};
|
|
31
|
+
|
|
32
|
+
return render(ui, {
|
|
33
|
+
wrapper: ({ children }: WrapperParams): ReactElement => <>{children}</>,
|
|
34
|
+
...renderHookOptions,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A custom testing-library hook renderer that wraps the hook being rendered
|
|
40
|
+
* with any Providers used in the app. Any test can pre-configure the
|
|
41
|
+
* Providers, to be in any state they wish.
|
|
42
|
+
*
|
|
43
|
+
* @param callback A function wrapping the hook being rendered.
|
|
44
|
+
* @param options The options to configure any providers.
|
|
45
|
+
*
|
|
46
|
+
* @returns The rendered hook.
|
|
47
|
+
*/
|
|
48
|
+
const customRenderHook = <T, P>(
|
|
49
|
+
callback: () => unknown,
|
|
50
|
+
options?: Options,
|
|
51
|
+
): RenderHookResult<T, P> => {
|
|
52
|
+
const { renderHookOptions } = options ?? {};
|
|
53
|
+
|
|
54
|
+
const wrapper = ({ children }: WrapperParams): ReactElement => <>{children}</>;
|
|
55
|
+
|
|
56
|
+
const utils = renderHook(() => callback(), { wrapper, ...renderHookOptions });
|
|
57
|
+
|
|
58
|
+
return utils as RenderHookResult<T, P>;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { screen, waitFor, within, act } from '@testing-library/react';
|
|
62
|
+
export { default as userEvent } from '@testing-library/user-event';
|
|
63
|
+
|
|
64
|
+
// Override render export with our custom render function.
|
|
65
|
+
export { customRender as render };
|
|
66
|
+
|
|
67
|
+
// Override renderHook export with our custom renderHook function.
|
|
68
|
+
export { customRenderHook as renderHook };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { decode } from 'jsonwebtoken';
|
|
2
|
+
import { twMerge } from 'tailwind-merge';
|
|
3
|
+
|
|
4
|
+
import type { Credentials, DecodedJWT } from '../types';
|
|
5
|
+
|
|
6
|
+
export const decodeAuthToken = (token: string): Credentials | null => {
|
|
7
|
+
if (!token) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const user = decode(token) as unknown as DecodedJWT;
|
|
13
|
+
|
|
14
|
+
return { token, user };
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Utility function to merge Tailwind CSS classes with conflict resolution
|
|
22
|
+
* Uses tailwind-merge to handle conflicting utility classes
|
|
23
|
+
*/
|
|
24
|
+
export const cn = (...classes: (string | undefined | null | false)[]): string => {
|
|
25
|
+
return twMerge(classes.filter(Boolean).join(' '));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Debounce utility function
|
|
30
|
+
*/
|
|
31
|
+
export const debounce = <T extends (...args: never[]) => unknown>(
|
|
32
|
+
func: T,
|
|
33
|
+
wait: number,
|
|
34
|
+
): ((...args: Parameters<T>) => void) => {
|
|
35
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
36
|
+
|
|
37
|
+
return (...args: Parameters<T>) => {
|
|
38
|
+
const later = () => {
|
|
39
|
+
clearTimeout(timeout);
|
|
40
|
+
func(...args);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
clearTimeout(timeout);
|
|
44
|
+
timeout = setTimeout(later, wait);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Format bytes to human readable format
|
|
50
|
+
*/
|
|
51
|
+
export const formatBytes = (bytes: number, decimals = 2): string => {
|
|
52
|
+
if (bytes === 0) {
|
|
53
|
+
return '0 Bytes';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const k = 1024;
|
|
57
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
58
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
59
|
+
|
|
60
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
61
|
+
|
|
62
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
63
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
// CSS module declarations
|
|
4
|
+
declare module '*.css' {
|
|
5
|
+
const content: string;
|
|
6
|
+
export default content;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '*.scss' {
|
|
10
|
+
const content: string;
|
|
11
|
+
export default content;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.sass' {
|
|
15
|
+
const content: string;
|
|
16
|
+
export default content;
|
|
17
|
+
}
|