torgbox-ui 1.0.7 → 1.0.8
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/dist/.storybook/decorators/ReduxDecorator.d.ts +2 -0
- package/dist/.storybook/decorators/ReduxDecorator.js +4 -0
- package/dist/.storybook/decorators/RouterDecorator.d.ts +2 -0
- package/dist/.storybook/decorators/RouterDecorator.js +3 -0
- package/dist/.storybook/decorators/index.d.ts +2 -0
- package/dist/.storybook/decorators/index.js +2 -0
- package/dist/src/Inputs/Button/Button.js +30 -0
- package/dist/src/Inputs/Button/Button.stories.d.ts +21 -0
- package/dist/src/Inputs/Button/Button.stories.js +210 -0
- package/dist/src/Inputs/Button/Icon.stories.d.ts +20 -0
- package/dist/src/Inputs/Button/Icon.stories.js +196 -0
- package/dist/src/Inputs/Button/button.scss +358 -0
- package/dist/src/Inputs/Button/index.js +1 -0
- package/dist/src/Inputs/Checkbox/Checkbox.js +29 -0
- package/dist/src/Inputs/Checkbox/Checkbox.stories.d.ts +11 -0
- package/dist/src/Inputs/Checkbox/Checkbox.stories.js +108 -0
- package/dist/src/Inputs/Checkbox/checkbox.scss +63 -0
- package/dist/src/Inputs/Checkbox/index.js +1 -0
- package/dist/src/Inputs/EmailField/EmailField.js +61 -0
- package/dist/src/Inputs/EmailField/EmailField.stories.d.ts +8 -0
- package/dist/src/Inputs/EmailField/EmailField.stories.js +43 -0
- package/dist/src/Inputs/EmailField/ErrorMessages.js +3 -0
- package/dist/src/Inputs/EmailField/index.js +2 -0
- package/dist/src/Inputs/InnField/ErrorMessages.js +1 -0
- package/dist/src/Inputs/InnField/InnField.js +33 -0
- package/dist/src/Inputs/InnField/InnField.stories.d.ts +8 -0
- package/dist/src/Inputs/InnField/InnField.stories.js +43 -0
- package/dist/src/Inputs/InnField/index.js +2 -0
- package/dist/src/Inputs/NameField/ErrorMessages.js +8 -0
- package/dist/src/Inputs/NameField/NameField.js +54 -0
- package/dist/src/Inputs/NameField/NameField.stories.d.ts +8 -0
- package/dist/src/Inputs/NameField/NameField.stories.js +43 -0
- package/dist/src/Inputs/NameField/index.js +2 -0
- package/dist/src/Inputs/OtpInput/ErrorMessages.js +1 -0
- package/dist/src/Inputs/OtpInput/OtpInput.js +78 -0
- package/dist/src/Inputs/OtpInput/OtpInput.stories.d.ts +8 -0
- package/dist/src/Inputs/OtpInput/OtpInput.stories.js +52 -0
- package/dist/src/Inputs/OtpInput/index.js +2 -0
- package/dist/src/Inputs/OtpInput/otpInput.scss +39 -0
- package/dist/src/Inputs/PasswordField/ErrorMessages.js +2 -0
- package/dist/src/Inputs/PasswordField/PasswordField.js +35 -0
- package/dist/src/Inputs/PasswordField/PasswordField.stories.d.ts +8 -0
- package/dist/src/Inputs/PasswordField/PasswordField.stories.js +43 -0
- package/dist/src/Inputs/PasswordField/index.js +2 -0
- package/dist/src/Inputs/PhoneField/ErrorMessages.js +2 -0
- package/dist/src/Inputs/PhoneField/PhoneField.js +74 -0
- package/dist/src/Inputs/PhoneField/PhoneField.stories.d.ts +8 -0
- package/dist/src/Inputs/PhoneField/PhoneField.stories.js +43 -0
- package/dist/src/Inputs/PhoneField/index.js +2 -0
- package/dist/src/Inputs/RepeatPasswordField/ErrorMessages.js +2 -0
- package/dist/src/Inputs/RepeatPasswordField/RepeatPasswordField.js +22 -0
- package/dist/src/Inputs/RepeatPasswordField/index.js +2 -0
- package/dist/src/Inputs/Selector/Collapse.js +40 -0
- package/dist/src/Inputs/Selector/Collapse.stories.d.ts +8 -0
- package/dist/src/Inputs/Selector/Collapse.stories.js +108 -0
- package/dist/src/Inputs/Selector/Dropdown.js +81 -0
- package/dist/src/Inputs/Selector/Dropdown.stories.d.ts +9 -0
- package/dist/src/Inputs/Selector/Dropdown.stories.js +103 -0
- package/dist/src/Inputs/Selector/Option/Option.js +10 -0
- package/dist/src/Inputs/Selector/Option/Option.stories.d.ts +9 -0
- package/dist/src/Inputs/Selector/Option/Option.stories.js +47 -0
- package/dist/src/Inputs/Selector/Option/option.scss +44 -0
- package/dist/src/Inputs/Selector/index.js +3 -0
- package/dist/src/Inputs/Selector/selector.scss +101 -0
- package/dist/src/Inputs/TextField/TextField.js +85 -0
- package/dist/src/Inputs/TextField/TextField.stories.d.ts +12 -0
- package/dist/src/Inputs/TextField/TextField.stories.js +101 -0
- package/dist/src/Inputs/TextField/index.js +1 -0
- package/dist/src/Inputs/TextField/textField.module.scss +157 -0
- package/dist/src/Inputs/TextField/textField.scss +156 -0
- package/dist/src/Inputs/index.js +11 -0
- package/dist/src/Inputs/index.scss +6 -0
- package/dist/src/Pages/ContentPage/ContentPage.js +22 -0
- package/dist/src/Pages/ContentPage/ContentPage.stories.d.ts +6 -0
- package/dist/src/Pages/ContentPage/ContentPage.stories.js +17 -0
- package/dist/src/Pages/ContentPage/contentPage.scss +10 -0
- package/dist/src/Pages/ContentPage/index.js +1 -0
- package/dist/src/Pages/CreatePasswordPage/CreatePasswordPage.js +47 -0
- package/dist/src/Pages/CreatePasswordPage/CreatePasswordPage.stories.d.ts +7 -0
- package/dist/src/Pages/CreatePasswordPage/CreatePasswordPage.stories.js +96 -0
- package/dist/src/Pages/CreatePasswordPage/createPasswordPage.scss +42 -0
- package/dist/src/Pages/CreatePasswordPage/index.js +1 -0
- package/dist/src/Pages/CreateTeamPage/CreateTeamPage.js +46 -0
- package/dist/src/Pages/CreateTeamPage/CreateTeamPage.stories.d.ts +7 -0
- package/dist/src/Pages/CreateTeamPage/CreateTeamPage.stories.js +82 -0
- package/dist/src/Pages/CreateTeamPage/createTeamPage.scss +82 -0
- package/dist/src/Pages/CreateTeamPage/index.js +1 -0
- package/dist/src/Pages/EmailConfirmationPage/EmailConfirmationPage.js +34 -0
- package/dist/src/Pages/EmailConfirmationPage/EmailConfirmationPage.stories.d.ts +8 -0
- package/dist/src/Pages/EmailConfirmationPage/EmailConfirmationPage.stories.js +86 -0
- package/dist/src/Pages/EmailConfirmationPage/emailConfirmationPage.scss +92 -0
- package/dist/src/Pages/EmailConfirmationPage/index.js +1 -0
- package/dist/src/Pages/JoinTeamPage/JoinTeamPage.js +6 -0
- package/dist/src/Pages/JoinTeamPage/JoinTeamPage.stories.d.ts +7 -0
- package/dist/src/Pages/JoinTeamPage/JoinTeamPage.stories.js +24 -0
- package/dist/src/Pages/JoinTeamPage/index.js +1 -0
- package/dist/src/Pages/JoinTeamPage/joinTeamPage.scss +50 -0
- package/dist/src/Pages/LoginPage/LoginPage.js +32 -0
- package/dist/src/Pages/LoginPage/LoginPage.stories.d.ts +7 -0
- package/dist/src/Pages/LoginPage/LoginPage.stories.js +108 -0
- package/dist/src/Pages/LoginPage/index.js +1 -0
- package/dist/src/Pages/LoginPage/loginPage.scss +80 -0
- package/dist/src/Pages/RegisterPage/RegisterPage.js +34 -0
- package/dist/src/Pages/RegisterPage/RegisterPage.stories.d.ts +7 -0
- package/dist/src/Pages/RegisterPage/RegisterPage.stories.js +149 -0
- package/dist/src/Pages/RegisterPage/index.js +1 -0
- package/dist/src/Pages/RegisterPage/registerPage.scss +72 -0
- package/dist/src/Pages/ResetPasswordPage/ResetPasswordPage.js +10 -0
- package/dist/src/Pages/ResetPasswordPage/ResetPasswordPage.stories.d.ts +7 -0
- package/dist/src/Pages/ResetPasswordPage/ResetPasswordPage.stories.js +24 -0
- package/dist/src/Pages/ResetPasswordPage/index.js +1 -0
- package/dist/src/Pages/ResetPasswordPage/resetPasswordPage.scss +41 -0
- package/dist/src/Pages/StartPage/StartPage.js +22 -0
- package/dist/src/Pages/StartPage/StartPage.stories.d.ts +7 -0
- package/dist/src/Pages/StartPage/StartPage.stories.js +48 -0
- package/dist/src/Pages/StartPage/index.js +1 -0
- package/dist/src/Pages/StartPage/startPage.scss +58 -0
- package/dist/src/Pages/index.js +6 -0
- package/dist/src/Pages/index.scss +9 -0
- package/dist/src/Utils/Divider/Divider.js +2 -0
- package/dist/src/Utils/Divider/divider.scss +11 -0
- package/dist/src/Utils/ErrorBanner/ErrorBanner.js +6 -0
- package/dist/src/Utils/ErrorBanner/errorBanner.scss +24 -0
- package/dist/src/Utils/ErrorBanner/index.js +1 -0
- package/dist/src/Utils/Link/Link.js +5 -0
- package/dist/src/Utils/Link/Link.stories.d.ts +8 -0
- package/dist/src/Utils/Link/Link.stories.js +49 -0
- package/dist/src/Utils/Link/index.js +1 -0
- package/dist/src/Utils/Link/index.scss +1 -0
- package/dist/src/Utils/Link/link.scss +21 -0
- package/dist/src/Utils/Modal/Modal.js +24 -0
- package/dist/src/Utils/Modal/Modal.stories.d.ts +6 -0
- package/dist/src/Utils/Modal/Modal.stories.js +38 -0
- package/dist/src/Utils/Modal/index.js +1 -0
- package/dist/src/Utils/Modal/modal.scss +33 -0
- package/dist/src/Utils/Portal/Portal.js +5 -0
- package/dist/src/Utils/SectionPlaceholder/SectionPlaceholder.js +2 -0
- package/dist/src/Utils/SectionPlaceholder/sectionPlaceholder.scss +22 -0
- package/dist/src/Utils/Spinner/Spinner.js +5 -0
- package/dist/src/Utils/Spinner/spinner.scss +41 -0
- package/dist/src/Utils/api.js +7 -0
- package/dist/src/Utils/index.js +7 -0
- package/dist/src/Utils/index.scss +6 -0
- package/dist/src/Widgets/Header/Header.js +18 -0
- package/dist/src/Widgets/Header/Header.stories.d.ts +6 -0
- package/dist/src/Widgets/Header/Header.stories.js +17 -0
- package/dist/src/Widgets/Header/header.scss +50 -0
- package/dist/src/Widgets/Header/index.js +1 -0
- package/dist/src/Widgets/Sidebar/Sidebar.js +25 -0
- package/dist/src/Widgets/Sidebar/Sidebar.stories.d.ts +6 -0
- package/dist/src/Widgets/Sidebar/Sidebar.stories.js +17 -0
- package/dist/src/Widgets/Sidebar/index.js +1 -0
- package/dist/src/Widgets/Sidebar/sidebar.scss +23 -0
- package/dist/src/Widgets/index.js +2 -0
- package/dist/src/Widgets/index.scss +2 -0
- package/dist/src/app/main.js +7 -0
- package/dist/src/app/routes/AppRouter.js +31 -0
- package/dist/src/app/routes/index.js +1 -0
- package/dist/src/app/store/index.js +1 -0
- package/dist/src/app/store/store.js +13 -0
- package/dist/src/assets/scss/index.scss +5 -0
- package/dist/src/assets/scss/settings/fonts.scss +29 -0
- package/dist/src/assets/scss/settings/globals.scss +5 -0
- package/dist/src/assets/scss/settings/helpers.scss +3 -0
- package/dist/src/assets/scss/settings/reset.scss +8 -0
- package/dist/src/assets/scss/settings/variables.scss +91 -0
- package/dist/src/entities/user/api/api.js +41 -0
- package/dist/src/entities/user/api/index.js +1 -0
- package/dist/src/entities/user/index.js +2 -0
- package/dist/src/entities/user/model/index.js +2 -0
- package/dist/src/entities/user/model/selectors.js +2 -0
- package/dist/src/entities/user/model/slice.js +31 -0
- package/dist/src/entities/user/model/types.js +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.scss +6 -0
- package/dist/src/shared/model/api.js +6 -0
- package/dist/src/shared/model/constants.js +1 -0
- package/dist/src/shared/model/index.js +2 -0
- package/dist/src/shared/ui/Avatar/Avatar.js +6 -0
- package/dist/src/shared/ui/Avatar/Avatar.stories.d.ts +6 -0
- package/dist/src/shared/ui/Avatar/Avatar.stories.js +17 -0
- package/dist/src/shared/ui/Avatar/avatar.scss +62 -0
- package/dist/src/shared/ui/index.d.ts +1 -0
- package/dist/src/shared/ui/index.js +1 -0
- package/dist/src/shared/ui/index.scss +1 -0
- package/dist/src/tools/customValidators.js +19 -0
- package/dist/src/tools/getCoords.js +18 -0
- package/dist/src/tools/regExp.js +5 -0
- package/dist/{types → src}/ui.d.ts +0 -1
- package/dist/src/ui.js +3 -0
- package/dist/src/ui.scss +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -8
- package/dist/torgbox-ui.cjs.js +0 -31
- package/dist/torgbox-ui.css +0 -1
- package/dist/torgbox-ui.es.js +0 -4799
- /package/dist/{types → src}/Inputs/Button/Button.d.ts +0 -0
- /package/dist/{types → src}/Inputs/Button/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/Checkbox/Checkbox.d.ts +0 -0
- /package/dist/{types → src}/Inputs/Checkbox/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/EmailField/EmailField.d.ts +0 -0
- /package/dist/{types → src}/Inputs/EmailField/ErrorMessages.d.ts +0 -0
- /package/dist/{types → src}/Inputs/EmailField/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/InnField/ErrorMessages.d.ts +0 -0
- /package/dist/{types → src}/Inputs/InnField/InnField.d.ts +0 -0
- /package/dist/{types → src}/Inputs/InnField/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/NameField/ErrorMessages.d.ts +0 -0
- /package/dist/{types → src}/Inputs/NameField/NameField.d.ts +0 -0
- /package/dist/{types → src}/Inputs/NameField/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/OtpInput/ErrorMessages.d.ts +0 -0
- /package/dist/{types → src}/Inputs/OtpInput/OtpInput.d.ts +0 -0
- /package/dist/{types → src}/Inputs/OtpInput/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/PasswordField/ErrorMessages.d.ts +0 -0
- /package/dist/{types → src}/Inputs/PasswordField/PasswordField.d.ts +0 -0
- /package/dist/{types → src}/Inputs/PasswordField/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/PhoneField/ErrorMessages.d.ts +0 -0
- /package/dist/{types → src}/Inputs/PhoneField/PhoneField.d.ts +0 -0
- /package/dist/{types → src}/Inputs/PhoneField/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/RepeatPasswordField/ErrorMessages.d.ts +0 -0
- /package/dist/{types → src}/Inputs/RepeatPasswordField/RepeatPasswordField.d.ts +0 -0
- /package/dist/{types → src}/Inputs/RepeatPasswordField/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/Selector/Collapse.d.ts +0 -0
- /package/dist/{types → src}/Inputs/Selector/Dropdown.d.ts +0 -0
- /package/dist/{types → src}/Inputs/Selector/Option/Option.d.ts +0 -0
- /package/dist/{types → src}/Inputs/Selector/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/TextField/TextField.d.ts +0 -0
- /package/dist/{types → src}/Inputs/TextField/index.d.ts +0 -0
- /package/dist/{types → src}/Inputs/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/ContentPage/ContentPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/ContentPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/CreatePasswordPage/CreatePasswordPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/CreatePasswordPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/CreateTeamPage/CreateTeamPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/CreateTeamPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/EmailConfirmationPage/EmailConfirmationPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/EmailConfirmationPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/JoinTeamPage/JoinTeamPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/JoinTeamPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/LoginPage/LoginPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/LoginPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/RegisterPage/RegisterPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/RegisterPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/ResetPasswordPage/ResetPasswordPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/ResetPasswordPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/StartPage/StartPage.d.ts +0 -0
- /package/dist/{types → src}/Pages/StartPage/index.d.ts +0 -0
- /package/dist/{types → src}/Pages/index.d.ts +0 -0
- /package/dist/{types → src}/Utils/Divider/Divider.d.ts +0 -0
- /package/dist/{types → src}/Utils/ErrorBanner/ErrorBanner.d.ts +0 -0
- /package/dist/{types → src}/Utils/ErrorBanner/index.d.ts +0 -0
- /package/dist/{types → src}/Utils/Link/Link.d.ts +0 -0
- /package/dist/{types → src}/Utils/Link/index.d.ts +0 -0
- /package/dist/{types → src}/Utils/Modal/Modal.d.ts +0 -0
- /package/dist/{types → src}/Utils/Modal/index.d.ts +0 -0
- /package/dist/{types → src}/Utils/Portal/Portal.d.ts +0 -0
- /package/dist/{types → src}/Utils/SectionPlaceholder/SectionPlaceholder.d.ts +0 -0
- /package/dist/{types → src}/Utils/Spinner/Spinner.d.ts +0 -0
- /package/dist/{types → src}/Utils/api.d.ts +0 -0
- /package/dist/{types → src}/Utils/index.d.ts +0 -0
- /package/dist/{types → src}/Widgets/Header/Header.d.ts +0 -0
- /package/dist/{types → src}/Widgets/Header/index.d.ts +0 -0
- /package/dist/{types → src}/Widgets/Sidebar/Sidebar.d.ts +0 -0
- /package/dist/{types → src}/Widgets/Sidebar/index.d.ts +0 -0
- /package/dist/{types → src}/Widgets/index.d.ts +0 -0
- /package/dist/{types → src}/app/main.d.ts +0 -0
- /package/dist/{types → src}/app/routes/AppRouter.d.ts +0 -0
- /package/dist/{types → src}/app/routes/index.d.ts +0 -0
- /package/dist/{types → src}/app/store/index.d.ts +0 -0
- /package/dist/{types → src}/app/store/store.d.ts +0 -0
- /package/dist/{types → src}/entities/user/api/api.d.ts +0 -0
- /package/dist/{types → src}/entities/user/api/index.d.ts +0 -0
- /package/dist/{types → src}/entities/user/index.d.ts +0 -0
- /package/dist/{types → src}/entities/user/model/index.d.ts +0 -0
- /package/dist/{types → src}/entities/user/model/selectors.d.ts +0 -0
- /package/dist/{types → src}/entities/user/model/slice.d.ts +0 -0
- /package/dist/{types → src}/entities/user/model/types.d.ts +0 -0
- /package/dist/{types → src}/index.d.ts +0 -0
- /package/dist/{types → src}/shared/model/api.d.ts +0 -0
- /package/dist/{types → src}/shared/model/constants.d.ts +0 -0
- /package/dist/{types → src}/shared/model/index.d.ts +0 -0
- /package/dist/{types → src}/shared/ui/Avatar/Avatar.d.ts +0 -0
- /package/dist/{types → src}/shared/ui/Avatar/index.d.ts +0 -0
- /package/dist/{types/shared/ui/index.d.ts → src/shared/ui/Avatar/index.js} +0 -0
- /package/dist/{types → src}/tools/customValidators.d.ts +0 -0
- /package/dist/{types → src}/tools/getCoords.d.ts +0 -0
- /package/dist/{types → src}/tools/regExp.d.ts +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { innValidator } from '../../tools/customValidators';
|
|
4
|
+
import { TextField } from '../TextField';
|
|
5
|
+
import { InnError } from './ErrorMessages';
|
|
6
|
+
export const InnField = (props) => {
|
|
7
|
+
const { onValidated, onTextValid } = props;
|
|
8
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
9
|
+
const [touched, setTouched] = useState(false);
|
|
10
|
+
const [inn, setInn] = useState('');
|
|
11
|
+
const getInputNumbersValue = (value) => {
|
|
12
|
+
return value.replace(/\D/g, '');
|
|
13
|
+
};
|
|
14
|
+
const onInnInput = (value, e) => {
|
|
15
|
+
setInn(getInputNumbersValue(value));
|
|
16
|
+
};
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!touched) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const valid = innValidator(inn);
|
|
22
|
+
if (!valid) {
|
|
23
|
+
onValidated(false);
|
|
24
|
+
onTextValid('');
|
|
25
|
+
setErrorMessage(InnError);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
onValidated(true);
|
|
29
|
+
onTextValid(inn);
|
|
30
|
+
setErrorMessage('');
|
|
31
|
+
}, [inn, onTextValid, onValidated, touched]);
|
|
32
|
+
return (_jsx(TextField, { onChange: onInnInput, onTouched: setTouched, state: touched && errorMessage ? 'error' : 'idle', errorMessage: errorMessage, label: '\u0418\u041D\u041D', type: 'text', description: '\u0412\u0432\u0435\u0434\u0438\u0442\u0435 10 \u0446\u0438\u0444\u0440 \u0434\u043B\u044F \u042E\u041B \u0438\u043B\u0438 12 \u0434\u043B\u044F \u0424\u041B', value: inn, maxLength: 12, required: true, searchIcon: true, ...props }));
|
|
33
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import type { ITextField } from '../TextField';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<ITextField>;
|
|
6
|
+
export declare const InnFieldInactive: Story;
|
|
7
|
+
export declare const InnFieldError: Story;
|
|
8
|
+
export declare const InnFieldWithValue: Story;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { InnField } from './InnField';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Inputs/InnField',
|
|
4
|
+
component: InnField,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
args: {
|
|
7
|
+
onValidated: () => { },
|
|
8
|
+
onTextValid: () => { }
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export const InnFieldInactive = {
|
|
13
|
+
args: {},
|
|
14
|
+
parameters: {
|
|
15
|
+
design: {
|
|
16
|
+
type: 'figma',
|
|
17
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12816-23279&mode=design&t=wnKZYt4uc5mLPiqN-4',
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const InnFieldError = {
|
|
22
|
+
args: {
|
|
23
|
+
state: 'error',
|
|
24
|
+
errorMessage: 'Some error'
|
|
25
|
+
},
|
|
26
|
+
parameters: {
|
|
27
|
+
design: {
|
|
28
|
+
type: 'figma',
|
|
29
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12816-23279&mode=design&t=wnKZYt4uc5mLPiqN-4',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export const InnFieldWithValue = {
|
|
34
|
+
args: {
|
|
35
|
+
value: '1024120485',
|
|
36
|
+
},
|
|
37
|
+
parameters: {
|
|
38
|
+
design: {
|
|
39
|
+
type: 'figma',
|
|
40
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12816-23279&mode=design&t=wnKZYt4uc5mLPiqN-4',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const emptyFirstNameError = 'Введите имя';
|
|
2
|
+
export const emptyLastNameError = 'Введите фамилию';
|
|
3
|
+
export const emptyPatronymicNameError = 'Введите отчество';
|
|
4
|
+
export const emptyFullNameError = 'Введите ФИО';
|
|
5
|
+
export const notCorrectFirstNameError = 'Некорректное имя';
|
|
6
|
+
export const notCorrectLastNameError = 'Некорректная фамилия';
|
|
7
|
+
export const notCorrectPatronymicNameError = 'Некорректное отчество';
|
|
8
|
+
export const notCorrectFullNameError = 'Некорректное ФИО';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { nameValidator } from '../../tools/customValidators';
|
|
4
|
+
import { TextField } from '../TextField';
|
|
5
|
+
import { emptyFirstNameError, emptyLastNameError, emptyPatronymicNameError, emptyFullNameError, notCorrectFirstNameError, notCorrectLastNameError, notCorrectPatronymicNameError, notCorrectFullNameError } from './ErrorMessages';
|
|
6
|
+
;
|
|
7
|
+
export const NameField = (props) => {
|
|
8
|
+
const { nameType = 'fullName', onValidated, onTextValid } = props;
|
|
9
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
10
|
+
const [touched, setTouched] = useState(false);
|
|
11
|
+
const [name, setName] = useState('');
|
|
12
|
+
const nameArgs = {
|
|
13
|
+
firstName: {
|
|
14
|
+
label: 'Имя',
|
|
15
|
+
emptyMessage: emptyFirstNameError,
|
|
16
|
+
notCorrectMessage: notCorrectFirstNameError,
|
|
17
|
+
},
|
|
18
|
+
lastName: {
|
|
19
|
+
label: 'Фамилия',
|
|
20
|
+
emptyMessage: emptyLastNameError,
|
|
21
|
+
notCorrectMessage: notCorrectLastNameError,
|
|
22
|
+
},
|
|
23
|
+
patronymic: {
|
|
24
|
+
label: 'Отчество',
|
|
25
|
+
emptyMessage: emptyPatronymicNameError,
|
|
26
|
+
notCorrectMessage: notCorrectPatronymicNameError,
|
|
27
|
+
},
|
|
28
|
+
fullName: {
|
|
29
|
+
label: 'ФИО',
|
|
30
|
+
emptyMessage: emptyFullNameError,
|
|
31
|
+
notCorrectMessage: notCorrectFullNameError,
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const { label, emptyMessage, notCorrectMessage } = nameArgs[nameType];
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!touched) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const valid = nameValidator(nameType === 'fullName' ? name.split(' ') : name);
|
|
40
|
+
if (!valid) {
|
|
41
|
+
onValidated(false);
|
|
42
|
+
onTextValid('');
|
|
43
|
+
const error = (!name && emptyMessage) ||
|
|
44
|
+
(!valid && notCorrectMessage) ||
|
|
45
|
+
'';
|
|
46
|
+
setErrorMessage(error);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
onValidated(true);
|
|
50
|
+
onTextValid(name);
|
|
51
|
+
setErrorMessage('');
|
|
52
|
+
}, [emptyMessage, name, nameType, notCorrectMessage, onTextValid, onValidated, touched]);
|
|
53
|
+
return (_jsx(TextField, { onChange: setName, onTouched: setTouched, state: touched && errorMessage ? 'error' : 'idle', errorMessage: errorMessage, label: label, type: 'text', value: name, required: true, checkIcon: true, ...props }));
|
|
54
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import type { ITextField } from '../TextField';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<ITextField>;
|
|
6
|
+
export declare const NameFieldInactive: Story;
|
|
7
|
+
export declare const NameFieldError: Story;
|
|
8
|
+
export declare const NameFieldWithValue: Story;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NameField } from './NameField';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Inputs/NameField',
|
|
4
|
+
component: NameField,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
args: {
|
|
7
|
+
onValidated: () => { },
|
|
8
|
+
onTextValid: () => { }
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export const NameFieldInactive = {
|
|
13
|
+
args: {},
|
|
14
|
+
parameters: {
|
|
15
|
+
design: {
|
|
16
|
+
type: 'figma',
|
|
17
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-34704&mode=design&t=H9AcJSW51fS3aPiW-4',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const NameFieldError = {
|
|
22
|
+
args: {
|
|
23
|
+
state: 'error',
|
|
24
|
+
errorMessage: 'Some error'
|
|
25
|
+
},
|
|
26
|
+
parameters: {
|
|
27
|
+
design: {
|
|
28
|
+
type: 'figma',
|
|
29
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-36350&mode=design&t=H9AcJSW51fS3aPiW-4',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export const NameFieldWithValue = {
|
|
34
|
+
args: {
|
|
35
|
+
value: 'Константин',
|
|
36
|
+
},
|
|
37
|
+
parameters: {
|
|
38
|
+
design: {
|
|
39
|
+
type: 'figma',
|
|
40
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-34760&mode=design&t=H9AcJSW51fS3aPiW-4',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const otpError = 'Неверный код. Сверьтесь с письмом';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import _ from 'lodash/fp';
|
|
4
|
+
import { useRef, useState, useEffect } from 'react';
|
|
5
|
+
export const OtpInput = (props) => {
|
|
6
|
+
const { length = 6, onComplete = _.noop, errorMessage = '', setErrorMessage = _.noop, responseReceived = false, loading = false, } = props;
|
|
7
|
+
const inputRef = useRef(Array(length).fill(null));
|
|
8
|
+
const [Otp, setOtp] = useState(Array(length).fill(''));
|
|
9
|
+
const currentTarget = inputRef.current;
|
|
10
|
+
const handleComplete = (value, index) => {
|
|
11
|
+
onComplete(value.join(''));
|
|
12
|
+
currentTarget[index].blur();
|
|
13
|
+
};
|
|
14
|
+
const handleTextChange = (index) => (e) => {
|
|
15
|
+
setErrorMessage('');
|
|
16
|
+
const newPin = [...Otp];
|
|
17
|
+
const input = e.target.value.replace(/\D/g, '');
|
|
18
|
+
newPin[index] = input;
|
|
19
|
+
setOtp(newPin);
|
|
20
|
+
if (input.length === 1 && index < length - 1) {
|
|
21
|
+
currentTarget[index + 1]?.focus();
|
|
22
|
+
}
|
|
23
|
+
if (input.length === 0 && index > 0) {
|
|
24
|
+
currentTarget[index - 1]?.focus();
|
|
25
|
+
}
|
|
26
|
+
if (newPin.every((digit) => digit !== '')) {
|
|
27
|
+
onComplete(newPin.join(''));
|
|
28
|
+
currentTarget[index].blur();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const handlePaste = (index) => (e) => {
|
|
32
|
+
setErrorMessage('');
|
|
33
|
+
const value = e.clipboardData?.getData('text');
|
|
34
|
+
const updatedValue = value
|
|
35
|
+
.toString()
|
|
36
|
+
.replace(/\D/g, '')
|
|
37
|
+
.split('')
|
|
38
|
+
.slice(0, length);
|
|
39
|
+
setOtp(updatedValue);
|
|
40
|
+
if (updatedValue.length === length) {
|
|
41
|
+
handleComplete(updatedValue, index);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const goToFirstEmptyInput = () => {
|
|
45
|
+
const firstEmptyInput = currentTarget.findIndex((el) => el.value === '');
|
|
46
|
+
firstEmptyInput >= 0
|
|
47
|
+
?
|
|
48
|
+
currentTarget[firstEmptyInput].focus()
|
|
49
|
+
:
|
|
50
|
+
currentTarget[length - 1].focus();
|
|
51
|
+
setErrorMessage('');
|
|
52
|
+
};
|
|
53
|
+
const handleBackspace = (index) => (e) => {
|
|
54
|
+
if (e.key === 'Backspace' &&
|
|
55
|
+
index !== 0 &&
|
|
56
|
+
currentTarget[index].value.length === 0) {
|
|
57
|
+
currentTarget[index - 1]?.focus();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const handleKeyDown = (e) => {
|
|
61
|
+
if (Number.parseInt(e.key) >= 0) {
|
|
62
|
+
goToFirstEmptyInput();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const inputMods = [
|
|
66
|
+
'otp__input',
|
|
67
|
+
{ 'otp__input--error': errorMessage },
|
|
68
|
+
];
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
!loading && currentTarget[0].focus();
|
|
71
|
+
}, [responseReceived, loading, currentTarget]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (responseReceived) {
|
|
74
|
+
setOtp(Array(length).fill(''));
|
|
75
|
+
}
|
|
76
|
+
}, [responseReceived, length]);
|
|
77
|
+
return (_jsxs("div", { className: 'otp', children: [Array.from({ length }, (_, index) => (_jsx("input", { value: Otp[index], onChange: handleTextChange(index), onPaste: handlePaste(index), onKeyUp: handleBackspace(index), onKeyDown: handleKeyDown, onClick: goToFirstEmptyInput, ref: (ref) => (currentTarget[index] = ref), type: 'text', maxLength: 1, className: cn(inputMods), tabIndex: index + 1 }, index))), errorMessage && (_jsx("span", { className: 'otp__error', children: errorMessage }))] }));
|
|
78
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { type IOtpInput } from './OtpInput';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<IOtpInput>;
|
|
6
|
+
export declare const OtpInputDefault: Story;
|
|
7
|
+
export declare const OtpInputError: Story;
|
|
8
|
+
export declare const OtpInputWithValue: Story;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { userEvent, within } from '@storybook/test';
|
|
2
|
+
import { OtpInput } from './OtpInput';
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Inputs/OtpInput',
|
|
5
|
+
component: OtpInput,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
args: {
|
|
8
|
+
length: 6
|
|
9
|
+
},
|
|
10
|
+
argTypes: {
|
|
11
|
+
length: {
|
|
12
|
+
control: 'text',
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export default meta;
|
|
17
|
+
export const OtpInputDefault = {
|
|
18
|
+
args: {},
|
|
19
|
+
parameters: {
|
|
20
|
+
design: {
|
|
21
|
+
type: 'figma',
|
|
22
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12659-13838&mode=design&t=5Wp3lAOqtDnPV63y-4',
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const OtpInputError = {
|
|
27
|
+
args: {
|
|
28
|
+
errorMessage: 'some error'
|
|
29
|
+
},
|
|
30
|
+
parameters: {
|
|
31
|
+
design: {
|
|
32
|
+
type: 'figma',
|
|
33
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12659-13838&mode=design&t=5Wp3lAOqtDnPV63y-4',
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export const OtpInputWithValue = {
|
|
38
|
+
args: {},
|
|
39
|
+
parameters: {
|
|
40
|
+
design: {
|
|
41
|
+
type: 'figma',
|
|
42
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12659-13838&mode=design&t=5Wp3lAOqtDnPV63y-4',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
play: async ({ canvasElement, step }) => {
|
|
46
|
+
const canvas = within(canvasElement);
|
|
47
|
+
const input = canvas.getAllByRole('textbox');
|
|
48
|
+
await step('Typing OTP', async () => {
|
|
49
|
+
await userEvent.type(input[0], '222222', { delay: 500 });
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
$border-color: $neutral-border-low;
|
|
2
|
+
$border-color-focus: $primary-border-high;
|
|
3
|
+
$error-message: $error-high;
|
|
4
|
+
$border-error: $error-border-high;
|
|
5
|
+
|
|
6
|
+
.otp {
|
|
7
|
+
display: flex;
|
|
8
|
+
gap: 8px;
|
|
9
|
+
position: relative;
|
|
10
|
+
|
|
11
|
+
&__input {
|
|
12
|
+
font-size: 16px;
|
|
13
|
+
line-height: 24px;
|
|
14
|
+
height: 44px;
|
|
15
|
+
width: 36px;
|
|
16
|
+
border: 1px solid $border-color;
|
|
17
|
+
border-radius: 4px;
|
|
18
|
+
text-align: center;
|
|
19
|
+
outline: none;
|
|
20
|
+
|
|
21
|
+
&:focus,
|
|
22
|
+
:active {
|
|
23
|
+
border-color: $border-color-focus;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&--error,
|
|
27
|
+
&--error:focus {
|
|
28
|
+
border-color: $border-error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
&__error {
|
|
32
|
+
font-size: 12px;
|
|
33
|
+
line-height: 16px;
|
|
34
|
+
color: $error-message;
|
|
35
|
+
position: absolute;
|
|
36
|
+
bottom: -16px;
|
|
37
|
+
left: 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import _ from 'lodash/fp';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { passwordValidator } from '../../tools/customValidators';
|
|
5
|
+
import { TextField, } from '../TextField';
|
|
6
|
+
import { emptyPasswordError, notCorrectPasswordError } from './ErrorMessages';
|
|
7
|
+
export const PasswordField = (props) => {
|
|
8
|
+
const { onValidated, onPasswordInput, hidePassword = true, } = props;
|
|
9
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
10
|
+
const [touched, setTouched] = useState(false);
|
|
11
|
+
const [password, setPassword] = useState('');
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!touched) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
onPasswordInput(password);
|
|
17
|
+
const valid = passwordValidator(password);
|
|
18
|
+
if (!valid) {
|
|
19
|
+
onValidated(false);
|
|
20
|
+
setErrorMessage(_.cond([
|
|
21
|
+
[() => !password, () => emptyPasswordError],
|
|
22
|
+
[() => !valid, () => notCorrectPasswordError],
|
|
23
|
+
]));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
onValidated(true);
|
|
27
|
+
setErrorMessage('');
|
|
28
|
+
}, [
|
|
29
|
+
password,
|
|
30
|
+
onPasswordInput,
|
|
31
|
+
onValidated,
|
|
32
|
+
touched
|
|
33
|
+
]);
|
|
34
|
+
return (_jsx(TextField, { onChange: setPassword, onTouched: setTouched, state: touched && errorMessage ? 'error' : 'idle', errorMessage: errorMessage, label: '\u041F\u0430\u0440\u043E\u043B\u044C', type: hidePassword ? 'password' : 'text', value: password, eyeIcon: true, checkIcon: true, required: true, ...props }));
|
|
35
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { type ITextField } from '../index';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<ITextField>;
|
|
6
|
+
export declare const PasswordFieldInactive: Story;
|
|
7
|
+
export declare const PasswordFieldError: Story;
|
|
8
|
+
export declare const PasswordFieldWithValue: Story;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PasswordField } from '../index';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Inputs/PasswordField',
|
|
4
|
+
component: PasswordField,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
args: {
|
|
7
|
+
onValidated: () => { },
|
|
8
|
+
onPasswordInput: () => { }
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export const PasswordFieldInactive = {
|
|
13
|
+
args: {},
|
|
14
|
+
parameters: {
|
|
15
|
+
design: {
|
|
16
|
+
type: 'figma',
|
|
17
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-38832&mode=design&t=mI94vejMFxk5S920-4',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const PasswordFieldError = {
|
|
22
|
+
args: {
|
|
23
|
+
state: 'error',
|
|
24
|
+
errorMessage: 'Some error'
|
|
25
|
+
},
|
|
26
|
+
parameters: {
|
|
27
|
+
design: {
|
|
28
|
+
type: 'figma',
|
|
29
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-38856&mode=design&t=mI94vejMFxk5S920-4',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export const PasswordFieldWithValue = {
|
|
34
|
+
args: {
|
|
35
|
+
value: 'somePass',
|
|
36
|
+
},
|
|
37
|
+
parameters: {
|
|
38
|
+
design: {
|
|
39
|
+
type: 'figma',
|
|
40
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12816-20475&mode=design&t=mI94vejMFxk5S920-4',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import _ from 'lodash/fp';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { phoneValidator } from '../../tools/customValidators';
|
|
5
|
+
import { TextField } from '../TextField';
|
|
6
|
+
import { emptyPhoneError, notCorrectPhoneError } from './ErrorMessages';
|
|
7
|
+
export const PhoneField = (props) => {
|
|
8
|
+
const { onValidated, onTextValid } = props;
|
|
9
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
10
|
+
const [touched, setTouched] = useState(false);
|
|
11
|
+
const [phoneNumber, setPhoneNumber] = useState('');
|
|
12
|
+
const getInputNumbersValue = (value) => {
|
|
13
|
+
return value.replace(/\D/g, '');
|
|
14
|
+
};
|
|
15
|
+
const onPhoneInput = (value, e) => {
|
|
16
|
+
const { target } = e;
|
|
17
|
+
const { selectionStart } = target;
|
|
18
|
+
let inputNumbersValue = getInputNumbersValue(value);
|
|
19
|
+
let formattedInputValue = '';
|
|
20
|
+
const { data, inputType } = e.nativeEvent;
|
|
21
|
+
if (inputType === 'deleteContentBackward' && value.length === 0) {
|
|
22
|
+
setPhoneNumber('');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (value.length !== selectionStart) {
|
|
26
|
+
if (data === null || /\d/g.test(data)) {
|
|
27
|
+
setPhoneNumber(value);
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (['7', '8', '9'].includes(inputNumbersValue[0])) {
|
|
32
|
+
if (inputNumbersValue[0] === '9')
|
|
33
|
+
inputNumbersValue = '7' + inputNumbersValue;
|
|
34
|
+
const firstSymbols = (inputNumbersValue[0] === '8') ? '8' : '+7';
|
|
35
|
+
formattedInputValue = firstSymbols;
|
|
36
|
+
if (inputNumbersValue.length > 1) {
|
|
37
|
+
formattedInputValue += '(' + inputNumbersValue.substring(1, 4);
|
|
38
|
+
}
|
|
39
|
+
if (inputNumbersValue.length >= 5) {
|
|
40
|
+
formattedInputValue += ')' + inputNumbersValue.substring(4, 7);
|
|
41
|
+
}
|
|
42
|
+
if (inputNumbersValue.length >= 8) {
|
|
43
|
+
formattedInputValue += '-' + inputNumbersValue.substring(7, 9);
|
|
44
|
+
}
|
|
45
|
+
if (inputNumbersValue.length >= 10) {
|
|
46
|
+
formattedInputValue += '-' + inputNumbersValue.substring(9, 11);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
formattedInputValue = '+' + inputNumbersValue.substring(0, 16);
|
|
51
|
+
}
|
|
52
|
+
setPhoneNumber(formattedInputValue);
|
|
53
|
+
};
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!touched) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const valid = phoneValidator(phoneNumber);
|
|
59
|
+
if (!valid) {
|
|
60
|
+
onValidated(false);
|
|
61
|
+
onTextValid('');
|
|
62
|
+
setErrorMessage(_.cond([
|
|
63
|
+
[_.isEmpty, () => emptyPhoneError],
|
|
64
|
+
[() => !valid, () => notCorrectPhoneError],
|
|
65
|
+
[_.stubTrue, _.stubString]
|
|
66
|
+
]));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
onValidated(true);
|
|
70
|
+
onTextValid(phoneNumber.replace(/\D/g, ''));
|
|
71
|
+
setErrorMessage('');
|
|
72
|
+
}, [onTextValid, onValidated, phoneNumber, touched]);
|
|
73
|
+
return (_jsx(TextField, { onChange: onPhoneInput, onTouched: setTouched, state: touched && errorMessage ? 'error' : 'idle', errorMessage: errorMessage, label: '\u041C\u043E\u0431\u0438\u043B\u044C\u043D\u044B\u0439 \u0442\u0435\u043B\u0435\u0444\u043E\u043D', type: 'tel', value: phoneNumber, required: true, checkIcon: true, ...props }));
|
|
74
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import type { ITextField } from '../TextField';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<ITextField>;
|
|
6
|
+
export declare const PhoneFieldInactive: Story;
|
|
7
|
+
export declare const PhoneFieldError: Story;
|
|
8
|
+
export declare const PhoneFieldWithValue: Story;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PhoneField } from './PhoneField';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Inputs/PhoneField',
|
|
4
|
+
component: PhoneField,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
args: {
|
|
7
|
+
onValidated: () => { },
|
|
8
|
+
onTextValid: () => { }
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export const PhoneFieldInactive = {
|
|
13
|
+
args: {},
|
|
14
|
+
parameters: {
|
|
15
|
+
design: {
|
|
16
|
+
type: 'figma',
|
|
17
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-37669&mode=design&t=H9AcJSW51fS3aPiW-4',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const PhoneFieldError = {
|
|
22
|
+
args: {
|
|
23
|
+
state: 'error',
|
|
24
|
+
errorMessage: 'Some error'
|
|
25
|
+
},
|
|
26
|
+
parameters: {
|
|
27
|
+
design: {
|
|
28
|
+
type: 'figma',
|
|
29
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-37685&mode=design&t=H9AcJSW51fS3aPiW-4',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export const PhoneFieldWithValue = {
|
|
34
|
+
args: {
|
|
35
|
+
value: '79990002211',
|
|
36
|
+
},
|
|
37
|
+
parameters: {
|
|
38
|
+
design: {
|
|
39
|
+
type: 'figma',
|
|
40
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12786-37681&mode=design&t=H9AcJSW51fS3aPiW-4',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import _ from 'lodash/fp';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { TextField, } from '../TextField';
|
|
5
|
+
import { emptyRepeatPasswordError, notCorrectRepeatPasswordError } from './ErrorMessages';
|
|
6
|
+
export const RepeatPasswordField = (props) => {
|
|
7
|
+
const { equalHandler, comparedValue } = props;
|
|
8
|
+
const [touched, setTouched] = useState(false);
|
|
9
|
+
const [password, setPassword] = useState('');
|
|
10
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
equalHandler(comparedValue === password);
|
|
13
|
+
if (!touched) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
setErrorMessage(_.cond([
|
|
17
|
+
[() => !password, () => emptyRepeatPasswordError],
|
|
18
|
+
[() => comparedValue !== password, () => notCorrectRepeatPasswordError],
|
|
19
|
+
]));
|
|
20
|
+
}, [touched, password, comparedValue, equalHandler]);
|
|
21
|
+
return (_jsx(TextField, { onChange: setPassword, onTouched: setTouched, state: touched && errorMessage ? 'error' : 'idle', errorMessage: errorMessage, label: '\u041F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435 \u043F\u0430\u0440\u043E\u043B\u044C', type: 'password', value: password, eyeIcon: true, checkIcon: true, required: true, ...props }));
|
|
22
|
+
};
|