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

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