@sonardigital/carbon-ui 1.1.28 → 1.1.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonardigital/carbon-ui",
3
- "version": "1.1.28",
3
+ "version": "1.1.31",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -0,0 +1,49 @@
1
+ import { AutocompleteProps, Stack } from '@mui/material';
2
+ import { Controller } from 'react-hook-form';
3
+ import { FormLabel } from '../layout';
4
+ import { FormError } from '../layout/FormError';
5
+ import { MultiselectAutocomplete } from '../../inputs';
6
+
7
+ interface MultiselectAutocompleteProps
8
+ extends Omit<
9
+ // eslint-disable-next-line
10
+ AutocompleteProps<any, false, false, false>,
11
+ 'renderInput' | 'options' | 'value' | 'onChange'
12
+ > {
13
+ name: string;
14
+ label: string;
15
+ placeholder?: string;
16
+ options: { label: string; value: string | number }[];
17
+ helperText?: string;
18
+ fetchOptions?: () => Promise<{ label: string; value: string | number }[]>;
19
+ }
20
+
21
+ export function FormMultiselect({
22
+ name,
23
+ label,
24
+ options,
25
+ ...rest
26
+ }: MultiselectAutocompleteProps): React.ReactElement {
27
+ return (
28
+ <Controller
29
+ name={name}
30
+ render={({ field, fieldState }) => {
31
+ const { value, onChange } = field;
32
+ return (
33
+ <FormLabel label={label}>
34
+ <Stack gap={0.8}>
35
+ <MultiselectAutocomplete
36
+ {...field}
37
+ {...rest}
38
+ options={options}
39
+ value={value as { label: string; value: string | number }[]}
40
+ onChange={onChange}
41
+ />
42
+ {fieldState.error && <FormError label={fieldState.error?.message ?? ''} />}
43
+ </Stack>
44
+ </FormLabel>
45
+ );
46
+ }}
47
+ />
48
+ );
49
+ }
@@ -2,3 +2,4 @@ export * from './FormInput';
2
2
  export * from './FormPassword';
3
3
  export * from './FormTextArea';
4
4
  export * from './FormSelect';
5
+ export * from './FormMultiselect';
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import {
3
+ Autocomplete,
4
+ AutocompleteProps,
5
+ Chip,
6
+ IconButton,
7
+ TextField,
8
+ Typography,
9
+ useTheme,
10
+ } from '@mui/material';
11
+ import { RiCloseFill } from 'react-icons/ri';
12
+
13
+ interface SelectAutocompleteProps
14
+ extends Omit<
15
+ AutocompleteProps<{ label: string; value: string | number }, false, false, false>,
16
+ 'renderInput' | 'onChange' | 'value'
17
+ > {
18
+ value: { label: string; value: string | number }[];
19
+ onChange: (value: (string | number | null)[]) => void;
20
+ placeholder?: string;
21
+ options: { label: string; value: string | number }[];
22
+ helperText?: string;
23
+ fetchOptions?: () => Promise<{ label: string; value: string | number }[]>;
24
+ }
25
+
26
+ export function MultiselectAutocomplete(props: SelectAutocompleteProps): React.ReactElement {
27
+ const { options, value, onChange, placeholder } = props;
28
+
29
+ const theme = useTheme();
30
+
31
+ return (
32
+ <Autocomplete
33
+ value={value}
34
+ multiple
35
+ options={options || []}
36
+ getOptionLabel={(option: { label: string; value: string | number }) => option.label}
37
+ clearIcon={
38
+ <IconButton size="small" onClick={() => onChange([])}>
39
+ <RiCloseFill size={18} />
40
+ </IconButton>
41
+ }
42
+ popupIcon={null}
43
+ defaultValue={[]}
44
+ renderValue={(selected) => {
45
+ return (
46
+ <>
47
+ {selected?.map((item) => (
48
+ <Chip
49
+ key={item.value}
50
+ style={{
51
+ alignSelf: 'center',
52
+ marginRight: 5,
53
+ }}
54
+ color="primary"
55
+ label={<Typography variant="caption">{item.label}</Typography>}
56
+ />
57
+ ))}
58
+ </>
59
+ );
60
+ }}
61
+ renderInput={(params) => (
62
+ <TextField
63
+ inputProps={params.inputProps}
64
+ InputLabelProps={params.InputLabelProps}
65
+ placeholder={placeholder}
66
+ InputProps={{
67
+ ...params.InputProps,
68
+
69
+ sx: {
70
+ ...theme.components?.MuiTextField?.defaultProps?.InputProps?.sx,
71
+ height: '100%',
72
+ },
73
+ }}
74
+ />
75
+ )}
76
+ />
77
+ );
78
+ }
@@ -1 +1,2 @@
1
1
  export * from './SelectAutocomplete';
2
+ export * from './MultiselectAutocomplete';