@groupeactual/ui-kit 1.7.10 → 2.0.0-beta.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/dist/cjs/index.js +15095 -66
- package/dist/es/{src/DesignSystemProvider.d.ts → DesignSystemProvider.d.ts} +6 -5
- package/dist/es/{src/components → components}/Accordion/Accordion.d.ts +1 -1
- package/dist/es/{src/components → components}/BannerNotification/BannerNotification.d.ts +1 -1
- package/dist/es/{src/components → components}/Breadcrumbs/Breadcrumbs.d.ts +2 -2
- package/dist/es/{src/components → components}/Button/Button.d.ts +2 -2
- package/dist/es/{src/components → components}/Chip/Chip.d.ts +1 -1
- package/dist/es/components/Datatable/Datatable.d.ts +4 -0
- package/dist/es/{src/components → components}/EmbbededNotification/EmbeddedNotification.d.ts +1 -1
- package/dist/es/{src/components/UploadDocument → components/FileUploader}/FileUploader.d.ts +1 -1
- package/dist/es/components/Form/AutoCompleteMulti/AutoCompleteMulti.d.ts +23 -0
- package/dist/es/{src/components → components}/Form/AutoCompleteSingle/AutoCompleteSingle.d.ts +8 -5
- package/dist/es/components/Form/Checkbox/Checkbox.d.ts +12 -0
- package/dist/es/components/Form/CheckboxGroup/CheckboxGroup.d.ts +12 -0
- package/dist/es/components/Form/CheckboxGroup/checkboxgroup.interface.d.ts +6 -0
- package/dist/es/{src/components → components}/Form/DatePicker/DatePicker.d.ts +6 -4
- package/dist/es/{src/components → components}/Form/MultiSelect/MultiSelect.d.ts +3 -3
- package/dist/es/components/Form/RadioGroup/RadioGroup.d.ts +16 -0
- package/dist/es/{src/components → components}/Form/Select/Select.d.ts +3 -3
- package/dist/es/components/Form/Switch/Switch.d.ts +11 -0
- package/dist/es/{src/components → components}/Form/TextField/TextField.d.ts +6 -5
- package/dist/es/{src/components → components}/Form/TimePicker/TimePicker.d.ts +3 -3
- package/dist/es/{src/components → components}/IconButton/IconButton.d.ts +3 -3
- package/dist/es/components/IconProvider/IconProvider.d.ts +24 -0
- package/dist/es/{src/components → components}/Link/Link.d.ts +1 -2
- package/dist/es/components/MenuItem/MenuItem.d.ts +9 -0
- package/dist/es/components/Modal/Dialog/Dialog.d.ts +4 -0
- package/dist/es/components/Modal/Drawer/Drawer.d.ts +4 -0
- package/dist/es/{src/components → components}/Navigation/Stepper/Stepper.d.ts +1 -1
- package/dist/es/{src/components → components}/Pagination/Pagination.d.ts +2 -1
- package/dist/es/{src/components → components}/Snackbar/Snackbar.d.ts +1 -1
- package/dist/es/components/TabsPanel/TabsPanel.d.ts +4 -0
- package/dist/es/components/TabsPanel/index.d.ts +1 -0
- package/dist/es/components/TabsPanel/tab.interface.d.ts +17 -0
- package/dist/es/components/Text/Text.d.ts +8 -0
- package/dist/es/{src/components → components}/Tooltip/Tooltip.d.ts +1 -1
- package/dist/es/{src/components → components}/index.d.ts +3 -2
- package/dist/es/index.d.ts +104 -152
- package/dist/es/index.js +37 -79
- package/package.json +20 -17
- package/src/DesignSystemProvider.tsx +21 -36
- package/src/components/Accordion/Accordion.tsx +41 -59
- package/src/components/BannerNotification/BannerNotification.tsx +19 -20
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +32 -28
- package/src/components/Button/Button.tsx +70 -17
- package/src/components/Chip/Chip.tsx +88 -117
- package/src/components/Datatable/Datatable.tsx +49 -37
- package/src/components/Datatable/DatatableCellRender.tsx +1 -1
- package/src/components/EmbbededNotification/EmbeddedNotification.tsx +78 -69
- package/src/components/FileUploader/FileUploader.tsx +767 -0
- package/src/components/Form/AutoCompleteMulti/AutoCompleteMulti.tsx +289 -172
- package/src/components/Form/AutoCompleteSingle/AutoCompleteSingle.tsx +228 -126
- package/src/components/Form/Checkbox/Checkbox.tsx +38 -96
- package/src/components/Form/CheckboxGroup/CheckboxGroup.tsx +86 -60
- package/src/components/Form/CheckboxGroup/checkboxgroup.interface.ts +0 -15
- package/src/components/Form/DatePicker/DatePicker.tsx +88 -40
- package/src/components/Form/MultiSelect/MultiSelect.tsx +196 -171
- package/src/components/Form/RadioGroup/RadioGroup.tsx +76 -82
- package/src/components/Form/Select/Select.tsx +156 -136
- package/src/components/Form/Switch/Switch.tsx +87 -47
- package/src/components/Form/TextField/TextField.tsx +125 -76
- package/src/components/Form/TimePicker/TimePicker.tsx +26 -7
- package/src/components/IconButton/IconButton.tsx +64 -39
- package/src/components/IconProvider/IconProvider.tsx +88 -69
- package/src/components/Link/Link.tsx +6 -10
- package/src/components/MenuItem/MenuItem.tsx +35 -23
- package/src/components/Modal/Dialog/Dialog.tsx +17 -14
- package/src/components/Modal/Drawer/Drawer.tsx +95 -74
- package/src/components/Navigation/Stepper/Step.tsx +7 -6
- package/src/components/Navigation/Stepper/Stepper.tsx +24 -23
- package/src/components/NotistackAdapter/NotistackAdapter.tsx +1 -1
- package/src/components/Pagination/Pagination.tsx +131 -118
- package/src/components/Snackbar/Snackbar.tsx +29 -29
- package/src/components/TabsPanel/TabsPanel.tsx +151 -0
- package/src/components/TabsPanel/index.ts +1 -0
- package/src/components/TabsPanel/tab.interface.ts +20 -0
- package/src/components/Text/Text.tsx +25 -12
- package/src/components/Tooltip/Tooltip.tsx +54 -51
- package/src/components/index.ts +3 -2
- package/src/index.ts +0 -1
- package/dist/es/src/components/Datatable/Datatable.d.ts +0 -4
- package/dist/es/src/components/Form/AutoCompleteMulti/AutoCompleteMulti.d.ts +0 -19
- package/dist/es/src/components/Form/Checkbox/Checkbox.d.ts +0 -14
- package/dist/es/src/components/Form/CheckboxGroup/CheckboxGroup.d.ts +0 -12
- package/dist/es/src/components/Form/CheckboxGroup/checkboxgroup.interface.d.ts +0 -8
- package/dist/es/src/components/Form/RadioGroup/RadioGroup.d.ts +0 -18
- package/dist/es/src/components/Form/Switch/Switch.d.ts +0 -10
- package/dist/es/src/components/IconProvider/IconProvider.d.ts +0 -19
- package/dist/es/src/components/MenuItem/MenuItem.d.ts +0 -10
- package/dist/es/src/components/Modal/Dialog/Dialog.d.ts +0 -4
- package/dist/es/src/components/Modal/Drawer/Drawer.d.ts +0 -4
- package/dist/es/src/components/Text/Text.d.ts +0 -8
- package/dist/es/src/index.d.ts +0 -5
- package/dist/es/src/interfaces/theme.d.ts +0 -51
- package/src/components/UploadDocument/FileUploader.tsx +0 -728
- package/src/interfaces/theme.ts +0 -51
- /package/dist/es/{src/components → components}/Accordion/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/BannerNotification/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Breadcrumbs/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Button/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Chip/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Datatable/DatatableCellRender.d.ts +0 -0
- /package/dist/es/{src/components → components}/Datatable/datatable.interface.d.ts +0 -0
- /package/dist/es/{src/components → components}/Datatable/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Datatable/use-pagination-props.hook.d.ts +0 -0
- /package/dist/es/{src/components → components}/EmbbededNotification/index.d.ts +0 -0
- /package/dist/es/{src/components/UploadDocument → components/FileUploader}/fileuploader.interface.d.ts +0 -0
- /package/dist/es/{src/components/UploadDocument → components/FileUploader}/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/AutoCompleteMulti/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/AutoCompleteSingle/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/Checkbox/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/CheckboxGroup/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/DatePicker/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/MultiSelect/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/RadioGroup/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/Select/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/Switch/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/TextField/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Form/TimePicker/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/IconButton/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/IconProvider/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Link/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/MenuItem/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Modal/Dialog/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Modal/Drawer/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Modal/modal.interface.d.ts +0 -0
- /package/dist/es/{src/components → components}/Navigation/Stepper/Step.d.ts +0 -0
- /package/dist/es/{src/components → components}/Navigation/Stepper/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Navigation/Stepper/stepper.helper.d.ts +0 -0
- /package/dist/es/{src/components → components}/Navigation/Stepper/stepper.interface.d.ts +0 -0
- /package/dist/es/{src/components → components}/NotistackAdapter/NotistackAdapter.d.ts +0 -0
- /package/dist/es/{src/components → components}/NotistackAdapter/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Pagination/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Pagination/pagination.helper.d.ts +0 -0
- /package/dist/es/{src/components → components}/Snackbar/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Text/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Tooltip/index.d.ts +0 -0
- /package/dist/es/{src/components → components}/Tooltip/tooltip.interface.d.ts +0 -0
- /package/dist/es/{src/helpers → helpers}/GooglePickerWrapper.d.ts +0 -0
- /package/dist/es/{src/hooks → hooks}/useGooleDrivePicker.d.ts +0 -0
- /package/dist/es/{src/types → types}/googleDrive.d.ts +0 -0
- /package/src/components/{UploadDocument → FileUploader}/fileuploader.interface.ts +0 -0
- /package/src/components/{UploadDocument → FileUploader}/index.ts +0 -0
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import React, { BaseSyntheticEvent, useMemo } from 'react';
|
|
1
|
+
import React, { BaseSyntheticEvent, ReactNode, useId, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
4
4
|
import { faCheck, faChevronDown } from '@fortawesome/pro-regular-svg-icons';
|
|
5
|
-
import { SelectStyle } from '@groupeactual/design-tokens';
|
|
6
5
|
import {
|
|
7
6
|
Box,
|
|
8
|
-
FormControl,
|
|
9
7
|
FormHelperText,
|
|
10
8
|
InputLabel,
|
|
11
9
|
MenuItem,
|
|
12
10
|
Select as MuiSelect,
|
|
13
11
|
SelectChangeEvent,
|
|
14
12
|
SelectProps,
|
|
15
|
-
styled,
|
|
16
|
-
useTheme,
|
|
17
13
|
} from '@mui/material';
|
|
18
14
|
|
|
19
15
|
import IconProvider from '@/components/IconProvider';
|
|
16
|
+
import Text from '@/components/Text';
|
|
20
17
|
|
|
21
18
|
interface Props<T>
|
|
22
19
|
extends Omit<SelectProps<T>, 'value' | 'onChange' | 'color' | 'error'> {
|
|
20
|
+
label?: ReactNode;
|
|
23
21
|
options: T[];
|
|
24
22
|
placeholder?: string;
|
|
25
23
|
disabled?: boolean;
|
|
26
|
-
label?: string;
|
|
27
24
|
helperText?: string;
|
|
28
25
|
color?: 'success';
|
|
29
26
|
value: T | undefined;
|
|
@@ -47,161 +44,184 @@ const MenuProps = {
|
|
|
47
44
|
},
|
|
48
45
|
};
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
function fixedForwardRef<T, P = {}>(
|
|
48
|
+
render: (_props: P, _ref: React.Ref<T>) => React.ReactNode,
|
|
49
|
+
): (_props: P & React.RefAttributes<T>) => React.ReactNode {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
return React.forwardRef(render as any) as any;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const SelectComponent = <T,>(
|
|
55
|
+
{
|
|
56
|
+
value,
|
|
57
|
+
label = '',
|
|
58
|
+
options,
|
|
59
|
+
color,
|
|
60
|
+
error,
|
|
61
|
+
placeholder = '',
|
|
62
|
+
helperText,
|
|
63
|
+
width = '100%',
|
|
64
|
+
disabled,
|
|
65
|
+
popupIcon = faChevronDown,
|
|
66
|
+
onChange,
|
|
67
|
+
getRenderValue,
|
|
68
|
+
...props
|
|
69
|
+
}: Props<T>,
|
|
70
|
+
ref: React.ForwardedRef<HTMLSelectElement>,
|
|
71
|
+
) => {
|
|
72
|
+
const generatedId = useId();
|
|
73
|
+
|
|
74
|
+
const inputId = props.name || `select-${generatedId}`;
|
|
70
75
|
|
|
71
76
|
const [isOpened, setIsOpened] = React.useState(props.open ?? false);
|
|
72
77
|
|
|
73
78
|
const handleChange = (event: SelectChangeEvent<T>) =>
|
|
74
79
|
onChange?.(event.target.value as T);
|
|
75
80
|
|
|
76
|
-
const
|
|
81
|
+
const getClassName = useMemo(() => {
|
|
77
82
|
const classNames = [
|
|
78
|
-
'DSSingleSelect',
|
|
79
|
-
(!placeholder && 'Select-mui') || 'Select-ds',
|
|
80
83
|
value && 'Mui-filled',
|
|
81
84
|
error && 'Mui-error',
|
|
85
|
+
disabled && 'Mui-disabled',
|
|
86
|
+
color === 'success' && 'Mui-success',
|
|
82
87
|
];
|
|
83
88
|
|
|
84
89
|
return classNames.filter(Boolean).join(' ');
|
|
85
|
-
}, [value, error,
|
|
90
|
+
}, [value, error, color, disabled]);
|
|
86
91
|
|
|
87
92
|
return (
|
|
88
|
-
<Box
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
<Box
|
|
94
|
+
sx={{
|
|
95
|
+
'.MuiOutlinedInput-input': {
|
|
96
|
+
marginTop: value ? '0px' : '2px',
|
|
97
|
+
},
|
|
98
|
+
}}
|
|
99
|
+
data-testid="ds-select-container"
|
|
100
|
+
>
|
|
101
|
+
{label && (
|
|
102
|
+
<InputLabel
|
|
103
|
+
htmlFor={inputId}
|
|
104
|
+
disabled={disabled}
|
|
105
|
+
className={getClassName}
|
|
106
|
+
id={props?.labelId}
|
|
107
|
+
data-testid="ds-select-label"
|
|
108
|
+
>
|
|
101
109
|
{label}
|
|
102
110
|
</InputLabel>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
notched={(placeholder && true) || undefined}
|
|
116
|
-
onChange={handleChange}
|
|
117
|
-
IconComponent={({ className }) => (
|
|
118
|
-
<IconProvider
|
|
119
|
-
className={disabled ? 'Mui-disabled SelectIcon' : 'SelectIcon'}
|
|
120
|
-
icon={color === 'success' ? faCheck : popupIcon}
|
|
121
|
-
onClick={() => {
|
|
122
|
-
if (!disabled) {
|
|
123
|
-
setIsOpened(!isOpened);
|
|
124
|
-
}
|
|
125
|
-
}}
|
|
126
|
-
size="md"
|
|
127
|
-
sx={{
|
|
128
|
-
':hover': {
|
|
129
|
-
cursor: disabled ? 'auto' : 'pointer',
|
|
130
|
-
},
|
|
131
|
-
marginTop: color === 'success' ? '2px' : '0px',
|
|
132
|
-
transform:
|
|
133
|
-
className.toString().includes('iconOpen') &&
|
|
134
|
-
color !== 'success'
|
|
135
|
-
? 'rotate(180deg)'
|
|
136
|
-
: 'none',
|
|
137
|
-
}}
|
|
138
|
-
/>
|
|
139
|
-
)}
|
|
140
|
-
MenuProps={MenuProps}
|
|
141
|
-
renderValue={(value) => getRenderValue(value)}
|
|
142
|
-
{...props}
|
|
143
|
-
open={isOpened}
|
|
144
|
-
onClose={(e) => {
|
|
145
|
-
if (!disabled) {
|
|
146
|
-
if (props.onClose) {
|
|
147
|
-
props.onClose(e);
|
|
111
|
+
)}
|
|
112
|
+
<MuiSelect
|
|
113
|
+
id={inputId}
|
|
114
|
+
ref={ref}
|
|
115
|
+
disabled={disabled}
|
|
116
|
+
className={getClassName}
|
|
117
|
+
sx={{
|
|
118
|
+
width,
|
|
119
|
+
'& .MuiSelect-select .notranslate::after': placeholder
|
|
120
|
+
? {
|
|
121
|
+
content: `"${placeholder}"`,
|
|
122
|
+
opacity: !placeholder ? '0 !important' : '1 !important',
|
|
148
123
|
}
|
|
149
|
-
|
|
150
|
-
|
|
124
|
+
: {},
|
|
125
|
+
}}
|
|
126
|
+
value={value !== undefined ? value : ''}
|
|
127
|
+
notched={(placeholder && true) || undefined}
|
|
128
|
+
onChange={handleChange}
|
|
129
|
+
IconComponent={({ className }) => (
|
|
130
|
+
<IconProvider
|
|
131
|
+
className={
|
|
132
|
+
getClassName + (color === 'success' ? '' : ' SelectIcon')
|
|
151
133
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
props.onOpen(e);
|
|
134
|
+
icon={color === 'success' ? faCheck : popupIcon}
|
|
135
|
+
onClick={() => {
|
|
136
|
+
if (!disabled) {
|
|
137
|
+
setIsOpened(!isOpened);
|
|
157
138
|
}
|
|
139
|
+
}}
|
|
140
|
+
size="md"
|
|
141
|
+
sx={{
|
|
142
|
+
marginTop: color === 'success' ? '2px' : '0px',
|
|
143
|
+
transform:
|
|
144
|
+
className.toString().includes('iconOpen') && color !== 'success'
|
|
145
|
+
? 'rotate(180deg)'
|
|
146
|
+
: 'none',
|
|
147
|
+
':hover': {
|
|
148
|
+
cursor: disabled ? 'auto' : 'pointer',
|
|
149
|
+
},
|
|
150
|
+
}}
|
|
151
|
+
data-testid="ds-icon-component"
|
|
152
|
+
/>
|
|
153
|
+
)}
|
|
154
|
+
MenuProps={MenuProps}
|
|
155
|
+
renderValue={(value) => getRenderValue(value)}
|
|
156
|
+
{...props}
|
|
157
|
+
open={isOpened}
|
|
158
|
+
onClose={(e) => {
|
|
159
|
+
if (!disabled) {
|
|
160
|
+
if (props.onClose) {
|
|
161
|
+
props.onClose(e);
|
|
162
|
+
}
|
|
158
163
|
|
|
159
|
-
|
|
164
|
+
setIsOpened(false);
|
|
165
|
+
}
|
|
166
|
+
}}
|
|
167
|
+
onOpen={(e) => {
|
|
168
|
+
if (!disabled) {
|
|
169
|
+
if (props.onOpen) {
|
|
170
|
+
props.onOpen(e);
|
|
160
171
|
}
|
|
172
|
+
|
|
173
|
+
setIsOpened(true);
|
|
174
|
+
}
|
|
175
|
+
}}
|
|
176
|
+
data-testid="ds-mui-select"
|
|
177
|
+
>
|
|
178
|
+
{options?.map((option, i) => (
|
|
179
|
+
<MenuItem
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
181
|
+
{...(props as any)}
|
|
182
|
+
key={i}
|
|
183
|
+
value={option as never}
|
|
184
|
+
data-testid={`ds-menu-item-${i}`}
|
|
185
|
+
sx={{
|
|
186
|
+
wordBreak: 'break-word',
|
|
187
|
+
overflowWrap: 'break-word',
|
|
188
|
+
whiteSpace: 'normal',
|
|
189
|
+
hyphens: 'auto',
|
|
190
|
+
width: '100%',
|
|
191
|
+
justifyContent:
|
|
192
|
+
props.className === 'PaginationSelect'
|
|
193
|
+
? 'center'
|
|
194
|
+
: 'flex-start',
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
<Text variant="body2">
|
|
198
|
+
{getRenderValue ? getRenderValue(option) : option['label']}
|
|
199
|
+
</Text>
|
|
200
|
+
</MenuItem>
|
|
201
|
+
))}
|
|
202
|
+
</MuiSelect>
|
|
203
|
+
{(error || helperText) && (
|
|
204
|
+
<FormHelperText
|
|
205
|
+
component="span"
|
|
206
|
+
className={getClassName}
|
|
207
|
+
sx={{
|
|
208
|
+
display: 'table',
|
|
209
|
+
width: '100%',
|
|
210
|
+
marginRight: '4px',
|
|
211
|
+
marginTop: '4px',
|
|
212
|
+
marginLeft: 0,
|
|
161
213
|
}}
|
|
214
|
+
data-testid="ds-form-helper-text"
|
|
162
215
|
>
|
|
163
|
-
{
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
'&:hover': {
|
|
167
|
-
backgroundColor: theme.palette['blueHoverEquivalence'],
|
|
168
|
-
},
|
|
169
|
-
'&.Mui-selected': {
|
|
170
|
-
backgroundColor: theme.palette['greyXLight'] + ' !important',
|
|
171
|
-
},
|
|
172
|
-
fontSize: 14,
|
|
173
|
-
fontWeight: value === option ? 500 : 400,
|
|
174
|
-
whiteSpace: 'normal',
|
|
175
|
-
wordWrap: 'break-word',
|
|
176
|
-
minWidth: '100%',
|
|
177
|
-
maxWidth: '100%',
|
|
178
|
-
backgroundColor:
|
|
179
|
-
value === option ? 'blueHoverEquivalence' : 'white',
|
|
180
|
-
}}
|
|
181
|
-
key={i}
|
|
182
|
-
value={option as never}
|
|
183
|
-
onMouseEnter={(e: BaseSyntheticEvent) =>
|
|
184
|
-
(e.target.style.backgroundColor =
|
|
185
|
-
theme.palette['blueHoverEquivalence'])
|
|
186
|
-
}
|
|
187
|
-
onMouseLeave={(e: BaseSyntheticEvent) => {
|
|
188
|
-
if (value !== option) {
|
|
189
|
-
e.target.style.backgroundColor = theme.palette['white'];
|
|
190
|
-
}
|
|
191
|
-
}}
|
|
192
|
-
>
|
|
193
|
-
{getRenderValue ? getRenderValue(option) : option['label']}
|
|
194
|
-
</MenuItem>
|
|
195
|
-
))}
|
|
196
|
-
</MuiSelect>
|
|
197
|
-
{(error || helperText) && (
|
|
198
|
-
<FormHelperText component="span" className={error ? 'Mui-error' : ''}>
|
|
199
|
-
{error || helperText}
|
|
200
|
-
</FormHelperText>
|
|
201
|
-
)}
|
|
202
|
-
</StyledSelectForm>
|
|
216
|
+
{error || helperText}
|
|
217
|
+
</FormHelperText>
|
|
218
|
+
)}
|
|
203
219
|
</Box>
|
|
204
220
|
);
|
|
205
221
|
};
|
|
206
222
|
|
|
223
|
+
SelectComponent.displayName = 'Select';
|
|
224
|
+
|
|
225
|
+
const Select = fixedForwardRef(SelectComponent);
|
|
226
|
+
|
|
207
227
|
export default Select;
|
|
@@ -1,68 +1,108 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
1
|
+
import React, { ReactNode, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import { SwitchStyle } from '@groupeactual/design-tokens';
|
|
4
3
|
import {
|
|
4
|
+
Box,
|
|
5
5
|
FormControl,
|
|
6
6
|
FormControlLabel,
|
|
7
7
|
FormGroup,
|
|
8
|
+
FormHelperText,
|
|
8
9
|
Switch as SwitchMui,
|
|
9
10
|
SwitchProps,
|
|
10
11
|
Typography,
|
|
11
|
-
styled,
|
|
12
|
-
useTheme,
|
|
13
12
|
} from '@mui/material';
|
|
14
13
|
|
|
15
14
|
interface Props {
|
|
16
|
-
label
|
|
15
|
+
label?: ReactNode;
|
|
16
|
+
helperText?: string;
|
|
17
17
|
checked: boolean;
|
|
18
18
|
leftSideLabel?: string;
|
|
19
19
|
onClick: () => void;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const Switch = (
|
|
23
|
-
label,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const theme = useTheme();
|
|
30
|
-
const StyledSwitch = useMemo(
|
|
31
|
-
() => styled(SwitchMui)(SwitchStyle(theme)),
|
|
32
|
-
[theme],
|
|
33
|
-
);
|
|
22
|
+
const Switch = React.forwardRef<HTMLButtonElement, SwitchProps & Props>(
|
|
23
|
+
({ label, helperText, checked, leftSideLabel, onClick, ...props }, ref) => {
|
|
24
|
+
const getClassName = useMemo(() => {
|
|
25
|
+
const classNames = [
|
|
26
|
+
props.disabled && 'Mui-disabled',
|
|
27
|
+
checked && 'Mui-checked',
|
|
28
|
+
];
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
disableFocusRipple
|
|
51
|
-
onClick={() => {
|
|
52
|
-
if (!props.disabled) {
|
|
53
|
-
if (onClick) {
|
|
54
|
-
onClick();
|
|
55
|
-
}
|
|
30
|
+
return classNames.filter(Boolean).join(' ');
|
|
31
|
+
}, [props.disabled, checked]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Box data-testid="ds-switch-container">
|
|
35
|
+
<FormControl
|
|
36
|
+
component="fieldset"
|
|
37
|
+
disabled={props.disabled}
|
|
38
|
+
sx={
|
|
39
|
+
props.disabled
|
|
40
|
+
? {
|
|
41
|
+
'.MuiTypography-root': {
|
|
42
|
+
color: 'text.disabled',
|
|
43
|
+
fontWeight: 500,
|
|
44
|
+
},
|
|
56
45
|
}
|
|
57
|
-
}
|
|
58
|
-
checked={checked}
|
|
59
|
-
/>
|
|
46
|
+
: {}
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
data-testid="ds-switch-form-control"
|
|
49
|
+
>
|
|
50
|
+
<FormGroup
|
|
51
|
+
sx={{
|
|
52
|
+
display: 'flex',
|
|
53
|
+
flexDirection: 'row',
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
gap: '10px',
|
|
56
|
+
}}
|
|
57
|
+
data-testid="ds-switch-form-group"
|
|
58
|
+
>
|
|
59
|
+
{leftSideLabel && (
|
|
60
|
+
<Typography data-testid="ds-left-side-label">
|
|
61
|
+
{leftSideLabel}
|
|
62
|
+
</Typography>
|
|
63
|
+
)}
|
|
64
|
+
<FormControlLabel
|
|
65
|
+
control={
|
|
66
|
+
<SwitchMui
|
|
67
|
+
{...props}
|
|
68
|
+
ref={ref}
|
|
69
|
+
className={getClassName}
|
|
70
|
+
role="switch"
|
|
71
|
+
disableFocusRipple
|
|
72
|
+
onClick={() => {
|
|
73
|
+
if (!props.disabled) {
|
|
74
|
+
if (onClick) {
|
|
75
|
+
onClick();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}}
|
|
79
|
+
checked={checked}
|
|
80
|
+
data-testid="ds-switch"
|
|
81
|
+
/>
|
|
82
|
+
}
|
|
83
|
+
label={
|
|
84
|
+
label && (
|
|
85
|
+
<Typography data-testid="ds-switch-label">{label}</Typography>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
/>
|
|
89
|
+
</FormGroup>
|
|
90
|
+
{helperText && (
|
|
91
|
+
<FormHelperText
|
|
92
|
+
sx={{ margin: 0 }}
|
|
93
|
+
component="span"
|
|
94
|
+
className={getClassName}
|
|
95
|
+
data-testid="ds-form-helper-text"
|
|
96
|
+
>
|
|
97
|
+
{helperText}
|
|
98
|
+
</FormHelperText>
|
|
99
|
+
)}
|
|
100
|
+
</FormControl>
|
|
101
|
+
</Box>
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
Switch.displayName = 'Switch';
|
|
67
107
|
|
|
68
108
|
export default Switch;
|