@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.
Files changed (188) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/package.json +38 -38
  4. package/packages/app/README.md +50 -50
  5. package/packages/app/eslint.config.js +28 -28
  6. package/packages/app/index.html +13 -13
  7. package/packages/app/jest.config.js +12 -12
  8. package/packages/app/package.json +36 -36
  9. package/packages/app/src/App.css +5 -5
  10. package/packages/app/src/App.tsx +35 -35
  11. package/packages/app/src/i18n/config.ts +21 -21
  12. package/packages/app/src/i18n/en/translation.json +4 -4
  13. package/packages/app/src/i18n/fr/translation.json +4 -4
  14. package/packages/app/src/i18n/index.ts +3 -3
  15. package/packages/app/src/main.tsx +16 -16
  16. package/packages/app/src/styles/1-reset.scss +72 -72
  17. package/packages/app/src/styles/2-colors.scss +11 -11
  18. package/packages/app/src/vite-env.d.ts +1 -1
  19. package/packages/app/tsconfig.app.json +26 -26
  20. package/packages/app/tsconfig.json +7 -7
  21. package/packages/app/tsconfig.node.json +24 -24
  22. package/packages/app/vite.config.ts +7 -7
  23. package/packages/lib/.babelrc +9 -9
  24. package/packages/lib/.storybook/main.js +50 -50
  25. package/packages/lib/.storybook/preview.js +13 -13
  26. package/packages/lib/declaration.d.ts +9 -9
  27. package/packages/lib/dist/esm/index.esm.css +0 -2
  28. package/packages/lib/dist/esm/index.esm.js +1 -1
  29. package/packages/lib/dist/esm/index.esm.js.map +1 -1
  30. package/packages/lib/dist/esm/index.esm.scss +1401 -1403
  31. package/packages/lib/dist/index.css +0 -2
  32. package/packages/lib/dist/index.js +1 -1
  33. package/packages/lib/dist/index.js.map +1 -1
  34. package/packages/lib/dist/index.scss +1401 -1403
  35. package/packages/lib/jest.config.js +19 -19
  36. package/packages/lib/package.json +100 -102
  37. package/packages/lib/plop/component/index.js +43 -43
  38. package/packages/lib/plop/index.js +3 -3
  39. package/packages/lib/plop/templates/component/component.hbs +19 -19
  40. package/packages/lib/plop/templates/component/index.hbs +1 -1
  41. package/packages/lib/plop/templates/component/stories.hbs +17 -17
  42. package/packages/lib/plop/templates/component/style.hbs +1 -1
  43. package/packages/lib/plop/templates/component/test.hbs +11 -11
  44. package/packages/lib/plopfile.js +1 -1
  45. package/packages/lib/rollup.config.mjs +64 -64
  46. package/packages/lib/src/components/Accordion/Accordion.scss +67 -67
  47. package/packages/lib/src/components/Accordion/Accordion.tsx +36 -36
  48. package/packages/lib/src/components/Button/Button.scss +60 -62
  49. package/packages/lib/src/components/Button/Button.stories.tsx +26 -26
  50. package/packages/lib/src/components/Button/Button.tsx +40 -40
  51. package/packages/lib/src/components/Button/index.tsx +1 -1
  52. package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.scss +3 -3
  53. package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.stories.tsx +17 -17
  54. package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.test.tsx +11 -11
  55. package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.tsx +17 -17
  56. package/packages/lib/src/components/ButtonsGroup/index.tsx +1 -1
  57. package/packages/lib/src/components/CheckBox/CheckBox.scss +63 -63
  58. package/packages/lib/src/components/CheckBox/CheckBox.stories.tsx +22 -22
  59. package/packages/lib/src/components/CheckBox/CheckBox.tsx +42 -42
  60. package/packages/lib/src/components/CheckBox/index.tsx +1 -1
  61. package/packages/lib/src/components/DialogPrompt/DialogPrompt.scss +6 -6
  62. package/packages/lib/src/components/DialogPrompt/DialogPrompt.stories.tsx +17 -17
  63. package/packages/lib/src/components/DialogPrompt/DialogPrompt.test.tsx +11 -11
  64. package/packages/lib/src/components/DialogPrompt/DialogPrompt.tsx +41 -41
  65. package/packages/lib/src/components/DialogPrompt/index.tsx +1 -1
  66. package/packages/lib/src/components/Divider/Divider.scss +22 -22
  67. package/packages/lib/src/components/Divider/Divider.tsx +20 -20
  68. package/packages/lib/src/components/DropDown/DropDown.scss +70 -70
  69. package/packages/lib/src/components/DropDown/DropDown.stories.tsx +45 -45
  70. package/packages/lib/src/components/DropDown/DropDown.tsx +61 -61
  71. package/packages/lib/src/components/DropDown/index.tsx +1 -1
  72. package/packages/lib/src/components/Form/Form.scss +3 -3
  73. package/packages/lib/src/components/Form/Form.stories.tsx +20 -20
  74. package/packages/lib/src/components/Form/Form.tsx +25 -25
  75. package/packages/lib/src/components/FormButtons/FormButtons.scss +5 -5
  76. package/packages/lib/src/components/FormButtons/FormButtons.tsx +18 -18
  77. package/packages/lib/src/components/HeaderButtons/HeaderButtons.scss +6 -6
  78. package/packages/lib/src/components/HeaderButtons/HeaderButtons.stories.tsx +17 -17
  79. package/packages/lib/src/components/HeaderButtons/HeaderButtons.test.tsx +11 -11
  80. package/packages/lib/src/components/HeaderButtons/HeaderButtons.tsx +28 -28
  81. package/packages/lib/src/components/HeaderButtons/index.tsx +1 -1
  82. package/packages/lib/src/components/IconButton/IconButton.scss +64 -64
  83. package/packages/lib/src/components/IconButton/IconButton.tsx +44 -44
  84. package/packages/lib/src/components/MenuItem/MenuItem.scss +13 -13
  85. package/packages/lib/src/components/MenuItem/MenuItem.tsx +36 -36
  86. package/packages/lib/src/components/Modal/Modal.scss +71 -71
  87. package/packages/lib/src/components/Modal/Modal.tsx +60 -60
  88. package/packages/lib/src/components/Navbar/Navbar.scss +52 -52
  89. package/packages/lib/src/components/Navbar/Navbar.stories.tsx +25 -25
  90. package/packages/lib/src/components/Navbar/Navbar.tsx +38 -38
  91. package/packages/lib/src/components/NavbarLink/NavbarLink.scss +15 -15
  92. package/packages/lib/src/components/NavbarLink/NavbarLink.tsx +34 -34
  93. package/packages/lib/src/components/NavbarMenu/NavbarMenu.scss +156 -156
  94. package/packages/lib/src/components/NavbarMenu/NavbarMenu.stories.tsx +24 -24
  95. package/packages/lib/src/components/NavbarMenu/NavbarMenu.tsx +72 -72
  96. package/packages/lib/src/components/Panel/Panel.scss +29 -29
  97. package/packages/lib/src/components/Panel/Panel.stories.tsx +32 -32
  98. package/packages/lib/src/components/Panel/Panel.test.tsx +11 -11
  99. package/packages/lib/src/components/Panel/Panel.tsx +29 -29
  100. package/packages/lib/src/components/Panel/index.tsx +1 -1
  101. package/packages/lib/src/components/Paper/Paper.scss +5 -5
  102. package/packages/lib/src/components/Paper/Paper.stories.tsx +18 -18
  103. package/packages/lib/src/components/Paper/Paper.tsx +18 -18
  104. package/packages/lib/src/components/Paper/index.tsx +1 -1
  105. package/packages/lib/src/components/RangeSlider/RangeSlider.scss +83 -83
  106. package/packages/lib/src/components/RangeSlider/RangeSlider.stories.tsx +24 -24
  107. package/packages/lib/src/components/RangeSlider/RangeSlider.tsx +150 -150
  108. package/packages/lib/src/components/ResponsiveBar/ResponsiveBar.scss +72 -72
  109. package/packages/lib/src/components/ResponsiveBar/ResponsiveBar.tsx +38 -38
  110. package/packages/lib/src/components/ScrollView/ScrollView.scss +20 -20
  111. package/packages/lib/src/components/ScrollView/ScrollView.stories.tsx +17 -17
  112. package/packages/lib/src/components/ScrollView/ScrollView.test.tsx +11 -11
  113. package/packages/lib/src/components/ScrollView/ScrollView.tsx +19 -19
  114. package/packages/lib/src/components/ScrollView/index.tsx +1 -1
  115. package/packages/lib/src/components/Section/Section.scss +17 -17
  116. package/packages/lib/src/components/Section/Section.tsx +26 -26
  117. package/packages/lib/src/components/SelectField/SelectField.scss +42 -42
  118. package/packages/lib/src/components/SelectField/SelectField.stories.tsx +14 -14
  119. package/packages/lib/src/components/SelectField/SelectField.tsx +54 -54
  120. package/packages/lib/src/components/SelectField/index.tsx +1 -1
  121. package/packages/lib/src/components/Spacer/Spacer.scss +2 -2
  122. package/packages/lib/src/components/Spacer/Spacer.tsx +6 -6
  123. package/packages/lib/src/components/StackPanel/StackPanel.scss +8 -8
  124. package/packages/lib/src/components/StackPanel/StackPanel.stories.tsx +17 -17
  125. package/packages/lib/src/components/StackPanel/StackPanel.test.tsx +11 -11
  126. package/packages/lib/src/components/StackPanel/StackPanel.tsx +31 -31
  127. package/packages/lib/src/components/StackPanel/index.tsx +1 -1
  128. package/packages/lib/src/components/Submenu/Submenu.scss +55 -55
  129. package/packages/lib/src/components/Submenu/Submenu.stories.tsx +45 -45
  130. package/packages/lib/src/components/Submenu/Submenu.tsx +59 -59
  131. package/packages/lib/src/components/Submenu/index.tsx +1 -1
  132. package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.scss +75 -75
  133. package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.stories.tsx +17 -17
  134. package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.test.tsx +11 -11
  135. package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.tsx +63 -63
  136. package/packages/lib/src/components/SuccessCongratulation/index.tsx +1 -1
  137. package/packages/lib/src/components/TextArea/TextArea.scss +41 -41
  138. package/packages/lib/src/components/TextArea/TextArea.stories.tsx +14 -14
  139. package/packages/lib/src/components/TextArea/TextArea.tsx +50 -50
  140. package/packages/lib/src/components/TextArea/index.tsx +1 -1
  141. package/packages/lib/src/components/TextField/TextField.scss +56 -56
  142. package/packages/lib/src/components/TextField/TextField.stories.tsx +14 -14
  143. package/packages/lib/src/components/TextField/TextField.tsx +89 -89
  144. package/packages/lib/src/components/TextField/index.tsx +1 -1
  145. package/packages/lib/src/components/TitleEdit/TitleEdit.scss +17 -17
  146. package/packages/lib/src/components/TitleEdit/TitleEdit.tsx +69 -69
  147. package/packages/lib/src/components/Toast/Toast.scss +32 -32
  148. package/packages/lib/src/components/Toast/Toast.tsx +29 -29
  149. package/packages/lib/src/components/ToggleButton/ToggleButton.scss +47 -47
  150. package/packages/lib/src/components/ToggleButton/ToggleButton.stories.tsx +22 -22
  151. package/packages/lib/src/components/ToggleButton/ToggleButton.tsx +41 -41
  152. package/packages/lib/src/components/ToggleButton/index.tsx +1 -1
  153. package/packages/lib/src/components/Toolbar/Toolbar.scss +16 -16
  154. package/packages/lib/src/components/Toolbar/Toolbar.stories.tsx +17 -17
  155. package/packages/lib/src/components/Toolbar/Toolbar.test.tsx +11 -11
  156. package/packages/lib/src/components/Toolbar/Toolbar.tsx +20 -20
  157. package/packages/lib/src/components/Toolbar/index.tsx +1 -1
  158. package/packages/lib/src/components/Typography/Typography.scss +51 -51
  159. package/packages/lib/src/components/Typography/Typography.stories.tsx +18 -18
  160. package/packages/lib/src/components/Typography/Typography.tsx +19 -19
  161. package/packages/lib/src/components/index.tsx +34 -34
  162. package/packages/lib/src/hooks/index.tsx +3 -3
  163. package/packages/lib/src/hooks/use-click-outside.tsx +19 -19
  164. package/packages/lib/src/hooks/use-form.tsx +107 -107
  165. package/packages/lib/src/hooks/use-keys-enteresc.tsx +25 -25
  166. package/packages/lib/src/hooks/use-set-startup-focus.tsx +8 -8
  167. package/packages/lib/src/i18n/config.ts +8 -8
  168. package/packages/lib/src/i18n/en/translation.json +11 -11
  169. package/packages/lib/src/i18n/fr/translation.json +11 -11
  170. package/packages/lib/src/i18n/index.ts +11 -11
  171. package/packages/lib/src/index.tsx +7 -7
  172. package/packages/lib/src/stories/Intrduction.mdx +171 -171
  173. package/packages/lib/src/stories/assets/github.svg +3 -3
  174. package/packages/lib/src/styles/1-color-vars.scss +51 -51
  175. package/packages/lib/src/styles/2-font-variables.scss +2 -2
  176. package/packages/lib/src/styles/variables.scss +1 -1
  177. package/packages/lib/src/test/i18n.ts +17 -17
  178. package/packages/lib/src/utils/bem.ts +4 -4
  179. package/packages/lib/src/utils/formatError.ts +5 -5
  180. package/packages/lib/src/utils/index.ts +1 -1
  181. package/packages/lib/src/utils/interfaces.ts +5 -5
  182. package/packages/lib/tsconfig.json +26 -25
  183. package/packages/lib/vite.config.js +18 -18
  184. package/packages/ui-test/package-lock.json +97 -97
  185. package/packages/ui-test/package.json +19 -19
  186. package/packages/ui-test/playwright.config.ts +80 -80
  187. package/packages/ui-test/tests/example.spec.ts +18 -18
  188. package/packages/ui-test/tests-examples/demo-todo-app.spec.ts +437 -437
@@ -1,50 +1,50 @@
1
- import { ChangeEventHandler, FC, forwardRef, RefObject } from "react";
2
- import { formatError } from "../../utils";
3
- import "./TextArea.scss"
4
- import clsx from "clsx";
5
- import { bem } from '../../utils/bem';
6
-
7
- interface ITextAreaProps {
8
- label?: string;
9
- name?: string;
10
- error?: string;
11
- rows?: number;
12
- validationError?: (name?: string) => string | undefined;
13
- onChange?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
14
- onBlur?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
15
- value?: string;
16
- autoFocus?: boolean;
17
- className?: string;
18
- readonly?: boolean;
19
- placeholder?: string;
20
- noLabel?: boolean;
21
- align?: "left" | "center" | "right";
22
- }
23
-
24
- const b = bem("text-area");
25
- export const TextArea = forwardRef<HTMLTextAreaElement, ITextAreaProps>(({value,
26
- onChange, noLabel = false, onBlur, name, rows = 3, className, autoFocus = false,
27
- readonly = false, label, error, placeholder, align = "right" }: ITextAreaProps, ref) => {
28
-
29
- return (<div className={clsx(b(), className)}>
30
- <div className={b("wrapper")}>
31
- {!noLabel && <label
32
- htmlFor={name} className={clsx(b("label"), b("label", align))}>{label}:</label>}
33
- <textarea
34
- rows={rows}
35
- id={name}
36
- name={name}
37
- className={b("input")}
38
- readOnly={readonly}
39
- value={value}
40
- onChange={onChange}
41
- onBlur={onBlur}
42
- ref={ref}
43
- autoFocus={autoFocus}
44
- autoComplete="on"
45
- placeholder={placeholder}
46
- />
47
- </div>
48
- {error && <div className={b("error-container")}>{formatError(error, label)}</div>}
49
- </div>)
50
- });
1
+ import { ChangeEventHandler, FC, forwardRef, RefObject } from "react";
2
+ import { formatError } from "../../utils";
3
+ import "./TextArea.scss"
4
+ import clsx from "clsx";
5
+ import { bem } from '../../utils/bem';
6
+
7
+ interface ITextAreaProps {
8
+ label?: string;
9
+ name?: string;
10
+ error?: string;
11
+ rows?: number;
12
+ validationError?: (name?: string) => string | undefined;
13
+ onChange?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
14
+ onBlur?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
15
+ value?: string;
16
+ autoFocus?: boolean;
17
+ className?: string;
18
+ readonly?: boolean;
19
+ placeholder?: string;
20
+ noLabel?: boolean;
21
+ align?: "left" | "center" | "right";
22
+ }
23
+
24
+ const b = bem("text-area");
25
+ export const TextArea = forwardRef<HTMLTextAreaElement, ITextAreaProps>(({value,
26
+ onChange, noLabel = false, onBlur, name, rows = 3, className, autoFocus = false,
27
+ readonly = false, label, error, placeholder, align = "right" }: ITextAreaProps, ref) => {
28
+
29
+ return (<div className={clsx(b(), className)}>
30
+ <div className={b("wrapper")}>
31
+ {!noLabel && <label
32
+ htmlFor={name} className={clsx(b("label"), b("label", align))}>{label}:</label>}
33
+ <textarea
34
+ rows={rows}
35
+ id={name}
36
+ name={name}
37
+ className={b("input")}
38
+ readOnly={readonly}
39
+ value={value}
40
+ onChange={onChange}
41
+ onBlur={onBlur}
42
+ ref={ref}
43
+ autoFocus={autoFocus}
44
+ autoComplete="on"
45
+ placeholder={placeholder}
46
+ />
47
+ </div>
48
+ {error && <div className={b("error-container")}>{formatError(error, label)}</div>}
49
+ </div>)
50
+ });
@@ -1 +1 @@
1
- export * from "./TextArea";
1
+ export * from "./TextArea";
@@ -1,57 +1,57 @@
1
- .r5ui-text-field {
2
- display: flex;
3
- flex-direction: column;
4
- align-items: center;
5
- justify-content: center;
6
- //flex: 1;
7
- margin: 0.5em;
8
- flex-wrap: wrap;
9
- gap: 16px;
10
-
11
- &__label {
12
- flex: 40%;
13
- padding: 3px;
14
- color: $page_text_color;
15
- align-self: center;
16
- margin-right: 0.5em;
17
- &--left {
18
- text-align: left;
19
- }
20
- &--center {
21
- text-align: center;
22
- }
23
- &--right {
24
- text-align: right;
25
- }
26
- }
27
- &__input-wrapper {
28
- flex: 60%;
29
- text-align: left;
30
- }
31
- &__input {
32
- border: $border_size solid $primary_border_color;
33
- border-radius: $border_radius;
34
- color: $control_text_color;
35
- background-color: $control_bg_color;
36
- &--number {
37
- width: 8em;
38
- }
39
- &--time {
40
- width: 8em;
41
- }
42
- &--text {
43
- width: 100%;
44
- }
45
- }
46
-
47
- &__wrapper {
48
- display: flex;
49
- justify-content: space-between;
50
- flex-direction: row;
51
- width: 100%;
52
- }
53
- &__error-container {
54
- text-align: right;
55
- color: $error_validation_color;
56
- }
1
+ .r5ui-text-field {
2
+ display: flex;
3
+ flex-direction: column;
4
+ align-items: center;
5
+ justify-content: center;
6
+ //flex: 1;
7
+ margin: 0.5em;
8
+ flex-wrap: wrap;
9
+ gap: 16px;
10
+
11
+ &__label {
12
+ flex: 40%;
13
+ padding: 3px;
14
+ color: $page_text_color;
15
+ align-self: center;
16
+ margin-right: 0.5em;
17
+ &--left {
18
+ text-align: left;
19
+ }
20
+ &--center {
21
+ text-align: center;
22
+ }
23
+ &--right {
24
+ text-align: right;
25
+ }
26
+ }
27
+ &__input-wrapper {
28
+ flex: 60%;
29
+ text-align: left;
30
+ }
31
+ &__input {
32
+ border: $border_size solid $primary_border_color;
33
+ border-radius: $border_radius;
34
+ color: $control_text_color;
35
+ background-color: $control_bg_color;
36
+ &--number {
37
+ width: 8em;
38
+ }
39
+ &--time {
40
+ width: 8em;
41
+ }
42
+ &--text {
43
+ width: 100%;
44
+ }
45
+ }
46
+
47
+ &__wrapper {
48
+ display: flex;
49
+ justify-content: space-between;
50
+ flex-direction: row;
51
+ width: 100%;
52
+ }
53
+ &__error-container {
54
+ text-align: right;
55
+ color: $error_validation_color;
56
+ }
57
57
  }
@@ -1,14 +1,14 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
- import { TextField } from './TextField';
3
-
4
- const meta: Meta<typeof TextField> = {
5
- title: 'Example/TextField',
6
- component: TextField,
7
- } as Meta;
8
- export default meta;
9
-
10
- type Story = StoryObj<typeof TextField>;
11
-
12
- export const TextButton: Story = {
13
- render: () => <TextField value="test" name="tf1" />,
14
- };
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { TextField } from './TextField';
3
+
4
+ const meta: Meta<typeof TextField> = {
5
+ title: 'Example/TextField',
6
+ component: TextField,
7
+ } as Meta;
8
+ export default meta;
9
+
10
+ type Story = StoryObj<typeof TextField>;
11
+
12
+ export const TextButton: Story = {
13
+ render: () => <TextField value="test" name="tf1" />,
14
+ };
@@ -1,89 +1,89 @@
1
- import { ChangeEventHandler, forwardRef, KeyboardEvent, ReactNode } from "react";
2
- import { formatError } from "../../utils";
3
- import "./TextField.scss"
4
- import clsx from "clsx";
5
- import { bem } from '../../utils/bem';
6
-
7
- interface ITextFieldProps {
8
- label?: string;
9
- name?: string;
10
- error?: string;
11
- validationError?: (name?: string) => string | undefined;
12
- onChange?: ChangeEventHandler<HTMLInputElement>;
13
- onBlur?: ChangeEventHandler<HTMLInputElement>;
14
- onEnter?: () => void;
15
- value?: string | number;
16
- isPassword?: boolean;
17
- autoFocus?: boolean;
18
- type?: "text" | "number" | "time" | "date";
19
- className?: string;
20
- readonly?: boolean;
21
- placeholder?: string;
22
- noLabel?: boolean;
23
- step?: number;
24
- align?: "left" | "center" | "right";
25
- }
26
-
27
- interface ITextFieldWrapperProps {
28
- id?: string;
29
- name?: string;
30
- className?: string;
31
- label?: string;
32
- children: ReactNode;
33
- align?: "left" | "center" | "right";
34
- }
35
-
36
- const b = bem("text-field");
37
-
38
- export const TextFieldWrapper = ({id, name, className, label, align = "right", children}: ITextFieldWrapperProps) => {
39
- return (
40
- <div className={clsx(b(), className)}>
41
- <div className={b('wrapper')}>
42
- <label
43
- htmlFor={id || name}
44
- className={clsx(b("label"), b("label", align))}>{label}:</label>
45
- <div className={b('input-wrapper')}>
46
- {children}
47
- </div>
48
- </div>
49
- </div>
50
- )
51
- }
52
-
53
- export const TextField = forwardRef<HTMLInputElement, ITextFieldProps>(({isPassword, value,
54
- onChange, onEnter, noLabel = false, onBlur, type = 'text', name, className, autoFocus = false,
55
- readonly = false, label, error, placeholder, step, align = "right" }: ITextFieldProps, ref) => {
56
-
57
- const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
58
- if (e.key === "Enter" && onEnter) {
59
- e.preventDefault();
60
- onEnter();
61
- }
62
- };
63
-
64
- return (<div className={clsx(b(), className)}>
65
- <div className={b("wrapper")}>
66
- {!noLabel && <label
67
- htmlFor={name} className={clsx(b("label"), b("label", align))}>{label}:</label>}
68
- <div className={b("input-wrapper")}>
69
- <input
70
- id={name}
71
- name={name}
72
- className={clsx(b("input"), b("input", type))}
73
- readOnly={readonly}
74
- type={isPassword ? "password" : type}
75
- value={value}
76
- onChange={onChange}
77
- onBlur={onBlur}
78
- ref={ref}
79
- autoFocus={autoFocus}
80
- autoComplete="on"
81
- onKeyDown={handleKeyDown}
82
- placeholder={placeholder}
83
- step={step}
84
- />
85
- </div>
86
- </div>
87
- {error && <div className={b("error-container")}>{formatError(error, label)}</div>}
88
- </div>)
89
- });
1
+ import { ChangeEventHandler, forwardRef, KeyboardEvent, ReactNode } from "react";
2
+ import { formatError } from "../../utils";
3
+ import "./TextField.scss"
4
+ import clsx from "clsx";
5
+ import { bem } from '../../utils/bem';
6
+
7
+ interface ITextFieldProps {
8
+ label?: string;
9
+ name?: string;
10
+ error?: string;
11
+ validationError?: (name?: string) => string | undefined;
12
+ onChange?: ChangeEventHandler<HTMLInputElement>;
13
+ onBlur?: ChangeEventHandler<HTMLInputElement>;
14
+ onEnter?: () => void;
15
+ value?: string | number;
16
+ isPassword?: boolean;
17
+ autoFocus?: boolean;
18
+ type?: "text" | "number" | "time" | "date";
19
+ className?: string;
20
+ readonly?: boolean;
21
+ placeholder?: string;
22
+ noLabel?: boolean;
23
+ step?: number;
24
+ align?: "left" | "center" | "right";
25
+ }
26
+
27
+ interface ITextFieldWrapperProps {
28
+ id?: string;
29
+ name?: string;
30
+ className?: string;
31
+ label?: string;
32
+ children: ReactNode;
33
+ align?: "left" | "center" | "right";
34
+ }
35
+
36
+ const b = bem("text-field");
37
+
38
+ export const TextFieldWrapper = ({id, name, className, label, align = "right", children}: ITextFieldWrapperProps) => {
39
+ return (
40
+ <div className={clsx(b(), className)}>
41
+ <div className={b('wrapper')}>
42
+ <label
43
+ htmlFor={id || name}
44
+ className={clsx(b("label"), b("label", align))}>{label}:</label>
45
+ <div className={b('input-wrapper')}>
46
+ {children}
47
+ </div>
48
+ </div>
49
+ </div>
50
+ )
51
+ }
52
+
53
+ export const TextField = forwardRef<HTMLInputElement, ITextFieldProps>(({isPassword, value,
54
+ onChange, onEnter, noLabel = false, onBlur, type = 'text', name, className, autoFocus = false,
55
+ readonly = false, label, error, placeholder, step, align = "right" }: ITextFieldProps, ref) => {
56
+
57
+ const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
58
+ if (e.key === "Enter" && onEnter) {
59
+ e.preventDefault();
60
+ onEnter();
61
+ }
62
+ };
63
+
64
+ return (<div className={clsx(b(), className)}>
65
+ <div className={b("wrapper")}>
66
+ {!noLabel && <label
67
+ htmlFor={name} className={clsx(b("label"), b("label", align))}>{label}:</label>}
68
+ <div className={b("input-wrapper")}>
69
+ <input
70
+ id={name}
71
+ name={name}
72
+ className={clsx(b("input"), b("input", type))}
73
+ readOnly={readonly}
74
+ type={isPassword ? "password" : type}
75
+ value={value}
76
+ onChange={onChange}
77
+ onBlur={onBlur}
78
+ ref={ref}
79
+ autoFocus={autoFocus}
80
+ autoComplete="on"
81
+ onKeyDown={handleKeyDown}
82
+ placeholder={placeholder}
83
+ step={step}
84
+ />
85
+ </div>
86
+ </div>
87
+ {error && <div className={b("error-container")}>{formatError(error, label)}</div>}
88
+ </div>)
89
+ });
@@ -1 +1 @@
1
- export * from "./TextField";
1
+ export * from "./TextField";
@@ -1,18 +1,18 @@
1
- .r5ui-title-edit {
2
- display: flex;
3
- &__container {
4
- display: flex;
5
- flex-direction: row;
6
- align-items: center;
7
- flex: 1;
8
- gap: 0.5em;
9
- }
10
- &__edit-field {
11
- border: $border_size solid $primary_border_color;
12
- border-radius: $border_radius;
13
- flex: 1;
14
- }
15
- &__edit-field--number {
16
- width: 4em;
17
- }
1
+ .r5ui-title-edit {
2
+ display: flex;
3
+ &__container {
4
+ display: flex;
5
+ flex-direction: row;
6
+ align-items: center;
7
+ flex: 1;
8
+ gap: 0.5em;
9
+ }
10
+ &__edit-field {
11
+ border: $border_size solid $primary_border_color;
12
+ border-radius: $border_radius;
13
+ flex: 1;
14
+ }
15
+ &__edit-field--number {
16
+ width: 4em;
17
+ }
18
18
  }
@@ -1,70 +1,70 @@
1
- import { ChangeEvent, useEffect, useRef, useState } from 'react';
2
- import './TitleEdit.scss'
3
- import { FaCheck, FaPen, FaXmark } from "react-icons/fa6";
4
- import clsx from "clsx";
5
- import { bem } from '../../utils/bem';
6
- import { Typography } from '../Typography';
7
- import { IconButton } from '../IconButton';
8
- import { useSetStartupFocus, useKeysEneterEsc } from '../../hooks'
9
-
10
- interface TitleEditProps<T extends string | number> {
11
- className?: string;
12
- name?: string;
13
- variant?: 'h1' | 'h2' | 'h3' | 'p' | 'div';
14
- value: T;
15
- noButton?: boolean;
16
- onChange: (newValue: T) => (void);
17
- postfix?: string;
18
- type?: "text" | "number";
19
- }
20
-
21
- const b = bem("title-edit");
22
- export const TitleEdit = <T extends string | number, >({className, variant = 'p', noButton = false,
23
- value, type = 'text', onChange, postfix, name}: TitleEditProps<T>) => {
24
-
25
- const [tempValue, setTempValue] = useState(value)
26
- const [isEditing, setEditing] = useState<boolean>(false);
27
- const inputRef = useRef<HTMLInputElement>(null);
28
- useSetStartupFocus(inputRef, isEditing);
29
- const handleOk = () => {
30
- onChange(tempValue)
31
- setEditing(false)
32
- }
33
- const handleCancel = () => {
34
- setTempValue(value);
35
- setEditing(false)
36
- }
37
- useKeysEneterEsc(inputRef, handleOk, handleCancel);
38
- useEffect(() => {
39
- setTempValue(value);
40
- }, [value])
41
- const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
42
- setTempValue(e.target.value as T)
43
- }
44
- const beginEditing = () => {
45
- setEditing(true)
46
- }
47
- return (
48
- <div className={clsx(b(), className)}>
49
- {isEditing && <div className={b("container")}>
50
- <input
51
- id={name}
52
- name={name}
53
- type={type}
54
- className={clsx(b("edit-field"), b("edit-field", type))}
55
- value={tempValue}
56
- onChange={handleChange}
57
- ref={inputRef}
58
- />
59
- <IconButton onClick={handleOk}><FaCheck/></IconButton>
60
- <IconButton onClick={handleCancel}><FaXmark/></IconButton>
61
- </div>
62
- }
63
- {!isEditing && <div className={b("container")}>
64
- <Typography variant={variant} onClick={beginEditing}>{value} {postfix}</Typography>
65
- {!noButton && <IconButton onClick={beginEditing}><FaPen/></IconButton>}
66
- </div>}
67
- </div>
68
- )
69
- }
1
+ import { ChangeEvent, useEffect, useRef, useState } from 'react';
2
+ import './TitleEdit.scss'
3
+ import { FaCheck, FaPen, FaXmark } from "react-icons/fa6";
4
+ import clsx from "clsx";
5
+ import { bem } from '../../utils/bem';
6
+ import { Typography } from '../Typography';
7
+ import { IconButton } from '../IconButton';
8
+ import { useSetStartupFocus, useKeysEneterEsc } from '../../hooks'
9
+
10
+ interface TitleEditProps<T extends string | number> {
11
+ className?: string;
12
+ name?: string;
13
+ variant?: 'h1' | 'h2' | 'h3' | 'p' | 'div';
14
+ value: T;
15
+ noButton?: boolean;
16
+ onChange: (newValue: T) => (void);
17
+ postfix?: string;
18
+ type?: "text" | "number";
19
+ }
20
+
21
+ const b = bem("title-edit");
22
+ export const TitleEdit = <T extends string | number, >({className, variant = 'p', noButton = false,
23
+ value, type = 'text', onChange, postfix, name}: TitleEditProps<T>) => {
24
+
25
+ const [tempValue, setTempValue] = useState(value)
26
+ const [isEditing, setEditing] = useState<boolean>(false);
27
+ const inputRef = useRef<HTMLInputElement>(null);
28
+ useSetStartupFocus(inputRef, isEditing);
29
+ const handleOk = () => {
30
+ onChange(tempValue)
31
+ setEditing(false)
32
+ }
33
+ const handleCancel = () => {
34
+ setTempValue(value);
35
+ setEditing(false)
36
+ }
37
+ useKeysEneterEsc(inputRef, handleOk, handleCancel);
38
+ useEffect(() => {
39
+ setTempValue(value);
40
+ }, [value])
41
+ const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
42
+ setTempValue(e.target.value as T)
43
+ }
44
+ const beginEditing = () => {
45
+ setEditing(true)
46
+ }
47
+ return (
48
+ <div className={clsx(b(), className)}>
49
+ {isEditing && <div className={b("container")}>
50
+ <input
51
+ id={name}
52
+ name={name}
53
+ type={type}
54
+ className={clsx(b("edit-field"), b("edit-field", type))}
55
+ value={tempValue}
56
+ onChange={handleChange}
57
+ ref={inputRef}
58
+ />
59
+ <IconButton onClick={handleOk}><FaCheck/></IconButton>
60
+ <IconButton onClick={handleCancel}><FaXmark/></IconButton>
61
+ </div>
62
+ }
63
+ {!isEditing && <div className={b("container")}>
64
+ <Typography variant={variant} onClick={beginEditing}>{value} {postfix}</Typography>
65
+ {!noButton && <IconButton onClick={beginEditing}><FaPen/></IconButton>}
66
+ </div>}
67
+ </div>
68
+ )
69
+ }
70
70
  export default TitleEdit