@lets-events/react 11.7.10 → 11.8.0
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 +3 -3
- package/dist/index.css +171 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +104 -76
- package/dist/index.mjs +110 -82
- 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 +176 -176
- package/src/components/Container.tsx +39 -39
- package/src/components/Drawer/index.tsx +55 -55
- package/src/components/Drawer/styledComponents.ts +46 -46
- package/src/components/Dropdown.tsx +302 -302
- package/src/components/Filter.tsx +164 -164
- package/src/components/Flex.tsx +118 -118
- package/src/components/FormFields/AddressFormFields/CityFormField.tsx +111 -111
- package/src/components/FormFields/AddressFormFields/CountryFormField.tsx +33 -33
- package/src/components/FormFields/AddressFormFields/PostalCodeFormField.tsx +39 -39
- package/src/components/FormFields/AddressFormFields/StateFormField.tsx +32 -32
- package/src/components/FormFields/AddressFormFields/index.tsx +141 -141
- package/src/components/FormFields/BirthDateFormField.tsx +84 -84
- package/src/components/FormFields/CNPJFormField.tsx +87 -87
- package/src/components/FormFields/CPFFormField.tsx +78 -78
- package/src/components/FormFields/CheckboxGroupFormField.tsx +91 -91
- package/src/components/FormFields/EmailFormField.tsx +27 -27
- package/src/components/FormFields/Form.tsx +39 -39
- package/src/components/FormFields/IdentityDocumentNumberFormField.tsx +40 -40
- package/src/components/FormFields/MultiSelectFormField.tsx +55 -55
- package/src/components/FormFields/PhoneFormField.tsx +40 -40
- package/src/components/FormFields/RadioGroupFormField.tsx +84 -84
- package/src/components/FormFields/SelectFormField.tsx +93 -93
- package/src/components/FormFields/TextAreaFormField.tsx +48 -48
- package/src/components/FormFields/TextFormField.tsx +112 -112
- package/src/components/FormFields/subComponents/ErrorFormMessage.tsx +36 -36
- package/src/components/FormFields/subComponents/FormLabel.tsx +29 -29
- package/src/components/FormFields/utils/validation.ts +23 -23
- package/src/components/Grid.tsx +137 -137
- package/src/components/Icon.tsx +47 -47
- package/src/components/MenuDropdown/index.tsx +38 -38
- package/src/components/MenuDropdown/styledComponents.ts +31 -31
- package/src/components/Modal.tsx +90 -90
- package/src/components/MultiSelect.tsx +252 -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 +365 -365
- 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/useCountries.ts +41 -41
- package/src/hooks/useOnClickOutside.tsx +20 -20
- package/src/index.tsx +54 -54
- package/src/styles/index.ts +38 -38
- package/src/types/typographyValues.ts +178 -178
- package/src/utils/getNestedValue.ts +3 -3
- package/src/utils/states.ts +29 -29
- package/tsconfig.json +3 -3
package/src/components/Modal.tsx
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import { ComponentProps } from "react";
|
|
2
|
-
import { styled } from "../styles";
|
|
3
|
-
import { Dialog as ModalRadix } from "radix-ui";
|
|
4
|
-
import Icon from "./Icon";
|
|
5
|
-
import { Box } from "./Box";
|
|
6
|
-
import { Text } from "./Text";
|
|
7
|
-
|
|
8
|
-
const ModalContentStyled = styled(ModalRadix.Content, {
|
|
9
|
-
fontFamily: "$default",
|
|
10
|
-
lineHeight: "$base",
|
|
11
|
-
fontSize: "$13",
|
|
12
|
-
maxWidth: "502px",
|
|
13
|
-
width: "100%",
|
|
14
|
-
border: "1px solid $neutral",
|
|
15
|
-
borderRadius: "$2xl",
|
|
16
|
-
boxShadow:
|
|
17
|
-
"0px 4px 4px 0px rgba(35, 53, 67, 0.08), 0px 2px 4px 0px rgba(35, 53, 67, 0.16)",
|
|
18
|
-
position: "fixed",
|
|
19
|
-
top: "50%",
|
|
20
|
-
left: "50%",
|
|
21
|
-
transform: "translate(-50%, -50%)",
|
|
22
|
-
backgroundColor: "$dark50",
|
|
23
|
-
zIndex: '10001'
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const ModalOverlay = styled(ModalRadix.Overlay, {
|
|
27
|
-
position: "fixed",
|
|
28
|
-
inset: 0,
|
|
29
|
-
opacity: 1,
|
|
30
|
-
backgroundColor: "rgba(0, 0, 0, .5)",
|
|
31
|
-
zIndex: '10000'
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const ModalHeaderStyled = styled("div", {
|
|
35
|
-
borderBottom: "1px solid $neutral300",
|
|
36
|
-
padding: "$18 $24",
|
|
37
|
-
textAlign: "center",
|
|
38
|
-
position: "relative",
|
|
39
|
-
display: "flex",
|
|
40
|
-
alignItems: "center",
|
|
41
|
-
justifyContent: "center",
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const ModalIconClose = styled(Icon, {
|
|
45
|
-
position: "absolute",
|
|
46
|
-
right: "$24",
|
|
47
|
-
cursor: "pointer",
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const ModalTitleStyled = styled(ModalRadix.Title, {
|
|
51
|
-
fontFamily: "$default",
|
|
52
|
-
lineHeight: "$base",
|
|
53
|
-
fontSize: "$18",
|
|
54
|
-
fontWeight: "medium",
|
|
55
|
-
fontStyle: "normal",
|
|
56
|
-
textTransform: "uppercase",
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
export type ModalProps = ComponentProps<typeof ModalRadix.Root> & {
|
|
60
|
-
trigger?: React.ReactNode;
|
|
61
|
-
title?: string;
|
|
62
|
-
children: React.ReactNode;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export function Modal({ children, title, trigger, ...props }: ModalProps) {
|
|
66
|
-
return (
|
|
67
|
-
<ModalRadix.Root {...props}>
|
|
68
|
-
{trigger && <ModalRadix.Trigger asChild>{trigger}</ModalRadix.Trigger>}
|
|
69
|
-
<ModalRadix.Portal>
|
|
70
|
-
<ModalOverlay>
|
|
71
|
-
<ModalContentStyled>
|
|
72
|
-
{title && (
|
|
73
|
-
<ModalHeaderStyled>
|
|
74
|
-
<ModalTitleStyled asChild>
|
|
75
|
-
<Text typography={"headline6"} fontWeight={"medium"}>
|
|
76
|
-
{title}
|
|
77
|
-
</Text>
|
|
78
|
-
</ModalTitleStyled>
|
|
79
|
-
<ModalRadix.Close asChild>
|
|
80
|
-
<ModalIconClose name="close" size="xl" />
|
|
81
|
-
</ModalRadix.Close>
|
|
82
|
-
</ModalHeaderStyled>
|
|
83
|
-
)}
|
|
84
|
-
<Box>{children}</Box>
|
|
85
|
-
</ModalContentStyled>
|
|
86
|
-
</ModalOverlay>
|
|
87
|
-
</ModalRadix.Portal>
|
|
88
|
-
</ModalRadix.Root>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
import { styled } from "../styles";
|
|
3
|
+
import { Dialog as ModalRadix } from "radix-ui";
|
|
4
|
+
import Icon from "./Icon";
|
|
5
|
+
import { Box } from "./Box";
|
|
6
|
+
import { Text } from "./Text";
|
|
7
|
+
|
|
8
|
+
const ModalContentStyled = styled(ModalRadix.Content, {
|
|
9
|
+
fontFamily: "$default",
|
|
10
|
+
lineHeight: "$base",
|
|
11
|
+
fontSize: "$13",
|
|
12
|
+
maxWidth: "502px",
|
|
13
|
+
width: "100%",
|
|
14
|
+
border: "1px solid $neutral",
|
|
15
|
+
borderRadius: "$2xl",
|
|
16
|
+
boxShadow:
|
|
17
|
+
"0px 4px 4px 0px rgba(35, 53, 67, 0.08), 0px 2px 4px 0px rgba(35, 53, 67, 0.16)",
|
|
18
|
+
position: "fixed",
|
|
19
|
+
top: "50%",
|
|
20
|
+
left: "50%",
|
|
21
|
+
transform: "translate(-50%, -50%)",
|
|
22
|
+
backgroundColor: "$dark50",
|
|
23
|
+
zIndex: '10001'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const ModalOverlay = styled(ModalRadix.Overlay, {
|
|
27
|
+
position: "fixed",
|
|
28
|
+
inset: 0,
|
|
29
|
+
opacity: 1,
|
|
30
|
+
backgroundColor: "rgba(0, 0, 0, .5)",
|
|
31
|
+
zIndex: '10000'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const ModalHeaderStyled = styled("div", {
|
|
35
|
+
borderBottom: "1px solid $neutral300",
|
|
36
|
+
padding: "$18 $24",
|
|
37
|
+
textAlign: "center",
|
|
38
|
+
position: "relative",
|
|
39
|
+
display: "flex",
|
|
40
|
+
alignItems: "center",
|
|
41
|
+
justifyContent: "center",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const ModalIconClose = styled(Icon, {
|
|
45
|
+
position: "absolute",
|
|
46
|
+
right: "$24",
|
|
47
|
+
cursor: "pointer",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const ModalTitleStyled = styled(ModalRadix.Title, {
|
|
51
|
+
fontFamily: "$default",
|
|
52
|
+
lineHeight: "$base",
|
|
53
|
+
fontSize: "$18",
|
|
54
|
+
fontWeight: "medium",
|
|
55
|
+
fontStyle: "normal",
|
|
56
|
+
textTransform: "uppercase",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type ModalProps = ComponentProps<typeof ModalRadix.Root> & {
|
|
60
|
+
trigger?: React.ReactNode;
|
|
61
|
+
title?: string;
|
|
62
|
+
children: React.ReactNode;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export function Modal({ children, title, trigger, ...props }: ModalProps) {
|
|
66
|
+
return (
|
|
67
|
+
<ModalRadix.Root {...props}>
|
|
68
|
+
{trigger && <ModalRadix.Trigger asChild>{trigger}</ModalRadix.Trigger>}
|
|
69
|
+
<ModalRadix.Portal>
|
|
70
|
+
<ModalOverlay>
|
|
71
|
+
<ModalContentStyled>
|
|
72
|
+
{title && (
|
|
73
|
+
<ModalHeaderStyled>
|
|
74
|
+
<ModalTitleStyled asChild>
|
|
75
|
+
<Text typography={"headline6"} fontWeight={"medium"}>
|
|
76
|
+
{title}
|
|
77
|
+
</Text>
|
|
78
|
+
</ModalTitleStyled>
|
|
79
|
+
<ModalRadix.Close asChild>
|
|
80
|
+
<ModalIconClose name="close" size="xl" />
|
|
81
|
+
</ModalRadix.Close>
|
|
82
|
+
</ModalHeaderStyled>
|
|
83
|
+
)}
|
|
84
|
+
<Box>{children}</Box>
|
|
85
|
+
</ModalContentStyled>
|
|
86
|
+
</ModalOverlay>
|
|
87
|
+
</ModalRadix.Portal>
|
|
88
|
+
</ModalRadix.Root>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -1,218 +1,252 @@
|
|
|
1
|
-
import { DropdownMenu, Theme } from "@radix-ui/themes";
|
|
2
|
-
import { Button } from "./Button";
|
|
3
|
-
import { CheckboxGroup, CheckboxItem } from "./CheckboxGroup";
|
|
4
|
-
import { styled, css } from "../styles";
|
|
5
|
-
import { Text } from "./Text";
|
|
6
|
-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
7
|
-
import {
|
|
8
|
-
faChevronDown,
|
|
9
|
-
faChevronUp,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
)
|
|
1
|
+
import { DropdownMenu, Theme } from "@radix-ui/themes";
|
|
2
|
+
import { Button } from "./Button";
|
|
3
|
+
import { CheckboxGroup, CheckboxItem } from "./CheckboxGroup";
|
|
4
|
+
import { styled, css } from "../styles";
|
|
5
|
+
import { Text } from "./Text";
|
|
6
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
7
|
+
import {
|
|
8
|
+
faChevronDown,
|
|
9
|
+
faChevronUp,
|
|
10
|
+
faSquareXmark,
|
|
11
|
+
faX,
|
|
12
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
13
|
+
import { colors } from "@lets-events/tokens";
|
|
14
|
+
import { ComponentProps, useCallback, useMemo, useRef, useState } from "react";
|
|
15
|
+
import { Flex } from "./Flex";
|
|
16
|
+
import { CSS } from "@stitches/react";
|
|
17
|
+
import React from "react";
|
|
18
|
+
import { Badge } from "./Badge";
|
|
19
|
+
|
|
20
|
+
const StyledContent = styled(DropdownMenu.Content, {
|
|
21
|
+
backgroundColor: "$dark50",
|
|
22
|
+
borderRadius: "$sm",
|
|
23
|
+
padding: "$8 0",
|
|
24
|
+
boxShadow: "0px 2px 4px 0px #23354329, 0px 4px 4px 0px #23354314",
|
|
25
|
+
boxSizing: "border-box",
|
|
26
|
+
border: "1px solid $dark300",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const StyledTrigger = styled("div", {
|
|
30
|
+
minHeight: "40px",
|
|
31
|
+
borderRadius: "$sm",
|
|
32
|
+
cursor: "pointer",
|
|
33
|
+
display: "flex",
|
|
34
|
+
justifyContent: "start",
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
padding: "$6 $14",
|
|
37
|
+
boxSizing: "border-box",
|
|
38
|
+
gap: "4px",
|
|
39
|
+
|
|
40
|
+
variants: {
|
|
41
|
+
color: {
|
|
42
|
+
default: {
|
|
43
|
+
border: "1px solid $dark300",
|
|
44
|
+
},
|
|
45
|
+
error: {
|
|
46
|
+
border: "1px solid $error400",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
defaultVariants: {
|
|
52
|
+
color: "default",
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const itemStyle: CSS = {
|
|
57
|
+
padding: "$4 $16",
|
|
58
|
+
minHeight: "$32",
|
|
59
|
+
boxSizing: "border-box",
|
|
60
|
+
backgroundColor: "$dark50",
|
|
61
|
+
display: "block",
|
|
62
|
+
cursor: "pointer",
|
|
63
|
+
|
|
64
|
+
"&:hover": {
|
|
65
|
+
backgroundColor: "$dark100",
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const StyledItem = styled("div", {
|
|
70
|
+
...itemStyle,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const BadgeWrapper = styled("div", {
|
|
74
|
+
flex: "1",
|
|
75
|
+
display: "flex",
|
|
76
|
+
gap: "4px",
|
|
77
|
+
marginTop: "8px",
|
|
78
|
+
flexDirection: "column",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const BadgeCloseBtn = styled("div", {
|
|
82
|
+
cursor: "pointer",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export type MultiSelectProps = ComponentProps<typeof StyledTrigger> & {
|
|
86
|
+
placeholder?: string;
|
|
87
|
+
value?: string[];
|
|
88
|
+
onValueChange?: (v: string[]) => void;
|
|
89
|
+
options: Array<{
|
|
90
|
+
label: string;
|
|
91
|
+
value: string;
|
|
92
|
+
}>;
|
|
93
|
+
width?: string;
|
|
94
|
+
zIndex?: string;
|
|
95
|
+
showSelectedValues?: boolean;
|
|
96
|
+
singleSelect?: boolean;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const MultiSelect = React.forwardRef<HTMLDivElement, MultiSelectProps>(
|
|
100
|
+
(
|
|
101
|
+
{
|
|
102
|
+
placeholder,
|
|
103
|
+
value: selectedValues = [],
|
|
104
|
+
onValueChange,
|
|
105
|
+
options,
|
|
106
|
+
color,
|
|
107
|
+
width = "100%",
|
|
108
|
+
zIndex = "auto",
|
|
109
|
+
showSelectedValues = true,
|
|
110
|
+
singleSelect = false,
|
|
111
|
+
},
|
|
112
|
+
fowardedRef
|
|
113
|
+
) => {
|
|
114
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
115
|
+
|
|
116
|
+
const triggerRef = useRef<HTMLDivElement>(null);
|
|
117
|
+
|
|
118
|
+
const labelByValue = useMemo(() => {
|
|
119
|
+
return options.reduce<{ [key: string]: string }>((prev, curr) => {
|
|
120
|
+
return {
|
|
121
|
+
...prev,
|
|
122
|
+
[curr.value]: curr.label,
|
|
123
|
+
};
|
|
124
|
+
}, {});
|
|
125
|
+
}, [options]);
|
|
126
|
+
|
|
127
|
+
const handleRemove = useCallback(
|
|
128
|
+
(value: string) => {
|
|
129
|
+
const newValue = selectedValues.filter((v) => v !== value);
|
|
130
|
+
onValueChange?.(newValue);
|
|
131
|
+
},
|
|
132
|
+
[selectedValues, onValueChange]
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const menuWidth = triggerRef.current?.offsetWidth;
|
|
136
|
+
|
|
137
|
+
const text = useMemo(() => {
|
|
138
|
+
if (selectedValues.length > 0 && singleSelect) {
|
|
139
|
+
const value = selectedValues[0];
|
|
140
|
+
return labelByValue[value];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return placeholder ?? "Selecione";
|
|
144
|
+
}, [selectedValues, placeholder, singleSelect]);
|
|
145
|
+
|
|
146
|
+
const handleItemClick = (v: string) => {
|
|
147
|
+
onValueChange?.([v]);
|
|
148
|
+
setIsOpen(false);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<Theme>
|
|
153
|
+
<DropdownMenu.Root open={isOpen} onOpenChange={() => setIsOpen(false)}>
|
|
154
|
+
<DropdownMenu.Trigger onClick={() => setIsOpen(true)}>
|
|
155
|
+
<StyledTrigger
|
|
156
|
+
css={{
|
|
157
|
+
width,
|
|
158
|
+
}}
|
|
159
|
+
ref={(r) => {
|
|
160
|
+
if (!r) return;
|
|
161
|
+
triggerRef.current = r;
|
|
162
|
+
if (fowardedRef) {
|
|
163
|
+
if (typeof fowardedRef === "function") fowardedRef(r);
|
|
164
|
+
else {
|
|
165
|
+
fowardedRef.current = r;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}}
|
|
169
|
+
color={color}
|
|
170
|
+
>
|
|
171
|
+
<Text
|
|
172
|
+
typography={"labelMedium"}
|
|
173
|
+
css={{
|
|
174
|
+
flex: 1,
|
|
175
|
+
overflow: "hidden",
|
|
176
|
+
whiteSpace: "nowrap",
|
|
177
|
+
textOverflow: "ellipsis",
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
{text}
|
|
181
|
+
</Text>
|
|
182
|
+
<FontAwesomeIcon
|
|
183
|
+
icon={isOpen ? faChevronUp : faChevronDown}
|
|
184
|
+
size="sm"
|
|
185
|
+
color={colors.dark600}
|
|
186
|
+
/>
|
|
187
|
+
</StyledTrigger>
|
|
188
|
+
</DropdownMenu.Trigger>
|
|
189
|
+
<StyledContent
|
|
190
|
+
css={{
|
|
191
|
+
width: menuWidth ? menuWidth + "px" : width,
|
|
192
|
+
zIndex,
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
{!singleSelect ? (
|
|
196
|
+
<CheckboxGroup
|
|
197
|
+
value={selectedValues}
|
|
198
|
+
onValueChange={(v) => {
|
|
199
|
+
onValueChange?.(v);
|
|
200
|
+
}}
|
|
201
|
+
>
|
|
202
|
+
<Flex direction={"column"} gap={8}>
|
|
203
|
+
{options.map(({ value, label }, i) => (
|
|
204
|
+
<CheckboxItem value={value} css={itemStyle} key={i}>
|
|
205
|
+
<Text typography={"labelSmall"}>{label}</Text>
|
|
206
|
+
</CheckboxItem>
|
|
207
|
+
))}
|
|
208
|
+
</Flex>
|
|
209
|
+
</CheckboxGroup>
|
|
210
|
+
) : (
|
|
211
|
+
<Flex direction={"column"} gap={8}>
|
|
212
|
+
{options.map(({ value, label }, i) => (
|
|
213
|
+
<StyledItem key={i} onClick={() => handleItemClick(value)}>
|
|
214
|
+
<Text typography={"labelSmall"}>{label}</Text>
|
|
215
|
+
</StyledItem>
|
|
216
|
+
))}
|
|
217
|
+
</Flex>
|
|
218
|
+
)}
|
|
219
|
+
</StyledContent>
|
|
220
|
+
</DropdownMenu.Root>
|
|
221
|
+
{selectedValues.length > 0 && showSelectedValues && (
|
|
222
|
+
<>
|
|
223
|
+
<BadgeWrapper>
|
|
224
|
+
{selectedValues.map((value) => {
|
|
225
|
+
return (
|
|
226
|
+
<Flex gap={4}>
|
|
227
|
+
<BadgeCloseBtn
|
|
228
|
+
onClick={(e) => {
|
|
229
|
+
e.stopPropagation();
|
|
230
|
+
handleRemove(value);
|
|
231
|
+
}}
|
|
232
|
+
role="button"
|
|
233
|
+
>
|
|
234
|
+
<FontAwesomeIcon icon={faSquareXmark} size="sm" />
|
|
235
|
+
</BadgeCloseBtn>
|
|
236
|
+
<Text
|
|
237
|
+
typography={"captionMedium"}
|
|
238
|
+
fontWeight={"regular"}
|
|
239
|
+
color="dark600"
|
|
240
|
+
>
|
|
241
|
+
{labelByValue[value]}
|
|
242
|
+
</Text>
|
|
243
|
+
</Flex>
|
|
244
|
+
);
|
|
245
|
+
})}
|
|
246
|
+
</BadgeWrapper>
|
|
247
|
+
</>
|
|
248
|
+
)}
|
|
249
|
+
</Theme>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
);
|