@buerokratt-ria/common-gui-components 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +18 -0
- package/CHANGELOG.md +7 -0
- package/MAKING_CHANGES.md +8 -0
- package/README.md +49 -0
- package/assets/ding.mp3 +0 -0
- package/assets/logo-white.svg +29 -0
- package/assets/logo.svg +31 -0
- package/assets/newMessageSound.mp3 +0 -0
- package/constants/config.ts +12 -0
- package/constants/index.ts +1 -0
- package/context/index.ts +1 -0
- package/context/toastContext.tsx +60 -0
- package/hooks/index.ts +3 -0
- package/hooks/useAudio.tsx +30 -0
- package/hooks/useDocumentEscapeListener.tsx +17 -0
- package/hooks/useToast.tsx +5 -0
- package/i18n.ts +26 -0
- package/index.ts +6 -0
- package/package.json +122 -0
- package/project.json +52 -0
- package/services/api.ts +74 -0
- package/services/index.ts +3 -0
- package/services/sse-service.ts +30 -0
- package/services/users.ts +58 -0
- package/store/index.ts +253 -0
- package/templates/history-page/index.ts +1 -0
- package/templates/history-page/src/History.scss +47 -0
- package/templates/history-page/src/index.tsx +998 -0
- package/templates/history-page/src/unfiyDate.tsx +7 -0
- package/translations/en/common.json +467 -0
- package/translations/et/common.json +467 -0
- package/tsconfig.base.json +21 -0
- package/tsconfig.json +17 -0
- package/tsconfig.spec.json +19 -0
- package/types/authorities.ts +8 -0
- package/types/botConfig.ts +7 -0
- package/types/chat.ts +126 -0
- package/types/customerSupportActivity.ts +5 -0
- package/types/deleteChatSettings.ts +9 -0
- package/types/emergencyNotice.ts +10 -0
- package/types/establishment.ts +4 -0
- package/types/index.ts +18 -0
- package/types/mainNavigation.ts +11 -0
- package/types/message.ts +74 -0
- package/types/organizationWorkingTime.ts +27 -0
- package/types/router.ts +4 -0
- package/types/service.ts +6 -0
- package/types/session.ts +7 -0
- package/types/skmConfig.ts +8 -0
- package/types/user.ts +40 -0
- package/types/userInfo.ts +16 -0
- package/types/userProfileSettings.ts +10 -0
- package/types/widgetConfig.ts +8 -0
- package/ui-components/Button/Button.scss +150 -0
- package/ui-components/Button/index.tsx +41 -0
- package/ui-components/ButtonMessage/ButtonMessage.scss +16 -0
- package/ui-components/ButtonMessage/index.tsx +19 -0
- package/ui-components/Card/Card.scss +69 -0
- package/ui-components/Card/index.tsx +39 -0
- package/ui-components/Chat/Chat.scss +447 -0
- package/ui-components/Chat/ChatMessage.tsx +270 -0
- package/ui-components/Chat/ChatTextArea.scss +110 -0
- package/ui-components/Chat/ChatTextArea.tsx +97 -0
- package/ui-components/Chat/LoaderOverlay.tsx +39 -0
- package/ui-components/Chat/Markdownify.tsx +49 -0
- package/ui-components/Chat/PreviewMessage.tsx +39 -0
- package/ui-components/Chat/Typing.scss +46 -0
- package/ui-components/Chat/index.tsx +1111 -0
- package/ui-components/ChatEvent/Chat.scss +40 -0
- package/ui-components/ChatEvent/index.tsx +216 -0
- package/ui-components/DataTable/CloseIcon.tsx +22 -0
- package/ui-components/DataTable/DataTable.scss +188 -0
- package/ui-components/DataTable/DeboucedInput.scss +11 -0
- package/ui-components/DataTable/DebouncedInput.tsx +54 -0
- package/ui-components/DataTable/Filter.tsx +121 -0
- package/ui-components/DataTable/index.tsx +432 -0
- package/ui-components/Dialog/Dialog.scss +63 -0
- package/ui-components/Dialog/index.tsx +44 -0
- package/ui-components/Drawer/Drawer.scss +40 -0
- package/ui-components/Drawer/index.tsx +42 -0
- package/ui-components/FormElements/FormCheckbox/FormCheckbox.scss +57 -0
- package/ui-components/FormElements/FormCheckbox/index.tsx +39 -0
- package/ui-components/FormElements/FormCheckboxes/FormCheckboxes.scss +63 -0
- package/ui-components/FormElements/FormCheckboxes/index.tsx +44 -0
- package/ui-components/FormElements/FormDatepicker/FormDatepicker.scss +154 -0
- package/ui-components/FormElements/FormDatepicker/index.tsx +123 -0
- package/ui-components/FormElements/FormInput/FormInput.scss +90 -0
- package/ui-components/FormElements/FormInput/index.tsx +47 -0
- package/ui-components/FormElements/FormRadios/FormRadios.scss +72 -0
- package/ui-components/FormElements/FormRadios/index.tsx +36 -0
- package/ui-components/FormElements/FormSelect/FormMultiselect.tsx +124 -0
- package/ui-components/FormElements/FormSelect/FormSelect.scss +121 -0
- package/ui-components/FormElements/FormSelect/index.tsx +100 -0
- package/ui-components/FormElements/FormTextarea/FormTextarea.scss +109 -0
- package/ui-components/FormElements/FormTextarea/index.tsx +154 -0
- package/ui-components/FormElements/Switch/Switch.scss +69 -0
- package/ui-components/FormElements/Switch/index.tsx +65 -0
- package/ui-components/FormElements/SwitchBox/SwitchBox.scss +45 -0
- package/ui-components/FormElements/SwitchBox/index.tsx +44 -0
- package/ui-components/FormElements/index.tsx +23 -0
- package/ui-components/HistoricalChat/ChatMessage.tsx +67 -0
- package/ui-components/HistoricalChat/HistoricalChat.scss +225 -0
- package/ui-components/HistoricalChat/index.tsx +282 -0
- package/ui-components/Icon/Icon.scss +17 -0
- package/ui-components/Icon/index.tsx +26 -0
- package/ui-components/Label/Label.scss +76 -0
- package/ui-components/Label/index.tsx +40 -0
- package/ui-components/OptionMessage/OptionMessage.scss +16 -0
- package/ui-components/OptionMessage/index.tsx +16 -0
- package/ui-components/Toast/Toast.scss +73 -0
- package/ui-components/Toast/index.tsx +54 -0
- package/ui-components/Tooltip/Tooltip.scss +17 -0
- package/ui-components/Tooltip/index.tsx +28 -0
- package/ui-components/Track/index.tsx +57 -0
- package/ui-components/index.tsx +53 -0
- package/utils/constants.ts +19 -0
- package/utils/format-bytes.ts +8 -0
- package/utils/generateUEID.ts +8 -0
- package/utils/local-storage-utils.ts +17 -0
- package/utils/parse-utils.ts +23 -0
- package/utils/state-management-utils.ts +13 -0
- package/vite.config.ts +67 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, { FC, ReactNode, SelectHTMLAttributes, useId, useState } from 'react';
|
|
2
|
+
import { useSelect } from 'downshift';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { MdArrowDropDown } from 'react-icons/md';
|
|
6
|
+
|
|
7
|
+
import { Icon } from '../..';
|
|
8
|
+
import './FormSelect.scss';
|
|
9
|
+
|
|
10
|
+
type SelectOption = { label: string, value: string };
|
|
11
|
+
|
|
12
|
+
type FormMultiselectProps = SelectHTMLAttributes<HTMLSelectElement> & {
|
|
13
|
+
label: ReactNode;
|
|
14
|
+
name: string;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
hideLabel?: boolean;
|
|
17
|
+
options: SelectOption[];
|
|
18
|
+
selectedOptions?: SelectOption[];
|
|
19
|
+
onSelectionChange?: (selection: SelectOption[] | null) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const FormMultiselect: FC<FormMultiselectProps> = (
|
|
23
|
+
{
|
|
24
|
+
label,
|
|
25
|
+
hideLabel,
|
|
26
|
+
options,
|
|
27
|
+
disabled,
|
|
28
|
+
placeholder,
|
|
29
|
+
defaultValue,
|
|
30
|
+
selectedOptions,
|
|
31
|
+
onSelectionChange,
|
|
32
|
+
...rest
|
|
33
|
+
},
|
|
34
|
+
) => {
|
|
35
|
+
const id = useId();
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
const [selectedItems, setSelectedItems] = useState<SelectOption[]>(selectedOptions ?? []);
|
|
38
|
+
const {
|
|
39
|
+
isOpen,
|
|
40
|
+
getToggleButtonProps,
|
|
41
|
+
getLabelProps,
|
|
42
|
+
getMenuProps,
|
|
43
|
+
highlightedIndex,
|
|
44
|
+
getItemProps,
|
|
45
|
+
} = useSelect({
|
|
46
|
+
items: options,
|
|
47
|
+
stateReducer: (state, actionAndChanges) => {
|
|
48
|
+
const { changes, type } = actionAndChanges;
|
|
49
|
+
if (type === useSelect.stateChangeTypes.ItemClick) {
|
|
50
|
+
return {
|
|
51
|
+
...changes,
|
|
52
|
+
isOpen: true,
|
|
53
|
+
highlightedIndex: state.highlightedIndex,
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
return changes;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
selectedItem: null,
|
|
60
|
+
onSelectedItemChange: ({ selectedItem }) => {
|
|
61
|
+
if (!selectedItem) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const index = selectedItems.findIndex((item) => item.value === selectedItem.value);
|
|
65
|
+
const items = [];
|
|
66
|
+
if (index > 0) {
|
|
67
|
+
items.push(
|
|
68
|
+
...selectedItems.slice(0, index),
|
|
69
|
+
...selectedItems.slice(index + 1)
|
|
70
|
+
);
|
|
71
|
+
} else if (index === 0) {
|
|
72
|
+
items.push(...selectedItems.slice(1));
|
|
73
|
+
} else {
|
|
74
|
+
items.push(...selectedItems, selectedItem);
|
|
75
|
+
}
|
|
76
|
+
setSelectedItems(items);
|
|
77
|
+
if (onSelectionChange) onSelectionChange(items);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const selectClasses = clsx(
|
|
82
|
+
'select',
|
|
83
|
+
disabled && 'select--disabled',
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const placeholderValue = placeholder || t('global.choose');
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div className={selectClasses} style={rest.style}>
|
|
90
|
+
{label && !hideLabel && <label htmlFor={id} className='select__label' {...getLabelProps()}>{label}</label>}
|
|
91
|
+
<div className='select__wrapper'>
|
|
92
|
+
<div className='select__trigger' {...getToggleButtonProps()}>
|
|
93
|
+
{selectedItems.length > 0 ? `${placeholder ?? t('global.chosen')} (${selectedItems.length})` : placeholderValue}
|
|
94
|
+
<Icon label='Dropdown icon' size='medium' icon={<MdArrowDropDown color='#5D6071' />} />
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<ul className='select__menu' {...getMenuProps()}>
|
|
98
|
+
{isOpen &&
|
|
99
|
+
options.map((item, index) => (
|
|
100
|
+
<li
|
|
101
|
+
key={`${item.label}-${index}`}
|
|
102
|
+
className={clsx('select__option', { 'select__option--selected': highlightedIndex === index })}
|
|
103
|
+
{...getItemProps({
|
|
104
|
+
item,
|
|
105
|
+
index,
|
|
106
|
+
})}
|
|
107
|
+
>
|
|
108
|
+
<input
|
|
109
|
+
type='checkbox'
|
|
110
|
+
checked={selectedItems.map((s) => s.value).includes(item.value)}
|
|
111
|
+
value={item.value}
|
|
112
|
+
onChange={() => null}
|
|
113
|
+
/>
|
|
114
|
+
<span>{item.label}</span>
|
|
115
|
+
</li>
|
|
116
|
+
))}
|
|
117
|
+
</ul>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
export default FormMultiselect;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
@import 'src/styles/tools/spacing';
|
|
2
|
+
@import 'src/styles/tools/color';
|
|
3
|
+
@import 'src/styles/settings/variables/other';
|
|
4
|
+
@import 'src/styles/settings/variables/typography';
|
|
5
|
+
|
|
6
|
+
.select {
|
|
7
|
+
$self: &;
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: get-spacing(paldiski);
|
|
11
|
+
width: 100%;
|
|
12
|
+
|
|
13
|
+
&__label {
|
|
14
|
+
flex: 0 0 185px;
|
|
15
|
+
font-size: $veera-font-size-100;
|
|
16
|
+
line-height: 24px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&__wrapper {
|
|
20
|
+
width: 100%;
|
|
21
|
+
position: relative;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&__trigger {
|
|
25
|
+
width: 100%;
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: space-between;
|
|
29
|
+
appearance: none;
|
|
30
|
+
background-color: get-color(white);
|
|
31
|
+
border: 1px solid get-color(black-coral-6);
|
|
32
|
+
border-radius: $veera-radius-s;
|
|
33
|
+
color: get-color(black);
|
|
34
|
+
font-size: $veera-font-size-100;
|
|
35
|
+
height: 40px;
|
|
36
|
+
line-height: 24px;
|
|
37
|
+
padding: get-spacing(paldiski);
|
|
38
|
+
|
|
39
|
+
.icon {
|
|
40
|
+
font-size: $veera-font-size-250;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&[aria-expanded=true] {
|
|
44
|
+
border-color: get-color(sapphire-blue-10);
|
|
45
|
+
border-radius: 3px;
|
|
46
|
+
|
|
47
|
+
+ #{$self}__menu {
|
|
48
|
+
display: block;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
+#{$self}__menu_up {
|
|
52
|
+
display: block;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.icon {
|
|
56
|
+
transform: rotate(180deg);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&__menu {
|
|
62
|
+
display: none;
|
|
63
|
+
position: absolute;
|
|
64
|
+
top: 100%;
|
|
65
|
+
left: 0;
|
|
66
|
+
right: 0;
|
|
67
|
+
background-color: get-color(white);
|
|
68
|
+
border-radius: 4px;
|
|
69
|
+
border: 1px solid get-color(black-coral-2);
|
|
70
|
+
border-top: 1;
|
|
71
|
+
z-index: 9998;
|
|
72
|
+
max-height: 320px;
|
|
73
|
+
overflow: auto;
|
|
74
|
+
margin-top: 3px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&__menu_up {
|
|
78
|
+
display: none;
|
|
79
|
+
position: absolute;
|
|
80
|
+
top: auto;
|
|
81
|
+
left: 0;
|
|
82
|
+
right: 0;
|
|
83
|
+
bottom: 100%;
|
|
84
|
+
background-color: get-color(white);
|
|
85
|
+
border-radius: 4px;
|
|
86
|
+
border: 1px solid get-color(black-coral-2);
|
|
87
|
+
border-top: 1;
|
|
88
|
+
z-index: 9998;
|
|
89
|
+
max-height: 320px;
|
|
90
|
+
overflow: auto;
|
|
91
|
+
margin-bottom: 3px;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
&__option {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
gap: 8px;
|
|
98
|
+
padding: 8px 15px;
|
|
99
|
+
|
|
100
|
+
span {
|
|
101
|
+
display: block;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&[aria-selected=true] {
|
|
105
|
+
background-color: get-color(sapphire-blue-10);
|
|
106
|
+
color: get-color(white);
|
|
107
|
+
|
|
108
|
+
&:hover,
|
|
109
|
+
&:focus {
|
|
110
|
+
background-color: get-color(sapphire-blue-10);
|
|
111
|
+
color: get-color(white);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
&:hover,
|
|
116
|
+
&:focus {
|
|
117
|
+
background-color: get-color(black-coral-0);
|
|
118
|
+
color: get-color(black-coral-20);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React, {forwardRef, ReactNode, SelectHTMLAttributes, useEffect, useId, useState} from 'react';
|
|
2
|
+
import { useSelect } from 'downshift';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { MdArrowDropDown } from 'react-icons/md';
|
|
6
|
+
|
|
7
|
+
import { Icon } from '../..';
|
|
8
|
+
import './FormSelect.scss';
|
|
9
|
+
import { ControllerRenderProps } from 'react-hook-form';
|
|
10
|
+
|
|
11
|
+
type FormSelectProps = Partial<ControllerRenderProps> & SelectHTMLAttributes<HTMLSelectElement> & {
|
|
12
|
+
label: ReactNode;
|
|
13
|
+
name: string;
|
|
14
|
+
hideLabel?: boolean;
|
|
15
|
+
direction?: 'down' | 'up';
|
|
16
|
+
defaultValue?: string | null;
|
|
17
|
+
options: {
|
|
18
|
+
label: string;
|
|
19
|
+
value: string;
|
|
20
|
+
}[];
|
|
21
|
+
onSelectionChange?: (selection: { label: string, value: string } | null) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const itemToString = (item: ({ label: string, value: string } | null)) => {
|
|
25
|
+
return item ? item.value : '';
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const FormSelect= forwardRef<HTMLSelectElement, FormSelectProps>((
|
|
29
|
+
{
|
|
30
|
+
label,
|
|
31
|
+
hideLabel,
|
|
32
|
+
direction = 'down',
|
|
33
|
+
options,
|
|
34
|
+
disabled,
|
|
35
|
+
placeholder,
|
|
36
|
+
defaultValue,
|
|
37
|
+
onSelectionChange,
|
|
38
|
+
...rest
|
|
39
|
+
},
|
|
40
|
+
ref
|
|
41
|
+
) => {
|
|
42
|
+
const id = useId();
|
|
43
|
+
const { t } = useTranslation();
|
|
44
|
+
const defaultSelected = options.find((o) => o.value === defaultValue) || null;
|
|
45
|
+
const [selectedItem, setSelectedItem] = useState<{ label: string, value: string } | null>(defaultSelected);
|
|
46
|
+
const {
|
|
47
|
+
isOpen,
|
|
48
|
+
getToggleButtonProps,
|
|
49
|
+
getLabelProps,
|
|
50
|
+
getMenuProps,
|
|
51
|
+
highlightedIndex,
|
|
52
|
+
getItemProps,
|
|
53
|
+
} = useSelect({
|
|
54
|
+
id,
|
|
55
|
+
items: options,
|
|
56
|
+
itemToString,
|
|
57
|
+
selectedItem,
|
|
58
|
+
onSelectedItemChange: ({ selectedItem: newSelectedItem }) => {
|
|
59
|
+
setSelectedItem(newSelectedItem ?? null);
|
|
60
|
+
if (onSelectionChange) onSelectionChange(newSelectedItem ?? null);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const updatedSelection = options.find((o) => o.value === defaultValue) || placeholderValue;
|
|
66
|
+
setSelectedItem(updatedSelection);
|
|
67
|
+
}, [defaultValue, options]);
|
|
68
|
+
|
|
69
|
+
const selectClasses = clsx(
|
|
70
|
+
'select',
|
|
71
|
+
disabled && 'select--disabled',
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const placeholderValue = placeholder || t('global.choose');
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div className={selectClasses} style={rest.style}>
|
|
78
|
+
{label && !hideLabel && <label htmlFor={id} className='select__label' {...getLabelProps()}>{label}</label>}
|
|
79
|
+
<div className='select__wrapper' >
|
|
80
|
+
<div className='select__trigger' {...getToggleButtonProps()}>
|
|
81
|
+
{selectedItem?.label ?? placeholderValue}
|
|
82
|
+
<Icon label='Dropdown icon' size='medium' icon={<MdArrowDropDown color='#5D6071' />} />
|
|
83
|
+
</div>
|
|
84
|
+
<ul ref={ref} className={direction === 'down' ? 'select__menu' : 'select__menu_up'} {...getMenuProps()}>
|
|
85
|
+
{isOpen && (
|
|
86
|
+
options.map((item, index) => (
|
|
87
|
+
<li className={clsx('select__option', { 'select__option--selected': highlightedIndex === index })}
|
|
88
|
+
key={`${item.value}${index}`} {...getItemProps({ item, index })}>
|
|
89
|
+
{item.label}
|
|
90
|
+
</li>
|
|
91
|
+
))
|
|
92
|
+
)}
|
|
93
|
+
</ul>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export default FormSelect;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
@import 'src/styles/tools/spacing';
|
|
2
|
+
@import 'src/styles/tools/color';
|
|
3
|
+
@import 'src/styles/settings/variables/other';
|
|
4
|
+
@import 'src/styles/settings/variables/typography';
|
|
5
|
+
|
|
6
|
+
.textarea {
|
|
7
|
+
$self: &;
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: get-spacing(paldiski);
|
|
11
|
+
width: 100%;
|
|
12
|
+
|
|
13
|
+
&__label {
|
|
14
|
+
flex: 0 0 185px;
|
|
15
|
+
font-size: $veera-font-size-100;
|
|
16
|
+
line-height: 24px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&__wrapper {
|
|
20
|
+
flex: 1;
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
gap: 7px;
|
|
24
|
+
position: relative;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&__error {
|
|
28
|
+
width: 100%;
|
|
29
|
+
margin-right: 6px;
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
gap: get-spacing(paldiski);
|
|
33
|
+
color: get-color(black-coral-20);
|
|
34
|
+
border-radius: $veera-radius-s;
|
|
35
|
+
background-color: get-color(jasper-3);
|
|
36
|
+
font-size: 13px;
|
|
37
|
+
line-height: 20px;
|
|
38
|
+
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
|
|
39
|
+
|
|
40
|
+
&::before {
|
|
41
|
+
content: '';
|
|
42
|
+
display: block;
|
|
43
|
+
background-color: get-color(jasper-3);
|
|
44
|
+
border-left: 16px solid transparent;
|
|
45
|
+
border-right: 16px solid transparent;
|
|
46
|
+
border-bottom: 25px;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&__max-length-top {
|
|
51
|
+
position: absolute;
|
|
52
|
+
top: 10px;
|
|
53
|
+
right: 8px;
|
|
54
|
+
font-size: $veera-font-size-80;
|
|
55
|
+
color: get-color(black-coral-12);
|
|
56
|
+
pointer-events: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&__max-length-bottom {
|
|
60
|
+
position: absolute;
|
|
61
|
+
bottom: 10px;
|
|
62
|
+
right: 8px;
|
|
63
|
+
font-size: $veera-font-size-80;
|
|
64
|
+
color: get-color(black-coral-12);
|
|
65
|
+
pointer-events: none;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
textarea {
|
|
69
|
+
width: 100%;
|
|
70
|
+
display: block;
|
|
71
|
+
appearance: none;
|
|
72
|
+
background-color: get-color(white);
|
|
73
|
+
border: 1px solid get-color(black-coral-6);
|
|
74
|
+
border-radius: $veera-radius-s;
|
|
75
|
+
color: var(--color-black);
|
|
76
|
+
font-size: $veera-font-size-80;
|
|
77
|
+
line-height: $veera-line-height-500;
|
|
78
|
+
height: 40px;
|
|
79
|
+
min-height: 40px;
|
|
80
|
+
padding: get-spacing(paldiski);
|
|
81
|
+
|
|
82
|
+
&::placeholder {
|
|
83
|
+
color: get-color(black-coral-6);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&:focus {
|
|
87
|
+
outline: none;
|
|
88
|
+
border-color: get-color(sapphire-blue-10);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&--error {
|
|
93
|
+
input {
|
|
94
|
+
border-color: get-color(jasper-10);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&--disabled & {
|
|
99
|
+
input {
|
|
100
|
+
background-color: get-color(black-coral-0);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&--maxlength-shown {
|
|
105
|
+
textarea {
|
|
106
|
+
padding-right: 70px;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import React, {ChangeEvent, forwardRef, useEffect, useId, useState} from 'react';
|
|
2
|
+
import TextareaAutosize, {
|
|
3
|
+
TextareaAutosizeProps,
|
|
4
|
+
} from 'react-textarea-autosize';
|
|
5
|
+
import {
|
|
6
|
+
createRegexRenderer,
|
|
7
|
+
RichTextarea,
|
|
8
|
+
RichTextareaProps,
|
|
9
|
+
} from 'rich-textarea';
|
|
10
|
+
import clsx from 'clsx';
|
|
11
|
+
|
|
12
|
+
import './FormTextarea.scss';
|
|
13
|
+
|
|
14
|
+
type TextareaProps = TextareaAutosizeProps &
|
|
15
|
+
RichTextareaProps & {
|
|
16
|
+
label: string;
|
|
17
|
+
name: string;
|
|
18
|
+
hideLabel?: boolean;
|
|
19
|
+
showMaxLength?: boolean;
|
|
20
|
+
maxLengthBottom?: boolean;
|
|
21
|
+
useRichText?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const FormTextarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
25
|
+
(
|
|
26
|
+
{
|
|
27
|
+
label,
|
|
28
|
+
name,
|
|
29
|
+
maxLength = 2000,
|
|
30
|
+
minRows = 3,
|
|
31
|
+
maxRows = 3,
|
|
32
|
+
disabled,
|
|
33
|
+
hideLabel,
|
|
34
|
+
showMaxLength,
|
|
35
|
+
maxLengthBottom,
|
|
36
|
+
defaultValue,
|
|
37
|
+
useRichText,
|
|
38
|
+
onChange,
|
|
39
|
+
...rest
|
|
40
|
+
},
|
|
41
|
+
ref
|
|
42
|
+
) => {
|
|
43
|
+
const id = useId();
|
|
44
|
+
const [initial, setInitial] = useState<boolean>(true);
|
|
45
|
+
const [currentLength, setCurrentLength] = useState(
|
|
46
|
+
(typeof defaultValue === 'string' && defaultValue.length) || 0
|
|
47
|
+
);
|
|
48
|
+
const textareaClasses = clsx(
|
|
49
|
+
'textarea',
|
|
50
|
+
disabled && 'textarea--disabled',
|
|
51
|
+
showMaxLength && 'textarea--maxlength-shown'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const handleOnChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
|
55
|
+
if (showMaxLength) {
|
|
56
|
+
setCurrentLength(e.target.value.length);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if(!initial) return;
|
|
62
|
+
if(showMaxLength && defaultValue && typeof defaultValue === 'string') {
|
|
63
|
+
setInitial(false);
|
|
64
|
+
setCurrentLength(defaultValue.toString().length)
|
|
65
|
+
}
|
|
66
|
+
}, [defaultValue]);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div className={textareaClasses}>
|
|
70
|
+
{label && !hideLabel && (
|
|
71
|
+
<label htmlFor={id} className="textarea__label">
|
|
72
|
+
{label}
|
|
73
|
+
</label>
|
|
74
|
+
)}
|
|
75
|
+
<div className="textarea__wrapper">
|
|
76
|
+
{useRichText ? (
|
|
77
|
+
<RichTextarea
|
|
78
|
+
id={id}
|
|
79
|
+
style={{ width: '100%', height: '95px' }}
|
|
80
|
+
maxLength={maxLength === -1 ? undefined : maxLength}
|
|
81
|
+
ref={ref}
|
|
82
|
+
defaultValue={defaultValue ?? ''}
|
|
83
|
+
aria-label={hideLabel ? label : undefined}
|
|
84
|
+
onChange={(e) => {
|
|
85
|
+
if (onChange) onChange(e);
|
|
86
|
+
handleOnChange(e);
|
|
87
|
+
}}
|
|
88
|
+
onFocus={(e) =>
|
|
89
|
+
e.currentTarget.setSelectionRange(
|
|
90
|
+
e.currentTarget.value.length,
|
|
91
|
+
e.currentTarget.value.length
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
>
|
|
95
|
+
{createRegexRenderer([
|
|
96
|
+
[
|
|
97
|
+
/https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+/g,
|
|
98
|
+
({ children, key, value }) => (
|
|
99
|
+
<a
|
|
100
|
+
style={{
|
|
101
|
+
color: 'blue',
|
|
102
|
+
textDecoration: 'underline',
|
|
103
|
+
cursor: 'pointer',
|
|
104
|
+
}}
|
|
105
|
+
key={key}
|
|
106
|
+
href={value}
|
|
107
|
+
target="_blank"
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
</a>
|
|
111
|
+
),
|
|
112
|
+
],
|
|
113
|
+
])}
|
|
114
|
+
</RichTextarea>
|
|
115
|
+
) : (
|
|
116
|
+
<TextareaAutosize
|
|
117
|
+
id={id}
|
|
118
|
+
maxLength={maxLength === -1 ? undefined : maxLength}
|
|
119
|
+
minRows={minRows}
|
|
120
|
+
maxRows={maxRows === -1 ? undefined : maxRows}
|
|
121
|
+
ref={ref}
|
|
122
|
+
defaultValue={defaultValue}
|
|
123
|
+
aria-label={hideLabel ? label : undefined}
|
|
124
|
+
onChange={(e) => {
|
|
125
|
+
if (onChange) onChange(e);
|
|
126
|
+
handleOnChange(e);
|
|
127
|
+
}}
|
|
128
|
+
{...rest}
|
|
129
|
+
onFocus={(e) =>
|
|
130
|
+
e.currentTarget.setSelectionRange(
|
|
131
|
+
e.currentTarget.value.length,
|
|
132
|
+
e.currentTarget.value.length
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
137
|
+
{showMaxLength && (
|
|
138
|
+
<div
|
|
139
|
+
className={
|
|
140
|
+
maxLengthBottom
|
|
141
|
+
? 'textarea__max-length-bottom'
|
|
142
|
+
: 'textarea__max-length-top'
|
|
143
|
+
}
|
|
144
|
+
>
|
|
145
|
+
{currentLength}/{maxLength}
|
|
146
|
+
</div>
|
|
147
|
+
)}
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
export default FormTextarea;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
@import 'src/styles/tools/spacing';
|
|
2
|
+
@import 'src/styles/tools/color';
|
|
3
|
+
@import 'src/styles/settings/variables/other';
|
|
4
|
+
@import 'src/styles/settings/variables/typography';
|
|
5
|
+
|
|
6
|
+
.switch {
|
|
7
|
+
$self: &;
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: get-spacing(paldiski);
|
|
11
|
+
width: 100%;
|
|
12
|
+
|
|
13
|
+
&__label {
|
|
14
|
+
flex: 0 0 185px;
|
|
15
|
+
font-size: $veera-font-size-100;
|
|
16
|
+
line-height: 24px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&__button {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
gap: 4px;
|
|
23
|
+
height: 40px;
|
|
24
|
+
isolation: isolate;
|
|
25
|
+
padding: 4px;
|
|
26
|
+
border-radius: 20px;
|
|
27
|
+
background-color: get-color(black-coral-1);
|
|
28
|
+
font-size: $veera-font-size-80;
|
|
29
|
+
line-height: $veera-line-height-500;
|
|
30
|
+
color: get-color(black-coral-12);
|
|
31
|
+
position: relative;
|
|
32
|
+
transition: background-color .25s ease-out;
|
|
33
|
+
|
|
34
|
+
&[aria-checked=true] {
|
|
35
|
+
background-color: var(--active-color, get-color(sapphire-blue-10));
|
|
36
|
+
color: get-color(sapphire-blue-10);
|
|
37
|
+
|
|
38
|
+
#{$self} {
|
|
39
|
+
&__off {
|
|
40
|
+
color: get-color(white);
|
|
41
|
+
background: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&__on {
|
|
45
|
+
color: var(--active-color, get-color(sapphire-blue-10));
|
|
46
|
+
background-color: get-color(white);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&__thumb {
|
|
53
|
+
display: none;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&__on,
|
|
57
|
+
&__off {
|
|
58
|
+
display: flex;
|
|
59
|
+
border-radius: 20px;
|
|
60
|
+
padding: 5.5px 10px;
|
|
61
|
+
font-weight: $veera-font-weight-delta;
|
|
62
|
+
transition: all .25s ease-out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&__off {
|
|
66
|
+
font-weight: $veera-font-weight-delta;
|
|
67
|
+
background-color: get-color(white);
|
|
68
|
+
}
|
|
69
|
+
}
|