@motor-hero/ui-kit 0.40.0 → 0.42.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/package.json
CHANGED
|
@@ -16,10 +16,13 @@ const MASK_REPLACEMENT = { _: /\d/ }
|
|
|
16
16
|
const DATE_FORMAT = "dd/MM/yyyy"
|
|
17
17
|
const TIME_FORMAT = "HH:mm"
|
|
18
18
|
const DATE_VALUE_FORMAT = "yyyy-MM-dd"
|
|
19
|
+
const DATETIME_VALUE_FORMAT = "yyyy-MM-dd'T'HH:mm"
|
|
19
20
|
|
|
20
21
|
export interface DatePickerProps {
|
|
21
|
-
/** `DatePicker`: data pura `"yyyy-MM-dd"
|
|
22
|
-
*
|
|
22
|
+
/** `DatePicker`: data pura `"yyyy-MM-dd"`. `DateTimePicker`: hora de parede
|
|
23
|
+
* `"yyyy-MM-ddTHH:mm"` — os dígitos digitados, tal qual. Nenhum dos dois
|
|
24
|
+
* passa por conversão de fuso: o significado (Brasília, local, UTC) é
|
|
25
|
+
* decisão do consumidor. `""`/`undefined` = sem valor. */
|
|
23
26
|
value?: string
|
|
24
27
|
onChange: (value: string) => void
|
|
25
28
|
placeholder?: string
|
|
@@ -60,8 +63,8 @@ function dateOnlyToDate(value: string | undefined): Date | undefined {
|
|
|
60
63
|
|
|
61
64
|
function dateTimeToDate(value: string | undefined): Date | undefined {
|
|
62
65
|
if (!value) return undefined
|
|
63
|
-
const parsed = new Date(
|
|
64
|
-
return
|
|
66
|
+
const parsed = parse(value, DATETIME_VALUE_FORMAT, new Date())
|
|
67
|
+
return isValid(parsed) ? parsed : undefined
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
function displayFor(value: string | undefined, withTime: boolean): string {
|
|
@@ -196,7 +199,7 @@ function DatePickerImpl({
|
|
|
196
199
|
if (!time) return
|
|
197
200
|
const combined = new Date(date)
|
|
198
201
|
combined.setHours(time.getHours(), time.getMinutes(), 0, 0)
|
|
199
|
-
onChange(combined
|
|
202
|
+
onChange(format(combined, DATETIME_VALUE_FORMAT))
|
|
200
203
|
setOpen(false)
|
|
201
204
|
}
|
|
202
205
|
|