@sonardigital/carbon-ui 1.1.45 → 1.1.48
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 +3 -1
- package/src/components/form/fields/FormDatePicker.tsx +21 -0
- package/src/components/form/fields/FormMultiselect.tsx +1 -1
- package/src/components/form/fields/FormSelect.tsx +1 -1
- package/src/components/form/fields/index.ts +1 -0
- package/src/components/inputs/DatePicker.tsx +119 -0
- package/src/components/inputs/SelectAutocomplete.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonardigital/carbon-ui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.48",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -38,9 +38,11 @@
|
|
|
38
38
|
"@emotion/styled": "^11.14.1",
|
|
39
39
|
"@mui/icons-material": "^7.3.2",
|
|
40
40
|
"@mui/material": "^7.3.2",
|
|
41
|
+
"@mui/x-date-pickers": "^8.12.0",
|
|
41
42
|
"@sonardigital/carbon-ui": "^1.1.18",
|
|
42
43
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
43
44
|
"@typescript-eslint/parser": "^7.18.0",
|
|
45
|
+
"dayjs": "^1.11.18",
|
|
44
46
|
"eslint": "^8.57.0",
|
|
45
47
|
"eslint-config-prettier": "^9.1.0",
|
|
46
48
|
"eslint-plugin-import": "^2.31.0",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Controller } from 'react-hook-form';
|
|
2
|
+
import { FormLabel } from '../layout';
|
|
3
|
+
import { DatePicker, DatePickerProps } from '../../inputs/DatePicker';
|
|
4
|
+
|
|
5
|
+
interface FormDatePickerProps extends DatePickerProps {
|
|
6
|
+
name: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function FormDatePicker({ name, label, ...props }: FormDatePickerProps): React.ReactElement {
|
|
11
|
+
return (
|
|
12
|
+
<Controller
|
|
13
|
+
name={name}
|
|
14
|
+
render={({ field }) => (
|
|
15
|
+
<FormLabel label={label}>
|
|
16
|
+
<DatePicker {...field} {...props} />
|
|
17
|
+
</FormLabel>
|
|
18
|
+
)}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -13,7 +13,7 @@ interface MultiselectAutocompleteProps
|
|
|
13
13
|
name: string;
|
|
14
14
|
label: string;
|
|
15
15
|
placeholder?: string;
|
|
16
|
-
options
|
|
16
|
+
options?: { label: string; value: string | number }[];
|
|
17
17
|
helperText?: string;
|
|
18
18
|
fetchOptions?: () => Promise<{ label: string; value: string | number }[]>;
|
|
19
19
|
}
|
|
@@ -12,7 +12,7 @@ interface SelectAutocompleteProps
|
|
|
12
12
|
name: string;
|
|
13
13
|
label: string;
|
|
14
14
|
placeholder?: string;
|
|
15
|
-
options
|
|
15
|
+
options?: { label: string; value: string | number }[];
|
|
16
16
|
helperText?: string;
|
|
17
17
|
fetchOptions?: () => Promise<{ label: string; value: string | number }[]>;
|
|
18
18
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
2
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
3
|
+
import {
|
|
4
|
+
DatePickerProps as MUIDatePickerProps,
|
|
5
|
+
DatePicker as MUIDatePicker,
|
|
6
|
+
} from '@mui/x-date-pickers/DatePicker';
|
|
7
|
+
import { IconButton, useTheme } from '@mui/material';
|
|
8
|
+
import { CalendarToday } from '@mui/icons-material';
|
|
9
|
+
import 'dayjs/locale/it';
|
|
10
|
+
import dayjs from 'dayjs';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
|
|
13
|
+
export interface DatePickerProps extends Omit<MUIDatePickerProps, 'value' | 'onChange'> {
|
|
14
|
+
value: string | null;
|
|
15
|
+
onChange: (value: string | null) => void;
|
|
16
|
+
adapterLocale?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const itLocale = dayjs.Ls.it;
|
|
20
|
+
|
|
21
|
+
dayjs.locale({
|
|
22
|
+
...itLocale,
|
|
23
|
+
months: itLocale.months?.map((m) => m.charAt(0).toUpperCase() + m.slice(1)),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export function DatePicker({
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
adapterLocale = 'it',
|
|
30
|
+
...props
|
|
31
|
+
}: DatePickerProps): React.ReactElement {
|
|
32
|
+
const theme = useTheme();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<LocalizationProvider
|
|
36
|
+
dateAdapter={AdapterDayjs}
|
|
37
|
+
adapterLocale={adapterLocale}
|
|
38
|
+
dateFormats={{
|
|
39
|
+
month: 'MMMM',
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
<MUIDatePicker
|
|
43
|
+
value={value ? dayjs(value) : null}
|
|
44
|
+
onChange={(v) => {
|
|
45
|
+
onChange(v ? dayjs(v).toISOString() : null);
|
|
46
|
+
}}
|
|
47
|
+
format="DD/MM/YYYY"
|
|
48
|
+
slots={{
|
|
49
|
+
openPickerButton: IconButton,
|
|
50
|
+
openPickerIcon: CalendarToday,
|
|
51
|
+
}}
|
|
52
|
+
slotProps={{
|
|
53
|
+
day: {
|
|
54
|
+
sx: {
|
|
55
|
+
fontWeight: 400,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
leftArrowIcon: {
|
|
59
|
+
sx: { width: 20, height: 20 },
|
|
60
|
+
},
|
|
61
|
+
mobileTransition: {
|
|
62
|
+
timeout: 0,
|
|
63
|
+
},
|
|
64
|
+
desktopTransition: {
|
|
65
|
+
timeout: 0,
|
|
66
|
+
},
|
|
67
|
+
rightArrowIcon: {
|
|
68
|
+
sx: { width: 20, height: 20 },
|
|
69
|
+
},
|
|
70
|
+
yearButton: {
|
|
71
|
+
sx: {
|
|
72
|
+
width: 75,
|
|
73
|
+
height: 40,
|
|
74
|
+
borderRadius: 1.5,
|
|
75
|
+
fontSize: 15,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
switchViewIcon: {
|
|
79
|
+
sx: { width: 20, height: 20, opacity: 0.9 },
|
|
80
|
+
},
|
|
81
|
+
desktopPaper: {
|
|
82
|
+
...theme.components?.MuiPaper?.defaultProps,
|
|
83
|
+
sx: {
|
|
84
|
+
...theme.components?.MuiPaper?.defaultProps?.sx,
|
|
85
|
+
mt: 1,
|
|
86
|
+
backgroundColor: 'background.default',
|
|
87
|
+
boxShadow: '0px 4px 10px rgba(0, 0, 0, 0)',
|
|
88
|
+
border: 1,
|
|
89
|
+
borderColor: 'grey.300',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
openPickerButton: {
|
|
93
|
+
size: 'large',
|
|
94
|
+
style: {
|
|
95
|
+
marginRight: -5,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
openPickerIcon: {
|
|
99
|
+
sx: {
|
|
100
|
+
width: 17,
|
|
101
|
+
height: 17,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
textField: {
|
|
105
|
+
variant: 'outlined',
|
|
106
|
+
...theme.components?.MuiTextField?.defaultProps,
|
|
107
|
+
InputProps: {
|
|
108
|
+
sx: {
|
|
109
|
+
...theme.components?.MuiTextField?.defaultProps?.InputProps?.sx,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
sx: {},
|
|
113
|
+
},
|
|
114
|
+
}}
|
|
115
|
+
{...props}
|
|
116
|
+
/>
|
|
117
|
+
</LocalizationProvider>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
@@ -5,7 +5,7 @@ import { RiCloseFill } from 'react-icons/ri';
|
|
|
5
5
|
interface SelectAutocompleteProps
|
|
6
6
|
extends Omit<
|
|
7
7
|
AutocompleteProps<{ label: string; value: string | number }, false, false, false>,
|
|
8
|
-
'renderInput' | 'onChange' | 'value'
|
|
8
|
+
'renderInput' | 'onChange' | 'value' | 'options'
|
|
9
9
|
> {
|
|
10
10
|
value: string | number | null;
|
|
11
11
|
onChange: (value: string | number | null) => void;
|