@lets-events/react 11.5.0 → 11.5.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/.eslintrc.json +2 -2
- package/.turbo/turbo-build.log +18 -20
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/index.mjs +3 -2
- package/package.json +1 -1
- package/src/components/Alert.tsx +303 -303
- package/src/components/Avatar.tsx +55 -55
- package/src/components/Badge.tsx +125 -125
- package/src/components/Box.tsx +3 -3
- package/src/components/Button/index.tsx +16 -16
- package/src/components/Button/styledComponents.ts +287 -287
- package/src/components/ButtonGroup.tsx +484 -484
- package/src/components/Calendar/index.tsx +136 -136
- package/src/components/Calendar/styledComponents.ts +209 -209
- package/src/components/Card.tsx +48 -48
- package/src/components/CheckboxGroup.tsx +196 -196
- package/src/components/Container.tsx +39 -39
- package/src/components/Drawer/index.tsx +48 -48
- package/src/components/Drawer/styledComponents.ts +46 -46
- package/src/components/Dropdown.tsx +167 -167
- package/src/components/Filter.tsx +164 -164
- package/src/components/Flex.tsx +118 -118
- package/src/components/FormFields/ErrorFormMessage.tsx +36 -36
- package/src/components/FormFields/Form.tsx +25 -25
- package/src/components/FormFields/FormLabel.tsx +29 -29
- package/src/components/FormFields/MultiSelectFormField.tsx +59 -59
- package/src/components/FormFields/PhoneFormField.tsx +130 -130
- package/src/components/FormFields/TextAreaFormField.tsx +49 -46
- package/src/components/FormFields/TextFormField.tsx +46 -46
- package/src/components/Grid.tsx +137 -137
- package/src/components/Icon.tsx +47 -47
- package/src/components/MenuDropdown/index.tsx +30 -30
- package/src/components/MenuDropdown/styledComponents.ts +31 -31
- package/src/components/Modal.tsx +90 -90
- package/src/components/MultiSelect.tsx +218 -218
- package/src/components/RadioGroup.tsx +210 -210
- package/src/components/Section.tsx +33 -33
- package/src/components/Step.tsx +164 -164
- package/src/components/Switch.tsx +108 -108
- package/src/components/Text.tsx +38 -38
- package/src/components/TextField.tsx +315 -315
- package/src/components/TextareaField.tsx +128 -128
- package/src/components/TimePicker.tsx +298 -298
- package/src/components/Toast/components/ToastItem.tsx +41 -41
- package/src/components/Toast/components/ToastProvider.tsx +63 -63
- package/src/components/Toast/hooks/useToast.ts +12 -12
- package/src/components/Toast/index.tsx +5 -5
- package/src/components/Toast/styles/index.ts +135 -135
- package/src/components/Toast/types/index.ts +46 -46
- package/src/components/Tooltip/index.tsx +66 -66
- package/src/components/Tooltip/styles.ts +77 -77
- package/src/hooks/useOnClickOutside.tsx +20 -20
- package/src/index.tsx +45 -45
- package/src/styles/index.ts +38 -38
- package/src/types/typographyValues.ts +178 -178
- package/tsconfig.json +3 -3
package/src/components/Flex.tsx
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import { ComponentProps, ElementType } from 'react';
|
|
2
|
-
import { styled } from '../styles'
|
|
3
|
-
import { Flex as FlexRadix } from "@radix-ui/themes";
|
|
4
|
-
export const FlexStyled = styled(FlexRadix, {
|
|
5
|
-
variants: {
|
|
6
|
-
display: {
|
|
7
|
-
'flex': { display: 'flex' },
|
|
8
|
-
'inline-flex': { display: 'inline-flex' }
|
|
9
|
-
},
|
|
10
|
-
align: {
|
|
11
|
-
start: { alignItems: 'flex-start' },
|
|
12
|
-
center: { alignItems: 'center' },
|
|
13
|
-
end: { alignItems: 'flex-end' },
|
|
14
|
-
stretch: { alignItems: 'stretch' },
|
|
15
|
-
baseline: { alignItems: 'baseline' },
|
|
16
|
-
},
|
|
17
|
-
justify: {
|
|
18
|
-
start: { justifyContent: 'flex-start' },
|
|
19
|
-
center: { justifyContent: 'center' },
|
|
20
|
-
end: { justifyContent: 'flex-end' },
|
|
21
|
-
between: { justifyContent: 'space-between' },
|
|
22
|
-
around: { justifyContent: 'space-around' },
|
|
23
|
-
evenly: { justifyContent: 'space-evenly' },
|
|
24
|
-
},
|
|
25
|
-
direction: {
|
|
26
|
-
row: { flexDirection: 'row' },
|
|
27
|
-
column: { flexDirection: 'column' },
|
|
28
|
-
'row-reverse': { flexDirection: 'row-reverse' },
|
|
29
|
-
'column-reverse': { flexDirection: 'column-reverse' },
|
|
30
|
-
},
|
|
31
|
-
gap: {
|
|
32
|
-
0: { gap: '0px' },
|
|
33
|
-
2: { gap: '$2' },
|
|
34
|
-
4: { gap: '$4' },
|
|
35
|
-
6: { gap: '$6' },
|
|
36
|
-
8: { gap: '$8' },
|
|
37
|
-
10: { gap: '$10' },
|
|
38
|
-
12: { gap: '$12' },
|
|
39
|
-
14: { gap: '$14' },
|
|
40
|
-
16: { gap: '$16' },
|
|
41
|
-
20: { gap: '$20' },
|
|
42
|
-
22: { gap: '$22' },
|
|
43
|
-
24: { gap: '$24' },
|
|
44
|
-
32: { gap: '$32' },
|
|
45
|
-
36: { gap: '$36' },
|
|
46
|
-
40: { gap: '$40' },
|
|
47
|
-
48: { gap: '$48' },
|
|
48
|
-
56: { gap: '$56' },
|
|
49
|
-
64: { gap: '$64' },
|
|
50
|
-
72: { gap: '$72' },
|
|
51
|
-
80: { gap: '$80' },
|
|
52
|
-
full: { gap: '$full' },
|
|
53
|
-
},
|
|
54
|
-
gapY: {
|
|
55
|
-
2: { gap: '$2' },
|
|
56
|
-
4: { gap: '$4' },
|
|
57
|
-
6: { gap: '$6' },
|
|
58
|
-
8: { gap: '$8' },
|
|
59
|
-
10: { gap: '$10' },
|
|
60
|
-
12: { gap: '$12' },
|
|
61
|
-
14: { gap: '$14' },
|
|
62
|
-
16: { gap: '$16' },
|
|
63
|
-
20: { gap: '$20' },
|
|
64
|
-
22: { gap: '$22' },
|
|
65
|
-
24: { gap: '$24' },
|
|
66
|
-
32: { gap: '$32' },
|
|
67
|
-
36: { gap: '$36' },
|
|
68
|
-
40: { gap: '$40' },
|
|
69
|
-
48: { gap: '$48' },
|
|
70
|
-
56: { gap: '$56' },
|
|
71
|
-
64: { gap: '$64' },
|
|
72
|
-
72: { gap: '$72' },
|
|
73
|
-
80: { gap: '$80' },
|
|
74
|
-
full: { gap: '$full' },
|
|
75
|
-
},
|
|
76
|
-
gapX: {
|
|
77
|
-
2: { gap: '$2' },
|
|
78
|
-
4: { gap: '$4' },
|
|
79
|
-
6: { gap: '$6' },
|
|
80
|
-
8: { gap: '$8' },
|
|
81
|
-
10: { gap: '$10' },
|
|
82
|
-
12: { gap: '$12' },
|
|
83
|
-
14: { gap: '$14' },
|
|
84
|
-
16: { gap: '$16' },
|
|
85
|
-
20: { gap: '$20' },
|
|
86
|
-
22: { gap: '$22' },
|
|
87
|
-
24: { gap: '$24' },
|
|
88
|
-
32: { gap: '$32' },
|
|
89
|
-
36: { gap: '$36' },
|
|
90
|
-
40: { gap: '$40' },
|
|
91
|
-
48: { gap: '$48' },
|
|
92
|
-
56: { gap: '$56' },
|
|
93
|
-
64: { gap: '$64' },
|
|
94
|
-
72: { gap: '$72' },
|
|
95
|
-
80: { gap: '$80' },
|
|
96
|
-
full: { gap: '$full' },
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
defaultVariants: {
|
|
100
|
-
display: 'flex',
|
|
101
|
-
direction: 'row',
|
|
102
|
-
gap: 10,
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
export type FlexProps = ComponentProps<typeof FlexStyled> & {
|
|
108
|
-
as?: ElementType,
|
|
109
|
-
children: React.ReactNode
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
export function Flex({ children, ...props }: FlexProps) {
|
|
114
|
-
return (
|
|
115
|
-
<FlexStyled {...props}>
|
|
116
|
-
{children}
|
|
117
|
-
</FlexStyled>
|
|
118
|
-
)
|
|
1
|
+
import { ComponentProps, ElementType } from 'react';
|
|
2
|
+
import { styled } from '../styles'
|
|
3
|
+
import { Flex as FlexRadix } from "@radix-ui/themes";
|
|
4
|
+
export const FlexStyled = styled(FlexRadix, {
|
|
5
|
+
variants: {
|
|
6
|
+
display: {
|
|
7
|
+
'flex': { display: 'flex' },
|
|
8
|
+
'inline-flex': { display: 'inline-flex' }
|
|
9
|
+
},
|
|
10
|
+
align: {
|
|
11
|
+
start: { alignItems: 'flex-start' },
|
|
12
|
+
center: { alignItems: 'center' },
|
|
13
|
+
end: { alignItems: 'flex-end' },
|
|
14
|
+
stretch: { alignItems: 'stretch' },
|
|
15
|
+
baseline: { alignItems: 'baseline' },
|
|
16
|
+
},
|
|
17
|
+
justify: {
|
|
18
|
+
start: { justifyContent: 'flex-start' },
|
|
19
|
+
center: { justifyContent: 'center' },
|
|
20
|
+
end: { justifyContent: 'flex-end' },
|
|
21
|
+
between: { justifyContent: 'space-between' },
|
|
22
|
+
around: { justifyContent: 'space-around' },
|
|
23
|
+
evenly: { justifyContent: 'space-evenly' },
|
|
24
|
+
},
|
|
25
|
+
direction: {
|
|
26
|
+
row: { flexDirection: 'row' },
|
|
27
|
+
column: { flexDirection: 'column' },
|
|
28
|
+
'row-reverse': { flexDirection: 'row-reverse' },
|
|
29
|
+
'column-reverse': { flexDirection: 'column-reverse' },
|
|
30
|
+
},
|
|
31
|
+
gap: {
|
|
32
|
+
0: { gap: '0px' },
|
|
33
|
+
2: { gap: '$2' },
|
|
34
|
+
4: { gap: '$4' },
|
|
35
|
+
6: { gap: '$6' },
|
|
36
|
+
8: { gap: '$8' },
|
|
37
|
+
10: { gap: '$10' },
|
|
38
|
+
12: { gap: '$12' },
|
|
39
|
+
14: { gap: '$14' },
|
|
40
|
+
16: { gap: '$16' },
|
|
41
|
+
20: { gap: '$20' },
|
|
42
|
+
22: { gap: '$22' },
|
|
43
|
+
24: { gap: '$24' },
|
|
44
|
+
32: { gap: '$32' },
|
|
45
|
+
36: { gap: '$36' },
|
|
46
|
+
40: { gap: '$40' },
|
|
47
|
+
48: { gap: '$48' },
|
|
48
|
+
56: { gap: '$56' },
|
|
49
|
+
64: { gap: '$64' },
|
|
50
|
+
72: { gap: '$72' },
|
|
51
|
+
80: { gap: '$80' },
|
|
52
|
+
full: { gap: '$full' },
|
|
53
|
+
},
|
|
54
|
+
gapY: {
|
|
55
|
+
2: { gap: '$2' },
|
|
56
|
+
4: { gap: '$4' },
|
|
57
|
+
6: { gap: '$6' },
|
|
58
|
+
8: { gap: '$8' },
|
|
59
|
+
10: { gap: '$10' },
|
|
60
|
+
12: { gap: '$12' },
|
|
61
|
+
14: { gap: '$14' },
|
|
62
|
+
16: { gap: '$16' },
|
|
63
|
+
20: { gap: '$20' },
|
|
64
|
+
22: { gap: '$22' },
|
|
65
|
+
24: { gap: '$24' },
|
|
66
|
+
32: { gap: '$32' },
|
|
67
|
+
36: { gap: '$36' },
|
|
68
|
+
40: { gap: '$40' },
|
|
69
|
+
48: { gap: '$48' },
|
|
70
|
+
56: { gap: '$56' },
|
|
71
|
+
64: { gap: '$64' },
|
|
72
|
+
72: { gap: '$72' },
|
|
73
|
+
80: { gap: '$80' },
|
|
74
|
+
full: { gap: '$full' },
|
|
75
|
+
},
|
|
76
|
+
gapX: {
|
|
77
|
+
2: { gap: '$2' },
|
|
78
|
+
4: { gap: '$4' },
|
|
79
|
+
6: { gap: '$6' },
|
|
80
|
+
8: { gap: '$8' },
|
|
81
|
+
10: { gap: '$10' },
|
|
82
|
+
12: { gap: '$12' },
|
|
83
|
+
14: { gap: '$14' },
|
|
84
|
+
16: { gap: '$16' },
|
|
85
|
+
20: { gap: '$20' },
|
|
86
|
+
22: { gap: '$22' },
|
|
87
|
+
24: { gap: '$24' },
|
|
88
|
+
32: { gap: '$32' },
|
|
89
|
+
36: { gap: '$36' },
|
|
90
|
+
40: { gap: '$40' },
|
|
91
|
+
48: { gap: '$48' },
|
|
92
|
+
56: { gap: '$56' },
|
|
93
|
+
64: { gap: '$64' },
|
|
94
|
+
72: { gap: '$72' },
|
|
95
|
+
80: { gap: '$80' },
|
|
96
|
+
full: { gap: '$full' },
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
defaultVariants: {
|
|
100
|
+
display: 'flex',
|
|
101
|
+
direction: 'row',
|
|
102
|
+
gap: 10,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
export type FlexProps = ComponentProps<typeof FlexStyled> & {
|
|
108
|
+
as?: ElementType,
|
|
109
|
+
children: React.ReactNode
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
export function Flex({ children, ...props }: FlexProps) {
|
|
114
|
+
return (
|
|
115
|
+
<FlexStyled {...props}>
|
|
116
|
+
{children}
|
|
117
|
+
</FlexStyled>
|
|
118
|
+
)
|
|
119
119
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { faXmarkCircle } from "@fortawesome/free-solid-svg-icons";
|
|
2
|
-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
3
|
-
import { colors } from "@lets-events/tokens";
|
|
4
|
-
import { Flex } from "../Flex";
|
|
5
|
-
import { Text } from "../Text";
|
|
6
|
-
import {
|
|
7
|
-
FieldError,
|
|
8
|
-
FieldErrorsImpl,
|
|
9
|
-
FieldValues,
|
|
10
|
-
Merge,
|
|
11
|
-
} from "react-hook-form";
|
|
12
|
-
|
|
13
|
-
export type ErrorFormMessageProps = {
|
|
14
|
-
message?:
|
|
15
|
-
| string
|
|
16
|
-
| FieldError
|
|
17
|
-
| Merge<FieldError, FieldErrorsImpl<any>>
|
|
18
|
-
| undefined;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const ErrorFormMessage = ({ message }: ErrorFormMessageProps) => {
|
|
22
|
-
if (!message) return null;
|
|
23
|
-
|
|
24
|
-
if (typeof message !== "string") {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Flex justify={"start"} align={"center"} gap={6}>
|
|
30
|
-
<FontAwesomeIcon icon={faXmarkCircle} color={colors.error600} size="1x" />
|
|
31
|
-
<Text typography={"bodyXS"} fontWeight={"medium"} color="error600">
|
|
32
|
-
{message}
|
|
33
|
-
</Text>
|
|
34
|
-
</Flex>
|
|
35
|
-
);
|
|
36
|
-
};
|
|
1
|
+
import { faXmarkCircle } from "@fortawesome/free-solid-svg-icons";
|
|
2
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
3
|
+
import { colors } from "@lets-events/tokens";
|
|
4
|
+
import { Flex } from "../Flex";
|
|
5
|
+
import { Text } from "../Text";
|
|
6
|
+
import {
|
|
7
|
+
FieldError,
|
|
8
|
+
FieldErrorsImpl,
|
|
9
|
+
FieldValues,
|
|
10
|
+
Merge,
|
|
11
|
+
} from "react-hook-form";
|
|
12
|
+
|
|
13
|
+
export type ErrorFormMessageProps = {
|
|
14
|
+
message?:
|
|
15
|
+
| string
|
|
16
|
+
| FieldError
|
|
17
|
+
| Merge<FieldError, FieldErrorsImpl<any>>
|
|
18
|
+
| undefined;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const ErrorFormMessage = ({ message }: ErrorFormMessageProps) => {
|
|
22
|
+
if (!message) return null;
|
|
23
|
+
|
|
24
|
+
if (typeof message !== "string") {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Flex justify={"start"} align={"center"} gap={6}>
|
|
30
|
+
<FontAwesomeIcon icon={faXmarkCircle} color={colors.error600} size="1x" />
|
|
31
|
+
<Text typography={"bodyXS"} fontWeight={"medium"} color="error600">
|
|
32
|
+
{message}
|
|
33
|
+
</Text>
|
|
34
|
+
</Flex>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { JSX } from "react";
|
|
2
|
-
import {
|
|
3
|
-
FormProvider,
|
|
4
|
-
useForm,
|
|
5
|
-
SubmitHandler,
|
|
6
|
-
FieldValues,
|
|
7
|
-
UseFormProps,
|
|
8
|
-
} from "react-hook-form";
|
|
9
|
-
|
|
10
|
-
export type FormProps = UseFormProps & {
|
|
11
|
-
onSubmit: SubmitHandler<FieldValues>;
|
|
12
|
-
children: JSX.Element;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const Form = ({ onSubmit, children, ...props }: FormProps) => {
|
|
16
|
-
const methods = useForm(props);
|
|
17
|
-
|
|
18
|
-
const { handleSubmit } = methods;
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<FormProvider {...methods}>
|
|
22
|
-
<form onSubmit={handleSubmit(onSubmit)}>{children}</form>
|
|
23
|
-
</FormProvider>
|
|
24
|
-
);
|
|
25
|
-
};
|
|
1
|
+
import { JSX } from "react";
|
|
2
|
+
import {
|
|
3
|
+
FormProvider,
|
|
4
|
+
useForm,
|
|
5
|
+
SubmitHandler,
|
|
6
|
+
FieldValues,
|
|
7
|
+
UseFormProps,
|
|
8
|
+
} from "react-hook-form";
|
|
9
|
+
|
|
10
|
+
export type FormProps = UseFormProps & {
|
|
11
|
+
onSubmit: SubmitHandler<FieldValues>;
|
|
12
|
+
children: JSX.Element;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Form = ({ onSubmit, children, ...props }: FormProps) => {
|
|
16
|
+
const methods = useForm(props);
|
|
17
|
+
|
|
18
|
+
const { handleSubmit } = methods;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<FormProvider {...methods}>
|
|
22
|
+
<form onSubmit={handleSubmit(onSubmit)}>{children}</form>
|
|
23
|
+
</FormProvider>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { Text } from "../Text";
|
|
2
|
-
|
|
3
|
-
export type FormLabelProps = {
|
|
4
|
-
name: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
haveError?: boolean;
|
|
7
|
-
required?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const FormLabel = ({
|
|
11
|
-
name,
|
|
12
|
-
label,
|
|
13
|
-
haveError,
|
|
14
|
-
required,
|
|
15
|
-
}: FormLabelProps) => {
|
|
16
|
-
if (!label) return null;
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<Text
|
|
20
|
-
typography={"labelMedium"}
|
|
21
|
-
fontWeight={"medium"}
|
|
22
|
-
color={haveError ? "error600" : "dark700"}
|
|
23
|
-
id={`${name}-label`}
|
|
24
|
-
>
|
|
25
|
-
{label}
|
|
26
|
-
{!required && <Text color="dark500"> (opcional)</Text>}
|
|
27
|
-
</Text>
|
|
28
|
-
);
|
|
29
|
-
};
|
|
1
|
+
import { Text } from "../Text";
|
|
2
|
+
|
|
3
|
+
export type FormLabelProps = {
|
|
4
|
+
name: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
haveError?: boolean;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const FormLabel = ({
|
|
11
|
+
name,
|
|
12
|
+
label,
|
|
13
|
+
haveError,
|
|
14
|
+
required,
|
|
15
|
+
}: FormLabelProps) => {
|
|
16
|
+
if (!label) return null;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Text
|
|
20
|
+
typography={"labelMedium"}
|
|
21
|
+
fontWeight={"medium"}
|
|
22
|
+
color={haveError ? "error600" : "dark700"}
|
|
23
|
+
id={`${name}-label`}
|
|
24
|
+
>
|
|
25
|
+
{label}
|
|
26
|
+
{!required && <Text color="dark500"> (opcional)</Text>}
|
|
27
|
+
</Text>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { useController, useFormContext } from "react-hook-form";
|
|
2
|
-
import { Flex } from "../Flex";
|
|
3
|
-
import { FormLabel } from "./FormLabel";
|
|
4
|
-
import { ErrorFormMessage } from "./ErrorFormMessage";
|
|
5
|
-
import { MultiSelect, MultiSelectProps } from "../MultiSelect";
|
|
6
|
-
|
|
7
|
-
export type MultiSelectFormFieldProps = MultiSelectProps & {
|
|
8
|
-
name: string;
|
|
9
|
-
label?: string;
|
|
10
|
-
required?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const MultiSelectFormField = ({
|
|
14
|
-
name,
|
|
15
|
-
label,
|
|
16
|
-
required,
|
|
17
|
-
...rest
|
|
18
|
-
}: MultiSelectFormFieldProps) => {
|
|
19
|
-
const {
|
|
20
|
-
formState: { errors },
|
|
21
|
-
} = useFormContext();
|
|
22
|
-
|
|
23
|
-
const { field } = useController({
|
|
24
|
-
name,
|
|
25
|
-
rules: {
|
|
26
|
-
required
|
|
27
|
-
},
|
|
28
|
-
defaultValue: [],
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const { value, onChange, ref, onBlur, disabled } = field;
|
|
32
|
-
|
|
33
|
-
const haveError = !!errors[name];
|
|
34
|
-
|
|
35
|
-
const errorMsg = errors[name]?.message;
|
|
36
|
-
|
|
37
|
-
const handleChange = (v: any) => {
|
|
38
|
-
onChange(v);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<Flex direction={"column"}>
|
|
43
|
-
<FormLabel
|
|
44
|
-
name={name}
|
|
45
|
-
label={label}
|
|
46
|
-
required={required}
|
|
47
|
-
haveError={haveError}
|
|
48
|
-
/>
|
|
49
|
-
<MultiSelect
|
|
50
|
-
value={value}
|
|
51
|
-
onValueChange={handleChange}
|
|
52
|
-
ref={ref}
|
|
53
|
-
color={haveError ? "error" : "default"}
|
|
54
|
-
{...rest}
|
|
55
|
-
/>
|
|
56
|
-
<ErrorFormMessage message={errorMsg} />
|
|
57
|
-
</Flex>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
1
|
+
import { useController, useFormContext } from "react-hook-form";
|
|
2
|
+
import { Flex } from "../Flex";
|
|
3
|
+
import { FormLabel } from "./FormLabel";
|
|
4
|
+
import { ErrorFormMessage } from "./ErrorFormMessage";
|
|
5
|
+
import { MultiSelect, MultiSelectProps } from "../MultiSelect";
|
|
6
|
+
|
|
7
|
+
export type MultiSelectFormFieldProps = MultiSelectProps & {
|
|
8
|
+
name: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const MultiSelectFormField = ({
|
|
14
|
+
name,
|
|
15
|
+
label,
|
|
16
|
+
required,
|
|
17
|
+
...rest
|
|
18
|
+
}: MultiSelectFormFieldProps) => {
|
|
19
|
+
const {
|
|
20
|
+
formState: { errors },
|
|
21
|
+
} = useFormContext();
|
|
22
|
+
|
|
23
|
+
const { field } = useController({
|
|
24
|
+
name,
|
|
25
|
+
rules: {
|
|
26
|
+
required
|
|
27
|
+
},
|
|
28
|
+
defaultValue: [],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const { value, onChange, ref, onBlur, disabled } = field;
|
|
32
|
+
|
|
33
|
+
const haveError = !!errors[name];
|
|
34
|
+
|
|
35
|
+
const errorMsg = errors[name]?.message;
|
|
36
|
+
|
|
37
|
+
const handleChange = (v: any) => {
|
|
38
|
+
onChange(v);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Flex direction={"column"}>
|
|
43
|
+
<FormLabel
|
|
44
|
+
name={name}
|
|
45
|
+
label={label}
|
|
46
|
+
required={required}
|
|
47
|
+
haveError={haveError}
|
|
48
|
+
/>
|
|
49
|
+
<MultiSelect
|
|
50
|
+
value={value}
|
|
51
|
+
onValueChange={handleChange}
|
|
52
|
+
ref={ref}
|
|
53
|
+
color={haveError ? "error" : "default"}
|
|
54
|
+
{...rest}
|
|
55
|
+
/>
|
|
56
|
+
<ErrorFormMessage message={errorMsg} />
|
|
57
|
+
</Flex>
|
|
58
|
+
);
|
|
59
|
+
};
|