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,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useRef, useState, useEffect } from 'react';
|
|
4
|
+
import ChevronDown from '../../assets/img/chevron-down.svg';
|
|
5
|
+
import { Option } from './Option/Option';
|
|
6
|
+
export const Collapse = (props) => {
|
|
7
|
+
const { options, selected, title, onSelect, chevron = true, optionsIcon, closeOnClick = true, } = props;
|
|
8
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
9
|
+
const rootRef = useRef(null);
|
|
10
|
+
const titleRef = useRef(null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const handleClick = (event) => {
|
|
13
|
+
const { target } = event;
|
|
14
|
+
if (target instanceof Node &&
|
|
15
|
+
rootRef.current &&
|
|
16
|
+
!rootRef.current.contains(target)) {
|
|
17
|
+
closeOnClick && setIsOpen(false);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
window.addEventListener('click', handleClick);
|
|
21
|
+
return () => {
|
|
22
|
+
window.removeEventListener('click', handleClick);
|
|
23
|
+
};
|
|
24
|
+
}, [closeOnClick, isOpen]);
|
|
25
|
+
const handleOptionClick = (value) => {
|
|
26
|
+
closeOnClick && setIsOpen(false);
|
|
27
|
+
onSelect(value);
|
|
28
|
+
};
|
|
29
|
+
const handleTitleClick = () => {
|
|
30
|
+
setIsOpen(!isOpen);
|
|
31
|
+
};
|
|
32
|
+
const chevronMods = [
|
|
33
|
+
'title__chevron',
|
|
34
|
+
isOpen && 'title__chevron--rotate',
|
|
35
|
+
];
|
|
36
|
+
const optionsBlock = (_jsx("div", { className: 'selector__options selector__options--slide-down', children: options.map((option) => (_jsx(Option, { option: option, onClick: handleOptionClick, optionsIcon: optionsIcon, selected: option.value === selected?.value }, option.value))) }));
|
|
37
|
+
const hasIcon = optionsIcon !== undefined || selected?.icon !== undefined;
|
|
38
|
+
const label = selected ? (_jsxs("div", { className: 'title__label', children: [hasIcon && (_jsx("div", { className: 'title__icon', children: selected?.icon ?? optionsIcon })), selected.label] })) : title;
|
|
39
|
+
return (_jsxs("div", { className: 'selector', ref: rootRef, children: [_jsxs("div", { className: cn('title', isOpen && 'title--active'), onClick: handleTitleClick, ref: titleRef, children: [label, chevron && (_jsx("div", { className: cn(chevronMods), children: _jsx(ChevronDown, {}) }))] }), isOpen && optionsBlock] }));
|
|
40
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { type ICollapse } from './Collapse';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<ICollapse>;
|
|
6
|
+
export declare const CollapseDefault: Story;
|
|
7
|
+
export declare const CollapseHovered: Story;
|
|
8
|
+
export declare const CollapseSelected: Story;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Dot from '../../assets/img/dot.svg';
|
|
3
|
+
import Star from '../../assets/img/star.svg';
|
|
4
|
+
import { Collapse } from './Collapse';
|
|
5
|
+
const data = [
|
|
6
|
+
{
|
|
7
|
+
value: '1',
|
|
8
|
+
label: 'Monday',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
value: '2',
|
|
12
|
+
label: 'Tuesday',
|
|
13
|
+
icon: _jsx(Star, {})
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
value: '3',
|
|
17
|
+
label: 'Wednesday',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
value: '4',
|
|
21
|
+
label: 'Thursday',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: '5',
|
|
25
|
+
label: 'Friday',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: '6',
|
|
29
|
+
label: 'Saturday',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
value: '7',
|
|
33
|
+
label: 'Sunday',
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const title = (_jsxs("div", { style: {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
justifyContent: 'space-around',
|
|
40
|
+
}, children: [_jsx("div", { style: {
|
|
41
|
+
display: 'flex',
|
|
42
|
+
width: '20px',
|
|
43
|
+
paddingRight: '8px'
|
|
44
|
+
}, children: _jsx(Star, {}) }), "Label"] }));
|
|
45
|
+
const meta = {
|
|
46
|
+
title: 'Inputs/Selector/Collapse',
|
|
47
|
+
component: Collapse,
|
|
48
|
+
tags: ['autodocs'],
|
|
49
|
+
args: {},
|
|
50
|
+
argTypes: {
|
|
51
|
+
title: {
|
|
52
|
+
table: {
|
|
53
|
+
disable: true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
optionsIcon: {
|
|
57
|
+
table: {
|
|
58
|
+
disable: true
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export default meta;
|
|
64
|
+
export const CollapseDefault = {
|
|
65
|
+
args: {
|
|
66
|
+
options: data,
|
|
67
|
+
title,
|
|
68
|
+
chevron: true,
|
|
69
|
+
optionsIcon: _jsx(Dot, {}),
|
|
70
|
+
},
|
|
71
|
+
parameters: {
|
|
72
|
+
design: {
|
|
73
|
+
type: 'figma',
|
|
74
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12695-13174&mode=dev',
|
|
75
|
+
},
|
|
76
|
+
pseudo: { hover: false },
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
export const CollapseHovered = {
|
|
80
|
+
args: {
|
|
81
|
+
options: data,
|
|
82
|
+
title,
|
|
83
|
+
chevron: true,
|
|
84
|
+
optionsIcon: _jsx(Dot, {}),
|
|
85
|
+
},
|
|
86
|
+
parameters: {
|
|
87
|
+
design: {
|
|
88
|
+
type: 'figma',
|
|
89
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12695-13277&mode=dev',
|
|
90
|
+
},
|
|
91
|
+
pseudo: { hover: true },
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
export const CollapseSelected = {
|
|
95
|
+
args: {
|
|
96
|
+
options: data,
|
|
97
|
+
title,
|
|
98
|
+
chevron: true,
|
|
99
|
+
optionsIcon: _jsx(Dot, {}),
|
|
100
|
+
selected: data[1],
|
|
101
|
+
},
|
|
102
|
+
parameters: {
|
|
103
|
+
design: {
|
|
104
|
+
type: 'figma',
|
|
105
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12702-24861&mode=dev',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useRef, useState, useEffect } from 'react';
|
|
4
|
+
import { getCoords } from '../../tools/getCoords';
|
|
5
|
+
import { Portal } from '../../Utils';
|
|
6
|
+
import { Option } from './Option/Option';
|
|
7
|
+
export const Dropdown = (props) => {
|
|
8
|
+
const { options, selected, title, onSelect, optionsIcon, optionsMaxHeight, optionsDirection = 'down', noFlip = false, } = props;
|
|
9
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
10
|
+
const [direction, setDirection] = useState(optionsDirection);
|
|
11
|
+
const [maxHeight, setMaxHeight] = useState(optionsMaxHeight);
|
|
12
|
+
const rootRef = useRef(null);
|
|
13
|
+
const titleRef = useRef(null);
|
|
14
|
+
const optionsRef = useRef(null);
|
|
15
|
+
const titleCoords = getCoords(titleRef);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const handleClick = (event) => {
|
|
18
|
+
const { target } = event;
|
|
19
|
+
if (target instanceof Node &&
|
|
20
|
+
rootRef.current &&
|
|
21
|
+
!rootRef.current.contains(target)) {
|
|
22
|
+
setIsOpen(false);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
window.addEventListener('click', handleClick);
|
|
26
|
+
return () => {
|
|
27
|
+
window.removeEventListener('click', handleClick);
|
|
28
|
+
};
|
|
29
|
+
}, [isOpen]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!optionsRef.current || !titleCoords) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const { topViewport: distanceToTop, bottomViewport } = titleCoords;
|
|
35
|
+
const windowHeight = window.innerHeight;
|
|
36
|
+
const optionsHeight = optionsRef.current.offsetHeight;
|
|
37
|
+
const distanceToBottom = windowHeight - bottomViewport;
|
|
38
|
+
const isDownDirection = optionsDirection === 'down';
|
|
39
|
+
setDirection(optionsDirection);
|
|
40
|
+
setMaxHeight(isDownDirection ? distanceToBottom : distanceToTop);
|
|
41
|
+
if (noFlip) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const hasSpaceToOptionsBelow = distanceToBottom - optionsHeight > 0;
|
|
45
|
+
const hasSpaceToOptionsAbove = distanceToTop - optionsHeight > 0;
|
|
46
|
+
const oppositeDirection = isDownDirection ? 'up' : 'down';
|
|
47
|
+
if (isDownDirection &&
|
|
48
|
+
!hasSpaceToOptionsBelow &&
|
|
49
|
+
hasSpaceToOptionsAbove) {
|
|
50
|
+
setDirection(oppositeDirection);
|
|
51
|
+
setMaxHeight(distanceToTop);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!isDownDirection &&
|
|
55
|
+
!hasSpaceToOptionsAbove &&
|
|
56
|
+
hasSpaceToOptionsBelow) {
|
|
57
|
+
setDirection(oppositeDirection);
|
|
58
|
+
setMaxHeight(distanceToBottom);
|
|
59
|
+
}
|
|
60
|
+
}, [isOpen, noFlip, optionsDirection, titleCoords]);
|
|
61
|
+
const handleOptionClick = (value) => {
|
|
62
|
+
setIsOpen(false);
|
|
63
|
+
onSelect(value);
|
|
64
|
+
};
|
|
65
|
+
const handleTitleClick = () => {
|
|
66
|
+
setIsOpen(!isOpen);
|
|
67
|
+
};
|
|
68
|
+
const optionsPosition = {
|
|
69
|
+
position: 'absolute',
|
|
70
|
+
left: `${titleCoords?.leftDocument ?? 0}px`,
|
|
71
|
+
minWidth: `${titleCoords?.width ?? 0}px`,
|
|
72
|
+
maxHeight: `${optionsMaxHeight ?? maxHeight}px`,
|
|
73
|
+
...(direction === 'down'
|
|
74
|
+
? { top: `${titleCoords?.bottomDocument ?? 0}px` }
|
|
75
|
+
: { bottom: `${window?.innerHeight - (titleCoords?.topDocument ?? 0)}px` }),
|
|
76
|
+
};
|
|
77
|
+
const optionsBlock = titleCoords && (_jsx("div", { className: `selector__options selector__options--slide-${direction}`, style: { ...optionsPosition }, ref: optionsRef, children: options.map((option) => (_jsx(Option, { option: option, onClick: handleOptionClick, optionsIcon: optionsIcon, selected: option.value === selected?.value }, option.value))) }));
|
|
78
|
+
const hasIcon = optionsIcon !== undefined || selected?.icon !== undefined;
|
|
79
|
+
const label = selected ? (_jsxs("div", { className: 'title__label', children: [hasIcon && (_jsx("div", { className: 'title__icon', children: selected?.icon ?? optionsIcon })), selected.label] })) : title;
|
|
80
|
+
return (_jsxs("div", { className: 'selector', ref: rootRef, children: [_jsx("div", { className: cn('title', isOpen && 'title--active'), onClick: handleTitleClick, ref: titleRef, children: label }), isOpen && _jsx(Portal, { children: optionsBlock })] }));
|
|
81
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { type IDropdown } from './Dropdown';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<IDropdown>;
|
|
6
|
+
export declare const DropdownDefault: Story;
|
|
7
|
+
export declare const DropdownHovered: Story;
|
|
8
|
+
export declare const DropdownSelected: Story;
|
|
9
|
+
export declare const DropdownSetMaxHeight: Story;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Logo from '../../assets/img/logo.svg';
|
|
3
|
+
import { Dropdown } from './Dropdown';
|
|
4
|
+
const data = [
|
|
5
|
+
{
|
|
6
|
+
value: '1',
|
|
7
|
+
label: 'Monday',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
value: '2',
|
|
11
|
+
label: 'Tuesday',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
value: '3',
|
|
15
|
+
label: 'Wednesday',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
value: '4',
|
|
19
|
+
label: 'Thursday',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
value: '5',
|
|
23
|
+
label: 'Friday',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: '6',
|
|
27
|
+
label: 'Saturday',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
value: '7',
|
|
31
|
+
label: 'Sunday',
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
const title = (_jsxs("div", { style: {
|
|
35
|
+
display: 'flex',
|
|
36
|
+
justifyContent: 'center',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
width: '100%'
|
|
39
|
+
}, children: [_jsx(Logo, {}), "Label"] }));
|
|
40
|
+
const meta = {
|
|
41
|
+
title: 'Inputs/Selector/Dropdown',
|
|
42
|
+
component: Dropdown,
|
|
43
|
+
tags: ['autodocs'],
|
|
44
|
+
args: {
|
|
45
|
+
title,
|
|
46
|
+
options: data,
|
|
47
|
+
},
|
|
48
|
+
argTypes: {
|
|
49
|
+
title: {
|
|
50
|
+
table: {
|
|
51
|
+
disable: true,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
optionsIcon: {
|
|
55
|
+
table: {
|
|
56
|
+
disable: true,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
parameters: {
|
|
61
|
+
pseudo: { hover: false },
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export default meta;
|
|
65
|
+
export const DropdownDefault = {
|
|
66
|
+
parameters: {
|
|
67
|
+
design: {
|
|
68
|
+
type: 'figma',
|
|
69
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12702-24861&mode=dev',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
export const DropdownHovered = {
|
|
74
|
+
parameters: {
|
|
75
|
+
design: {
|
|
76
|
+
type: 'figma',
|
|
77
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12695-13277&mode=dev',
|
|
78
|
+
},
|
|
79
|
+
pseudo: { hover: true },
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
export const DropdownSelected = {
|
|
83
|
+
args: {
|
|
84
|
+
selected: data[1]
|
|
85
|
+
},
|
|
86
|
+
parameters: {
|
|
87
|
+
design: {
|
|
88
|
+
type: 'figma',
|
|
89
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12695-13277&mode=dev',
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
export const DropdownSetMaxHeight = {
|
|
94
|
+
args: {
|
|
95
|
+
optionsMaxHeight: 150
|
|
96
|
+
},
|
|
97
|
+
parameters: {
|
|
98
|
+
design: {
|
|
99
|
+
type: 'figma',
|
|
100
|
+
url: 'https://www.figma.com/file/8cQcICaes5IWFubU66DMdl/Torgbox-CRM?type=design&node-id=12695-13277&mode=dev',
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
export const Option = (props) => {
|
|
4
|
+
const { option: { value, label, icon }, onClick, selected = false, optionsIcon, } = props;
|
|
5
|
+
const handleClick = (clickedValue) => () => {
|
|
6
|
+
onClick(clickedValue);
|
|
7
|
+
};
|
|
8
|
+
const hasIcon = optionsIcon !== undefined || icon !== undefined;
|
|
9
|
+
return (_jsxs("div", { className: cn('selector-option', selected && 'selector-option--selected'), onClick: handleClick(value), children: [hasIcon && (_jsx("div", { className: 'selector-option__icon', children: icon ?? optionsIcon })), label] }));
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { type IOption } from './Option';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<IOption>;
|
|
6
|
+
export declare const OptionDefault: Story;
|
|
7
|
+
export declare const OptionHovered: Story;
|
|
8
|
+
export declare const OptionSelected: Story;
|
|
9
|
+
export declare const OptionWithIcon: Story;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Star from '../../../assets/img/star.svg';
|
|
3
|
+
import { Option } from './Option';
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Inputs/Selector/Option',
|
|
6
|
+
component: Option,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
args: {}
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const OptionDefault = {
|
|
12
|
+
args: {
|
|
13
|
+
option: {
|
|
14
|
+
value: '1',
|
|
15
|
+
label: 'Monday',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export const OptionHovered = {
|
|
20
|
+
args: {
|
|
21
|
+
option: {
|
|
22
|
+
value: '1',
|
|
23
|
+
label: 'Monday',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
parameters: {
|
|
27
|
+
pseudo: { hover: true },
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export const OptionSelected = {
|
|
31
|
+
args: {
|
|
32
|
+
option: {
|
|
33
|
+
value: '1',
|
|
34
|
+
label: 'Monday',
|
|
35
|
+
},
|
|
36
|
+
selected: true
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export const OptionWithIcon = {
|
|
40
|
+
args: {
|
|
41
|
+
option: {
|
|
42
|
+
value: '1',
|
|
43
|
+
label: 'Monday',
|
|
44
|
+
},
|
|
45
|
+
optionsIcon: _jsx(Star, {})
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
$option-bg: $color-neutral-gray;
|
|
2
|
+
$option-bg-hover: $neutral-A8;
|
|
3
|
+
$option-bg-selected: $primary-A12;
|
|
4
|
+
$option-text: $neutral-high;
|
|
5
|
+
$option-text-selected: $primary-high;
|
|
6
|
+
$option-icon: $neutral-high;
|
|
7
|
+
$option-icon-selected: $primary-high;
|
|
8
|
+
|
|
9
|
+
.selector-option {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
|
|
15
|
+
padding: 8px 12px;
|
|
16
|
+
|
|
17
|
+
color: $option-text;
|
|
18
|
+
|
|
19
|
+
background: $option-bg;
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
|
|
22
|
+
fill: $option-icon;
|
|
23
|
+
|
|
24
|
+
&:hover {
|
|
25
|
+
background: $option-bg-hover;
|
|
26
|
+
transition: background-color 0.2s;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&--selected {
|
|
30
|
+
color: $option-text-selected;
|
|
31
|
+
background: $option-bg-selected;
|
|
32
|
+
fill: $option-icon-selected;
|
|
33
|
+
|
|
34
|
+
&:hover {
|
|
35
|
+
background: $option-bg-selected;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&__icon {
|
|
40
|
+
display: flex;
|
|
41
|
+
width: 20px;
|
|
42
|
+
padding-right: 8px;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
$title-bg: transparent;
|
|
2
|
+
$title-bg-hover: $neutral-A8;
|
|
3
|
+
$title-bg-active: $neutral-A12;
|
|
4
|
+
$title-text: $neutral-high;
|
|
5
|
+
$title-icon: $neutral-high;
|
|
6
|
+
$title-border: $neutral-border-low;
|
|
7
|
+
$options-bg: $color-neutral-gray;
|
|
8
|
+
|
|
9
|
+
.selector {
|
|
10
|
+
@keyframes slide-down {
|
|
11
|
+
from {
|
|
12
|
+
transform: translateY(-5%);
|
|
13
|
+
opacity: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
to {
|
|
17
|
+
transform: translateY(0);
|
|
18
|
+
opacity: 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@keyframes slide-up {
|
|
23
|
+
from {
|
|
24
|
+
transform: translateY(5%);
|
|
25
|
+
opacity: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
to {
|
|
29
|
+
transform: translateY(0);
|
|
30
|
+
opacity: 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
width: 200px;
|
|
35
|
+
|
|
36
|
+
.title {
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: space-between;
|
|
42
|
+
|
|
43
|
+
padding: 8px 12px;
|
|
44
|
+
|
|
45
|
+
color: $title-text;
|
|
46
|
+
|
|
47
|
+
background: $title-bg;
|
|
48
|
+
border-radius: 4px;
|
|
49
|
+
|
|
50
|
+
transition: background-color 0.2s;
|
|
51
|
+
|
|
52
|
+
&:hover {
|
|
53
|
+
background: $title-bg-hover;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&--active {
|
|
57
|
+
background: $title-bg-active;
|
|
58
|
+
border-bottom: 1px solid $title-border;
|
|
59
|
+
border-radius: 4px 4px 0 0;
|
|
60
|
+
&:hover {
|
|
61
|
+
background: $title-bg-active;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&__label {
|
|
66
|
+
display: flex;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&__icon {
|
|
70
|
+
display: flex;
|
|
71
|
+
width: 20px;
|
|
72
|
+
padding-right: 8px;
|
|
73
|
+
fill: $title-icon;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&__chevron {
|
|
77
|
+
display: flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
fill: $title-icon;
|
|
80
|
+
transition: all 200ms;
|
|
81
|
+
|
|
82
|
+
&--rotate {
|
|
83
|
+
transform: rotate(180deg);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&__options {
|
|
89
|
+
overflow: auto;
|
|
90
|
+
background: $options-bg;
|
|
91
|
+
border-radius: 0 0 4px 4px;
|
|
92
|
+
|
|
93
|
+
&--slide-up {
|
|
94
|
+
animation: slide-up 0.2s forwards;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&--slide-down {
|
|
98
|
+
animation: slide-down 0.2s forwards;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import _ from 'lodash/fp';
|
|
4
|
+
import { useEffect, useRef, useState, } from 'react';
|
|
5
|
+
import CheckIcon from '../../assets/img/check.svg';
|
|
6
|
+
import CrossIcon from '../../assets/img/cross.svg';
|
|
7
|
+
import EyeCloseIcon from '../../assets/img/eye-close.svg';
|
|
8
|
+
import EyeOpenIcon from '../../assets/img/eye-open.svg';
|
|
9
|
+
import SearchIcon from '../../assets/img/search.svg';
|
|
10
|
+
import styles from './textField.module.scss';
|
|
11
|
+
export const TextField = (props) => {
|
|
12
|
+
const { label, value, description, className, placeholder, type = 'text', size = 'large', state = 'idle', tabIndex, maxLength, errorMessage, onChange = _.noop, onClear = _.noop, onVisibilityToggle = _.noop, onTouched = _.noop, required = false, autoFocus = false, checkIcon = false, clearIcon = false, eyeIcon = false, searchIcon = false, alwaysShowError = false, } = props;
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
const [focused, setFocused] = useState(false);
|
|
15
|
+
const [inputType, setInputType] = useState(type);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setInputType(type);
|
|
18
|
+
}, [type]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (autoFocus) {
|
|
21
|
+
setFocused(true);
|
|
22
|
+
ref.current?.focus();
|
|
23
|
+
}
|
|
24
|
+
}, [autoFocus]);
|
|
25
|
+
const onChangeHandler = (e) => {
|
|
26
|
+
onChange(e.target.value, e);
|
|
27
|
+
};
|
|
28
|
+
const toggleVisibility = () => {
|
|
29
|
+
const newType = inputType === 'password' ? 'text' : 'password';
|
|
30
|
+
setInputType(newType);
|
|
31
|
+
onVisibilityToggle();
|
|
32
|
+
};
|
|
33
|
+
const onBlur = () => {
|
|
34
|
+
setFocused(false);
|
|
35
|
+
};
|
|
36
|
+
const onFocus = () => {
|
|
37
|
+
setFocused(true);
|
|
38
|
+
onTouched(true);
|
|
39
|
+
};
|
|
40
|
+
const disabledState = state === 'disabled';
|
|
41
|
+
const wrapperSizeClassBySize = {
|
|
42
|
+
medium: styles.textFieldWrapperMedium,
|
|
43
|
+
large: styles.textFieldWrapperLarge,
|
|
44
|
+
};
|
|
45
|
+
const labelSizeClassBySize = {
|
|
46
|
+
medium: styles.textFieldWrapperLabelMedium,
|
|
47
|
+
large: styles.textFieldWrapperLabelLarge,
|
|
48
|
+
};
|
|
49
|
+
const inputSizeClassBySize = {
|
|
50
|
+
medium: styles.textFieldInputMedium,
|
|
51
|
+
large: styles.textFieldInputLarge,
|
|
52
|
+
};
|
|
53
|
+
const iconsSizeClassBySize = {
|
|
54
|
+
medium: styles.textFieldIconsMedium,
|
|
55
|
+
large: styles.textFieldIconsLarge,
|
|
56
|
+
};
|
|
57
|
+
const fieldSizeClassBySize = {
|
|
58
|
+
medium: styles.textFieldMedium,
|
|
59
|
+
large: styles.textFieldLarge,
|
|
60
|
+
};
|
|
61
|
+
const stateClassByState = {
|
|
62
|
+
idle: styles.textFieldIdle,
|
|
63
|
+
error: styles.textFieldError,
|
|
64
|
+
disabled: styles.textFieldDisabled,
|
|
65
|
+
};
|
|
66
|
+
const textFieldWrapperClassName = cn(styles.textFieldWrapper, wrapperSizeClassBySize[size]);
|
|
67
|
+
const textFieldClassName = cn(styles.textField, fieldSizeClassBySize[size], stateClassByState[state], {
|
|
68
|
+
[styles.textFieldFocused]: !alwaysShowError ? focused : state !== 'error',
|
|
69
|
+
}, className);
|
|
70
|
+
const inputClassName = cn(styles.textFieldInput, inputSizeClassBySize[size]);
|
|
71
|
+
const iconsClassName = cn(styles.textFieldIcons, iconsSizeClassBySize[size]);
|
|
72
|
+
const labelClassName = cn(styles.textFieldWrapperLabel, labelSizeClassBySize[size], { [styles.textFieldWrapperLabelDisabled]: disabledState });
|
|
73
|
+
const bottomText = () => {
|
|
74
|
+
const showError = !!errorMessage && (alwaysShowError || !focused);
|
|
75
|
+
if (!showError && !description) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
return (_jsx("span", { className: cn(styles.textFieldWrapperBottomText, {
|
|
79
|
+
[styles.textFieldWrapperBottomTextDescription]: !!description,
|
|
80
|
+
[styles.textFieldWrapperBottomTextError]: showError,
|
|
81
|
+
}), children: showError ? errorMessage : description }));
|
|
82
|
+
};
|
|
83
|
+
const input = (_jsxs("div", { className: textFieldClassName, children: [searchIcon && (_jsx("div", { className: iconsClassName, children: _jsx(SearchIcon, {}) })), _jsx("input", { ref: ref, type: inputType, value: value, onChange: onChangeHandler, className: inputClassName, onFocus: onFocus, onBlur: onBlur, placeholder: disabledState ? '' : placeholder, disabled: disabledState, onClick: onFocus, tabIndex: tabIndex, maxLength: maxLength }), (checkIcon && value && !errorMessage && !disabledState) && (_jsx("div", { id: 'check-icon', className: iconsClassName, children: _jsx(CheckIcon, {}) })), clearIcon && value && !disabledState && (_jsx("div", { className: [iconsClassName, 'cursor-pointer'].join(' '), onClick: onClear, children: _jsx(CrossIcon, {}) })), eyeIcon && !disabledState && (_jsx("div", { id: 'eye-icon', className: [iconsClassName, 'cursor-pointer'].join(' '), onClick: toggleVisibility, children: inputType === 'password' ? _jsx(EyeOpenIcon, {}) : _jsx(EyeCloseIcon, {}) }))] }));
|
|
84
|
+
return (_jsxs("div", { className: textFieldWrapperClassName, children: [label && (_jsxs("div", { className: labelClassName, children: [label, required && (_jsx("span", { className: 'text-field-wrapper__label--required', children: "*" }))] })), input, bottomText()] }));
|
|
85
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
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 TextFieldDefault: Story;
|
|
7
|
+
export declare const TextFieldHovered: Story;
|
|
8
|
+
export declare const TextFieldActive: Story;
|
|
9
|
+
export declare const TextFieldDisabled: Story;
|
|
10
|
+
export declare const TextFieldError: Story;
|
|
11
|
+
export declare const TextFieldWithValue: Story;
|
|
12
|
+
export declare const TextFieldHiddenValue: Story;
|