@groupeactual/ui-kit 0.4.24 → 0.4.26
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/DesignSystemProvider.d.ts +2 -2
- package/dist/cjs/components/Button/Button.d.ts +4 -4
- package/dist/cjs/components/EmbbededNotification/EmbeddedNotification.d.ts +9 -0
- package/dist/cjs/components/EmbbededNotification/index.d.ts +1 -0
- package/dist/cjs/components/Form/MultiSelect/MultiSelect.d.ts +14 -0
- package/dist/cjs/components/Form/MultiSelect/index.d.ts +1 -0
- package/dist/cjs/components/Form/Select/Select.d.ts +14 -0
- package/dist/cjs/components/Form/Select/index.d.ts +1 -0
- package/dist/cjs/components/Form/TextField/TextField.d.ts +1 -2
- package/dist/cjs/components/Icon/Icon.d.ts +2 -2
- package/dist/cjs/components/Tooltip/Tooltip.d.ts +8 -0
- package/dist/cjs/components/Tooltip/index.d.ts +1 -0
- package/dist/cjs/components/index.d.ts +4 -0
- package/dist/cjs/index.js +4576 -687
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/DesignSystemProvider.d.ts +2 -2
- package/dist/esm/components/Button/Button.d.ts +4 -4
- package/dist/esm/components/EmbbededNotification/EmbeddedNotification.d.ts +9 -0
- package/dist/esm/components/EmbbededNotification/index.d.ts +1 -0
- package/dist/esm/components/Form/MultiSelect/MultiSelect.d.ts +14 -0
- package/dist/esm/components/Form/MultiSelect/index.d.ts +1 -0
- package/dist/esm/components/Form/Select/Select.d.ts +14 -0
- package/dist/esm/components/Form/Select/index.d.ts +1 -0
- package/dist/esm/components/Form/TextField/TextField.d.ts +1 -2
- package/dist/esm/components/Icon/Icon.d.ts +2 -2
- package/dist/esm/components/Tooltip/Tooltip.d.ts +8 -0
- package/dist/esm/components/Tooltip/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts +4 -0
- package/dist/esm/index.js +4572 -687
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +59 -23
- package/package.json +8 -3
- package/src/DesignSystemProvider.tsx +9 -2
- package/src/components/Accordion/Accordion.tsx +6 -1
- package/src/components/Button/Button.tsx +9 -4
- package/src/components/Chip/Chip.tsx +1 -0
- package/src/components/EmbbededNotification/EmbeddedNotification.tsx +95 -0
- package/src/components/EmbbededNotification/index.ts +1 -0
- package/src/components/Form/Checkbox/Checkbox.tsx +1 -1
- package/src/components/Form/MultiSelect/MultiSelect.tsx +176 -0
- package/src/components/Form/MultiSelect/index.ts +1 -0
- package/src/components/Form/Select/Select.tsx +154 -0
- package/src/components/Form/Select/index.ts +1 -0
- package/src/components/Form/TextField/TextField.tsx +13 -6
- package/src/components/Icon/Icon.tsx +14 -11
- package/src/components/Link/Link.tsx +1 -0
- package/src/components/Pagination/Pagination.tsx +2 -2
- package/src/components/Text/Text.tsx +1 -0
- package/src/components/Tooltip/Tooltip.tsx +24 -0
- package/src/components/Tooltip/index.ts +1 -0
- package/src/components/index.ts +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { TypographyProps, LinkProps } from '@mui/material';
|
|
2
|
+
import { TypographyProps, LinkProps, BoxProps as BoxProps$1, TooltipProps } from '@mui/material';
|
|
3
|
+
import React, { ReactNode, FocusEventHandler, MouseEventHandler, PropsWithChildren } from 'react';
|
|
3
4
|
import { ButtonProps } from '@mui/material/Button';
|
|
4
|
-
import * as react from 'react';
|
|
5
|
-
import { FocusEventHandler, ReactNode, MouseEventHandler, PropsWithChildren } from 'react';
|
|
6
5
|
import { TextFieldProps } from '@mui/material/TextField';
|
|
7
6
|
import { InputProps } from '@mui/material/Input/Input';
|
|
7
|
+
import { SelectProps } from '@mui/material/Select';
|
|
8
8
|
import { CheckboxProps } from '@mui/material/Checkbox';
|
|
9
9
|
import { AccordionProps } from '@mui/material/Accordion';
|
|
10
10
|
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
11
11
|
import { BoxProps } from '@mui/material/Box';
|
|
12
12
|
import { ChipProps } from '@mui/material/Chip';
|
|
13
13
|
|
|
14
|
-
interface Props$
|
|
14
|
+
interface Props$c extends Omit<TypographyProps, 'variant'> {
|
|
15
15
|
variant?: 'bigNumber' | 'body1Regular' | 'body1Medium' | 'body1Bold' | 'body2Regular' | 'body2Medium' | 'body2Bold' | 'caption' | 'buttonNotif' | 'header1' | 'header2' | 'header3' | 'header4';
|
|
16
16
|
component?: any;
|
|
17
17
|
}
|
|
18
|
-
declare const Text: (props: Props$
|
|
18
|
+
declare const Text: (props: Props$c) => JSX.Element;
|
|
19
19
|
|
|
20
|
-
interface Props$
|
|
20
|
+
interface Props$b extends Omit<LinkProps, 'variant'> {
|
|
21
21
|
variant?: 'link1' | 'link2';
|
|
22
22
|
component?: any;
|
|
23
23
|
}
|
|
24
|
-
declare const Link: (props: Props$
|
|
24
|
+
declare const Link: (props: Props$b) => JSX.Element;
|
|
25
25
|
|
|
26
|
-
interface Props$
|
|
26
|
+
interface Props$a extends Omit<ButtonProps, 'variant' | 'children'> {
|
|
27
27
|
variant?: 'primary' | 'secondary';
|
|
28
|
-
|
|
28
|
+
children?: ReactNode;
|
|
29
29
|
}
|
|
30
|
-
declare const Button: (props: Props$
|
|
30
|
+
declare const Button: ({ variant, children, ...props }: Props$a) => JSX.Element;
|
|
31
31
|
|
|
32
|
-
interface Props$
|
|
32
|
+
interface Props$9 extends Omit<TextFieldProps, 'error'> {
|
|
33
33
|
error?: string;
|
|
34
34
|
onBlur?: FocusEventHandler<unknown>;
|
|
35
35
|
onChange?: InputProps['onChange'];
|
|
@@ -38,29 +38,52 @@ interface Props$5 extends Omit<TextFieldProps, 'error'> {
|
|
|
38
38
|
name: string;
|
|
39
39
|
placeholder?: string;
|
|
40
40
|
disabled?: boolean;
|
|
41
|
-
isValid?: boolean;
|
|
42
41
|
endAdornment?: ReactNode;
|
|
43
42
|
maxLength?: number;
|
|
44
43
|
}
|
|
45
|
-
declare const TextField: ({ name, value, error, onBlur, onChange, label, disabled, endAdornment,
|
|
44
|
+
declare const TextField: ({ name, value, error, onBlur, onChange, label, disabled, endAdornment, placeholder, maxLength, ...props }: Props$9) => JSX.Element;
|
|
46
45
|
|
|
47
|
-
interface Props$
|
|
46
|
+
interface Props$8<T> extends Omit<SelectProps<T>, 'value' | 'onChange' | 'defaultValue' | 'color'> {
|
|
47
|
+
label?: string;
|
|
48
|
+
helperText?: string;
|
|
49
|
+
options: T[];
|
|
50
|
+
getOptionLabel?: (option: T) => string;
|
|
51
|
+
color?: 'success';
|
|
52
|
+
onChange: (value: T) => void;
|
|
53
|
+
defaultValue?: T | undefined;
|
|
54
|
+
width?: number;
|
|
55
|
+
}
|
|
56
|
+
declare const Select: <T extends {}>({ label, defaultValue, options, color, error, placeholder, onChange, getOptionLabel, helperText, onBlur, width, ...props }: Props$8<T>) => JSX.Element;
|
|
57
|
+
|
|
58
|
+
interface Props$7<T> extends Omit<SelectProps<T[]>, 'value' | 'onChange' | 'defaultValue' | 'color'> {
|
|
59
|
+
label: string;
|
|
60
|
+
options: T[];
|
|
61
|
+
helperText?: string;
|
|
62
|
+
color?: 'success';
|
|
63
|
+
getOptionLabel: (option: T) => string;
|
|
64
|
+
onChange: (value: T[]) => void;
|
|
65
|
+
defaultValue?: T[];
|
|
66
|
+
width?: number;
|
|
67
|
+
}
|
|
68
|
+
declare const MultiSelect: <T extends {}>({ label, options, color, error, placeholder, width, defaultValue, getOptionLabel, helperText, onChange, onBlur, ...props }: Props$7<T>) => JSX.Element;
|
|
69
|
+
|
|
70
|
+
interface Props$6 {
|
|
48
71
|
name: string;
|
|
49
72
|
value: boolean;
|
|
50
73
|
label: string;
|
|
51
74
|
onChange?: (field: string, value: any, shouldValidate?: boolean | undefined) => void;
|
|
52
75
|
error?: string;
|
|
53
76
|
}
|
|
54
|
-
declare const Checkbox: ({ name, value, error, label, onChange, ...props }: CheckboxProps & Props$
|
|
77
|
+
declare const Checkbox: ({ name, value, error, label, onChange, ...props }: CheckboxProps & Props$6) => JSX.Element;
|
|
55
78
|
|
|
56
|
-
interface Props$
|
|
79
|
+
interface Props$5 extends AccordionProps {
|
|
57
80
|
icon: ReactNode;
|
|
58
81
|
title?: string;
|
|
59
82
|
summaryHeight?: number;
|
|
60
83
|
expanded?: boolean;
|
|
61
84
|
onClick?: MouseEventHandler;
|
|
62
85
|
}
|
|
63
|
-
declare const Accordion: ({ icon, title, summaryHeight, expanded, onClick, children, ...props }: Props$
|
|
86
|
+
declare const Accordion: ({ icon, title, summaryHeight, expanded, onClick, children, ...props }: Props$5) => JSX.Element;
|
|
64
87
|
|
|
65
88
|
declare const FontSizes: {
|
|
66
89
|
xs: number;
|
|
@@ -71,15 +94,15 @@ declare const FontSizes: {
|
|
|
71
94
|
xxl: number;
|
|
72
95
|
xxxl: number;
|
|
73
96
|
};
|
|
74
|
-
interface Props$
|
|
97
|
+
interface Props$4 {
|
|
75
98
|
variant?: 'square' | 'none';
|
|
76
99
|
icon: IconDefinition;
|
|
77
100
|
color?: string;
|
|
78
101
|
size?: number | keyof typeof FontSizes;
|
|
79
102
|
}
|
|
80
|
-
declare const
|
|
103
|
+
declare const IconProvider: ({ variant, icon, color, size, ...props }: Props$4 & BoxProps) => JSX.Element;
|
|
81
104
|
|
|
82
|
-
interface Props$
|
|
105
|
+
interface Props$3 {
|
|
83
106
|
totalString: string;
|
|
84
107
|
totalPerPageString: string;
|
|
85
108
|
totalPages: number;
|
|
@@ -89,20 +112,33 @@ interface Props$1 {
|
|
|
89
112
|
page?: number;
|
|
90
113
|
limit?: number;
|
|
91
114
|
}
|
|
92
|
-
declare const Pagination: ({ totalString, totalPerPageString, totalPages, limitsPerPage, setLimit, setPage, page, limit }: Props$
|
|
115
|
+
declare const Pagination: ({ totalString, totalPerPageString, totalPages, limitsPerPage, setLimit, setPage, page, limit }: Props$3) => JSX.Element;
|
|
93
116
|
|
|
94
117
|
declare const Chip: (props: ChipProps) => JSX.Element;
|
|
95
118
|
|
|
119
|
+
interface Props$2 extends BoxProps$1 {
|
|
120
|
+
variant: 'warning' | 'error' | 'success' | 'infos';
|
|
121
|
+
title: string;
|
|
122
|
+
text?: ReactNode;
|
|
123
|
+
}
|
|
124
|
+
declare const EmbeddedNotification: ({ title, text, variant, ...props }: Props$2) => JSX.Element;
|
|
125
|
+
|
|
126
|
+
interface Props$1 extends Omit<TooltipProps, 'icon' | 'children'> {
|
|
127
|
+
title: string;
|
|
128
|
+
children: ReactNode;
|
|
129
|
+
}
|
|
130
|
+
declare const Tooltip: ({ title, children, ...props }: Props$1) => JSX.Element;
|
|
131
|
+
|
|
96
132
|
type Theme = 'Default' | 'Ep';
|
|
97
133
|
interface DesignSystemContextValues {
|
|
98
134
|
isDarkTheme: boolean;
|
|
99
135
|
themeName: Theme;
|
|
100
136
|
toggleDarkTheme: () => void;
|
|
101
137
|
}
|
|
102
|
-
declare const DesignSystemContext:
|
|
138
|
+
declare const DesignSystemContext: React.Context<DesignSystemContextValues>;
|
|
103
139
|
interface Props {
|
|
104
140
|
name?: Theme;
|
|
105
141
|
}
|
|
106
142
|
declare const DesignSystemProvider: ({ children, name: themeName }: PropsWithChildren<Props>) => JSX.Element;
|
|
107
143
|
|
|
108
|
-
export { Accordion, Button, Checkbox, Chip, DesignSystemContext, DesignSystemContextValues, DesignSystemProvider,
|
|
144
|
+
export { Accordion, Button, Checkbox, Chip, DesignSystemContext, DesignSystemContextValues, DesignSystemProvider, EmbeddedNotification, IconProvider, Link, MultiSelect, Pagination, Select, Text, TextField, Tooltip };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@groupeactual/ui-kit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.26",
|
|
4
4
|
"description": "A simple template for a custom React component library",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@babel/core": "^7.20.5",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"eslint-config-standard-with-typescript": "^23.0.0",
|
|
23
23
|
"eslint-plugin-import": "^2.26.0",
|
|
24
24
|
"eslint-plugin-jest": "^27.1.6",
|
|
25
|
+
"eslint-plugin-jsx-a11y": "^6.0.0",
|
|
25
26
|
"eslint-plugin-n": "^15.5.1",
|
|
26
27
|
"eslint-plugin-prettier": "^4.2.1",
|
|
27
28
|
"eslint-plugin-promise": "^6.1.1",
|
|
@@ -49,8 +50,10 @@
|
|
|
49
50
|
"@emotion/is-prop-valid": "^1.2.0",
|
|
50
51
|
"@emotion/react": "^11.10.5",
|
|
51
52
|
"@emotion/styled": "^11.10.5",
|
|
52
|
-
"@fortawesome/fontawesome-svg-core": "^6.3.0",
|
|
53
53
|
"@fortawesome/fontawesome-common-types": "^6.3.0",
|
|
54
|
+
"@fortawesome/fontawesome-svg-core": "^6.3.0",
|
|
55
|
+
"@fortawesome/pro-regular-svg-icons": "^6.3.0",
|
|
56
|
+
"@fortawesome/pro-solid-svg-icons": "^6.3.0",
|
|
54
57
|
"@groupeactual/design-tokens": "^0.3.0",
|
|
55
58
|
"@mui/base": "^5.0.0-alpha.108",
|
|
56
59
|
"@mui/material": "^5.10.16",
|
|
@@ -73,6 +76,8 @@
|
|
|
73
76
|
"scripts": {
|
|
74
77
|
"build": "rollup -c",
|
|
75
78
|
"build:watch": "rollup -c -w",
|
|
76
|
-
"dev": "npm run build:watch"
|
|
79
|
+
"dev": "npm run build:watch",
|
|
80
|
+
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
|
|
81
|
+
"lint": "npm run eslint"
|
|
77
82
|
}
|
|
78
83
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, {
|
|
2
|
+
PropsWithChildren,
|
|
3
|
+
useState,
|
|
4
|
+
createContext,
|
|
5
|
+
useContext
|
|
6
|
+
} from 'react';
|
|
2
7
|
import { useMaterialThemeTokens } from '@groupeactual/design-tokens';
|
|
3
8
|
import { createTheme, ThemeProvider } from '@mui/material';
|
|
4
9
|
|
|
@@ -16,7 +21,9 @@ export interface DesignSystemContextValues {
|
|
|
16
21
|
export const DesignSystemContext = createContext<DesignSystemContextValues>({
|
|
17
22
|
isDarkTheme: false,
|
|
18
23
|
themeName: 'Default',
|
|
19
|
-
toggleDarkTheme: () => {
|
|
24
|
+
toggleDarkTheme: () => {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
20
27
|
});
|
|
21
28
|
|
|
22
29
|
interface Props {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, {
|
|
2
|
+
MouseEventHandler,
|
|
3
|
+
ReactNode,
|
|
4
|
+
useEffect,
|
|
5
|
+
useState
|
|
6
|
+
} from 'react';
|
|
2
7
|
import AccordionMui, { AccordionProps } from '@mui/material/Accordion';
|
|
3
8
|
import AccordionSummary from '@mui/material/AccordionSummary';
|
|
4
9
|
import AccordionDetails from '@mui/material/AccordionDetails';
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
1
2
|
import { ButtonProps } from '@mui/material/Button';
|
|
2
3
|
import { Button as ButtonMUI } from '@mui/material';
|
|
3
4
|
|
|
4
|
-
interface Props extends Omit<ButtonProps, 'variant'> {
|
|
5
|
+
interface Props extends Omit<ButtonProps, 'variant' | 'children'> {
|
|
5
6
|
variant?: 'primary' | 'secondary';
|
|
6
|
-
|
|
7
|
+
children?: ReactNode;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
const Button = (props: Props) => {
|
|
10
|
-
return
|
|
10
|
+
const Button = ({ variant, children, ...props }: Props) => {
|
|
11
|
+
return (
|
|
12
|
+
<ButtonMUI variant={variant as 'text'} {...props}>
|
|
13
|
+
{children}
|
|
14
|
+
</ButtonMUI>
|
|
15
|
+
);
|
|
11
16
|
};
|
|
12
17
|
|
|
13
18
|
export default Button;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { Box, BoxProps } from '@mui/material';
|
|
3
|
+
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
4
|
+
import {
|
|
5
|
+
faCircleXmark,
|
|
6
|
+
faCircleInfo,
|
|
7
|
+
faCircleCheck,
|
|
8
|
+
faCircleExclamation
|
|
9
|
+
} from '@fortawesome/pro-solid-svg-icons';
|
|
10
|
+
|
|
11
|
+
import Text from '../Text';
|
|
12
|
+
import Icon from '../Icon/Icon';
|
|
13
|
+
|
|
14
|
+
interface Props extends BoxProps {
|
|
15
|
+
variant: 'warning' | 'error' | 'success' | 'infos';
|
|
16
|
+
title: string;
|
|
17
|
+
text?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const EmbeddedNotification = ({
|
|
21
|
+
title,
|
|
22
|
+
text,
|
|
23
|
+
variant = 'infos',
|
|
24
|
+
...props
|
|
25
|
+
}: Props) => {
|
|
26
|
+
interface EmbeddedNotifVariant {
|
|
27
|
+
color: string;
|
|
28
|
+
icon: IconDefinition;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const variantNotification: Record<string, EmbeddedNotifVariant> = {
|
|
32
|
+
warning: {
|
|
33
|
+
color: 'orangeWarning',
|
|
34
|
+
icon: faCircleExclamation
|
|
35
|
+
},
|
|
36
|
+
error: {
|
|
37
|
+
color: 'redError',
|
|
38
|
+
icon: faCircleXmark
|
|
39
|
+
},
|
|
40
|
+
success: {
|
|
41
|
+
color: 'greenSuccess',
|
|
42
|
+
icon: faCircleCheck
|
|
43
|
+
},
|
|
44
|
+
infos: {
|
|
45
|
+
color: 'blueInfo',
|
|
46
|
+
icon: faCircleInfo
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Box
|
|
52
|
+
border="1px solid"
|
|
53
|
+
borderColor={variantNotification[variant].color}
|
|
54
|
+
mt="4px"
|
|
55
|
+
p="4px"
|
|
56
|
+
borderRadius="5px"
|
|
57
|
+
{...props}
|
|
58
|
+
>
|
|
59
|
+
<Box display="flex" alignItems="center" pb="2px">
|
|
60
|
+
<Box sx={{ pl: '12px', pr: '16px', display: 'flex' }}>
|
|
61
|
+
<Icon
|
|
62
|
+
icon={variantNotification[variant].icon}
|
|
63
|
+
color={variantNotification[variant].color}
|
|
64
|
+
/>
|
|
65
|
+
</Box>
|
|
66
|
+
<Box>
|
|
67
|
+
<Box>
|
|
68
|
+
<Text
|
|
69
|
+
align="left"
|
|
70
|
+
variant="body1Bold"
|
|
71
|
+
color={variantNotification[variant].color}
|
|
72
|
+
display="inline-block"
|
|
73
|
+
>
|
|
74
|
+
{title}
|
|
75
|
+
</Text>
|
|
76
|
+
</Box>
|
|
77
|
+
{text && (
|
|
78
|
+
<Box>
|
|
79
|
+
<Text
|
|
80
|
+
align="left"
|
|
81
|
+
variant="body1Regular"
|
|
82
|
+
color="greyDark"
|
|
83
|
+
display="inline-block"
|
|
84
|
+
>
|
|
85
|
+
{text}
|
|
86
|
+
</Text>
|
|
87
|
+
</Box>
|
|
88
|
+
)}
|
|
89
|
+
</Box>
|
|
90
|
+
</Box>
|
|
91
|
+
</Box>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export default EmbeddedNotification;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './EmbeddedNotification';
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React, { BaseSyntheticEvent, useMemo, useState } from 'react';
|
|
2
|
+
import { FormHelperText, InputLabel, MenuItem } from '@mui/material';
|
|
3
|
+
import Box from '@mui/material/Box';
|
|
4
|
+
import FormControl from '@mui/material/FormControl';
|
|
5
|
+
import MuiSelect, {
|
|
6
|
+
SelectChangeEvent,
|
|
7
|
+
SelectProps
|
|
8
|
+
} from '@mui/material/Select';
|
|
9
|
+
import { faChevronDown, faCheck } from '@fortawesome/pro-solid-svg-icons';
|
|
10
|
+
import Icon from '../../Icon';
|
|
11
|
+
import Chip from '../../Chip/Chip';
|
|
12
|
+
|
|
13
|
+
interface Props<T>
|
|
14
|
+
extends Omit<
|
|
15
|
+
SelectProps<T[]>,
|
|
16
|
+
'value' | 'onChange' | 'defaultValue' | 'color'
|
|
17
|
+
> {
|
|
18
|
+
label: string;
|
|
19
|
+
options: T[];
|
|
20
|
+
helperText?: string;
|
|
21
|
+
color?: 'success';
|
|
22
|
+
getOptionLabel: (option: T) => string;
|
|
23
|
+
onChange: (value: T[]) => void;
|
|
24
|
+
defaultValue?: T[];
|
|
25
|
+
width?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const MultiSelect = <T extends {}>({
|
|
29
|
+
label,
|
|
30
|
+
options,
|
|
31
|
+
color,
|
|
32
|
+
error,
|
|
33
|
+
placeholder,
|
|
34
|
+
width = 200,
|
|
35
|
+
defaultValue = [],
|
|
36
|
+
getOptionLabel,
|
|
37
|
+
helperText,
|
|
38
|
+
onChange,
|
|
39
|
+
onBlur,
|
|
40
|
+
...props
|
|
41
|
+
}: Props<T>) => {
|
|
42
|
+
const [values, setValues] = useState(defaultValue);
|
|
43
|
+
|
|
44
|
+
const handleChange = (event: SelectChangeEvent<typeof options>) => {
|
|
45
|
+
const newValue = event.target.value as T[];
|
|
46
|
+
onChange(newValue);
|
|
47
|
+
setValues(newValue);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleDeleteChip = (chipValue: T) => {
|
|
51
|
+
const newValue = values?.filter((val) => val !== chipValue);
|
|
52
|
+
setValues(newValue);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const getFormControlClassName = useMemo(() => {
|
|
56
|
+
const classNames: string[] = ['DsSelect'];
|
|
57
|
+
if (props.disabled) classNames.push('Mui-disabled');
|
|
58
|
+
if (values?.length > 0) classNames.push('Mui-filled');
|
|
59
|
+
|
|
60
|
+
return classNames;
|
|
61
|
+
}, [values, props.disabled]);
|
|
62
|
+
|
|
63
|
+
const getInputLabelClassName = useMemo(() => {
|
|
64
|
+
const classNames: string[] = [];
|
|
65
|
+
if (error) classNames.push('Mui-error');
|
|
66
|
+
if (props.disabled) classNames.push('Mui-disabled');
|
|
67
|
+
|
|
68
|
+
return classNames;
|
|
69
|
+
}, [error, props.disabled]);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<Box sx={{ width }}>
|
|
73
|
+
<FormControl
|
|
74
|
+
id={label === placeholder ? 'select-mui' : 'select-ds'}
|
|
75
|
+
fullWidth
|
|
76
|
+
color={color}
|
|
77
|
+
className={getFormControlClassName.join(' ')}
|
|
78
|
+
sx={{
|
|
79
|
+
'.MuiOutlinedInput-input': {
|
|
80
|
+
marginTop: values?.length > 0 ? '-4px' : '2px'
|
|
81
|
+
}
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<InputLabel className={getInputLabelClassName.join(' ')}>
|
|
85
|
+
{label}
|
|
86
|
+
</InputLabel>
|
|
87
|
+
<MuiSelect
|
|
88
|
+
sx={{
|
|
89
|
+
color: color + '! important',
|
|
90
|
+
'& .MuiSelect-select .notranslate::after': placeholder
|
|
91
|
+
? {
|
|
92
|
+
content: `"${placeholder}"`,
|
|
93
|
+
opacity:
|
|
94
|
+
label === placeholder ? '0 !important' : '1 !important'
|
|
95
|
+
}
|
|
96
|
+
: {}
|
|
97
|
+
}}
|
|
98
|
+
multiple
|
|
99
|
+
label={label}
|
|
100
|
+
placeholder={label === placeholder ? '' : placeholder}
|
|
101
|
+
notched={
|
|
102
|
+
/* eslint-disable-next-line no-undefined */
|
|
103
|
+
label === placeholder ? undefined : true
|
|
104
|
+
}
|
|
105
|
+
value={values}
|
|
106
|
+
error={!!error}
|
|
107
|
+
onChange={handleChange}
|
|
108
|
+
onBlur={onBlur}
|
|
109
|
+
renderValue={(selected) => (
|
|
110
|
+
<Box sx={{ display: 'flex', flexWrap: 'nowrap', gap: 0.5 }}>
|
|
111
|
+
{selected?.map((selectedOption: T, i) => (
|
|
112
|
+
<Chip
|
|
113
|
+
key={i}
|
|
114
|
+
label={getOptionLabel(selectedOption)}
|
|
115
|
+
onDelete={() =>
|
|
116
|
+
!props.disabled && handleDeleteChip(selectedOption)
|
|
117
|
+
}
|
|
118
|
+
onMouseDown={(event) => {
|
|
119
|
+
event.stopPropagation();
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
))}
|
|
123
|
+
</Box>
|
|
124
|
+
)}
|
|
125
|
+
IconComponent={({ className }) => (
|
|
126
|
+
<Icon
|
|
127
|
+
className={
|
|
128
|
+
props.disabled ? 'Mui-disabled SelectIcon' : 'SelectIcon'
|
|
129
|
+
}
|
|
130
|
+
icon={color === 'success' ? faCheck : faChevronDown}
|
|
131
|
+
size={color === 'success' ? 'md' : 'sm'}
|
|
132
|
+
sx={{
|
|
133
|
+
marginRight: '12px',
|
|
134
|
+
marginTop: color === 'success' ? '2px' : '0px',
|
|
135
|
+
transform:
|
|
136
|
+
className.toString().includes('iconOpen') &&
|
|
137
|
+
color !== 'success'
|
|
138
|
+
? 'rotate(180deg)'
|
|
139
|
+
: 'none'
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
)}
|
|
143
|
+
MenuProps={{
|
|
144
|
+
PaperProps: {
|
|
145
|
+
style: {
|
|
146
|
+
width
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}}
|
|
150
|
+
{...props}
|
|
151
|
+
>
|
|
152
|
+
{options?.map((option, i) => (
|
|
153
|
+
<MenuItem
|
|
154
|
+
key={i}
|
|
155
|
+
value={option as any}
|
|
156
|
+
sx={{
|
|
157
|
+
fontWeight: values.indexOf(option) === -1 ? 400 : 500,
|
|
158
|
+
backgroundColor:
|
|
159
|
+
values.indexOf(option) === -1 ? '#ffffff' : '#D3E4F0'
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
{getOptionLabel(option)}
|
|
163
|
+
</MenuItem>
|
|
164
|
+
))}
|
|
165
|
+
</MuiSelect>
|
|
166
|
+
{(error || helperText) && (
|
|
167
|
+
<FormHelperText component="span" className={error ? 'Mui-error' : ''}>
|
|
168
|
+
{error || helperText}
|
|
169
|
+
</FormHelperText>
|
|
170
|
+
)}
|
|
171
|
+
</FormControl>
|
|
172
|
+
</Box>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export default MultiSelect;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './MultiSelect';
|