@lets-events/react 12.2.6 → 12.2.7
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 +19 -21
- package/CHANGELOG.md +6 -0
- package/dist/index.css +171 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- 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 +300 -300
- package/src/components/ButtonGroup.tsx +484 -484
- package/src/components/Calendar/index.tsx +146 -146
- package/src/components/Calendar/styledComponents.ts +250 -250
- 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 +138 -138
- package/src/components/Drawer/styledComponents.ts +52 -52
- 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/CalendarFormField.tsx +92 -92
- 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 +32 -32
- package/src/components/FormFields/MultiSelectFormField.tsx +64 -64
- package/src/components/FormFields/PhoneFormField.tsx +40 -40
- package/src/components/FormFields/RadioGroupFormField.tsx +84 -84
- package/src/components/FormFields/RichEditorFormField.tsx +102 -102
- package/src/components/FormFields/SelectFormField.tsx +93 -93
- package/src/components/FormFields/SwitchFormField.tsx +46 -46
- package/src/components/FormFields/TextAreaFormField.tsx +57 -57
- package/src/components/FormFields/TextFormField.tsx +112 -112
- package/src/components/FormFields/TimePickerFormField.tsx +88 -88
- 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/index.tsx +243 -243
- package/src/components/MultiSelect/styledComponents.ts +160 -160
- package/src/components/RadioGroup.tsx +210 -210
- package/src/components/RichEditor/QuillComponent.tsx +458 -458
- package/src/components/RichEditor/RichEditor.tsx +49 -49
- package/src/components/RichEditor/index.ts +2 -2
- package/src/components/RichEditor/styledComponents.ts +1151 -1151
- 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 +372 -372
- package/src/components/TextareaField.tsx +127 -127
- package/src/components/TimePicker.tsx +328 -328
- 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/useImageUpload.ts +139 -139
- package/src/hooks/useOnClickOutside.tsx +42 -42
- package/src/index.tsx +68 -68
- 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/src/utils/uploadService.ts +180 -180
- package/tsconfig.json +3 -3
- package/tsup.config.ts +38 -38
|
@@ -1,328 +1,328 @@
|
|
|
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
|
-
width: "fit-content",
|
|
13
|
-
fontFamily: "$default",
|
|
14
|
-
lineHeight: "$base",
|
|
15
|
-
fontSize: "$14",
|
|
16
|
-
borderRadius: "$sm",
|
|
17
|
-
"> div > div": {
|
|
18
|
-
input: {
|
|
19
|
-
textAlign: "right",
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
variants: {
|
|
23
|
-
expand: {
|
|
24
|
-
true: {
|
|
25
|
-
width: "100%",
|
|
26
|
-
flex: "1",
|
|
27
|
-
display: "flex",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export const TimePickerDropdownStyled = styled("div", {
|
|
34
|
-
position: "absolute",
|
|
35
|
-
zIndex: 10,
|
|
36
|
-
width: "100%",
|
|
37
|
-
maxWidth: "min-content",
|
|
38
|
-
backgroundColor: "$neutral50",
|
|
39
|
-
border: "1px solid $neutral300",
|
|
40
|
-
borderRadius: "$sm",
|
|
41
|
-
boxShadow: "0px 2px 8px 0px $shadow50",
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
export const TimePickerFooterStyled = styled("div", {
|
|
45
|
-
borderTop: "2px solid $neutral100",
|
|
46
|
-
padding: "$4 $16",
|
|
47
|
-
display: "flex",
|
|
48
|
-
justifyContent: "center",
|
|
49
|
-
alignItems: "center",
|
|
50
|
-
height: "3rem",
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export const TimerPickerContentStyled = styled("div", {
|
|
54
|
-
display: "flex",
|
|
55
|
-
gap: "$16",
|
|
56
|
-
alignItems: "center",
|
|
57
|
-
padding: "$16 $16 $8 ",
|
|
58
|
-
"& > div:nth-child(2)": {
|
|
59
|
-
order: 2,
|
|
60
|
-
},
|
|
61
|
-
input: {
|
|
62
|
-
padding: "0",
|
|
63
|
-
textAlign: "center!important",
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
export const InputStyled = styled("input", {
|
|
68
|
-
height: "$40",
|
|
69
|
-
fontFamily: "$default",
|
|
70
|
-
borderRadius: "$sm",
|
|
71
|
-
boxSizing: "border-box",
|
|
72
|
-
color: "$dark500",
|
|
73
|
-
border: "1px solid $dark300",
|
|
74
|
-
position: "relative",
|
|
75
|
-
display: "flex",
|
|
76
|
-
width: "100%",
|
|
77
|
-
alignItems: "center",
|
|
78
|
-
padding: "0",
|
|
79
|
-
outline: "none",
|
|
80
|
-
margin: 0,
|
|
81
|
-
textAlign: "center",
|
|
82
|
-
"&:has(input:focus)": {
|
|
83
|
-
border: "2px solid $brand300",
|
|
84
|
-
},
|
|
85
|
-
"&:has(input:disabled)": {
|
|
86
|
-
backgroundColor: "$dark100",
|
|
87
|
-
color: "$dark400",
|
|
88
|
-
border: "1px solid $dark200",
|
|
89
|
-
cursor: "not-allowed",
|
|
90
|
-
},
|
|
91
|
-
inputMode: "numeric",
|
|
92
|
-
"&::-webkit-inner-spin-button": {
|
|
93
|
-
WebkitAppearance: "none",
|
|
94
|
-
margin: 0,
|
|
95
|
-
},
|
|
96
|
-
"&::-webkit-outer-spin-button": {
|
|
97
|
-
WebkitAppearance: "none",
|
|
98
|
-
margin: 0,
|
|
99
|
-
},
|
|
100
|
-
"&[type='number']": {
|
|
101
|
-
MozAppearance: "textfield",
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
export const TimePickerButtonStyled = styled("button", {
|
|
106
|
-
backgroundColor: "transparent",
|
|
107
|
-
border: "none",
|
|
108
|
-
padding: "0",
|
|
109
|
-
cursor: "pointer",
|
|
110
|
-
"> div > div": {
|
|
111
|
-
input: {
|
|
112
|
-
textAlign: "right",
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
variants: {
|
|
116
|
-
expand: {
|
|
117
|
-
true: {
|
|
118
|
-
flex: "1",
|
|
119
|
-
display: "flex",
|
|
120
|
-
maxWidth: "100%",
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
export const TimePickerIconButton = styled(Button, {
|
|
126
|
-
padding: "0 !important",
|
|
127
|
-
});
|
|
128
|
-
export type TimePickerProps = {
|
|
129
|
-
selected: string | undefined;
|
|
130
|
-
setSelected: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
131
|
-
position?: "bottom" | "top" | "top-right" | "bottom-right";
|
|
132
|
-
hasError?: boolean;
|
|
133
|
-
expand?: boolean;
|
|
134
|
-
};
|
|
135
|
-
const pad = (num: number) => String(num).padStart(2, "0");
|
|
136
|
-
|
|
137
|
-
export function TimePicker({
|
|
138
|
-
selected,
|
|
139
|
-
setSelected,
|
|
140
|
-
position = "bottom",
|
|
141
|
-
hasError,
|
|
142
|
-
expand = false,
|
|
143
|
-
}: TimePickerProps) {
|
|
144
|
-
const [hours, setHours] = useState("00");
|
|
145
|
-
const [minutes, setMinutes] = useState("00");
|
|
146
|
-
const [rawHours, setRawHours] = useState("00");
|
|
147
|
-
const [rawMinutes, setRawMinutes] = useState("00");
|
|
148
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
149
|
-
const dropdownRef = useRef(null);
|
|
150
|
-
|
|
151
|
-
useOnClickOutside(dropdownRef, () => setIsOpen(false));
|
|
152
|
-
|
|
153
|
-
const handleIncrement = useCallback(
|
|
154
|
-
(type: "hours" | "minutes") => {
|
|
155
|
-
if (type === "hours") {
|
|
156
|
-
const next = (parseInt(hours) + 1) % 24;
|
|
157
|
-
setHours(pad(next));
|
|
158
|
-
setRawHours(pad(next));
|
|
159
|
-
} else {
|
|
160
|
-
const next = (parseInt(minutes) + 1) % 60;
|
|
161
|
-
setMinutes(pad(next));
|
|
162
|
-
setRawMinutes(pad(next));
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
[hours, minutes]
|
|
166
|
-
);
|
|
167
|
-
const handleDecrement = useCallback(
|
|
168
|
-
(type: "hours" | "minutes") => {
|
|
169
|
-
if (type === "hours") {
|
|
170
|
-
const prev = (parseInt(hours) - 1 + 24) % 24;
|
|
171
|
-
setHours(pad(prev));
|
|
172
|
-
setRawHours(pad(prev));
|
|
173
|
-
} else {
|
|
174
|
-
const prev = (parseInt(minutes) - 1 + 60) % 60;
|
|
175
|
-
setMinutes(pad(prev));
|
|
176
|
-
setRawMinutes(pad(prev));
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
[hours, minutes]
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<TimePickerStyled ref={dropdownRef} expand={expand}>
|
|
184
|
-
<TimePickerButtonStyled
|
|
185
|
-
type="button"
|
|
186
|
-
onClick={() => setIsOpen((prev) => !prev)}
|
|
187
|
-
expand={expand}
|
|
188
|
-
>
|
|
189
|
-
<TextField
|
|
190
|
-
value={selected}
|
|
191
|
-
readOnly
|
|
192
|
-
type="text"
|
|
193
|
-
placeholder="00:00"
|
|
194
|
-
typography="labelSmall"
|
|
195
|
-
fontWeight="regular"
|
|
196
|
-
color={hasError ? "error" : "default"}
|
|
197
|
-
>
|
|
198
|
-
<TextFieldSlot>
|
|
199
|
-
<Icon name="clock" size="xl" />
|
|
200
|
-
</TextFieldSlot>
|
|
201
|
-
</TextField>
|
|
202
|
-
</TimePickerButtonStyled>
|
|
203
|
-
|
|
204
|
-
{isOpen && (
|
|
205
|
-
<TimePickerDropdownStyled
|
|
206
|
-
style={
|
|
207
|
-
position === "top"
|
|
208
|
-
? { bottom: "110%", left: "0" }
|
|
209
|
-
: position === "top-right"
|
|
210
|
-
? { bottom: "110%", right: "0" }
|
|
211
|
-
: position === "bottom-right"
|
|
212
|
-
? { top: "110%", right: "0" }
|
|
213
|
-
: { top: "110%", left: "0" }
|
|
214
|
-
}
|
|
215
|
-
>
|
|
216
|
-
<TimerPickerContentStyled>
|
|
217
|
-
{["hours", "minutes"].map((unit) => (
|
|
218
|
-
<Box
|
|
219
|
-
key={unit}
|
|
220
|
-
style={{
|
|
221
|
-
display: "flex",
|
|
222
|
-
alignItems: "center",
|
|
223
|
-
flexDirection: "column",
|
|
224
|
-
}}
|
|
225
|
-
>
|
|
226
|
-
<TimePickerIconButton
|
|
227
|
-
type="button"
|
|
228
|
-
variant="text"
|
|
229
|
-
onClick={() => handleIncrement(unit as "hours" | "minutes")}
|
|
230
|
-
>
|
|
231
|
-
<svg
|
|
232
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
233
|
-
width="32"
|
|
234
|
-
height="32"
|
|
235
|
-
viewBox="0 0 32 32"
|
|
236
|
-
fill="none"
|
|
237
|
-
>
|
|
238
|
-
<path
|
|
239
|
-
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"
|
|
240
|
-
fill="white"
|
|
241
|
-
/>
|
|
242
|
-
<path
|
|
243
|
-
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"
|
|
244
|
-
fill="#808289"
|
|
245
|
-
/>
|
|
246
|
-
</svg>
|
|
247
|
-
</TimePickerIconButton>
|
|
248
|
-
<InputStyled
|
|
249
|
-
inputMode="numeric"
|
|
250
|
-
pattern="[0-9]*"
|
|
251
|
-
type="text"
|
|
252
|
-
placeholder="00"
|
|
253
|
-
value={unit === "hours" ? rawHours : rawMinutes}
|
|
254
|
-
onChange={(e) => {
|
|
255
|
-
const rawValue = e.target.value.replace(/\D/g, "");
|
|
256
|
-
if (unit === "hours") {
|
|
257
|
-
setRawHours(rawValue);
|
|
258
|
-
} else {
|
|
259
|
-
setRawMinutes(rawValue);
|
|
260
|
-
}
|
|
261
|
-
}}
|
|
262
|
-
onBlur={() => {
|
|
263
|
-
let num = 0;
|
|
264
|
-
if (unit === "hours") {
|
|
265
|
-
num = Math.min(parseInt(rawHours || "0", 10), 23);
|
|
266
|
-
const padded = pad(num);
|
|
267
|
-
setHours(padded);
|
|
268
|
-
setRawHours(padded);
|
|
269
|
-
} else {
|
|
270
|
-
num = Math.min(parseInt(rawMinutes || "0", 10), 59);
|
|
271
|
-
const padded = pad(num);
|
|
272
|
-
setMinutes(padded);
|
|
273
|
-
setRawMinutes(padded);
|
|
274
|
-
}
|
|
275
|
-
}}
|
|
276
|
-
onPaste={(e) => {
|
|
277
|
-
const paste = e.clipboardData.getData("Text");
|
|
278
|
-
if (!/^\d{1,2}$/.test(paste)) {
|
|
279
|
-
e.preventDefault();
|
|
280
|
-
}
|
|
281
|
-
}}
|
|
282
|
-
/>
|
|
283
|
-
<TimePickerIconButton
|
|
284
|
-
type="button"
|
|
285
|
-
variant="text"
|
|
286
|
-
onClick={() => handleDecrement(unit as "hours" | "minutes")}
|
|
287
|
-
>
|
|
288
|
-
<svg
|
|
289
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
290
|
-
width="32"
|
|
291
|
-
height="32"
|
|
292
|
-
viewBox="0 0 32 32"
|
|
293
|
-
fill="none"
|
|
294
|
-
>
|
|
295
|
-
<path
|
|
296
|
-
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"
|
|
297
|
-
fill="white"
|
|
298
|
-
/>
|
|
299
|
-
<path
|
|
300
|
-
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"
|
|
301
|
-
fill="#808289"
|
|
302
|
-
/>
|
|
303
|
-
</svg>
|
|
304
|
-
</TimePickerIconButton>
|
|
305
|
-
</Box>
|
|
306
|
-
))}
|
|
307
|
-
<Text>:</Text>
|
|
308
|
-
</TimerPickerContentStyled>
|
|
309
|
-
<TimePickerFooterStyled>
|
|
310
|
-
<Button
|
|
311
|
-
type="button"
|
|
312
|
-
variant="text"
|
|
313
|
-
color="brand"
|
|
314
|
-
onClick={() => {
|
|
315
|
-
setSelected(`${hours}:${minutes}`);
|
|
316
|
-
setIsOpen(false);
|
|
317
|
-
}}
|
|
318
|
-
size={"medium"}
|
|
319
|
-
fontWeight="medium"
|
|
320
|
-
>
|
|
321
|
-
Aplicar
|
|
322
|
-
</Button>
|
|
323
|
-
</TimePickerFooterStyled>
|
|
324
|
-
</TimePickerDropdownStyled>
|
|
325
|
-
)}
|
|
326
|
-
</TimePickerStyled>
|
|
327
|
-
);
|
|
328
|
-
}
|
|
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
|
+
width: "fit-content",
|
|
13
|
+
fontFamily: "$default",
|
|
14
|
+
lineHeight: "$base",
|
|
15
|
+
fontSize: "$14",
|
|
16
|
+
borderRadius: "$sm",
|
|
17
|
+
"> div > div": {
|
|
18
|
+
input: {
|
|
19
|
+
textAlign: "right",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
variants: {
|
|
23
|
+
expand: {
|
|
24
|
+
true: {
|
|
25
|
+
width: "100%",
|
|
26
|
+
flex: "1",
|
|
27
|
+
display: "flex",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const TimePickerDropdownStyled = styled("div", {
|
|
34
|
+
position: "absolute",
|
|
35
|
+
zIndex: 10,
|
|
36
|
+
width: "100%",
|
|
37
|
+
maxWidth: "min-content",
|
|
38
|
+
backgroundColor: "$neutral50",
|
|
39
|
+
border: "1px solid $neutral300",
|
|
40
|
+
borderRadius: "$sm",
|
|
41
|
+
boxShadow: "0px 2px 8px 0px $shadow50",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const TimePickerFooterStyled = styled("div", {
|
|
45
|
+
borderTop: "2px solid $neutral100",
|
|
46
|
+
padding: "$4 $16",
|
|
47
|
+
display: "flex",
|
|
48
|
+
justifyContent: "center",
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
height: "3rem",
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const TimerPickerContentStyled = styled("div", {
|
|
54
|
+
display: "flex",
|
|
55
|
+
gap: "$16",
|
|
56
|
+
alignItems: "center",
|
|
57
|
+
padding: "$16 $16 $8 ",
|
|
58
|
+
"& > div:nth-child(2)": {
|
|
59
|
+
order: 2,
|
|
60
|
+
},
|
|
61
|
+
input: {
|
|
62
|
+
padding: "0",
|
|
63
|
+
textAlign: "center!important",
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const InputStyled = styled("input", {
|
|
68
|
+
height: "$40",
|
|
69
|
+
fontFamily: "$default",
|
|
70
|
+
borderRadius: "$sm",
|
|
71
|
+
boxSizing: "border-box",
|
|
72
|
+
color: "$dark500",
|
|
73
|
+
border: "1px solid $dark300",
|
|
74
|
+
position: "relative",
|
|
75
|
+
display: "flex",
|
|
76
|
+
width: "100%",
|
|
77
|
+
alignItems: "center",
|
|
78
|
+
padding: "0",
|
|
79
|
+
outline: "none",
|
|
80
|
+
margin: 0,
|
|
81
|
+
textAlign: "center",
|
|
82
|
+
"&:has(input:focus)": {
|
|
83
|
+
border: "2px solid $brand300",
|
|
84
|
+
},
|
|
85
|
+
"&:has(input:disabled)": {
|
|
86
|
+
backgroundColor: "$dark100",
|
|
87
|
+
color: "$dark400",
|
|
88
|
+
border: "1px solid $dark200",
|
|
89
|
+
cursor: "not-allowed",
|
|
90
|
+
},
|
|
91
|
+
inputMode: "numeric",
|
|
92
|
+
"&::-webkit-inner-spin-button": {
|
|
93
|
+
WebkitAppearance: "none",
|
|
94
|
+
margin: 0,
|
|
95
|
+
},
|
|
96
|
+
"&::-webkit-outer-spin-button": {
|
|
97
|
+
WebkitAppearance: "none",
|
|
98
|
+
margin: 0,
|
|
99
|
+
},
|
|
100
|
+
"&[type='number']": {
|
|
101
|
+
MozAppearance: "textfield",
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const TimePickerButtonStyled = styled("button", {
|
|
106
|
+
backgroundColor: "transparent",
|
|
107
|
+
border: "none",
|
|
108
|
+
padding: "0",
|
|
109
|
+
cursor: "pointer",
|
|
110
|
+
"> div > div": {
|
|
111
|
+
input: {
|
|
112
|
+
textAlign: "right",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
variants: {
|
|
116
|
+
expand: {
|
|
117
|
+
true: {
|
|
118
|
+
flex: "1",
|
|
119
|
+
display: "flex",
|
|
120
|
+
maxWidth: "100%",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
export const TimePickerIconButton = styled(Button, {
|
|
126
|
+
padding: "0 !important",
|
|
127
|
+
});
|
|
128
|
+
export type TimePickerProps = {
|
|
129
|
+
selected: string | undefined;
|
|
130
|
+
setSelected: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
131
|
+
position?: "bottom" | "top" | "top-right" | "bottom-right";
|
|
132
|
+
hasError?: boolean;
|
|
133
|
+
expand?: boolean;
|
|
134
|
+
};
|
|
135
|
+
const pad = (num: number) => String(num).padStart(2, "0");
|
|
136
|
+
|
|
137
|
+
export function TimePicker({
|
|
138
|
+
selected,
|
|
139
|
+
setSelected,
|
|
140
|
+
position = "bottom",
|
|
141
|
+
hasError,
|
|
142
|
+
expand = false,
|
|
143
|
+
}: TimePickerProps) {
|
|
144
|
+
const [hours, setHours] = useState("00");
|
|
145
|
+
const [minutes, setMinutes] = useState("00");
|
|
146
|
+
const [rawHours, setRawHours] = useState("00");
|
|
147
|
+
const [rawMinutes, setRawMinutes] = useState("00");
|
|
148
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
149
|
+
const dropdownRef = useRef(null);
|
|
150
|
+
|
|
151
|
+
useOnClickOutside(dropdownRef, () => setIsOpen(false));
|
|
152
|
+
|
|
153
|
+
const handleIncrement = useCallback(
|
|
154
|
+
(type: "hours" | "minutes") => {
|
|
155
|
+
if (type === "hours") {
|
|
156
|
+
const next = (parseInt(hours) + 1) % 24;
|
|
157
|
+
setHours(pad(next));
|
|
158
|
+
setRawHours(pad(next));
|
|
159
|
+
} else {
|
|
160
|
+
const next = (parseInt(minutes) + 1) % 60;
|
|
161
|
+
setMinutes(pad(next));
|
|
162
|
+
setRawMinutes(pad(next));
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
[hours, minutes]
|
|
166
|
+
);
|
|
167
|
+
const handleDecrement = useCallback(
|
|
168
|
+
(type: "hours" | "minutes") => {
|
|
169
|
+
if (type === "hours") {
|
|
170
|
+
const prev = (parseInt(hours) - 1 + 24) % 24;
|
|
171
|
+
setHours(pad(prev));
|
|
172
|
+
setRawHours(pad(prev));
|
|
173
|
+
} else {
|
|
174
|
+
const prev = (parseInt(minutes) - 1 + 60) % 60;
|
|
175
|
+
setMinutes(pad(prev));
|
|
176
|
+
setRawMinutes(pad(prev));
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
[hours, minutes]
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<TimePickerStyled ref={dropdownRef} expand={expand}>
|
|
184
|
+
<TimePickerButtonStyled
|
|
185
|
+
type="button"
|
|
186
|
+
onClick={() => setIsOpen((prev) => !prev)}
|
|
187
|
+
expand={expand}
|
|
188
|
+
>
|
|
189
|
+
<TextField
|
|
190
|
+
value={selected}
|
|
191
|
+
readOnly
|
|
192
|
+
type="text"
|
|
193
|
+
placeholder="00:00"
|
|
194
|
+
typography="labelSmall"
|
|
195
|
+
fontWeight="regular"
|
|
196
|
+
color={hasError ? "error" : "default"}
|
|
197
|
+
>
|
|
198
|
+
<TextFieldSlot>
|
|
199
|
+
<Icon name="clock" size="xl" />
|
|
200
|
+
</TextFieldSlot>
|
|
201
|
+
</TextField>
|
|
202
|
+
</TimePickerButtonStyled>
|
|
203
|
+
|
|
204
|
+
{isOpen && (
|
|
205
|
+
<TimePickerDropdownStyled
|
|
206
|
+
style={
|
|
207
|
+
position === "top"
|
|
208
|
+
? { bottom: "110%", left: "0" }
|
|
209
|
+
: position === "top-right"
|
|
210
|
+
? { bottom: "110%", right: "0" }
|
|
211
|
+
: position === "bottom-right"
|
|
212
|
+
? { top: "110%", right: "0" }
|
|
213
|
+
: { top: "110%", left: "0" }
|
|
214
|
+
}
|
|
215
|
+
>
|
|
216
|
+
<TimerPickerContentStyled>
|
|
217
|
+
{["hours", "minutes"].map((unit) => (
|
|
218
|
+
<Box
|
|
219
|
+
key={unit}
|
|
220
|
+
style={{
|
|
221
|
+
display: "flex",
|
|
222
|
+
alignItems: "center",
|
|
223
|
+
flexDirection: "column",
|
|
224
|
+
}}
|
|
225
|
+
>
|
|
226
|
+
<TimePickerIconButton
|
|
227
|
+
type="button"
|
|
228
|
+
variant="text"
|
|
229
|
+
onClick={() => handleIncrement(unit as "hours" | "minutes")}
|
|
230
|
+
>
|
|
231
|
+
<svg
|
|
232
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
233
|
+
width="32"
|
|
234
|
+
height="32"
|
|
235
|
+
viewBox="0 0 32 32"
|
|
236
|
+
fill="none"
|
|
237
|
+
>
|
|
238
|
+
<path
|
|
239
|
+
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"
|
|
240
|
+
fill="white"
|
|
241
|
+
/>
|
|
242
|
+
<path
|
|
243
|
+
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"
|
|
244
|
+
fill="#808289"
|
|
245
|
+
/>
|
|
246
|
+
</svg>
|
|
247
|
+
</TimePickerIconButton>
|
|
248
|
+
<InputStyled
|
|
249
|
+
inputMode="numeric"
|
|
250
|
+
pattern="[0-9]*"
|
|
251
|
+
type="text"
|
|
252
|
+
placeholder="00"
|
|
253
|
+
value={unit === "hours" ? rawHours : rawMinutes}
|
|
254
|
+
onChange={(e) => {
|
|
255
|
+
const rawValue = e.target.value.replace(/\D/g, "");
|
|
256
|
+
if (unit === "hours") {
|
|
257
|
+
setRawHours(rawValue);
|
|
258
|
+
} else {
|
|
259
|
+
setRawMinutes(rawValue);
|
|
260
|
+
}
|
|
261
|
+
}}
|
|
262
|
+
onBlur={() => {
|
|
263
|
+
let num = 0;
|
|
264
|
+
if (unit === "hours") {
|
|
265
|
+
num = Math.min(parseInt(rawHours || "0", 10), 23);
|
|
266
|
+
const padded = pad(num);
|
|
267
|
+
setHours(padded);
|
|
268
|
+
setRawHours(padded);
|
|
269
|
+
} else {
|
|
270
|
+
num = Math.min(parseInt(rawMinutes || "0", 10), 59);
|
|
271
|
+
const padded = pad(num);
|
|
272
|
+
setMinutes(padded);
|
|
273
|
+
setRawMinutes(padded);
|
|
274
|
+
}
|
|
275
|
+
}}
|
|
276
|
+
onPaste={(e) => {
|
|
277
|
+
const paste = e.clipboardData.getData("Text");
|
|
278
|
+
if (!/^\d{1,2}$/.test(paste)) {
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
}
|
|
281
|
+
}}
|
|
282
|
+
/>
|
|
283
|
+
<TimePickerIconButton
|
|
284
|
+
type="button"
|
|
285
|
+
variant="text"
|
|
286
|
+
onClick={() => handleDecrement(unit as "hours" | "minutes")}
|
|
287
|
+
>
|
|
288
|
+
<svg
|
|
289
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
290
|
+
width="32"
|
|
291
|
+
height="32"
|
|
292
|
+
viewBox="0 0 32 32"
|
|
293
|
+
fill="none"
|
|
294
|
+
>
|
|
295
|
+
<path
|
|
296
|
+
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"
|
|
297
|
+
fill="white"
|
|
298
|
+
/>
|
|
299
|
+
<path
|
|
300
|
+
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"
|
|
301
|
+
fill="#808289"
|
|
302
|
+
/>
|
|
303
|
+
</svg>
|
|
304
|
+
</TimePickerIconButton>
|
|
305
|
+
</Box>
|
|
306
|
+
))}
|
|
307
|
+
<Text>:</Text>
|
|
308
|
+
</TimerPickerContentStyled>
|
|
309
|
+
<TimePickerFooterStyled>
|
|
310
|
+
<Button
|
|
311
|
+
type="button"
|
|
312
|
+
variant="text"
|
|
313
|
+
color="brand"
|
|
314
|
+
onClick={() => {
|
|
315
|
+
setSelected(`${hours}:${minutes}`);
|
|
316
|
+
setIsOpen(false);
|
|
317
|
+
}}
|
|
318
|
+
size={"medium"}
|
|
319
|
+
fontWeight="medium"
|
|
320
|
+
>
|
|
321
|
+
Aplicar
|
|
322
|
+
</Button>
|
|
323
|
+
</TimePickerFooterStyled>
|
|
324
|
+
</TimePickerDropdownStyled>
|
|
325
|
+
)}
|
|
326
|
+
</TimePickerStyled>
|
|
327
|
+
);
|
|
328
|
+
}
|