@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
|
@@ -1,298 +1,298 @@
|
|
|
1
|
-
import React, { useCallback, useRef, useState } from "react";
|
|
2
|
-
import { Box } from "./Box";
|
|
3
|
-
import { Button } from "./Button";
|
|
4
|
-
import { TextField, TextFieldSlot } from "./TextField";
|
|
5
|
-
import { Text } from "./Text";
|
|
6
|
-
import Icon from "./Icon";
|
|
7
|
-
import { styled } from "../styles";
|
|
8
|
-
import { useOnClickOutside } from "../hooks/useOnClickOutside";
|
|
9
|
-
|
|
10
|
-
export const TimePickerStyled = styled("div", {
|
|
11
|
-
position: "relative",
|
|
12
|
-
fontFamily: "$default",
|
|
13
|
-
lineHeight: "$base",
|
|
14
|
-
fontSize: "$14",
|
|
15
|
-
maxWidth: "200px",
|
|
16
|
-
borderRadius: "$sm",
|
|
17
|
-
"> div > div": {
|
|
18
|
-
paddingLeft: "1rem",
|
|
19
|
-
input: {
|
|
20
|
-
textAlign: "right",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const TimePickerDropdownStyled = styled("div", {
|
|
26
|
-
position: "absolute",
|
|
27
|
-
left: 0,
|
|
28
|
-
zIndex: 10,
|
|
29
|
-
width: "100%",
|
|
30
|
-
maxWidth: "8.875rem",
|
|
31
|
-
backgroundColor: "$neutral50",
|
|
32
|
-
border: "1px solid $neutral300",
|
|
33
|
-
borderRadius: "$sm",
|
|
34
|
-
boxShadow: "0px 2px 8px 0px $shadow50",
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const TimePickerFooterStyled = styled("div", {
|
|
38
|
-
borderTop: "2px solid $neutral100",
|
|
39
|
-
padding: "$4 $16",
|
|
40
|
-
display: "flex",
|
|
41
|
-
justifyContent: "center",
|
|
42
|
-
alignItems: "center",
|
|
43
|
-
height: "3rem",
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export const TimerPickerContentStyled = styled("div", {
|
|
47
|
-
display: "flex",
|
|
48
|
-
gap: "$16",
|
|
49
|
-
alignItems: "center",
|
|
50
|
-
padding: "$16 $16 $8 ",
|
|
51
|
-
"& > div:nth-child(2)": {
|
|
52
|
-
order: 2,
|
|
53
|
-
},
|
|
54
|
-
input: {
|
|
55
|
-
padding: "0",
|
|
56
|
-
textAlign: "center!important",
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
export const InputStyled = styled("input", {
|
|
61
|
-
height: "$40",
|
|
62
|
-
fontFamily: "$default",
|
|
63
|
-
borderRadius: "$sm",
|
|
64
|
-
boxSizing: "border-box",
|
|
65
|
-
color: "$dark500",
|
|
66
|
-
border: "1px solid $dark300",
|
|
67
|
-
position: "relative",
|
|
68
|
-
display: "flex",
|
|
69
|
-
width: "100%",
|
|
70
|
-
alignItems: "center",
|
|
71
|
-
padding: "0",
|
|
72
|
-
outline: "none",
|
|
73
|
-
margin: 0,
|
|
74
|
-
textAlign: "center",
|
|
75
|
-
"&:has(input:focus)": {
|
|
76
|
-
border: "2px solid $brand300",
|
|
77
|
-
},
|
|
78
|
-
"&:has(input:disabled)": {
|
|
79
|
-
backgroundColor: "$dark100",
|
|
80
|
-
color: "$dark400",
|
|
81
|
-
border: "1px solid $dark200",
|
|
82
|
-
cursor: "not-allowed",
|
|
83
|
-
},
|
|
84
|
-
inputMode: "numeric",
|
|
85
|
-
"&::-webkit-inner-spin-button": {
|
|
86
|
-
WebkitAppearance: "none",
|
|
87
|
-
margin: 0,
|
|
88
|
-
},
|
|
89
|
-
"&::-webkit-outer-spin-button": {
|
|
90
|
-
WebkitAppearance: "none",
|
|
91
|
-
margin: 0,
|
|
92
|
-
},
|
|
93
|
-
"&[type='number']": {
|
|
94
|
-
MozAppearance: "textfield",
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
export const TimePickerButtonStyled = styled("button", {
|
|
99
|
-
backgroundColor: "transparent",
|
|
100
|
-
border: "none",
|
|
101
|
-
maxWidth: "200px",
|
|
102
|
-
padding: "0",
|
|
103
|
-
cursor: "pointer",
|
|
104
|
-
"> div > div": {
|
|
105
|
-
paddingLeft: "1rem",
|
|
106
|
-
input: {
|
|
107
|
-
textAlign: "right",
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
export type TimePickerProps = {
|
|
113
|
-
selected: string | undefined;
|
|
114
|
-
setSelected: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
115
|
-
position?: "bottom" | "top";
|
|
116
|
-
};
|
|
117
|
-
const pad = (num: number) => String(num).padStart(2, "0");
|
|
118
|
-
|
|
119
|
-
export function TimePicker({
|
|
120
|
-
selected,
|
|
121
|
-
setSelected,
|
|
122
|
-
position = "bottom",
|
|
123
|
-
}: TimePickerProps) {
|
|
124
|
-
const [hours, setHours] = useState("00");
|
|
125
|
-
const [minutes, setMinutes] = useState("00");
|
|
126
|
-
const [rawHours, setRawHours] = useState("00");
|
|
127
|
-
const [rawMinutes, setRawMinutes] = useState("00");
|
|
128
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
129
|
-
const dropdownRef = useRef(null);
|
|
130
|
-
|
|
131
|
-
useOnClickOutside(dropdownRef, () => setIsOpen(false));
|
|
132
|
-
|
|
133
|
-
const handleIncrement = useCallback(
|
|
134
|
-
(type: "hours" | "minutes") => {
|
|
135
|
-
if (type === "hours") {
|
|
136
|
-
const next = (parseInt(hours) + 1) % 24;
|
|
137
|
-
setHours(pad(next));
|
|
138
|
-
setRawHours(pad(next));
|
|
139
|
-
} else {
|
|
140
|
-
const next = (parseInt(minutes) + 1) % 60;
|
|
141
|
-
setMinutes(pad(next));
|
|
142
|
-
setRawMinutes(pad(next));
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
[hours, minutes]
|
|
146
|
-
);
|
|
147
|
-
const handleDecrement = useCallback(
|
|
148
|
-
(type: "hours" | "minutes") => {
|
|
149
|
-
if (type === "hours") {
|
|
150
|
-
const prev = (parseInt(hours) - 1 + 24) % 24;
|
|
151
|
-
setHours(pad(prev));
|
|
152
|
-
setRawHours(pad(prev));
|
|
153
|
-
} else {
|
|
154
|
-
const prev = (parseInt(minutes) - 1 + 60) % 60;
|
|
155
|
-
setMinutes(pad(prev));
|
|
156
|
-
setRawMinutes(pad(prev));
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
[hours, minutes]
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<TimePickerStyled ref={dropdownRef}>
|
|
164
|
-
<TimePickerButtonStyled
|
|
165
|
-
type="button"
|
|
166
|
-
onClick={() => setIsOpen((prev) => !prev)}
|
|
167
|
-
>
|
|
168
|
-
<TextField
|
|
169
|
-
value={selected}
|
|
170
|
-
readOnly
|
|
171
|
-
type="text"
|
|
172
|
-
placeholder="00:00"
|
|
173
|
-
typography="labelSmall"
|
|
174
|
-
fontWeight="regular"
|
|
175
|
-
>
|
|
176
|
-
<TextFieldSlot>
|
|
177
|
-
<Icon name="clock" size="xl" />
|
|
178
|
-
</TextFieldSlot>
|
|
179
|
-
</TextField>
|
|
180
|
-
</TimePickerButtonStyled>
|
|
181
|
-
|
|
182
|
-
{isOpen && (
|
|
183
|
-
<TimePickerDropdownStyled
|
|
184
|
-
style={position === "top" ? { bottom: "110%" } : { top: "110%" }}
|
|
185
|
-
>
|
|
186
|
-
<TimerPickerContentStyled>
|
|
187
|
-
{["hours", "minutes"].map((unit) => (
|
|
188
|
-
<Box
|
|
189
|
-
key={unit}
|
|
190
|
-
style={{
|
|
191
|
-
display: "flex",
|
|
192
|
-
alignItems: "center",
|
|
193
|
-
flexDirection: "column",
|
|
194
|
-
}}
|
|
195
|
-
>
|
|
196
|
-
<Button
|
|
197
|
-
type="button"
|
|
198
|
-
variant="text"
|
|
199
|
-
onClick={() => handleIncrement(unit as "hours" | "minutes")}
|
|
200
|
-
>
|
|
201
|
-
<svg
|
|
202
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
203
|
-
width="32"
|
|
204
|
-
height="32"
|
|
205
|
-
viewBox="0 0 32 32"
|
|
206
|
-
fill="none"
|
|
207
|
-
>
|
|
208
|
-
<path
|
|
209
|
-
d="M0 8C0 3.58172 3.58172 0 8 0H24C28.4183 0 32 3.58172 32 8V24C32 28.4183 28.4183 32 24 32H8C3.58172 32 0 28.4183 0 24V8Z"
|
|
210
|
-
fill="white"
|
|
211
|
-
/>
|
|
212
|
-
<path
|
|
213
|
-
d="M16.7063 12.2937C16.3157 11.9031 15.6813 11.9031 15.2907 12.2937L10.2907 17.2937C9.9001 17.6843 9.9001 18.3187 10.2907 18.7093C10.6813 19.1 11.3157 19.1 11.7063 18.7093L16.0001 14.4156L20.2938 18.7062C20.6845 19.0968 21.3188 19.0968 21.7095 18.7062C22.1001 18.3156 22.1001 17.6812 21.7095 17.2906L16.7095 12.2906L16.7063 12.2937Z"
|
|
214
|
-
fill="#808289"
|
|
215
|
-
/>
|
|
216
|
-
</svg>
|
|
217
|
-
</Button>
|
|
218
|
-
<InputStyled
|
|
219
|
-
inputMode="numeric"
|
|
220
|
-
pattern="[0-9]*"
|
|
221
|
-
type="text"
|
|
222
|
-
placeholder="00"
|
|
223
|
-
value={unit === "hours" ? rawHours : rawMinutes}
|
|
224
|
-
onChange={(e) => {
|
|
225
|
-
const rawValue = e.target.value.replace(/\D/g, "");
|
|
226
|
-
if (unit === "hours") {
|
|
227
|
-
setRawHours(rawValue);
|
|
228
|
-
} else {
|
|
229
|
-
setRawMinutes(rawValue);
|
|
230
|
-
}
|
|
231
|
-
}}
|
|
232
|
-
onBlur={() => {
|
|
233
|
-
let num = 0;
|
|
234
|
-
if (unit === "hours") {
|
|
235
|
-
num = Math.min(parseInt(rawHours || "0", 10), 23);
|
|
236
|
-
const padded = pad(num);
|
|
237
|
-
setHours(padded);
|
|
238
|
-
setRawHours(padded);
|
|
239
|
-
} else {
|
|
240
|
-
num = Math.min(parseInt(rawMinutes || "0", 10), 59);
|
|
241
|
-
const padded = pad(num);
|
|
242
|
-
setMinutes(padded);
|
|
243
|
-
setRawMinutes(padded);
|
|
244
|
-
}
|
|
245
|
-
}}
|
|
246
|
-
onPaste={(e) => {
|
|
247
|
-
const paste = e.clipboardData.getData("Text");
|
|
248
|
-
if (!/^\d{1,2}$/.test(paste)) {
|
|
249
|
-
e.preventDefault();
|
|
250
|
-
}
|
|
251
|
-
}}
|
|
252
|
-
/>
|
|
253
|
-
<Button
|
|
254
|
-
type="button"
|
|
255
|
-
variant="text"
|
|
256
|
-
onClick={() => handleDecrement(unit as "hours" | "minutes")}
|
|
257
|
-
>
|
|
258
|
-
<svg
|
|
259
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
260
|
-
width="32"
|
|
261
|
-
height="32"
|
|
262
|
-
viewBox="0 0 32 32"
|
|
263
|
-
fill="none"
|
|
264
|
-
>
|
|
265
|
-
<path
|
|
266
|
-
d="M0 8C0 3.58172 3.58172 0 8 0H24C28.4183 0 32 3.58172 32 8V24C32 28.4183 28.4183 32 24 32H8C3.58172 32 0 28.4183 0 24V8Z"
|
|
267
|
-
fill="white"
|
|
268
|
-
/>
|
|
269
|
-
<path
|
|
270
|
-
d="M15.2937 19.7063C15.6843 20.0969 16.3187 20.0969 16.7093 19.7063L21.7093 14.7063C22.0999 14.3157 22.0999 13.6813 21.7093 13.2907C21.3187 12.9 20.6843 12.9 20.2937 13.2907L15.9999 17.5844L11.7062 13.2938C11.3155 12.9032 10.6812 12.9032 10.2905 13.2938C9.8999 13.6844 9.8999 14.3188 10.2905 14.7094L15.2905 19.7094L15.2937 19.7063Z"
|
|
271
|
-
fill="#808289"
|
|
272
|
-
/>
|
|
273
|
-
</svg>
|
|
274
|
-
</Button>
|
|
275
|
-
</Box>
|
|
276
|
-
))}
|
|
277
|
-
<Text>:</Text>
|
|
278
|
-
</TimerPickerContentStyled>
|
|
279
|
-
<TimePickerFooterStyled>
|
|
280
|
-
<Button
|
|
281
|
-
type="button"
|
|
282
|
-
variant="text"
|
|
283
|
-
color="brand"
|
|
284
|
-
onClick={() => {
|
|
285
|
-
setSelected(`${hours}:${minutes}`);
|
|
286
|
-
setIsOpen(false);
|
|
287
|
-
}}
|
|
288
|
-
size={"medium"}
|
|
289
|
-
fontWeight="medium"
|
|
290
|
-
>
|
|
291
|
-
Aplicar
|
|
292
|
-
</Button>
|
|
293
|
-
</TimePickerFooterStyled>
|
|
294
|
-
</TimePickerDropdownStyled>
|
|
295
|
-
)}
|
|
296
|
-
</TimePickerStyled>
|
|
297
|
-
);
|
|
298
|
-
}
|
|
1
|
+
import React, { useCallback, useRef, useState } from "react";
|
|
2
|
+
import { Box } from "./Box";
|
|
3
|
+
import { Button } from "./Button";
|
|
4
|
+
import { TextField, TextFieldSlot } from "./TextField";
|
|
5
|
+
import { Text } from "./Text";
|
|
6
|
+
import Icon from "./Icon";
|
|
7
|
+
import { styled } from "../styles";
|
|
8
|
+
import { useOnClickOutside } from "../hooks/useOnClickOutside";
|
|
9
|
+
|
|
10
|
+
export const TimePickerStyled = styled("div", {
|
|
11
|
+
position: "relative",
|
|
12
|
+
fontFamily: "$default",
|
|
13
|
+
lineHeight: "$base",
|
|
14
|
+
fontSize: "$14",
|
|
15
|
+
maxWidth: "200px",
|
|
16
|
+
borderRadius: "$sm",
|
|
17
|
+
"> div > div": {
|
|
18
|
+
paddingLeft: "1rem",
|
|
19
|
+
input: {
|
|
20
|
+
textAlign: "right",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const TimePickerDropdownStyled = styled("div", {
|
|
26
|
+
position: "absolute",
|
|
27
|
+
left: 0,
|
|
28
|
+
zIndex: 10,
|
|
29
|
+
width: "100%",
|
|
30
|
+
maxWidth: "8.875rem",
|
|
31
|
+
backgroundColor: "$neutral50",
|
|
32
|
+
border: "1px solid $neutral300",
|
|
33
|
+
borderRadius: "$sm",
|
|
34
|
+
boxShadow: "0px 2px 8px 0px $shadow50",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const TimePickerFooterStyled = styled("div", {
|
|
38
|
+
borderTop: "2px solid $neutral100",
|
|
39
|
+
padding: "$4 $16",
|
|
40
|
+
display: "flex",
|
|
41
|
+
justifyContent: "center",
|
|
42
|
+
alignItems: "center",
|
|
43
|
+
height: "3rem",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const TimerPickerContentStyled = styled("div", {
|
|
47
|
+
display: "flex",
|
|
48
|
+
gap: "$16",
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
padding: "$16 $16 $8 ",
|
|
51
|
+
"& > div:nth-child(2)": {
|
|
52
|
+
order: 2,
|
|
53
|
+
},
|
|
54
|
+
input: {
|
|
55
|
+
padding: "0",
|
|
56
|
+
textAlign: "center!important",
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const InputStyled = styled("input", {
|
|
61
|
+
height: "$40",
|
|
62
|
+
fontFamily: "$default",
|
|
63
|
+
borderRadius: "$sm",
|
|
64
|
+
boxSizing: "border-box",
|
|
65
|
+
color: "$dark500",
|
|
66
|
+
border: "1px solid $dark300",
|
|
67
|
+
position: "relative",
|
|
68
|
+
display: "flex",
|
|
69
|
+
width: "100%",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
padding: "0",
|
|
72
|
+
outline: "none",
|
|
73
|
+
margin: 0,
|
|
74
|
+
textAlign: "center",
|
|
75
|
+
"&:has(input:focus)": {
|
|
76
|
+
border: "2px solid $brand300",
|
|
77
|
+
},
|
|
78
|
+
"&:has(input:disabled)": {
|
|
79
|
+
backgroundColor: "$dark100",
|
|
80
|
+
color: "$dark400",
|
|
81
|
+
border: "1px solid $dark200",
|
|
82
|
+
cursor: "not-allowed",
|
|
83
|
+
},
|
|
84
|
+
inputMode: "numeric",
|
|
85
|
+
"&::-webkit-inner-spin-button": {
|
|
86
|
+
WebkitAppearance: "none",
|
|
87
|
+
margin: 0,
|
|
88
|
+
},
|
|
89
|
+
"&::-webkit-outer-spin-button": {
|
|
90
|
+
WebkitAppearance: "none",
|
|
91
|
+
margin: 0,
|
|
92
|
+
},
|
|
93
|
+
"&[type='number']": {
|
|
94
|
+
MozAppearance: "textfield",
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const TimePickerButtonStyled = styled("button", {
|
|
99
|
+
backgroundColor: "transparent",
|
|
100
|
+
border: "none",
|
|
101
|
+
maxWidth: "200px",
|
|
102
|
+
padding: "0",
|
|
103
|
+
cursor: "pointer",
|
|
104
|
+
"> div > div": {
|
|
105
|
+
paddingLeft: "1rem",
|
|
106
|
+
input: {
|
|
107
|
+
textAlign: "right",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
export type TimePickerProps = {
|
|
113
|
+
selected: string | undefined;
|
|
114
|
+
setSelected: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
115
|
+
position?: "bottom" | "top";
|
|
116
|
+
};
|
|
117
|
+
const pad = (num: number) => String(num).padStart(2, "0");
|
|
118
|
+
|
|
119
|
+
export function TimePicker({
|
|
120
|
+
selected,
|
|
121
|
+
setSelected,
|
|
122
|
+
position = "bottom",
|
|
123
|
+
}: TimePickerProps) {
|
|
124
|
+
const [hours, setHours] = useState("00");
|
|
125
|
+
const [minutes, setMinutes] = useState("00");
|
|
126
|
+
const [rawHours, setRawHours] = useState("00");
|
|
127
|
+
const [rawMinutes, setRawMinutes] = useState("00");
|
|
128
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
129
|
+
const dropdownRef = useRef(null);
|
|
130
|
+
|
|
131
|
+
useOnClickOutside(dropdownRef, () => setIsOpen(false));
|
|
132
|
+
|
|
133
|
+
const handleIncrement = useCallback(
|
|
134
|
+
(type: "hours" | "minutes") => {
|
|
135
|
+
if (type === "hours") {
|
|
136
|
+
const next = (parseInt(hours) + 1) % 24;
|
|
137
|
+
setHours(pad(next));
|
|
138
|
+
setRawHours(pad(next));
|
|
139
|
+
} else {
|
|
140
|
+
const next = (parseInt(minutes) + 1) % 60;
|
|
141
|
+
setMinutes(pad(next));
|
|
142
|
+
setRawMinutes(pad(next));
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
[hours, minutes]
|
|
146
|
+
);
|
|
147
|
+
const handleDecrement = useCallback(
|
|
148
|
+
(type: "hours" | "minutes") => {
|
|
149
|
+
if (type === "hours") {
|
|
150
|
+
const prev = (parseInt(hours) - 1 + 24) % 24;
|
|
151
|
+
setHours(pad(prev));
|
|
152
|
+
setRawHours(pad(prev));
|
|
153
|
+
} else {
|
|
154
|
+
const prev = (parseInt(minutes) - 1 + 60) % 60;
|
|
155
|
+
setMinutes(pad(prev));
|
|
156
|
+
setRawMinutes(pad(prev));
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[hours, minutes]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<TimePickerStyled ref={dropdownRef}>
|
|
164
|
+
<TimePickerButtonStyled
|
|
165
|
+
type="button"
|
|
166
|
+
onClick={() => setIsOpen((prev) => !prev)}
|
|
167
|
+
>
|
|
168
|
+
<TextField
|
|
169
|
+
value={selected}
|
|
170
|
+
readOnly
|
|
171
|
+
type="text"
|
|
172
|
+
placeholder="00:00"
|
|
173
|
+
typography="labelSmall"
|
|
174
|
+
fontWeight="regular"
|
|
175
|
+
>
|
|
176
|
+
<TextFieldSlot>
|
|
177
|
+
<Icon name="clock" size="xl" />
|
|
178
|
+
</TextFieldSlot>
|
|
179
|
+
</TextField>
|
|
180
|
+
</TimePickerButtonStyled>
|
|
181
|
+
|
|
182
|
+
{isOpen && (
|
|
183
|
+
<TimePickerDropdownStyled
|
|
184
|
+
style={position === "top" ? { bottom: "110%" } : { top: "110%" }}
|
|
185
|
+
>
|
|
186
|
+
<TimerPickerContentStyled>
|
|
187
|
+
{["hours", "minutes"].map((unit) => (
|
|
188
|
+
<Box
|
|
189
|
+
key={unit}
|
|
190
|
+
style={{
|
|
191
|
+
display: "flex",
|
|
192
|
+
alignItems: "center",
|
|
193
|
+
flexDirection: "column",
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
<Button
|
|
197
|
+
type="button"
|
|
198
|
+
variant="text"
|
|
199
|
+
onClick={() => handleIncrement(unit as "hours" | "minutes")}
|
|
200
|
+
>
|
|
201
|
+
<svg
|
|
202
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
203
|
+
width="32"
|
|
204
|
+
height="32"
|
|
205
|
+
viewBox="0 0 32 32"
|
|
206
|
+
fill="none"
|
|
207
|
+
>
|
|
208
|
+
<path
|
|
209
|
+
d="M0 8C0 3.58172 3.58172 0 8 0H24C28.4183 0 32 3.58172 32 8V24C32 28.4183 28.4183 32 24 32H8C3.58172 32 0 28.4183 0 24V8Z"
|
|
210
|
+
fill="white"
|
|
211
|
+
/>
|
|
212
|
+
<path
|
|
213
|
+
d="M16.7063 12.2937C16.3157 11.9031 15.6813 11.9031 15.2907 12.2937L10.2907 17.2937C9.9001 17.6843 9.9001 18.3187 10.2907 18.7093C10.6813 19.1 11.3157 19.1 11.7063 18.7093L16.0001 14.4156L20.2938 18.7062C20.6845 19.0968 21.3188 19.0968 21.7095 18.7062C22.1001 18.3156 22.1001 17.6812 21.7095 17.2906L16.7095 12.2906L16.7063 12.2937Z"
|
|
214
|
+
fill="#808289"
|
|
215
|
+
/>
|
|
216
|
+
</svg>
|
|
217
|
+
</Button>
|
|
218
|
+
<InputStyled
|
|
219
|
+
inputMode="numeric"
|
|
220
|
+
pattern="[0-9]*"
|
|
221
|
+
type="text"
|
|
222
|
+
placeholder="00"
|
|
223
|
+
value={unit === "hours" ? rawHours : rawMinutes}
|
|
224
|
+
onChange={(e) => {
|
|
225
|
+
const rawValue = e.target.value.replace(/\D/g, "");
|
|
226
|
+
if (unit === "hours") {
|
|
227
|
+
setRawHours(rawValue);
|
|
228
|
+
} else {
|
|
229
|
+
setRawMinutes(rawValue);
|
|
230
|
+
}
|
|
231
|
+
}}
|
|
232
|
+
onBlur={() => {
|
|
233
|
+
let num = 0;
|
|
234
|
+
if (unit === "hours") {
|
|
235
|
+
num = Math.min(parseInt(rawHours || "0", 10), 23);
|
|
236
|
+
const padded = pad(num);
|
|
237
|
+
setHours(padded);
|
|
238
|
+
setRawHours(padded);
|
|
239
|
+
} else {
|
|
240
|
+
num = Math.min(parseInt(rawMinutes || "0", 10), 59);
|
|
241
|
+
const padded = pad(num);
|
|
242
|
+
setMinutes(padded);
|
|
243
|
+
setRawMinutes(padded);
|
|
244
|
+
}
|
|
245
|
+
}}
|
|
246
|
+
onPaste={(e) => {
|
|
247
|
+
const paste = e.clipboardData.getData("Text");
|
|
248
|
+
if (!/^\d{1,2}$/.test(paste)) {
|
|
249
|
+
e.preventDefault();
|
|
250
|
+
}
|
|
251
|
+
}}
|
|
252
|
+
/>
|
|
253
|
+
<Button
|
|
254
|
+
type="button"
|
|
255
|
+
variant="text"
|
|
256
|
+
onClick={() => handleDecrement(unit as "hours" | "minutes")}
|
|
257
|
+
>
|
|
258
|
+
<svg
|
|
259
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
260
|
+
width="32"
|
|
261
|
+
height="32"
|
|
262
|
+
viewBox="0 0 32 32"
|
|
263
|
+
fill="none"
|
|
264
|
+
>
|
|
265
|
+
<path
|
|
266
|
+
d="M0 8C0 3.58172 3.58172 0 8 0H24C28.4183 0 32 3.58172 32 8V24C32 28.4183 28.4183 32 24 32H8C3.58172 32 0 28.4183 0 24V8Z"
|
|
267
|
+
fill="white"
|
|
268
|
+
/>
|
|
269
|
+
<path
|
|
270
|
+
d="M15.2937 19.7063C15.6843 20.0969 16.3187 20.0969 16.7093 19.7063L21.7093 14.7063C22.0999 14.3157 22.0999 13.6813 21.7093 13.2907C21.3187 12.9 20.6843 12.9 20.2937 13.2907L15.9999 17.5844L11.7062 13.2938C11.3155 12.9032 10.6812 12.9032 10.2905 13.2938C9.8999 13.6844 9.8999 14.3188 10.2905 14.7094L15.2905 19.7094L15.2937 19.7063Z"
|
|
271
|
+
fill="#808289"
|
|
272
|
+
/>
|
|
273
|
+
</svg>
|
|
274
|
+
</Button>
|
|
275
|
+
</Box>
|
|
276
|
+
))}
|
|
277
|
+
<Text>:</Text>
|
|
278
|
+
</TimerPickerContentStyled>
|
|
279
|
+
<TimePickerFooterStyled>
|
|
280
|
+
<Button
|
|
281
|
+
type="button"
|
|
282
|
+
variant="text"
|
|
283
|
+
color="brand"
|
|
284
|
+
onClick={() => {
|
|
285
|
+
setSelected(`${hours}:${minutes}`);
|
|
286
|
+
setIsOpen(false);
|
|
287
|
+
}}
|
|
288
|
+
size={"medium"}
|
|
289
|
+
fontWeight="medium"
|
|
290
|
+
>
|
|
291
|
+
Aplicar
|
|
292
|
+
</Button>
|
|
293
|
+
</TimePickerFooterStyled>
|
|
294
|
+
</TimePickerDropdownStyled>
|
|
295
|
+
)}
|
|
296
|
+
</TimePickerStyled>
|
|
297
|
+
);
|
|
298
|
+
}
|