@react5/ui 1.0.26 → 1.0.28
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/LICENSE +21 -21
- package/README.md +2 -2
- package/package.json +38 -38
- package/packages/app/README.md +50 -50
- package/packages/app/eslint.config.js +28 -28
- package/packages/app/index.html +13 -13
- package/packages/app/jest.config.js +12 -12
- package/packages/app/package.json +36 -36
- package/packages/app/src/App.css +5 -5
- package/packages/app/src/App.tsx +35 -35
- package/packages/app/src/i18n/config.ts +21 -21
- package/packages/app/src/i18n/en/translation.json +4 -4
- package/packages/app/src/i18n/fr/translation.json +4 -4
- package/packages/app/src/i18n/index.ts +3 -3
- package/packages/app/src/main.tsx +16 -16
- package/packages/app/src/styles/1-reset.scss +72 -72
- package/packages/app/src/styles/2-colors.scss +11 -11
- package/packages/app/src/vite-env.d.ts +1 -1
- package/packages/app/tsconfig.app.json +26 -26
- package/packages/app/tsconfig.json +7 -7
- package/packages/app/tsconfig.node.json +24 -24
- package/packages/app/vite.config.ts +7 -7
- package/packages/lib/.babelrc +9 -9
- package/packages/lib/.storybook/main.js +50 -50
- package/packages/lib/.storybook/preview.js +13 -13
- package/packages/lib/declaration.d.ts +9 -9
- package/packages/lib/dist/esm/index.esm.css +0 -2
- package/packages/lib/dist/esm/index.esm.js +1 -1
- package/packages/lib/dist/esm/index.esm.js.map +1 -1
- package/packages/lib/dist/esm/index.esm.scss +1401 -1403
- package/packages/lib/dist/index.css +0 -2
- package/packages/lib/dist/index.js +1 -1
- package/packages/lib/dist/index.js.map +1 -1
- package/packages/lib/dist/index.scss +1401 -1403
- package/packages/lib/jest.config.js +19 -19
- package/packages/lib/package.json +100 -102
- package/packages/lib/plop/component/index.js +43 -43
- package/packages/lib/plop/index.js +3 -3
- package/packages/lib/plop/templates/component/component.hbs +19 -19
- package/packages/lib/plop/templates/component/index.hbs +1 -1
- package/packages/lib/plop/templates/component/stories.hbs +17 -17
- package/packages/lib/plop/templates/component/style.hbs +1 -1
- package/packages/lib/plop/templates/component/test.hbs +11 -11
- package/packages/lib/plopfile.js +1 -1
- package/packages/lib/rollup.config.mjs +64 -64
- package/packages/lib/src/components/Accordion/Accordion.scss +67 -67
- package/packages/lib/src/components/Accordion/Accordion.tsx +36 -36
- package/packages/lib/src/components/Button/Button.scss +60 -62
- package/packages/lib/src/components/Button/Button.stories.tsx +26 -26
- package/packages/lib/src/components/Button/Button.tsx +40 -40
- package/packages/lib/src/components/Button/index.tsx +1 -1
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.scss +3 -3
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.stories.tsx +17 -17
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.test.tsx +11 -11
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.tsx +17 -17
- package/packages/lib/src/components/ButtonsGroup/index.tsx +1 -1
- package/packages/lib/src/components/CheckBox/CheckBox.scss +63 -63
- package/packages/lib/src/components/CheckBox/CheckBox.stories.tsx +22 -22
- package/packages/lib/src/components/CheckBox/CheckBox.tsx +42 -42
- package/packages/lib/src/components/CheckBox/index.tsx +1 -1
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.scss +6 -6
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.stories.tsx +17 -17
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.test.tsx +11 -11
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.tsx +41 -41
- package/packages/lib/src/components/DialogPrompt/index.tsx +1 -1
- package/packages/lib/src/components/Divider/Divider.scss +22 -22
- package/packages/lib/src/components/Divider/Divider.tsx +20 -20
- package/packages/lib/src/components/DropDown/DropDown.scss +70 -70
- package/packages/lib/src/components/DropDown/DropDown.stories.tsx +45 -45
- package/packages/lib/src/components/DropDown/DropDown.tsx +61 -61
- package/packages/lib/src/components/DropDown/index.tsx +1 -1
- package/packages/lib/src/components/Form/Form.scss +3 -3
- package/packages/lib/src/components/Form/Form.stories.tsx +20 -20
- package/packages/lib/src/components/Form/Form.tsx +25 -25
- package/packages/lib/src/components/FormButtons/FormButtons.scss +5 -5
- package/packages/lib/src/components/FormButtons/FormButtons.tsx +18 -18
- package/packages/lib/src/components/HeaderButtons/HeaderButtons.scss +6 -6
- package/packages/lib/src/components/HeaderButtons/HeaderButtons.stories.tsx +17 -17
- package/packages/lib/src/components/HeaderButtons/HeaderButtons.test.tsx +11 -11
- package/packages/lib/src/components/HeaderButtons/HeaderButtons.tsx +28 -28
- package/packages/lib/src/components/HeaderButtons/index.tsx +1 -1
- package/packages/lib/src/components/IconButton/IconButton.scss +64 -64
- package/packages/lib/src/components/IconButton/IconButton.tsx +44 -44
- package/packages/lib/src/components/MenuItem/MenuItem.scss +13 -13
- package/packages/lib/src/components/MenuItem/MenuItem.tsx +36 -36
- package/packages/lib/src/components/Modal/Modal.scss +71 -71
- package/packages/lib/src/components/Modal/Modal.tsx +60 -60
- package/packages/lib/src/components/Navbar/Navbar.scss +52 -52
- package/packages/lib/src/components/Navbar/Navbar.stories.tsx +25 -25
- package/packages/lib/src/components/Navbar/Navbar.tsx +38 -38
- package/packages/lib/src/components/NavbarLink/NavbarLink.scss +15 -15
- package/packages/lib/src/components/NavbarLink/NavbarLink.tsx +34 -34
- package/packages/lib/src/components/NavbarMenu/NavbarMenu.scss +156 -156
- package/packages/lib/src/components/NavbarMenu/NavbarMenu.stories.tsx +24 -24
- package/packages/lib/src/components/NavbarMenu/NavbarMenu.tsx +72 -72
- package/packages/lib/src/components/Panel/Panel.scss +29 -29
- package/packages/lib/src/components/Panel/Panel.stories.tsx +32 -32
- package/packages/lib/src/components/Panel/Panel.test.tsx +11 -11
- package/packages/lib/src/components/Panel/Panel.tsx +29 -29
- package/packages/lib/src/components/Panel/index.tsx +1 -1
- package/packages/lib/src/components/Paper/Paper.scss +5 -5
- package/packages/lib/src/components/Paper/Paper.stories.tsx +18 -18
- package/packages/lib/src/components/Paper/Paper.tsx +18 -18
- package/packages/lib/src/components/Paper/index.tsx +1 -1
- package/packages/lib/src/components/RangeSlider/RangeSlider.scss +83 -83
- package/packages/lib/src/components/RangeSlider/RangeSlider.stories.tsx +24 -24
- package/packages/lib/src/components/RangeSlider/RangeSlider.tsx +150 -150
- package/packages/lib/src/components/ResponsiveBar/ResponsiveBar.scss +72 -72
- package/packages/lib/src/components/ResponsiveBar/ResponsiveBar.tsx +38 -38
- package/packages/lib/src/components/ScrollView/ScrollView.scss +20 -20
- package/packages/lib/src/components/ScrollView/ScrollView.stories.tsx +17 -17
- package/packages/lib/src/components/ScrollView/ScrollView.test.tsx +11 -11
- package/packages/lib/src/components/ScrollView/ScrollView.tsx +19 -19
- package/packages/lib/src/components/ScrollView/index.tsx +1 -1
- package/packages/lib/src/components/Section/Section.scss +17 -17
- package/packages/lib/src/components/Section/Section.tsx +26 -26
- package/packages/lib/src/components/SelectField/SelectField.scss +42 -42
- package/packages/lib/src/components/SelectField/SelectField.stories.tsx +14 -14
- package/packages/lib/src/components/SelectField/SelectField.tsx +54 -54
- package/packages/lib/src/components/SelectField/index.tsx +1 -1
- package/packages/lib/src/components/Spacer/Spacer.scss +2 -2
- package/packages/lib/src/components/Spacer/Spacer.tsx +6 -6
- package/packages/lib/src/components/StackPanel/StackPanel.scss +8 -8
- package/packages/lib/src/components/StackPanel/StackPanel.stories.tsx +17 -17
- package/packages/lib/src/components/StackPanel/StackPanel.test.tsx +11 -11
- package/packages/lib/src/components/StackPanel/StackPanel.tsx +31 -31
- package/packages/lib/src/components/StackPanel/index.tsx +1 -1
- package/packages/lib/src/components/Submenu/Submenu.scss +55 -55
- package/packages/lib/src/components/Submenu/Submenu.stories.tsx +45 -45
- package/packages/lib/src/components/Submenu/Submenu.tsx +59 -59
- package/packages/lib/src/components/Submenu/index.tsx +1 -1
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.scss +75 -75
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.stories.tsx +17 -17
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.test.tsx +11 -11
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.tsx +63 -63
- package/packages/lib/src/components/SuccessCongratulation/index.tsx +1 -1
- package/packages/lib/src/components/TextArea/TextArea.scss +41 -41
- package/packages/lib/src/components/TextArea/TextArea.stories.tsx +14 -14
- package/packages/lib/src/components/TextArea/TextArea.tsx +50 -50
- package/packages/lib/src/components/TextArea/index.tsx +1 -1
- package/packages/lib/src/components/TextField/TextField.scss +56 -56
- package/packages/lib/src/components/TextField/TextField.stories.tsx +14 -14
- package/packages/lib/src/components/TextField/TextField.tsx +89 -89
- package/packages/lib/src/components/TextField/index.tsx +1 -1
- package/packages/lib/src/components/TitleEdit/TitleEdit.scss +17 -17
- package/packages/lib/src/components/TitleEdit/TitleEdit.tsx +69 -69
- package/packages/lib/src/components/Toast/Toast.scss +32 -32
- package/packages/lib/src/components/Toast/Toast.tsx +29 -29
- package/packages/lib/src/components/ToggleButton/ToggleButton.scss +47 -47
- package/packages/lib/src/components/ToggleButton/ToggleButton.stories.tsx +22 -22
- package/packages/lib/src/components/ToggleButton/ToggleButton.tsx +41 -41
- package/packages/lib/src/components/ToggleButton/index.tsx +1 -1
- package/packages/lib/src/components/Toolbar/Toolbar.scss +16 -16
- package/packages/lib/src/components/Toolbar/Toolbar.stories.tsx +17 -17
- package/packages/lib/src/components/Toolbar/Toolbar.test.tsx +11 -11
- package/packages/lib/src/components/Toolbar/Toolbar.tsx +20 -20
- package/packages/lib/src/components/Toolbar/index.tsx +1 -1
- package/packages/lib/src/components/Typography/Typography.scss +51 -51
- package/packages/lib/src/components/Typography/Typography.stories.tsx +18 -18
- package/packages/lib/src/components/Typography/Typography.tsx +19 -19
- package/packages/lib/src/components/index.tsx +34 -34
- package/packages/lib/src/hooks/index.tsx +3 -3
- package/packages/lib/src/hooks/use-click-outside.tsx +19 -19
- package/packages/lib/src/hooks/use-form.tsx +107 -107
- package/packages/lib/src/hooks/use-keys-enteresc.tsx +25 -25
- package/packages/lib/src/hooks/use-set-startup-focus.tsx +8 -8
- package/packages/lib/src/i18n/config.ts +8 -8
- package/packages/lib/src/i18n/en/translation.json +11 -11
- package/packages/lib/src/i18n/fr/translation.json +11 -11
- package/packages/lib/src/i18n/index.ts +11 -11
- package/packages/lib/src/index.tsx +7 -7
- package/packages/lib/src/stories/Intrduction.mdx +171 -171
- package/packages/lib/src/stories/assets/github.svg +3 -3
- package/packages/lib/src/styles/1-color-vars.scss +51 -51
- package/packages/lib/src/styles/2-font-variables.scss +2 -2
- package/packages/lib/src/styles/variables.scss +1 -1
- package/packages/lib/src/test/i18n.ts +17 -17
- package/packages/lib/src/utils/bem.ts +4 -4
- package/packages/lib/src/utils/formatError.ts +5 -5
- package/packages/lib/src/utils/index.ts +1 -1
- package/packages/lib/src/utils/interfaces.ts +5 -5
- package/packages/lib/tsconfig.json +26 -25
- package/packages/lib/vite.config.js +18 -18
- package/packages/ui-test/package-lock.json +97 -97
- package/packages/ui-test/package.json +19 -19
- package/packages/ui-test/playwright.config.ts +80 -80
- package/packages/ui-test/tests/example.spec.ts +18 -18
- package/packages/ui-test/tests-examples/demo-todo-app.spec.ts +437 -437
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { ReactNode } from "react"
|
|
2
|
-
import './Typography.scss'
|
|
3
|
-
import clsx from "clsx";
|
|
4
|
-
import { bem } from '../../utils/bem';
|
|
5
|
-
|
|
6
|
-
export interface ITypographyProps {
|
|
7
|
-
onClick?: () => void;
|
|
8
|
-
children: ReactNode
|
|
9
|
-
className?: string
|
|
10
|
-
variant?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'li' | 'div',
|
|
11
|
-
align?: "left" | "center" | "right";
|
|
12
|
-
}
|
|
13
|
-
const b = bem("typography");
|
|
14
|
-
export const Typography = ({children, onClick, className, align = "left", variant: Variant = "p"}: ITypographyProps) => {
|
|
15
|
-
return (
|
|
16
|
-
<Variant
|
|
17
|
-
className={clsx(b(), b(Variant), b(align), className)}
|
|
18
|
-
onClick={onClick}
|
|
19
|
-
>{children}</Variant>)
|
|
1
|
+
import { ReactNode } from "react"
|
|
2
|
+
import './Typography.scss'
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { bem } from '../../utils/bem';
|
|
5
|
+
|
|
6
|
+
export interface ITypographyProps {
|
|
7
|
+
onClick?: () => void;
|
|
8
|
+
children: ReactNode
|
|
9
|
+
className?: string
|
|
10
|
+
variant?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'li' | 'div',
|
|
11
|
+
align?: "left" | "center" | "right";
|
|
12
|
+
}
|
|
13
|
+
const b = bem("typography");
|
|
14
|
+
export const Typography = ({children, onClick, className, align = "left", variant: Variant = "p"}: ITypographyProps) => {
|
|
15
|
+
return (
|
|
16
|
+
<Variant
|
|
17
|
+
className={clsx(b(), b(Variant), b(align), className)}
|
|
18
|
+
onClick={onClick}
|
|
19
|
+
>{children}</Variant>)
|
|
20
20
|
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export * from "./Accordion";
|
|
2
|
-
export * from "./Button";
|
|
3
|
-
export * from "./ButtonsGroup";
|
|
4
|
-
export * from "./CheckBox";
|
|
5
|
-
export * from "./DialogPrompt";
|
|
6
|
-
export * from "./Divider";
|
|
7
|
-
export * from "./DropDown";
|
|
8
|
-
export * from "./Form";
|
|
9
|
-
export * from "./FormButtons";
|
|
10
|
-
export * from "./IconButton";
|
|
11
|
-
export * from "./MenuItem";
|
|
12
|
-
export * from "./Modal";
|
|
13
|
-
export * from "./Navbar";
|
|
14
|
-
export * from "./NavbarLink";
|
|
15
|
-
export * from "./NavbarMenu";
|
|
16
|
-
export * from "./Panel";
|
|
17
|
-
export * from "./Paper";
|
|
18
|
-
export * from "./RangeSlider";
|
|
19
|
-
export * from "./ResponsiveBar";
|
|
20
|
-
export * from "./ScrollView";
|
|
21
|
-
export * from "./Section";
|
|
22
|
-
export * from "./SelectField";
|
|
23
|
-
export * from "./Spacer";
|
|
24
|
-
export * from "./StackPanel";
|
|
25
|
-
export * from "./Submenu";
|
|
26
|
-
export * from "./SuccessCongratulation";
|
|
27
|
-
export * from "./TextArea";
|
|
28
|
-
export * from "./TextField";
|
|
29
|
-
export * from "./TitleEdit";
|
|
30
|
-
export * from "./Toast";
|
|
31
|
-
export * from "./ToggleButton";
|
|
32
|
-
export * from "./Toolbar";
|
|
33
|
-
export * from "./Typography";
|
|
34
|
-
|
|
1
|
+
export * from "./Accordion";
|
|
2
|
+
export * from "./Button";
|
|
3
|
+
export * from "./ButtonsGroup";
|
|
4
|
+
export * from "./CheckBox";
|
|
5
|
+
export * from "./DialogPrompt";
|
|
6
|
+
export * from "./Divider";
|
|
7
|
+
export * from "./DropDown";
|
|
8
|
+
export * from "./Form";
|
|
9
|
+
export * from "./FormButtons";
|
|
10
|
+
export * from "./IconButton";
|
|
11
|
+
export * from "./MenuItem";
|
|
12
|
+
export * from "./Modal";
|
|
13
|
+
export * from "./Navbar";
|
|
14
|
+
export * from "./NavbarLink";
|
|
15
|
+
export * from "./NavbarMenu";
|
|
16
|
+
export * from "./Panel";
|
|
17
|
+
export * from "./Paper";
|
|
18
|
+
export * from "./RangeSlider";
|
|
19
|
+
export * from "./ResponsiveBar";
|
|
20
|
+
export * from "./ScrollView";
|
|
21
|
+
export * from "./Section";
|
|
22
|
+
export * from "./SelectField";
|
|
23
|
+
export * from "./Spacer";
|
|
24
|
+
export * from "./StackPanel";
|
|
25
|
+
export * from "./Submenu";
|
|
26
|
+
export * from "./SuccessCongratulation";
|
|
27
|
+
export * from "./TextArea";
|
|
28
|
+
export * from "./TextField";
|
|
29
|
+
export * from "./TitleEdit";
|
|
30
|
+
export * from "./Toast";
|
|
31
|
+
export * from "./ToggleButton";
|
|
32
|
+
export * from "./Toolbar";
|
|
33
|
+
export * from "./Typography";
|
|
34
|
+
|
|
35
35
|
export * from './HeaderButtons'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './use-click-outside'
|
|
2
|
-
export * from './use-keys-enteresc'
|
|
3
|
-
export * from './use-set-startup-focus'
|
|
1
|
+
export * from './use-click-outside'
|
|
2
|
+
export * from './use-keys-enteresc'
|
|
3
|
+
export * from './use-set-startup-focus'
|
|
4
4
|
export * from './use-form'
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { RefObject, useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
export function useClickOutside(refs: RefObject<HTMLElement | null>[], onClickOutside: () => void) {
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
const handleClickOutside = (event: MouseEvent) => {
|
|
6
|
-
const isOutside = refs.every(ref => ref.current && !ref.current.contains(event.target as Node));
|
|
7
|
-
if (isOutside) {
|
|
8
|
-
onClickOutside();
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
13
|
-
|
|
14
|
-
return () => {
|
|
15
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
16
|
-
};
|
|
17
|
-
}, [refs, onClickOutside]);
|
|
18
|
-
}
|
|
19
|
-
|
|
1
|
+
import { RefObject, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
export function useClickOutside(refs: RefObject<HTMLElement | null>[], onClickOutside: () => void) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
6
|
+
const isOutside = refs.every(ref => ref.current && !ref.current.contains(event.target as Node));
|
|
7
|
+
if (isOutside) {
|
|
8
|
+
onClickOutside();
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
13
|
+
|
|
14
|
+
return () => {
|
|
15
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
16
|
+
};
|
|
17
|
+
}, [refs, onClickOutside]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
20
|
export default useClickOutside;
|
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import { useState, ChangeEvent, FormEvent } from 'react';
|
|
2
|
-
|
|
3
|
-
type FormFields = Record<string, any>;
|
|
4
|
-
type Validator<T> = (values: T) => Partial<Record<keyof T, string>>;
|
|
5
|
-
|
|
6
|
-
type ChEv = ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>;
|
|
7
|
-
interface IRegisterInfo {
|
|
8
|
-
name: string,
|
|
9
|
-
onChange: (e: ChEv) => (void),
|
|
10
|
-
value?: any,
|
|
11
|
-
checked?: boolean,
|
|
12
|
-
error?: string
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
interface IRegisterInfo2 {
|
|
16
|
-
name: string,
|
|
17
|
-
onChange: (v: any) => (void),
|
|
18
|
-
value?: any,
|
|
19
|
-
checked?: boolean,
|
|
20
|
-
error?: string
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export function useForm<T extends FormFields>(
|
|
24
|
-
initialValues: T,
|
|
25
|
-
validate?: Validator<T>
|
|
26
|
-
) {
|
|
27
|
-
const [values, setValues] = useState<T>(initialValues);
|
|
28
|
-
const [errors, setErrors] = useState<Partial<Record<keyof T, string>>>({});
|
|
29
|
-
|
|
30
|
-
// Standard change handler for native elements
|
|
31
|
-
const handleChange = (
|
|
32
|
-
e: ChEv
|
|
33
|
-
) => {
|
|
34
|
-
const { name, type, value } = e.target;
|
|
35
|
-
const fieldValue = type === 'checkbox' ? (e.target as HTMLInputElement).checked : value;
|
|
36
|
-
|
|
37
|
-
setValues((prevValues) => {
|
|
38
|
-
const newValues = { ...prevValues, [name]: fieldValue };
|
|
39
|
-
if (validate) {
|
|
40
|
-
const newErrors = validate(newValues);
|
|
41
|
-
setErrors(newErrors);
|
|
42
|
-
}
|
|
43
|
-
return newValues;
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const handleCustomChange = (name: string) => (v: any) => {
|
|
48
|
-
const fieldValue = v;
|
|
49
|
-
|
|
50
|
-
setValues((prevValues) => {
|
|
51
|
-
const newValues = { ...prevValues, [name]: fieldValue };
|
|
52
|
-
if (validate) {
|
|
53
|
-
const newErrors = validate(newValues);
|
|
54
|
-
setErrors(newErrors);
|
|
55
|
-
}
|
|
56
|
-
return newValues;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// New helper: update a specific field directly.
|
|
61
|
-
const setFieldValue = <K extends keyof T>(field: K, value: T[K]) => {
|
|
62
|
-
setValues((prevValues) => {
|
|
63
|
-
const newValues = { ...prevValues, [field]: value };
|
|
64
|
-
if (validate) {
|
|
65
|
-
const newErrors = validate(newValues);
|
|
66
|
-
setErrors(newErrors);
|
|
67
|
-
}
|
|
68
|
-
return newValues;
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const validateForm = (): Partial<Record<keyof T, string>> => {
|
|
73
|
-
if (validate) {
|
|
74
|
-
const newErrors = validate(values);
|
|
75
|
-
setErrors(newErrors);
|
|
76
|
-
return newErrors;
|
|
77
|
-
}
|
|
78
|
-
return {};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const reset = (newValues = initialValues) => {
|
|
82
|
-
setValues(newValues);
|
|
83
|
-
setErrors({});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const register = (name: string): IRegisterInfo => {
|
|
87
|
-
const cm = {name, value: values[name] || '', checked: values[name] || false, error: errors[name]};
|
|
88
|
-
return {...cm, onChange: handleChange };
|
|
89
|
-
}
|
|
90
|
-
const registerC = (name: string): IRegisterInfo2 => {
|
|
91
|
-
const cm = {name, value: values[name] || '', checked: values[name] || false, error: errors[name]};
|
|
92
|
-
return {...cm, onChange: handleCustomChange(name) };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const handleFormSubmit = (onUserSubmit?: (data: T) => void) => (e: FormEvent<HTMLFormElement>) => {
|
|
96
|
-
e.preventDefault();
|
|
97
|
-
onUserSubmit?.(values);
|
|
98
|
-
|
|
99
|
-
reset();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const registerForm = (onUserSubmit?: (data: T) => void) => {
|
|
103
|
-
return { onSubmit: handleFormSubmit(onUserSubmit) };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return { values, errors, handleChange, setFieldValue, reset, setValues, validateForm, register, registerC, registerForm };
|
|
107
|
-
}
|
|
1
|
+
import { useState, ChangeEvent, FormEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
type FormFields = Record<string, any>;
|
|
4
|
+
type Validator<T> = (values: T) => Partial<Record<keyof T, string>>;
|
|
5
|
+
|
|
6
|
+
type ChEv = ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>;
|
|
7
|
+
interface IRegisterInfo {
|
|
8
|
+
name: string,
|
|
9
|
+
onChange: (e: ChEv) => (void),
|
|
10
|
+
value?: any,
|
|
11
|
+
checked?: boolean,
|
|
12
|
+
error?: string
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
interface IRegisterInfo2 {
|
|
16
|
+
name: string,
|
|
17
|
+
onChange: (v: any) => (void),
|
|
18
|
+
value?: any,
|
|
19
|
+
checked?: boolean,
|
|
20
|
+
error?: string
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function useForm<T extends FormFields>(
|
|
24
|
+
initialValues: T,
|
|
25
|
+
validate?: Validator<T>
|
|
26
|
+
) {
|
|
27
|
+
const [values, setValues] = useState<T>(initialValues);
|
|
28
|
+
const [errors, setErrors] = useState<Partial<Record<keyof T, string>>>({});
|
|
29
|
+
|
|
30
|
+
// Standard change handler for native elements
|
|
31
|
+
const handleChange = (
|
|
32
|
+
e: ChEv
|
|
33
|
+
) => {
|
|
34
|
+
const { name, type, value } = e.target;
|
|
35
|
+
const fieldValue = type === 'checkbox' ? (e.target as HTMLInputElement).checked : value;
|
|
36
|
+
|
|
37
|
+
setValues((prevValues) => {
|
|
38
|
+
const newValues = { ...prevValues, [name]: fieldValue };
|
|
39
|
+
if (validate) {
|
|
40
|
+
const newErrors = validate(newValues);
|
|
41
|
+
setErrors(newErrors);
|
|
42
|
+
}
|
|
43
|
+
return newValues;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleCustomChange = (name: string) => (v: any) => {
|
|
48
|
+
const fieldValue = v;
|
|
49
|
+
|
|
50
|
+
setValues((prevValues) => {
|
|
51
|
+
const newValues = { ...prevValues, [name]: fieldValue };
|
|
52
|
+
if (validate) {
|
|
53
|
+
const newErrors = validate(newValues);
|
|
54
|
+
setErrors(newErrors);
|
|
55
|
+
}
|
|
56
|
+
return newValues;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// New helper: update a specific field directly.
|
|
61
|
+
const setFieldValue = <K extends keyof T>(field: K, value: T[K]) => {
|
|
62
|
+
setValues((prevValues) => {
|
|
63
|
+
const newValues = { ...prevValues, [field]: value };
|
|
64
|
+
if (validate) {
|
|
65
|
+
const newErrors = validate(newValues);
|
|
66
|
+
setErrors(newErrors);
|
|
67
|
+
}
|
|
68
|
+
return newValues;
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const validateForm = (): Partial<Record<keyof T, string>> => {
|
|
73
|
+
if (validate) {
|
|
74
|
+
const newErrors = validate(values);
|
|
75
|
+
setErrors(newErrors);
|
|
76
|
+
return newErrors;
|
|
77
|
+
}
|
|
78
|
+
return {};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const reset = (newValues = initialValues) => {
|
|
82
|
+
setValues(newValues);
|
|
83
|
+
setErrors({});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const register = (name: string): IRegisterInfo => {
|
|
87
|
+
const cm = {name, value: values[name] || '', checked: values[name] || false, error: errors[name]};
|
|
88
|
+
return {...cm, onChange: handleChange };
|
|
89
|
+
}
|
|
90
|
+
const registerC = (name: string): IRegisterInfo2 => {
|
|
91
|
+
const cm = {name, value: values[name] || '', checked: values[name] || false, error: errors[name]};
|
|
92
|
+
return {...cm, onChange: handleCustomChange(name) };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const handleFormSubmit = (onUserSubmit?: (data: T) => void) => (e: FormEvent<HTMLFormElement>) => {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
onUserSubmit?.(values);
|
|
98
|
+
|
|
99
|
+
reset();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const registerForm = (onUserSubmit?: (data: T) => void) => {
|
|
103
|
+
return { onSubmit: handleFormSubmit(onUserSubmit) };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { values, errors, handleChange, setFieldValue, reset, setValues, validateForm, register, registerC, registerForm };
|
|
107
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { useEffect, RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
export function useKeysEneterEsc(inputRef: RefObject<HTMLInputElement|null>, onOk: () => void, onCancel?: () => void) {
|
|
4
|
-
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
const handleKeyDown = (e: KeyboardEvent) => {
|
|
7
|
-
|
|
8
|
-
if (e.key === 'Enter') {
|
|
9
|
-
onOk();
|
|
10
|
-
e.preventDefault();
|
|
11
|
-
} else if (e.key === 'Escape') {
|
|
12
|
-
onCancel && onCancel();
|
|
13
|
-
e.preventDefault();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const inputElement = inputRef.current;
|
|
17
|
-
if (inputElement) {
|
|
18
|
-
inputElement.addEventListener('keydown', handleKeyDown);
|
|
19
|
-
}
|
|
20
|
-
return () => {
|
|
21
|
-
if (inputElement) {
|
|
22
|
-
inputElement.removeEventListener('keydown', handleKeyDown);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}, [inputRef, onOk, onCancel]);
|
|
1
|
+
import { useEffect, RefObject } from "react";
|
|
2
|
+
|
|
3
|
+
export function useKeysEneterEsc(inputRef: RefObject<HTMLInputElement|null>, onOk: () => void, onCancel?: () => void) {
|
|
4
|
+
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
7
|
+
|
|
8
|
+
if (e.key === 'Enter') {
|
|
9
|
+
onOk();
|
|
10
|
+
e.preventDefault();
|
|
11
|
+
} else if (e.key === 'Escape') {
|
|
12
|
+
onCancel && onCancel();
|
|
13
|
+
e.preventDefault();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const inputElement = inputRef.current;
|
|
17
|
+
if (inputElement) {
|
|
18
|
+
inputElement.addEventListener('keydown', handleKeyDown);
|
|
19
|
+
}
|
|
20
|
+
return () => {
|
|
21
|
+
if (inputElement) {
|
|
22
|
+
inputElement.removeEventListener('keydown', handleKeyDown);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}, [inputRef, onOk, onCancel]);
|
|
26
26
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { RefObject, useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
export function useSetStartupFocus(inputRef: RefObject<HTMLElement | null>, enabled: boolean = true) {
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
if (enabled && inputRef.current) {
|
|
6
|
-
inputRef.current.focus();
|
|
7
|
-
}
|
|
8
|
-
}, [enabled, inputRef]);
|
|
1
|
+
import { RefObject, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
export function useSetStartupFocus(inputRef: RefObject<HTMLElement | null>, enabled: boolean = true) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (enabled && inputRef.current) {
|
|
6
|
+
inputRef.current.focus();
|
|
7
|
+
}
|
|
8
|
+
}, [enabled, inputRef]);
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type i18n } from 'i18next';
|
|
2
|
-
import en from './en/translation.json';
|
|
3
|
-
import fr from './fr/translation.json';
|
|
4
|
-
import { translationNs } from './ns';
|
|
5
|
-
|
|
6
|
-
export function addTranslations(n: i18n) {
|
|
7
|
-
n.addResourceBundle('en', translationNs, en, true, true);
|
|
8
|
-
n.addResourceBundle('fr', translationNs, fr, true, true);
|
|
1
|
+
import { type i18n } from 'i18next';
|
|
2
|
+
import en from './en/translation.json';
|
|
3
|
+
import fr from './fr/translation.json';
|
|
4
|
+
import { translationNs } from './ns';
|
|
5
|
+
|
|
6
|
+
export function addTranslations(n: i18n) {
|
|
7
|
+
n.addResourceBundle('en', translationNs, en, true, true);
|
|
8
|
+
n.addResourceBundle('fr', translationNs, fr, true, true);
|
|
9
9
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"core": {
|
|
3
|
-
"edit": "Edit",
|
|
4
|
-
"view": "View",
|
|
5
|
-
"name": "Name",
|
|
6
|
-
"title": "Title",
|
|
7
|
-
"description": "Description",
|
|
8
|
-
"next": "Next",
|
|
9
|
-
"previous": "Previous",
|
|
10
|
-
"settings": "Settings"
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"core": {
|
|
3
|
+
"edit": "Edit",
|
|
4
|
+
"view": "View",
|
|
5
|
+
"name": "Name",
|
|
6
|
+
"title": "Title",
|
|
7
|
+
"description": "Description",
|
|
8
|
+
"next": "Next",
|
|
9
|
+
"previous": "Previous",
|
|
10
|
+
"settings": "Settings"
|
|
11
|
+
}
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"core": {
|
|
3
|
-
"view": "Voir",
|
|
4
|
-
"edit": "Editer",
|
|
5
|
-
"name": "Nom",
|
|
6
|
-
"title": "Titre",
|
|
7
|
-
"description": "Description",
|
|
8
|
-
"next": "Suivant",
|
|
9
|
-
"previous": "Précédent",
|
|
10
|
-
"settings": "Paramètres"
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"core": {
|
|
3
|
+
"view": "Voir",
|
|
4
|
+
"edit": "Editer",
|
|
5
|
+
"name": "Nom",
|
|
6
|
+
"title": "Titre",
|
|
7
|
+
"description": "Description",
|
|
8
|
+
"next": "Suivant",
|
|
9
|
+
"previous": "Précédent",
|
|
10
|
+
"settings": "Paramètres"
|
|
11
|
+
}
|
|
12
12
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './config';
|
|
2
|
-
|
|
3
|
-
export function ta(t: Function, key: string, options?: any): string[] | null {
|
|
4
|
-
const a = t(key, { ...options, returnObjects: true }) as unknown;
|
|
5
|
-
return Array.isArray(a) ? a as string[] : null;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function to(t: Function, key: string, options?: any): unknown | null {
|
|
9
|
-
const a = t(key, { ...options, returnObjects: true }) as unknown;
|
|
10
|
-
return a;
|
|
11
|
-
}
|
|
1
|
+
export * from './config';
|
|
2
|
+
|
|
3
|
+
export function ta(t: Function, key: string, options?: any): string[] | null {
|
|
4
|
+
const a = t(key, { ...options, returnObjects: true }) as unknown;
|
|
5
|
+
return Array.isArray(a) ? a as string[] : null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function to(t: Function, key: string, options?: any): unknown | null {
|
|
9
|
+
const a = t(key, { ...options, returnObjects: true }) as unknown;
|
|
10
|
+
return a;
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./styles/1-color-vars.scss";
|
|
2
|
-
import "./styles/2-font-variables.scss";
|
|
3
|
-
import "./index.scss";
|
|
4
|
-
export * from "./i18n";
|
|
5
|
-
export * from "./components";
|
|
6
|
-
export * from "./utils";
|
|
7
|
-
export * from "./hooks";
|
|
1
|
+
import "./styles/1-color-vars.scss";
|
|
2
|
+
import "./styles/2-font-variables.scss";
|
|
3
|
+
import "./index.scss";
|
|
4
|
+
export * from "./i18n";
|
|
5
|
+
export * from "./components";
|
|
6
|
+
export * from "./utils";
|
|
7
|
+
export * from "./hooks";
|