@sonardigital/carbon-ui 1.1.92 → 1.1.93
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
|
@@ -2,67 +2,85 @@ import { Card, Grow, Stack } from '@mui/material';
|
|
|
2
2
|
import { Controller } from 'react-hook-form';
|
|
3
3
|
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
|
|
4
4
|
|
|
5
|
-
export interface FormBoxProps {
|
|
6
|
-
value:
|
|
5
|
+
export interface FormBoxProps<T> {
|
|
6
|
+
value: T;
|
|
7
7
|
color?: string;
|
|
8
|
+
multiple?: boolean;
|
|
8
9
|
children: React.ReactNode;
|
|
9
10
|
sx?: Record<string, unknown>;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
interface LocalFormBoxProps extends FormBoxProps {
|
|
13
|
+
interface LocalFormBoxProps<T> extends FormBoxProps<T> {
|
|
13
14
|
name: string;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export function FormBox({
|
|
17
|
+
export function FormBox<T>({
|
|
17
18
|
name,
|
|
19
|
+
multiple,
|
|
18
20
|
children,
|
|
19
21
|
value,
|
|
20
22
|
color,
|
|
21
23
|
sx,
|
|
22
|
-
}: LocalFormBoxProps): React.ReactElement {
|
|
24
|
+
}: LocalFormBoxProps<T>): React.ReactElement {
|
|
23
25
|
return (
|
|
24
26
|
<Controller
|
|
25
27
|
name={name}
|
|
26
|
-
render={({ field }) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</Grow>
|
|
41
|
-
)}
|
|
42
|
-
<Card
|
|
43
|
-
// eslint-disable-next-line
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
variant="numeric"
|
|
46
|
-
sx={{
|
|
47
|
-
bgcolor: `${color}.light`,
|
|
48
|
-
height: 65,
|
|
49
|
-
width: '100%',
|
|
50
|
-
borderRadius: 2.2,
|
|
51
|
-
border: 2,
|
|
52
|
-
transition: '0.2s',
|
|
53
|
-
borderColor: `${color}.${value === field.value ? 'main' : 'light'}`,
|
|
54
|
-
...sx,
|
|
55
|
-
}}
|
|
56
|
-
onClick={() =>
|
|
57
|
-
field.value === value
|
|
58
|
-
? field.onChange(null)
|
|
59
|
-
: field.onChange(value)
|
|
28
|
+
render={({ field }) => {
|
|
29
|
+
const onChange = () => {
|
|
30
|
+
if (multiple) {
|
|
31
|
+
if (!field.value) {
|
|
32
|
+
field.onChange([value] as T[]);
|
|
33
|
+
return;
|
|
34
|
+
} else {
|
|
35
|
+
if (field.value.includes(value)) {
|
|
36
|
+
field.onChange(
|
|
37
|
+
field.value.filter((v: T) => v !== value) as T[],
|
|
38
|
+
);
|
|
39
|
+
} else {
|
|
40
|
+
field.onChange([...field.value, value] as T[]);
|
|
41
|
+
}
|
|
60
42
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
43
|
+
}
|
|
44
|
+
field.onChange(value as T);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Stack sx={{ position: 'relative' }}>
|
|
49
|
+
{value === field.value && (
|
|
50
|
+
<Grow in={true} timeout={250}>
|
|
51
|
+
<CheckCircleIcon
|
|
52
|
+
sx={{
|
|
53
|
+
width: 19,
|
|
54
|
+
height: 19,
|
|
55
|
+
position: 'absolute',
|
|
56
|
+
top: 10,
|
|
57
|
+
right: 10,
|
|
58
|
+
color: `${color}.main`,
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
</Grow>
|
|
62
|
+
)}
|
|
63
|
+
<Card
|
|
64
|
+
// eslint-disable-next-line
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
variant="numeric"
|
|
67
|
+
sx={{
|
|
68
|
+
bgcolor: `${color}.light`,
|
|
69
|
+
height: 65,
|
|
70
|
+
width: '100%',
|
|
71
|
+
borderRadius: 2.2,
|
|
72
|
+
border: 2,
|
|
73
|
+
transition: '0.2s',
|
|
74
|
+
borderColor: `${color}.${value === field.value ? 'main' : 'light'}`,
|
|
75
|
+
...sx,
|
|
76
|
+
}}
|
|
77
|
+
onClick={onChange}
|
|
78
|
+
>
|
|
79
|
+
{children}
|
|
80
|
+
</Card>
|
|
81
|
+
</Stack>
|
|
82
|
+
);
|
|
83
|
+
}}
|
|
66
84
|
/>
|
|
67
85
|
);
|
|
68
86
|
}
|
|
@@ -2,38 +2,44 @@ import { Controller } from 'react-hook-form';
|
|
|
2
2
|
import { FormBox, FormBoxProps } from './FormBox';
|
|
3
3
|
import { Grid, Typography } from '@mui/material';
|
|
4
4
|
|
|
5
|
-
interface LocalFormBoxProps extends FormBoxProps {
|
|
5
|
+
interface LocalFormBoxProps<T> extends FormBoxProps<T> {
|
|
6
6
|
label: string;
|
|
7
7
|
size?: { xs: number; sm: number; md: number };
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function FormBoxes({
|
|
10
|
+
export function FormBoxes<T>({
|
|
11
11
|
name,
|
|
12
12
|
options,
|
|
13
|
+
multiple,
|
|
13
14
|
sx,
|
|
14
15
|
}: {
|
|
15
16
|
name: string;
|
|
16
|
-
|
|
17
|
+
multiple: boolean;
|
|
18
|
+
options: LocalFormBoxProps<T>[];
|
|
17
19
|
sx?: Record<string, unknown>;
|
|
18
20
|
}): React.ReactElement {
|
|
19
21
|
return (
|
|
20
22
|
<Grid container width="100%" spacing={2}>
|
|
21
|
-
{options.map(option => (
|
|
23
|
+
{options.map((option, i) => (
|
|
22
24
|
<Controller
|
|
23
25
|
name={name}
|
|
24
26
|
render={({ field }) => {
|
|
25
|
-
const isEmpty =
|
|
26
|
-
field.value
|
|
27
|
-
|
|
27
|
+
const isEmpty = multiple
|
|
28
|
+
? field.value.length === 0
|
|
29
|
+
: field.value === undefined || field.value === null;
|
|
30
|
+
const isSelected = multiple
|
|
31
|
+
? field.value?.includes(option.value)
|
|
32
|
+
: option.value === field.value;
|
|
28
33
|
return (
|
|
29
34
|
<Grid
|
|
30
35
|
size={{ xs: 6, sm: 4, md: 3, ...option.size }}
|
|
31
|
-
key={
|
|
36
|
+
key={i}
|
|
32
37
|
>
|
|
33
38
|
<FormBox
|
|
34
39
|
name={name}
|
|
35
40
|
value={option.value}
|
|
36
41
|
color={option.color}
|
|
42
|
+
multiple={multiple}
|
|
37
43
|
sx={{
|
|
38
44
|
height: 90,
|
|
39
45
|
transition: 'all 0.1s',
|