linear-react-components-ui 2.1.0-beta.1 → 2.1.0-beta.3

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.
Files changed (44) hide show
  1. package/lib/assets/styles/datepicker2.css +77 -4
  2. package/lib/inputs2/date/calendarbox.d.ts +23 -0
  3. package/lib/inputs2/date/calendarbox.js +254 -0
  4. package/lib/inputs2/date/calendarbox.js.map +1 -0
  5. package/lib/inputs2/date/datefield/base.js +599 -215
  6. package/lib/inputs2/date/datefield/base.js.map +1 -1
  7. package/lib/inputs2/date/datefield/triggers.js +4 -4
  8. package/lib/inputs2/date/datefield/triggers.js.map +1 -1
  9. package/lib/inputs2/date/datefield/types.d.ts +5 -12
  10. package/lib/inputs2/date/dateperiodfield/base.js +645 -751
  11. package/lib/inputs2/date/dateperiodfield/base.js.map +1 -1
  12. package/lib/inputs2/date/dateperiodfield/triggers.js +21 -9
  13. package/lib/inputs2/date/dateperiodfield/triggers.js.map +1 -1
  14. package/lib/inputs2/date/dateperiodfield/types.d.ts +7 -23
  15. package/lib/inputs2/date/helpers.d.ts +25 -4
  16. package/lib/inputs2/date/helpers.js +79 -4
  17. package/lib/inputs2/date/helpers.js.map +1 -1
  18. package/lib/inputs2/date/{base/constants.d.ts → hooks/useCalendarPosition.d.ts} +1 -1
  19. package/lib/inputs2/date/hooks/useCalendarPosition.js +93 -0
  20. package/lib/inputs2/date/hooks/useCalendarPosition.js.map +1 -0
  21. package/lib/inputs2/date/hooks/useDateCalendarState.d.ts +14 -0
  22. package/lib/inputs2/date/hooks/useDateCalendarState.js +250 -0
  23. package/lib/inputs2/date/hooks/useDateCalendarState.js.map +1 -0
  24. package/lib/inputs2/date/hooks/useDateMask.d.ts +22 -0
  25. package/lib/inputs2/date/hooks/useDateMask.js +215 -0
  26. package/lib/inputs2/date/hooks/useDateMask.js.map +1 -0
  27. package/lib/inputs2/date/timeselector.d.ts +15 -0
  28. package/lib/inputs2/date/timeselector.js +228 -0
  29. package/lib/inputs2/date/timeselector.js.map +1 -0
  30. package/lib/inputs2/date/types.d.ts +16 -1
  31. package/lib/inputs2/date/types.js.map +1 -1
  32. package/lib/menus/float/SubMenuContainer.js +8 -16
  33. package/lib/menus/float/SubMenuContainer.js.map +1 -1
  34. package/lib/node_modules/moment/dist/locale/pt-br.js +54 -0
  35. package/lib/node_modules/moment/dist/locale/pt-br.js.map +1 -0
  36. package/package.json +1 -1
  37. package/lib/inputs2/date/base/constants.js +0 -69
  38. package/lib/inputs2/date/base/constants.js.map +0 -1
  39. package/lib/inputs2/date/datefield/calendarbox.d.ts +0 -6
  40. package/lib/inputs2/date/datefield/calendarbox.js +0 -228
  41. package/lib/inputs2/date/datefield/calendarbox.js.map +0 -1
  42. package/lib/inputs2/date/dateperiodfield/calendarbox.d.ts +0 -6
  43. package/lib/inputs2/date/dateperiodfield/calendarbox.js +0 -282
  44. package/lib/inputs2/date/dateperiodfield/calendarbox.js.map +0 -1
@@ -1,252 +1,636 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { c as compilerRuntimeExports } from "../../../_virtual/compiler-runtime.js";
2
3
  import React from "react";
3
4
  import _ from "../../../_virtual/lodash.js";
4
- import { useIMask } from "react-imask";
5
5
  import { createPortal } from "react-dom";
6
6
  import hooks from "../../../node_modules/moment/dist/moment.js";
7
7
  import Hint from "../../../hint/index.js";
8
8
  import { Tooltip } from "../../../tooltip/index.js";
9
9
  import { mergeRefs } from "../../../form2/helpers.js";
10
- import { Keys } from "../types.js";
11
- import { Root, Label, Container, Input } from "../base/index.js";
12
- import { TOKEN_PTBR_FORMAT, TOKEN_ISO_FORMAT, TOKEN_MASK, NAVIGATION_KEYS } from "../helpers.js";
10
+ import { Label, Input, Container, Root } from "../base/index.js";
11
+ import { useDateMask } from "../hooks/useDateMask.js";
12
+ import { useDateCalendarState } from "../hooks/useDateCalendarState.js";
13
+ import { TimeSelector } from "../timeselector.js";
14
+ import { parseBoundary, isDayOutOfBounds, TOKEN_ISO_FORMAT, getDateFormats, clampDateToBounds, parseDateValue } from "../helpers.js";
15
+ import { CalendarBox } from "../calendarbox.js";
13
16
  import { Triggers } from "./triggers.js";
14
- import { CalendarBox } from "./calendarbox.js";
15
17
  import { DateFieldContext } from "./context.js";
16
18
  import v1 from "../../../node_modules/uuid/dist/v1.js";
17
19
  const InputBase = React.forwardRef((props, ref) => {
20
+ const $ = compilerRuntimeExports.c(186);
21
+ let disabled;
22
+ let errors;
23
+ let label;
24
+ let max;
25
+ let min;
26
+ let onChange;
27
+ let placeholder;
28
+ let readOnly;
29
+ let rest;
30
+ let shouldCloseOnSelect;
31
+ let t0;
32
+ let t1;
33
+ let t10;
34
+ let t11;
35
+ let t12;
36
+ let t13;
37
+ let t14;
38
+ let t15;
39
+ let t2;
40
+ let t3;
41
+ let t4;
42
+ let t5;
43
+ let t6;
44
+ let t7;
45
+ let t8;
46
+ let t9;
47
+ let tooltip;
48
+ let tooltipPosition;
49
+ let tooltipWidth;
50
+ if ($[0] !== props) {
51
+ ({
52
+ label,
53
+ errors,
54
+ tooltip,
55
+ tooltipPosition,
56
+ tooltipWidth,
57
+ returnValueType: t0,
58
+ customClass: t1,
59
+ customClassLabel: t2,
60
+ customClassWrapper: t3,
61
+ customClassInputContainer: t4,
62
+ textAlign: t5,
63
+ labelUppercase: t6,
64
+ skeletonize: t7,
65
+ hintPosition: t8,
66
+ themePopover: t9,
67
+ popoverAlign: t10,
68
+ showCalendarButton: t11,
69
+ openCalendarOnFocus: t12,
70
+ undigitable: t13,
71
+ showClearDateButton: t14,
72
+ variant: t15,
73
+ placeholder,
74
+ shouldCloseOnSelect,
75
+ min,
76
+ max,
77
+ onChange,
78
+ readOnly,
79
+ disabled,
80
+ ...rest
81
+ } = props);
82
+ $[0] = props;
83
+ $[1] = disabled;
84
+ $[2] = errors;
85
+ $[3] = label;
86
+ $[4] = max;
87
+ $[5] = min;
88
+ $[6] = onChange;
89
+ $[7] = placeholder;
90
+ $[8] = readOnly;
91
+ $[9] = rest;
92
+ $[10] = shouldCloseOnSelect;
93
+ $[11] = t0;
94
+ $[12] = t1;
95
+ $[13] = t10;
96
+ $[14] = t11;
97
+ $[15] = t12;
98
+ $[16] = t13;
99
+ $[17] = t14;
100
+ $[18] = t15;
101
+ $[19] = t2;
102
+ $[20] = t3;
103
+ $[21] = t4;
104
+ $[22] = t5;
105
+ $[23] = t6;
106
+ $[24] = t7;
107
+ $[25] = t8;
108
+ $[26] = t9;
109
+ $[27] = tooltip;
110
+ $[28] = tooltipPosition;
111
+ $[29] = tooltipWidth;
112
+ } else {
113
+ disabled = $[1];
114
+ errors = $[2];
115
+ label = $[3];
116
+ max = $[4];
117
+ min = $[5];
118
+ onChange = $[6];
119
+ placeholder = $[7];
120
+ readOnly = $[8];
121
+ rest = $[9];
122
+ shouldCloseOnSelect = $[10];
123
+ t0 = $[11];
124
+ t1 = $[12];
125
+ t10 = $[13];
126
+ t11 = $[14];
127
+ t12 = $[15];
128
+ t13 = $[16];
129
+ t14 = $[17];
130
+ t15 = $[18];
131
+ t2 = $[19];
132
+ t3 = $[20];
133
+ t4 = $[21];
134
+ t5 = $[22];
135
+ t6 = $[23];
136
+ t7 = $[24];
137
+ t8 = $[25];
138
+ t9 = $[26];
139
+ tooltip = $[27];
140
+ tooltipPosition = $[28];
141
+ tooltipWidth = $[29];
142
+ }
143
+ const returnValueType = t0 === void 0 ? "default" : t0;
144
+ const customClass = t1 === void 0 ? "" : t1;
145
+ const customClassLabel = t2 === void 0 ? "" : t2;
146
+ const customClassWrapper = t3 === void 0 ? "" : t3;
147
+ const customClassInputContainer = t4 === void 0 ? "" : t4;
148
+ const textAlign = t5 === void 0 ? "left" : t5;
149
+ const labelUppercase = t6 === void 0 ? false : t6;
150
+ const skeletonize = t7 === void 0 ? false : t7;
151
+ const hintPosition = t8 === void 0 ? "below" : t8;
152
+ const themePopover = t9 === void 0 ? "light" : t9;
153
+ const popoverAlign = t10 === void 0 ? "left" : t10;
154
+ const showCalendarButton = t11 === void 0 ? true : t11;
155
+ const openCalendarOnFocus = t12 === void 0 ? true : t12;
156
+ const undigitable = t13 === void 0 ? false : t13;
157
+ const showClearDateButton = t14 === void 0 ? true : t14;
158
+ const variant = t15 === void 0 ? "date" : t15;
159
+ const isDateTime = variant === "datetime";
18
160
  const {
19
- label,
20
- errors,
21
- tooltip,
22
- tooltipPosition,
23
- tooltipWidth,
24
- shouldCloseOnSelect = true,
25
- returnValueType = "default",
26
- customClass = "",
27
- customClassLabel = "",
28
- customClassWrapper = "",
29
- customClassInputContainer = "",
30
- textAlign = "left",
31
- labelUppercase = false,
32
- skeletonize = false,
33
- hintPosition = "below",
34
- themePopover = "light",
35
- popoverAlign = "left",
36
- showCalendarButton = true,
37
- openCalendarOnFocus = true,
38
- undigitable = false,
39
- showClearDateButton = true,
40
- placeholder = TOKEN_PTBR_FORMAT,
41
- readOnly,
42
- disabled,
43
- ...rest
44
- } = props;
45
- const [calendarBoxOpen, setCalendarBoxOpen] = React.useState(false);
46
- const [activeDescendant, setActiveDescendant] = React.useState(hooks().format(TOKEN_ISO_FORMAT));
161
+ isoFormat,
162
+ ptbrFormat,
163
+ digits
164
+ } = getDateFormats(variant);
165
+ const shouldCloseCalendarOnSelect = shouldCloseOnSelect ?? !isDateTime;
166
+ const inputPlaceholder = placeholder ?? ptbrFormat;
167
+ let t16;
168
+ if ($[30] !== min) {
169
+ t16 = parseBoundary(min);
170
+ $[30] = min;
171
+ $[31] = t16;
172
+ } else {
173
+ t16 = $[31];
174
+ }
175
+ const minDate = t16;
176
+ let t17;
177
+ if ($[32] !== max) {
178
+ t17 = parseBoundary(max);
179
+ $[32] = max;
180
+ $[33] = t17;
181
+ } else {
182
+ t17 = $[33];
183
+ }
184
+ const maxDate = t17;
185
+ const hasBounds = Boolean(minDate || maxDate);
47
186
  const [selectedDate, setSelectedDate] = React.useState(null);
48
- const [calendarDisplayDate, setCalendarDisplayDate] = React.useState(selectedDate ?? hooks());
49
- const calendarRef = React.useRef(null);
50
187
  const inputRootRef = React.useRef(null);
51
188
  const dateInputRef = React.useRef(null);
52
- const dateContainerRef = React.useRef(null);
189
+ const calendarState = useDateCalendarState({
190
+ inputRef: dateInputRef,
191
+ min: minDate,
192
+ max: maxDate,
193
+ onPressEnter: (descendant) => handleSelectDay(hooks(_.toString(descendant), TOKEN_ISO_FORMAT))
194
+ });
53
195
  const {
54
- setValue: setMaskValue,
196
+ calendarBoxOpen,
197
+ activeDescendant,
198
+ calendarDisplayDate,
199
+ calendarRef,
200
+ dateContainerRef,
201
+ handleNextMonth,
202
+ handlePreviousMonth,
203
+ handleSetCalendarBoxOpen,
204
+ handleChangeActiveDescendant,
205
+ handleChangeCalendarDisplayDate,
206
+ handleKeyDownNavigation
207
+ } = calendarState;
208
+ const {
209
+ maskedValue,
55
210
  unmaskedValue,
56
- value: maskedValue
57
- } = useIMask({
58
- mask: TOKEN_MASK,
59
- lazy: false,
60
- placeholderChar: "_"
61
- }, {
62
- ref: dateInputRef,
63
- defaultValue: selectedDate?.format(TOKEN_PTBR_FORMAT),
64
- onComplete: (value) => {
65
- const date = hooks(value, TOKEN_PTBR_FORMAT);
66
- if (date.isValid()) {
67
- handleUpdateDateState(date);
68
- }
69
- }
211
+ setMaskValue,
212
+ handleOnPaste,
213
+ handleOnBeforeInput,
214
+ handleOnKeyDownCapture
215
+ } = useDateMask({
216
+ inputRef: dateInputRef,
217
+ variant,
218
+ defaultValue: selectedDate?.format(ptbrFormat),
219
+ undigitable,
220
+ readOnly,
221
+ onCommit: (date) => handleUpdateDateState(date),
222
+ onPaste: props.onPaste,
223
+ onBeforeInput: props.onBeforeInput
70
224
  });
71
- const inputId = React.useMemo(() => props.id || props.name || v1(), [props.id, props.name]);
72
- const hasLabel = !_.isEmpty(props?.label);
225
+ let t18;
226
+ if ($[34] !== props.id || $[35] !== props.name) {
227
+ t18 = props.id || props.name || v1();
228
+ $[34] = props.id;
229
+ $[35] = props.name;
230
+ $[36] = t18;
231
+ } else {
232
+ t18 = $[36];
233
+ }
234
+ const inputId = t18;
235
+ let t19;
236
+ if ($[37] !== props.label) {
237
+ t19 = _.isEmpty(props?.label);
238
+ $[37] = props.label;
239
+ $[38] = t19;
240
+ } else {
241
+ t19 = $[38];
242
+ }
243
+ const hasLabel = !t19;
73
244
  const hasHintMessages = Boolean(props.hint?.length);
74
245
  const hasValidationErrors = Boolean(errors?.length);
75
- const hasValidDateSelected = !_.isEmpty(props?.value);
76
- const handleUpdateDateState = React.useCallback((date_0) => {
77
- const nonIsoDateFormat = date_0.format(TOKEN_ISO_FORMAT);
246
+ let t20;
247
+ if ($[39] !== props.value) {
248
+ t20 = _.isEmpty(props?.value);
249
+ $[39] = props.value;
250
+ $[40] = t20;
251
+ } else {
252
+ t20 = $[40];
253
+ }
254
+ const hasValidDateSelected = !t20;
255
+ const handleUpdateDateState = (date_0) => {
256
+ const nonIsoDateFormat = date_0.format(isoFormat);
78
257
  const isoDateFormat = date_0.toISOString();
79
258
  setSelectedDate(date_0.clone());
80
- setCalendarDisplayDate(date_0.clone());
81
- props.onChange?.({
259
+ handleChangeActiveDescendant(date_0.format(TOKEN_ISO_FORMAT));
260
+ handleChangeCalendarDisplayDate(date_0.clone());
261
+ onChange?.({
82
262
  target: {
83
263
  name: props.name,
84
264
  value: returnValueType === "default" ? nonIsoDateFormat : isoDateFormat
85
265
  }
86
266
  });
87
- if (shouldCloseOnSelect) handleCloseCalendar();
88
- }, [selectedDate, props.name, props.onChange, shouldCloseOnSelect]);
89
- const handleOpenCalendar = React.useCallback(() => setCalendarBoxOpen(true), []);
90
- const handleCloseCalendar = React.useCallback(() => setCalendarBoxOpen(false), []);
91
- const handleNextMonth = React.useCallback(() => setCalendarDisplayDate((prevDisplayDate) => prevDisplayDate.clone().add(1, "month")), []);
92
- const handlePreviousMonth = React.useCallback(() => setCalendarDisplayDate((prevDisplayDate_0) => prevDisplayDate_0.clone().subtract(1, "month")), []);
93
- const handleChangeCalendarBoxState = React.useCallback(() => {
94
- setCalendarBoxOpen((prevState) => {
95
- if (dateInputRef.current !== document.activeElement) {
96
- dateInputRef?.current?.focus?.();
267
+ if (shouldCloseCalendarOnSelect) {
268
+ handleSetCalendarBoxOpen(false);
269
+ }
270
+ };
271
+ let t21;
272
+ if ($[41] !== handleSetCalendarBoxOpen || $[42] !== onChange || $[43] !== props.name || $[44] !== setMaskValue || $[45] !== setSelectedDate) {
273
+ t21 = () => {
274
+ onChange?.({
275
+ target: {
276
+ name: props.name,
277
+ value: ""
278
+ }
279
+ });
280
+ setSelectedDate(null);
281
+ setMaskValue("");
282
+ handleSetCalendarBoxOpen(false);
283
+ };
284
+ $[41] = handleSetCalendarBoxOpen;
285
+ $[42] = onChange;
286
+ $[43] = props.name;
287
+ $[44] = setMaskValue;
288
+ $[45] = setSelectedDate;
289
+ $[46] = t21;
290
+ } else {
291
+ t21 = $[46];
292
+ }
293
+ const handleOnClickClearSelectedDate = t21;
294
+ let t22;
295
+ if ($[47] !== digits || $[48] !== handleChangeActiveDescendant || $[49] !== handleChangeCalendarDisplayDate || $[50] !== handleSetCalendarBoxOpen || $[51] !== props || $[52] !== ptbrFormat || $[53] !== selectedDate || $[54] !== setMaskValue || $[55] !== unmaskedValue || $[56] !== variant) {
296
+ t22 = (event) => {
297
+ props?.onBlur?.(event);
298
+ handleSetCalendarBoxOpen(false);
299
+ handleChangeActiveDescendant((selectedDate ?? hooks()).format(TOKEN_ISO_FORMAT));
300
+ handleChangeCalendarDisplayDate(selectedDate ?? hooks());
301
+ if (_.size(unmaskedValue) !== digits) {
302
+ const date_1 = parseDateValue(props?.value, variant);
303
+ if (date_1.isValid()) {
304
+ setMaskValue(date_1.format(ptbrFormat));
305
+ }
97
306
  }
98
- return !prevState;
99
- });
100
- }, []);
101
- const handleNavigateWithDays = React.useCallback((offset) => {
102
- setCalendarDisplayDate((prevDisplayDate_1) => {
103
- const daySelected = prevDisplayDate_1.clone().add(offset, "day");
104
- setActiveDescendant(daySelected.format(TOKEN_ISO_FORMAT));
105
- return daySelected;
106
- });
107
- }, []);
108
- const handleNavigateWithWeeks = React.useCallback((when) => {
109
- setCalendarDisplayDate((prevDisplayDate_2) => {
110
- let daySelected_0 = prevDisplayDate_2;
111
- if (when === "end") daySelected_0 = prevDisplayDate_2.clone().endOf("week");
112
- if (when === "start") daySelected_0 = prevDisplayDate_2.clone().startOf("week");
113
- setActiveDescendant(daySelected_0.format(TOKEN_ISO_FORMAT));
114
- return daySelected_0;
115
- });
116
- }, []);
117
- const handleOnClickClearSelectedDate = React.useCallback(() => {
118
- props.onChange?.({
119
- target: {
120
- name: props.name,
121
- value: ""
307
+ };
308
+ $[47] = digits;
309
+ $[48] = handleChangeActiveDescendant;
310
+ $[49] = handleChangeCalendarDisplayDate;
311
+ $[50] = handleSetCalendarBoxOpen;
312
+ $[51] = props;
313
+ $[52] = ptbrFormat;
314
+ $[53] = selectedDate;
315
+ $[54] = setMaskValue;
316
+ $[55] = unmaskedValue;
317
+ $[56] = variant;
318
+ $[57] = t22;
319
+ } else {
320
+ t22 = $[57];
321
+ }
322
+ const handleOnBlur = t22;
323
+ let t23;
324
+ if ($[58] !== handleChangeActiveDescendant || $[59] !== handleChangeCalendarDisplayDate || $[60] !== handleSetCalendarBoxOpen || $[61] !== openCalendarOnFocus || $[62] !== props || $[63] !== readOnly || $[64] !== selectedDate) {
325
+ t23 = (event_0) => {
326
+ props?.onFocus?.(event_0);
327
+ handleChangeActiveDescendant((selectedDate ?? hooks()).format(TOKEN_ISO_FORMAT));
328
+ handleChangeCalendarDisplayDate(selectedDate ?? hooks());
329
+ if (!readOnly && openCalendarOnFocus) {
330
+ handleSetCalendarBoxOpen(true);
122
331
  }
123
- });
124
- setSelectedDate(null);
125
- setMaskValue("");
126
- handleCloseCalendar();
127
- }, [props.onChange]);
128
- const handleOnBlur = (event) => {
129
- props?.onBlur?.(event);
130
- handleCloseCalendar();
131
- setActiveDescendant((selectedDate ?? hooks()).format(TOKEN_ISO_FORMAT));
132
- setCalendarDisplayDate(selectedDate ?? hooks());
133
- if (_.size(unmaskedValue) !== 8) {
134
- const date_1 = hooks(_.toString(props?.value), TOKEN_ISO_FORMAT);
135
- if (date_1.isValid()) {
136
- setMaskValue(date_1.format("DD/MM/YYYY"));
332
+ };
333
+ $[58] = handleChangeActiveDescendant;
334
+ $[59] = handleChangeCalendarDisplayDate;
335
+ $[60] = handleSetCalendarBoxOpen;
336
+ $[61] = openCalendarOnFocus;
337
+ $[62] = props;
338
+ $[63] = readOnly;
339
+ $[64] = selectedDate;
340
+ $[65] = t23;
341
+ } else {
342
+ t23 = $[65];
343
+ }
344
+ const handleOnFocus = t23;
345
+ let t24;
346
+ if ($[66] !== handleKeyDownNavigation || $[67] !== props) {
347
+ t24 = (event_1) => {
348
+ props?.onKeyDown?.(event_1);
349
+ handleKeyDownNavigation(event_1);
350
+ };
351
+ $[66] = handleKeyDownNavigation;
352
+ $[67] = props;
353
+ $[68] = t24;
354
+ } else {
355
+ t24 = $[68];
356
+ }
357
+ const handleOnKeyDown = t24;
358
+ let t25;
359
+ if ($[69] !== handleUpdateDateState || $[70] !== selectedDate) {
360
+ t25 = (hour, minute) => {
361
+ if (!selectedDate) {
362
+ return;
137
363
  }
138
- }
139
- };
140
- const handleOnFocus = (event_0) => {
141
- props?.onFocus?.(event_0);
142
- setActiveDescendant((selectedDate ?? hooks()).format(TOKEN_ISO_FORMAT));
143
- setCalendarDisplayDate(selectedDate ?? hooks());
144
- if (!readOnly && openCalendarOnFocus) {
145
- handleOpenCalendar();
146
- }
147
- };
148
- const handleOnPaste = (event_1) => {
149
- if (undigitable) {
150
- event_1.preventDefault();
151
- } else {
152
- props.onPaste?.(event_1);
153
- }
364
+ handleUpdateDateState(selectedDate.clone().hour(hour).minute(minute).second(0));
365
+ };
366
+ $[69] = handleUpdateDateState;
367
+ $[70] = selectedDate;
368
+ $[71] = t25;
369
+ } else {
370
+ t25 = $[71];
371
+ }
372
+ const handleSelectTime = t25;
373
+ const handleSelectDay = (day) => {
374
+ const dayWithTime = isDateTime && selectedDate ? day.clone().hour(selectedDate.hour()).minute(selectedDate.minute()) : day;
375
+ handleUpdateDateState(clampDateToBounds(dayWithTime, minDate, maxDate));
154
376
  };
155
- const handleOnBeforeInput = (event_2) => {
156
- if (undigitable) {
157
- event_2.preventDefault();
158
- } else {
159
- props.onBeforeInput?.(event_2);
160
- }
161
- };
162
- const handleOnKeyDown = (event_3) => {
163
- props?.onKeyDown?.(event_3);
164
- if (calendarBoxOpen && event_3.key && !event_3.shiftKey && !event_3.altKey && NAVIGATION_KEYS.includes(event_3.key)) {
165
- event_3.preventDefault();
166
- switch (event_3.key) {
167
- case Keys.arrowLeft:
168
- handleNavigateWithDays(-1);
169
- break;
170
- case Keys.arrowRight:
171
- handleNavigateWithDays(1);
172
- break;
173
- case Keys.arrowUp:
174
- handleNavigateWithDays(-7);
175
- break;
176
- case Keys.arrowDown:
177
- handleNavigateWithDays(7);
178
- break;
179
- case Keys.pageUp:
180
- handleNextMonth();
181
- break;
182
- case Keys.pageDown:
183
- handlePreviousMonth();
184
- break;
185
- case Keys.home:
186
- handleNavigateWithWeeks("start");
187
- break;
188
- case Keys.end:
189
- handleNavigateWithWeeks("end");
190
- break;
191
- case Keys.escape:
192
- handleCloseCalendar();
193
- break;
194
- case Keys.enter:
195
- handleUpdateDateState(hooks(_.toString(activeDescendant), TOKEN_ISO_FORMAT));
196
- break;
377
+ let t26;
378
+ if ($[72] !== props.value || $[73] !== ptbrFormat || $[74] !== setMaskValue || $[75] !== setSelectedDate || $[76] !== variant) {
379
+ t26 = () => {
380
+ const date_2 = parseDateValue(props?.value ?? null, variant);
381
+ setSelectedDate(date_2.isValid() ? date_2 : null);
382
+ setMaskValue(date_2.format(ptbrFormat));
383
+ };
384
+ $[72] = props.value;
385
+ $[73] = ptbrFormat;
386
+ $[74] = setMaskValue;
387
+ $[75] = setSelectedDate;
388
+ $[76] = variant;
389
+ $[77] = t26;
390
+ } else {
391
+ t26 = $[77];
392
+ }
393
+ const t27 = props?.value;
394
+ let t28;
395
+ if ($[78] !== t27) {
396
+ t28 = [t27];
397
+ $[78] = t27;
398
+ $[79] = t28;
399
+ } else {
400
+ t28 = $[79];
401
+ }
402
+ React.useEffect(t26, t28);
403
+ const t29 = Boolean(readOnly);
404
+ const t30 = Boolean(disabled);
405
+ let t31;
406
+ if ($[80] !== calendarState || $[81] !== handleOnClickClearSelectedDate || $[82] !== handleUpdateDateState || $[83] !== hasValidDateSelected || $[84] !== inputId || $[85] !== label || $[86] !== maskedValue || $[87] !== selectedDate || $[88] !== showCalendarButton || $[89] !== showClearDateButton || $[90] !== skeletonize || $[91] !== t29 || $[92] !== t30 || $[93] !== unmaskedValue) {
407
+ t31 = {
408
+ ...calendarState,
409
+ label,
410
+ inputFieldId: inputId,
411
+ isReadOnly: t29,
412
+ isDisabled: t30,
413
+ skeletonize,
414
+ showCalendarButton,
415
+ hasValidDateSelected,
416
+ dateInputRef,
417
+ selectedDate,
418
+ unmaskedValue,
419
+ maskedValue,
420
+ showClearDateButton,
421
+ handleOnClickClearSelectedDate,
422
+ handleSelectDate: handleUpdateDateState
423
+ };
424
+ $[80] = calendarState;
425
+ $[81] = handleOnClickClearSelectedDate;
426
+ $[82] = handleUpdateDateState;
427
+ $[83] = hasValidDateSelected;
428
+ $[84] = inputId;
429
+ $[85] = label;
430
+ $[86] = maskedValue;
431
+ $[87] = selectedDate;
432
+ $[88] = showCalendarButton;
433
+ $[89] = showClearDateButton;
434
+ $[90] = skeletonize;
435
+ $[91] = t29;
436
+ $[92] = t30;
437
+ $[93] = unmaskedValue;
438
+ $[94] = t31;
439
+ } else {
440
+ t31 = $[94];
441
+ }
442
+ const contextValues = t31;
443
+ let t32;
444
+ if ($[95] !== customClassLabel || $[96] !== disabled || $[97] !== hasHintMessages || $[98] !== hasLabel || $[99] !== hintPosition || $[100] !== inputId || $[101] !== label || $[102] !== labelUppercase || $[103] !== popoverAlign || $[104] !== props.hint || $[105] !== props.required || $[106] !== readOnly || $[107] !== skeletonize || $[108] !== themePopover) {
445
+ t32 = hasLabel && /* @__PURE__ */ jsx(Label, { "data-testid": "test-date-field-label", label, inputId, hint: props?.hint, isDisabled: disabled, isReadOnly: readOnly, skeletonize, required: props?.required, hintPosition, themePopover, popoverAlign, labelUppercase, hasHintMessages, customClassLabel });
446
+ $[95] = customClassLabel;
447
+ $[96] = disabled;
448
+ $[97] = hasHintMessages;
449
+ $[98] = hasLabel;
450
+ $[99] = hintPosition;
451
+ $[100] = inputId;
452
+ $[101] = label;
453
+ $[102] = labelUppercase;
454
+ $[103] = popoverAlign;
455
+ $[104] = props.hint;
456
+ $[105] = props.required;
457
+ $[106] = readOnly;
458
+ $[107] = skeletonize;
459
+ $[108] = themePopover;
460
+ $[109] = t32;
461
+ } else {
462
+ t32 = $[109];
463
+ }
464
+ let t33;
465
+ if ($[110] !== ref) {
466
+ t33 = mergeRefs(ref, dateInputRef);
467
+ $[110] = ref;
468
+ $[111] = t33;
469
+ } else {
470
+ t33 = $[111];
471
+ }
472
+ const t34 = props?.name;
473
+ const t35 = !readOnly && !skeletonize ? 0 : -1;
474
+ let t36;
475
+ if ($[112] !== activeDescendant || $[113] !== calendarBoxOpen || $[114] !== customClass || $[115] !== disabled || $[116] !== handleOnBeforeInput || $[117] !== handleOnBlur || $[118] !== handleOnFocus || $[119] !== handleOnKeyDown || $[120] !== handleOnKeyDownCapture || $[121] !== handleOnPaste || $[122] !== hasValidationErrors || $[123] !== inputId || $[124] !== inputPlaceholder || $[125] !== maskedValue || $[126] !== readOnly || $[127] !== rest || $[128] !== skeletonize || $[129] !== t33 || $[130] !== t34 || $[131] !== t35 || $[132] !== textAlign || $[133] !== undigitable) {
476
+ t36 = /* @__PURE__ */ jsx(Input, { ...rest, ref: t33, id: inputId, name: t34, value: maskedValue, readOnly, disabled, customClass, tabIndex: t35, placeholder: inputPlaceholder, "aria-activedescendant": activeDescendant, "aria-expanded": calendarBoxOpen, "aria-controls": inputId, "aria-labelledby": inputId, "data-state-is-period-input": false, "data-testid": "test-date-field-input", "data-state-error": hasValidationErrors, "data-state-read-only": readOnly, "data-state-text-align": textAlign, "data-state-undigitable": undigitable, "data-state-skeletonize": skeletonize, onBlur: handleOnBlur, onFocus: handleOnFocus, onPaste: handleOnPaste, onKeyDown: handleOnKeyDown, onKeyDownCapture: handleOnKeyDownCapture, onBeforeInput: handleOnBeforeInput });
477
+ $[112] = activeDescendant;
478
+ $[113] = calendarBoxOpen;
479
+ $[114] = customClass;
480
+ $[115] = disabled;
481
+ $[116] = handleOnBeforeInput;
482
+ $[117] = handleOnBlur;
483
+ $[118] = handleOnFocus;
484
+ $[119] = handleOnKeyDown;
485
+ $[120] = handleOnKeyDownCapture;
486
+ $[121] = handleOnPaste;
487
+ $[122] = hasValidationErrors;
488
+ $[123] = inputId;
489
+ $[124] = inputPlaceholder;
490
+ $[125] = maskedValue;
491
+ $[126] = readOnly;
492
+ $[127] = rest;
493
+ $[128] = skeletonize;
494
+ $[129] = t33;
495
+ $[130] = t34;
496
+ $[131] = t35;
497
+ $[132] = textAlign;
498
+ $[133] = undigitable;
499
+ $[134] = t36;
500
+ } else {
501
+ t36 = $[134];
502
+ }
503
+ let t37;
504
+ if ($[135] === Symbol.for("react.memo_cache_sentinel")) {
505
+ t37 = /* @__PURE__ */ jsx(Triggers, {});
506
+ $[135] = t37;
507
+ } else {
508
+ t37 = $[135];
509
+ }
510
+ let t38;
511
+ if ($[136] !== customClassInputContainer || $[137] !== dateContainerRef || $[138] !== skeletonize || $[139] !== t36) {
512
+ t38 = /* @__PURE__ */ jsxs(Container, { ref: dateContainerRef, skeletonize, customClassInputContainer, children: [
513
+ t36,
514
+ t37
515
+ ] });
516
+ $[136] = customClassInputContainer;
517
+ $[137] = dateContainerRef;
518
+ $[138] = skeletonize;
519
+ $[139] = t36;
520
+ $[140] = t38;
521
+ } else {
522
+ t38 = $[140];
523
+ }
524
+ let t39;
525
+ if ($[141] !== activeDescendant || $[142] !== calendarBoxOpen || $[143] !== calendarDisplayDate || $[144] !== calendarRef || $[145] !== dateContainerRef || $[146] !== handleNextMonth || $[147] !== handlePreviousMonth || $[148] !== handleSelectDay || $[149] !== handleSelectTime || $[150] !== hasBounds || $[151] !== inputId || $[152] !== isDateTime || $[153] !== maxDate || $[154] !== minDate || $[155] !== selectedDate) {
526
+ t39 = calendarBoxOpen && createPortal(/* @__PURE__ */ jsx(CalendarBox, { ref: calendarRef, testIdPrefix: "test-date-field", headerId: inputId, calendarBoxOpen, activeDescendant, calendarDisplayDate, containerRef: dateContainerRef, onNextMonth: handleNextMonth, onPreviousMonth: handlePreviousMonth, getDayState: (day_0) => ({
527
+ isSelected: selectedDate ? day_0.isSame(selectedDate, "day") : false,
528
+ ...hasBounds && {
529
+ isDisabled: isDayOutOfBounds(day_0, minDate, maxDate)
197
530
  }
198
- }
199
- };
200
- React.useEffect(() => {
201
- const currentValue = props?.value ?? null;
202
- const date_2 = hooks(_.toString(currentValue), TOKEN_ISO_FORMAT);
203
- setSelectedDate(date_2.isValid() ? date_2 : null);
204
- setMaskValue(date_2.format(TOKEN_PTBR_FORMAT));
205
- }, [props?.value]);
206
- const contextValues = {
207
- label,
208
- inputFieldId: inputId,
209
- activeDescendant,
210
- calendarBoxOpen,
211
- isReadOnly: Boolean(readOnly),
212
- isDisabled: Boolean(disabled),
213
- skeletonize,
214
- showCalendarButton,
215
- hasValidDateSelected,
216
- dateInputRef,
217
- dateContainerRef,
218
- handleOpenCalendar,
219
- handleCloseCalendar,
220
- handleNextMonth,
221
- handlePreviousMonth,
222
- handleSelectDate: handleUpdateDateState,
223
- selectedDate,
224
- unmaskedValue,
225
- maskedValue,
226
- showClearDateButton,
227
- handleChangeCalendarBoxState,
228
- handleOnClickClearSelectedDate,
229
- calendarDisplayDate,
230
- calendarRef
231
- };
232
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [
233
- /* @__PURE__ */ jsx(DateFieldContext.Provider, { value: contextValues, children: /* @__PURE__ */ jsxs(Root, { ref: inputRootRef, "data-testid": "test-date-field-root", customClassWrapper, hasValidationErrors, children: [
234
- hasLabel && /* @__PURE__ */ jsx(Label, { "data-testid": "test-date-field-label", label, inputId, hint: props?.hint, isDisabled: disabled, isReadOnly: readOnly, skeletonize, required: props?.required, hintPosition, themePopover, popoverAlign, labelUppercase, hasHintMessages, customClassLabel }),
235
- /* @__PURE__ */ jsxs(Container, { ref: dateContainerRef, skeletonize, customClassInputContainer, children: [
236
- /* @__PURE__ */ jsx(Input, { ...rest, ref: mergeRefs(ref, dateInputRef), id: inputId, name: props?.name, value: maskedValue, readOnly, disabled, customClass, tabIndex: !readOnly && !skeletonize ? 0 : -1, placeholder, "aria-activedescendant": activeDescendant, "aria-expanded": calendarBoxOpen, "aria-controls": inputId, "aria-labelledby": inputId, "data-state-is-period-input": false, "data-testid": "test-date-field-input", "data-state-error": hasValidationErrors, "data-state-read-only": readOnly, "data-state-text-align": textAlign, "data-state-undigitable": undigitable, "data-state-skeletonize": skeletonize, onBlur: handleOnBlur, onFocus: handleOnFocus, onPaste: handleOnPaste, onKeyDown: handleOnKeyDown, onBeforeInput: handleOnBeforeInput }),
237
- /* @__PURE__ */ jsx(Triggers, {})
238
- ] }),
239
- calendarBoxOpen && createPortal(/* @__PURE__ */ jsx(CalendarBox, { ref: calendarRef }), document.body),
240
- hintPosition === "below" && /* @__PURE__ */ jsx(Hint, { customClass: "hint", description: props.hint, disabled, skeletonize, visible: hasHintMessages }),
241
- hasValidationErrors && /* @__PURE__ */ jsx("span", { "data-testid": "test-date-field-list-errors", className: "error", "data-state-skeletonize": skeletonize, "aria-describedby": String(props.name).concat("-errors"), children: errors?.map((error, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
242
- error,
243
- " "
244
- ] }, `${index + 1}-${error}`)) })
245
- ] }) }),
246
- /* @__PURE__ */ jsx(Tooltip, { targetRef: inputRootRef, text: tooltip, width: tooltipWidth, position: tooltipPosition })
247
- ] });
531
+ }), onSelectDay: handleSelectDay, children: isDateTime && /* @__PURE__ */ jsx(TimeSelector, { value: selectedDate, onSelectTime: handleSelectTime, min: minDate, max: maxDate, testIdPrefix: "test-date-field" }) }), document.body);
532
+ $[141] = activeDescendant;
533
+ $[142] = calendarBoxOpen;
534
+ $[143] = calendarDisplayDate;
535
+ $[144] = calendarRef;
536
+ $[145] = dateContainerRef;
537
+ $[146] = handleNextMonth;
538
+ $[147] = handlePreviousMonth;
539
+ $[148] = handleSelectDay;
540
+ $[149] = handleSelectTime;
541
+ $[150] = hasBounds;
542
+ $[151] = inputId;
543
+ $[152] = isDateTime;
544
+ $[153] = maxDate;
545
+ $[154] = minDate;
546
+ $[155] = selectedDate;
547
+ $[156] = t39;
548
+ } else {
549
+ t39 = $[156];
550
+ }
551
+ let t40;
552
+ if ($[157] !== disabled || $[158] !== hasHintMessages || $[159] !== hintPosition || $[160] !== props.hint || $[161] !== skeletonize) {
553
+ t40 = hintPosition === "below" && /* @__PURE__ */ jsx(Hint, { customClass: "hint", description: props.hint, disabled, skeletonize, visible: hasHintMessages });
554
+ $[157] = disabled;
555
+ $[158] = hasHintMessages;
556
+ $[159] = hintPosition;
557
+ $[160] = props.hint;
558
+ $[161] = skeletonize;
559
+ $[162] = t40;
560
+ } else {
561
+ t40 = $[162];
562
+ }
563
+ let t41;
564
+ if ($[163] !== errors || $[164] !== hasValidationErrors || $[165] !== props.name || $[166] !== skeletonize) {
565
+ t41 = hasValidationErrors && /* @__PURE__ */ jsx("span", { "data-testid": "test-date-field-list-errors", className: "error", "data-state-skeletonize": skeletonize, "aria-describedby": String(props.name).concat("-errors"), children: errors?.map(_temp) });
566
+ $[163] = errors;
567
+ $[164] = hasValidationErrors;
568
+ $[165] = props.name;
569
+ $[166] = skeletonize;
570
+ $[167] = t41;
571
+ } else {
572
+ t41 = $[167];
573
+ }
574
+ let t42;
575
+ if ($[168] !== customClassWrapper || $[169] !== hasValidationErrors || $[170] !== t32 || $[171] !== t38 || $[172] !== t39 || $[173] !== t40 || $[174] !== t41) {
576
+ t42 = /* @__PURE__ */ jsxs(Root, { ref: inputRootRef, "data-testid": "test-date-field-root", customClassWrapper, hasValidationErrors, children: [
577
+ t32,
578
+ t38,
579
+ t39,
580
+ t40,
581
+ t41
582
+ ] });
583
+ $[168] = customClassWrapper;
584
+ $[169] = hasValidationErrors;
585
+ $[170] = t32;
586
+ $[171] = t38;
587
+ $[172] = t39;
588
+ $[173] = t40;
589
+ $[174] = t41;
590
+ $[175] = t42;
591
+ } else {
592
+ t42 = $[175];
593
+ }
594
+ let t43;
595
+ if ($[176] !== contextValues || $[177] !== t42) {
596
+ t43 = /* @__PURE__ */ jsx(DateFieldContext.Provider, { value: contextValues, children: t42 });
597
+ $[176] = contextValues;
598
+ $[177] = t42;
599
+ $[178] = t43;
600
+ } else {
601
+ t43 = $[178];
602
+ }
603
+ let t44;
604
+ if ($[179] !== tooltip || $[180] !== tooltipPosition || $[181] !== tooltipWidth) {
605
+ t44 = /* @__PURE__ */ jsx(Tooltip, { targetRef: inputRootRef, text: tooltip, width: tooltipWidth, position: tooltipPosition });
606
+ $[179] = tooltip;
607
+ $[180] = tooltipPosition;
608
+ $[181] = tooltipWidth;
609
+ $[182] = t44;
610
+ } else {
611
+ t44 = $[182];
612
+ }
613
+ let t45;
614
+ if ($[183] !== t43 || $[184] !== t44) {
615
+ t45 = /* @__PURE__ */ jsxs(React.Fragment, { children: [
616
+ t43,
617
+ t44
618
+ ] });
619
+ $[183] = t43;
620
+ $[184] = t44;
621
+ $[185] = t45;
622
+ } else {
623
+ t45 = $[185];
624
+ }
625
+ return t45;
248
626
  });
249
627
  InputBase.displayName = "DateFieldInputBase";
628
+ function _temp(error, index) {
629
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
630
+ error,
631
+ " "
632
+ ] }, `${index + 1}-${error}`);
633
+ }
250
634
  export {
251
635
  InputBase
252
636
  };