linear-react-components-ui 1.1.25-beta.6 → 1.1.25-beta.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.
Files changed (59) hide show
  1. package/lib/{BaseMask-78847f45.d.ts → BaseMask-0c14ef51.d.ts} +1 -1
  2. package/lib/{Cnpj-8366781f.d.ts → Cnpj-53bfd6ab.d.ts} +2 -1
  3. package/lib/{Cpf-3dfd54eb.d.ts → Cpf-019b21e0.d.ts} +2 -1
  4. package/lib/{Phone-1962c0f2.d.ts → Phone-2bb0b397.d.ts} +1 -1
  5. package/lib/{ZipCode-be9c5b3b.d.ts → ZipCode-09460e18.d.ts} +1 -1
  6. package/lib/index-19761a50.d.ts +26 -0
  7. package/lib/{index-6fcf446c.d.ts → index-208e7f62.d.ts} +20 -2
  8. package/lib/{index-02a27c19.d.ts → index-3b70931d.d.ts} +20 -2
  9. package/lib/index-4bda404f.d.ts +42 -0
  10. package/lib/{index-25b80f32.d.ts → index-7dfa8924.d.ts} +1 -1
  11. package/lib/{index-6f5c772d.d.ts → index-9e576346.d.ts} +1 -1
  12. package/lib/{index-696662fe.d.ts → index-afb7b5a9.d.ts} +1 -1
  13. package/lib/inputs2/checkboxfield/index.d.ts +2 -3
  14. package/lib/inputs2/checkboxfield/index.js +125 -32
  15. package/lib/inputs2/colorfield/index.d.ts +5 -6
  16. package/lib/inputs2/date/datefield/index.js +322 -34
  17. package/lib/inputs2/date/datefield/types.d.ts +3 -5
  18. package/lib/inputs2/date/dateperiodfield/index.js +587 -34
  19. package/lib/inputs2/date/dateperiodfield/types.d.ts +3 -5
  20. package/lib/inputs2/filefield/index.d.ts +5 -6
  21. package/lib/inputs2/index.d.ts +15 -18
  22. package/lib/inputs2/mask/BaseMask.d.ts +5 -6
  23. package/lib/inputs2/mask/Cnpj.d.ts +6 -7
  24. package/lib/inputs2/mask/Cnpj.js +21 -18
  25. package/lib/inputs2/mask/Cpf.d.ts +6 -7
  26. package/lib/inputs2/mask/Cpf.js +19 -12
  27. package/lib/inputs2/mask/Phone.d.ts +6 -7
  28. package/lib/inputs2/mask/ZipCode.d.ts +6 -7
  29. package/lib/inputs2/numberfield/currency.d.ts +4 -5
  30. package/lib/inputs2/numberfield/decimal.d.ts +4 -5
  31. package/lib/inputs2/numberfield/index.d.ts +4 -5
  32. package/lib/inputs2/numberfield/types.d.ts +4 -5
  33. package/lib/inputs2/radiofield/index.d.ts +1 -1
  34. package/lib/inputs2/radiofield/index.js +126 -25
  35. package/lib/inputs2/radiofield/types.d.ts +4 -6
  36. package/lib/inputs2/selectfield/index.d.ts +1 -1
  37. package/lib/inputs2/selectfield/index.js +502 -35
  38. package/lib/inputs2/selectfield/types.d.ts +6 -8
  39. package/lib/inputs2/textareafield/index.d.ts +3 -4
  40. package/lib/inputs2/textareafield/index.js +154 -30
  41. package/lib/inputs2/textfield/index.d.ts +4 -5
  42. package/lib/inputs2/textfield/index.js +120 -30
  43. package/package.json +1 -1
  44. package/lib/index-053f615b.d.ts +0 -26
  45. package/lib/index-7159df18.d.ts +0 -21
  46. package/lib/inputs2/checkboxfield/base.d.ts +0 -29
  47. package/lib/inputs2/checkboxfield/base.js +0 -134
  48. package/lib/inputs2/date/datefield/base.d.ts +0 -13
  49. package/lib/inputs2/date/datefield/base.js +0 -330
  50. package/lib/inputs2/date/dateperiodfield/base.d.ts +0 -13
  51. package/lib/inputs2/date/dateperiodfield/base.js +0 -595
  52. package/lib/inputs2/radiofield/base.d.ts +0 -12
  53. package/lib/inputs2/radiofield/base.js +0 -156
  54. package/lib/inputs2/selectfield/base.d.ts +0 -11
  55. package/lib/inputs2/selectfield/base.js +0 -513
  56. package/lib/inputs2/textareafield/base.d.ts +0 -26
  57. package/lib/inputs2/textareafield/base.js +0 -166
  58. package/lib/inputs2/textfield/base.d.ts +0 -26
  59. package/lib/inputs2/textfield/base.js +0 -131
@@ -5,53 +5,606 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Input = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
+ var _lodash = _interopRequireDefault(require("lodash"));
9
+ var _reactImask = require("react-imask");
10
+ var _reactDom = require("react-dom");
11
+ var _moment = _interopRequireDefault(require("moment"));
12
+ var _hint = _interopRequireDefault(require("../../../hint"));
13
+ var _icons = _interopRequireDefault(require("../../../icons"));
8
14
  var _gridlayout = _interopRequireDefault(require("../../../gridlayout"));
15
+ var _tooltip = require("../../../tooltip");
16
+ var _helpers = require("../../../form2/helpers");
9
17
  var _permissionValidations = require("../../../permissionValidations");
10
- var _helpers = require("../helpers");
11
- var _base = require("./base");
12
- const _excluded = ["onDeniedActions", "permissionAttr", "disabled", "readOnly", "gridLayout"];
18
+ var _types = require("../types");
19
+ var BaseDate = _interopRequireWildcard(require("../base"));
20
+ var _helpers2 = require("../helpers");
21
+ var _triggers = require("./triggers");
22
+ var _calendarbox = require("./calendarbox");
23
+ var _context = require("./context");
24
+ const _excluded = ["label", "errors", "initialName", "finalName", "onDeniedActions", "permissionAttr", "customClass", "customClassLabel", "customClassWrapper", "customClassInputContainer", "labelUppercase", "undigitable", "skeletonize", "hintPosition", "gridLayout", "themePopover", "popoverAlign", "showCalendarButton", "textAlign", "openCalendarOnFocus", "shouldCloseOnSelect", "showPredefinedPeriodsButton", "showClearDateButton", "placeholder", "returnValueType", "tooltip", "tooltipPosition", "tooltipWidth"];
13
25
  /* eslint-disable @typescript-eslint/no-use-before-define */
26
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
14
27
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
28
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
16
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
19
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
20
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
29
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
22
30
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
23
- const Input = exports.Input = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
24
- let {
25
- onDeniedActions,
26
- permissionAttr,
27
- disabled,
28
- readOnly,
29
- gridLayout
30
- } = _ref,
31
- props = _objectWithoutProperties(_ref, _excluded);
31
+ const Input = exports.Input = /*#__PURE__*/_react.default.forwardRef((props, __) => {
32
+ var _selectedDate$inicial, _selectedDate$final, _props$hint;
33
+ const {
34
+ label,
35
+ errors,
36
+ initialName = 'inicial',
37
+ finalName = 'final',
38
+ onDeniedActions = undefined,
39
+ permissionAttr = undefined,
40
+ customClass = '',
41
+ customClassLabel = '',
42
+ customClassWrapper = '',
43
+ customClassInputContainer = '',
44
+ labelUppercase = false,
45
+ undigitable = false,
46
+ skeletonize = false,
47
+ hintPosition = 'below',
48
+ gridLayout = undefined,
49
+ themePopover = 'light',
50
+ popoverAlign = 'left',
51
+ showCalendarButton = true,
52
+ textAlign = 'left',
53
+ openCalendarOnFocus = true,
54
+ shouldCloseOnSelect = true,
55
+ showPredefinedPeriodsButton = true,
56
+ showClearDateButton = true,
57
+ placeholder = _helpers2.TOKEN_PTBR_FORMAT,
58
+ returnValueType = 'default',
59
+ tooltip,
60
+ tooltipPosition,
61
+ tooltipWidth
62
+ } = props,
63
+ rest = _objectWithoutProperties(props, _excluded);
32
64
  const onDenied = _react.default.useMemo(() => {
33
- return onDeniedActions || (0, _permissionValidations.actionsOnPermissionDenied)(_helpers.options, permissionAttr);
65
+ return onDeniedActions || (0, _permissionValidations.actionsOnPermissionDenied)(_helpers2.options, permissionAttr);
34
66
  }, [onDeniedActions, permissionAttr]);
35
67
  const {
36
68
  hideContent,
37
69
  unvisible
38
70
  } = onDenied;
39
- const isReadOnly = Boolean(readOnly || onDenied.readOnly);
40
- const isDisabled = Boolean(disabled || onDenied.disabled);
41
- const inputProps = _objectSpread({
42
- readOnly: isReadOnly,
43
- disabled: isDisabled
44
- }, props);
71
+ const [selectedDate, setSelectedDate] = _react.default.useState({
72
+ inicial: null,
73
+ final: null
74
+ });
75
+ const [calendarBoxOpen, setCalendarBoxOpen] = _react.default.useState(false);
76
+ const [activeDescendant, setActiveDescendant] = _react.default.useState((0, _moment.default)().format(_helpers2.TOKEN_ISO_FORMAT));
77
+ const [calendarDisplayDate, setCalendarDisplayDate] = _react.default.useState((0, _moment.default)());
78
+ const calendarRef = _react.default.useRef(null);
79
+ const inputRootRef = _react.default.useRef(null);
80
+ const finalInputRef = _react.default.useRef(null);
81
+ const initialInputRef = _react.default.useRef(null);
82
+ const dateContainerRef = _react.default.useRef(null);
83
+ const initialInputName = _react.default.useMemo(() => String(props.name).concat('.').concat(initialName), [props.name, initialName]);
84
+ const finalInputName = _react.default.useMemo(() => String(props.name).concat('.').concat(finalName), [props.name, finalName]);
85
+ const {
86
+ value: initialMaskedValue,
87
+ setValue: setInitialMaskValue,
88
+ unmaskedValue: initialUnmaskedValue
89
+ } = (0, _reactImask.useIMask)({
90
+ mask: _helpers2.TOKEN_MASK,
91
+ lazy: false,
92
+ placeholderChar: '_'
93
+ }, {
94
+ ref: initialInputRef,
95
+ defaultValue: (_selectedDate$inicial = selectedDate.inicial) === null || _selectedDate$inicial === void 0 ? void 0 : _selectedDate$inicial.format(_helpers2.TOKEN_PTBR_FORMAT),
96
+ onComplete: value => {
97
+ const date = (0, _moment.default)(value, _helpers2.TOKEN_PTBR_FORMAT);
98
+ if (date.isValid()) {
99
+ handleChangeUpdateDateState({
100
+ date,
101
+ inputType: 'initial',
102
+ typing: true
103
+ });
104
+ }
105
+ }
106
+ });
107
+ const {
108
+ value: finalMaskedValue,
109
+ setValue: setFinalMaskValue,
110
+ unmaskedValue: finalUnmaskedValue
111
+ } = (0, _reactImask.useIMask)({
112
+ mask: _helpers2.TOKEN_MASK,
113
+ lazy: false,
114
+ placeholderChar: '_'
115
+ }, {
116
+ ref: finalInputRef,
117
+ defaultValue: (_selectedDate$final = selectedDate.final) === null || _selectedDate$final === void 0 ? void 0 : _selectedDate$final.format(_helpers2.TOKEN_PTBR_FORMAT),
118
+ onComplete: value => {
119
+ const date = (0, _moment.default)(value, _helpers2.TOKEN_PTBR_FORMAT);
120
+ if (date.isValid()) {
121
+ handleChangeUpdateDateState({
122
+ date,
123
+ inputType: 'final',
124
+ typing: true
125
+ });
126
+ }
127
+ }
128
+ });
129
+ const hasLabel = !_lodash.default.isEmpty(props === null || props === void 0 ? void 0 : props.label);
130
+ const isReadOnly = Boolean(props.readOnly || onDenied.readOnly);
131
+ const isDisabled = Boolean(props.disabled || onDenied.disabled);
132
+ const hasHintMessages = Boolean((_props$hint = props.hint) === null || _props$hint === void 0 ? void 0 : _props$hint.length);
133
+ const hasValidationErrors = Boolean(errors === null || errors === void 0 ? void 0 : errors.length);
134
+ const handleChangeSelectedDate = _react.default.useCallback(object => setSelectedDate(object), []);
135
+ const handleChangeCalendarBoxState = _react.default.useCallback(value => setCalendarBoxOpen(value), []);
136
+ const handleChangeActiveDescendant = _react.default.useCallback(value => setActiveDescendant(value), []);
137
+ const handleChangeCalendarDisplayDate = _react.default.useCallback(value => setCalendarDisplayDate(value), []);
138
+ const handleChangePreviousMonth = _react.default.useCallback(() => setCalendarDisplayDate(prevDisplayDate => prevDisplayDate.clone().subtract(1, 'month')), []);
139
+ const handleChangeNextMonth = _react.default.useCallback(() => setCalendarDisplayDate(prevDisplayDate => prevDisplayDate.clone().add(1, 'month')), []);
140
+ const handleNavigateWithDays = _react.default.useCallback(offset => {
141
+ setCalendarDisplayDate(prevDisplayDate => {
142
+ const daySelected = prevDisplayDate.clone().add(offset, 'day');
143
+ handleChangeActiveDescendant(daySelected.format(_helpers2.TOKEN_ISO_FORMAT));
144
+ return daySelected;
145
+ });
146
+ }, []);
147
+ const handleNavigateWithWeeks = _react.default.useCallback(when => {
148
+ setCalendarDisplayDate(prevDisplayDate => {
149
+ let daySelected = prevDisplayDate;
150
+ if (when === 'end') daySelected = prevDisplayDate.clone().endOf('week');
151
+ if (when === 'start') daySelected = prevDisplayDate.clone().startOf('week');
152
+ handleChangeActiveDescendant(daySelected.format(_helpers2.TOKEN_ISO_FORMAT));
153
+ return daySelected;
154
+ });
155
+ }, []);
156
+ const verifyPeriodSelectedIsValid = _react.default.useCallback(() => {
157
+ const objectValue = props === null || props === void 0 ? void 0 : props.value;
158
+ const isValidInitialValue = !_lodash.default.isEmpty(objectValue[initialName]);
159
+ const isValidFinalValue = !_lodash.default.isEmpty(objectValue[finalName]);
160
+ return isValidInitialValue && isValidFinalValue;
161
+ }, [props === null || props === void 0 ? void 0 : props.value, initialName, finalName]);
162
+ const handleOnClickClearSelectedPeriod = _react.default.useCallback(() => {
163
+ var _props$onChange;
164
+ (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, {
165
+ target: {
166
+ name: props.name,
167
+ value: {
168
+ [initialName]: '',
169
+ [finalName]: ''
170
+ }
171
+ }
172
+ });
173
+ setSelectedDate(() => ({
174
+ inicial: null,
175
+ final: null
176
+ }));
177
+ setInitialMaskValue('');
178
+ setFinalMaskValue('');
179
+ handleChangeCalendarBoxState(false);
180
+ }, [props.onChange]);
181
+ const handleChangeUpdateDateState = _react.default.useCallback(params => {
182
+ const {
183
+ date,
184
+ inputType,
185
+ typing
186
+ } = params;
187
+ const rawDate = date.clone();
188
+ const verifyDateRangeOrder = (initialDate, finalDate) => {
189
+ const inicial = initialDate !== null && initialDate !== void 0 && initialDate.isAfter(finalDate) ? finalDate : initialDate;
190
+ const final = initialDate !== null && initialDate !== void 0 && initialDate.isAfter(finalDate) ? initialDate : finalDate;
191
+ return {
192
+ inicial,
193
+ final
194
+ };
195
+ };
196
+ switch (inputType) {
197
+ case 'initial':
198
+ {
199
+ var _props$onChange2;
200
+ setSelectedDate(prevSelectedDate => {
201
+ const {
202
+ inicial,
203
+ final
204
+ } = verifyDateRangeOrder(rawDate, prevSelectedDate.final);
205
+ const updatedState = {
206
+ inicial,
207
+ final
208
+ };
209
+ return updatedState;
210
+ });
211
+ const {
212
+ inicial,
213
+ final
214
+ } = verifyDateRangeOrder(rawDate, selectedDate.final);
215
+ (_props$onChange2 = props.onChange) === null || _props$onChange2 === void 0 ? void 0 : _props$onChange2.call(props, {
216
+ target: {
217
+ name: props.name,
218
+ value: {
219
+ [initialName]: returnValueType === 'default' ? inicial === null || inicial === void 0 ? void 0 : inicial.format(_helpers2.TOKEN_ISO_FORMAT) : inicial === null || inicial === void 0 ? void 0 : inicial.toISOString(),
220
+ [finalName]: returnValueType === 'default' ? final === null || final === void 0 ? void 0 : final.format(_helpers2.TOKEN_ISO_FORMAT) : final === null || final === void 0 ? void 0 : final.toISOString()
221
+ }
222
+ }
223
+ });
224
+ requestAnimationFrame(() => {
225
+ var _finalInputRef$curren, _finalInputRef$curren2;
226
+ if (!typing) (_finalInputRef$curren = finalInputRef.current) === null || _finalInputRef$curren === void 0 ? void 0 : (_finalInputRef$curren2 = _finalInputRef$curren.focus) === null || _finalInputRef$curren2 === void 0 ? void 0 : _finalInputRef$curren2.call(_finalInputRef$curren);
227
+ });
228
+ break;
229
+ }
230
+ case 'final':
231
+ {
232
+ var _props$onChange3;
233
+ setSelectedDate(prevSelectedDate => {
234
+ const {
235
+ inicial,
236
+ final
237
+ } = verifyDateRangeOrder(prevSelectedDate.inicial, rawDate);
238
+ const updatedState = {
239
+ inicial,
240
+ final
241
+ };
242
+ return updatedState;
243
+ });
244
+ const {
245
+ inicial,
246
+ final
247
+ } = verifyDateRangeOrder(selectedDate.inicial, rawDate);
248
+ (_props$onChange3 = props.onChange) === null || _props$onChange3 === void 0 ? void 0 : _props$onChange3.call(props, {
249
+ target: {
250
+ name: props.name,
251
+ value: {
252
+ [initialName]: returnValueType === 'default' ? inicial === null || inicial === void 0 ? void 0 : inicial.format(_helpers2.TOKEN_ISO_FORMAT) : inicial === null || inicial === void 0 ? void 0 : inicial.toISOString(),
253
+ [finalName]: returnValueType === 'default' ? final === null || final === void 0 ? void 0 : final.format(_helpers2.TOKEN_ISO_FORMAT) : final === null || final === void 0 ? void 0 : final.toISOString()
254
+ }
255
+ }
256
+ });
257
+ if (shouldCloseOnSelect) handleChangeCalendarBoxState(false);
258
+ break;
259
+ }
260
+ default:
261
+ break;
262
+ }
263
+ setCalendarDisplayDate(rawDate.clone());
264
+ }, [props.name, props.onChange, initialName, finalName, selectedDate, shouldCloseOnSelect]);
265
+ const handleChangeUpdateDateStateWithPredefinedPeriod = _react.default.useCallback(period => {
266
+ var _finalInputRef$curren3, _finalInputRef$curren4;
267
+ const localOnChange = (initialDate, finalDate) => {
268
+ var _props$onChange4;
269
+ const valueToUpdate = {
270
+ [initialName]: returnValueType === 'default' ? initialDate.format(_helpers2.TOKEN_ISO_FORMAT) : initialDate.toISOString(),
271
+ [finalName]: returnValueType === 'default' ? finalDate.format(_helpers2.TOKEN_ISO_FORMAT) : finalDate.toISOString()
272
+ };
273
+ setSelectedDate(() => {
274
+ const updatedState = {
275
+ inicial: initialDate.clone(),
276
+ final: finalDate.clone()
277
+ };
278
+ return updatedState;
279
+ });
280
+ (_props$onChange4 = props.onChange) === null || _props$onChange4 === void 0 ? void 0 : _props$onChange4.call(props, {
281
+ target: {
282
+ name: props.name,
283
+ value: valueToUpdate
284
+ }
285
+ });
286
+ };
287
+ switch (period) {
288
+ case 'today':
289
+ {
290
+ const date = (0, _moment.default)();
291
+ localOnChange(date, date);
292
+ break;
293
+ }
294
+ case 'week':
295
+ {
296
+ const startOfWeek = (0, _moment.default)().startOf('week');
297
+ const endOfWeek = (0, _moment.default)().endOf('week');
298
+ localOnChange(startOfWeek, endOfWeek);
299
+ break;
300
+ }
301
+ case 'lastweek':
302
+ {
303
+ const startOfLastWeek = (0, _moment.default)().add(-1, 'week').startOf('week');
304
+ const endOfLastWeek = (0, _moment.default)().add(-1, 'week').endOf('week');
305
+ localOnChange(startOfLastWeek, endOfLastWeek);
306
+ break;
307
+ }
308
+ case 'last15':
309
+ {
310
+ const startOfLastFifteenDays = (0, _moment.default)().add(-14, 'd');
311
+ const endOfLastFifteenDays = (0, _moment.default)();
312
+ localOnChange(startOfLastFifteenDays, endOfLastFifteenDays);
313
+ break;
314
+ }
315
+ case 'month':
316
+ {
317
+ const startOfMonth = (0, _moment.default)().startOf('month');
318
+ const endOfMonth = (0, _moment.default)().endOf('month');
319
+ localOnChange(startOfMonth, endOfMonth);
320
+ break;
321
+ }
322
+ case 'lastmonth':
323
+ {
324
+ const startOfMonth = (0, _moment.default)().add(-1, 'month').startOf('month');
325
+ const endOfMonth = (0, _moment.default)().add(-1, 'month').endOf('month');
326
+ localOnChange(startOfMonth, endOfMonth);
327
+ break;
328
+ }
329
+ default:
330
+ break;
331
+ }
332
+ finalInputRef === null || finalInputRef === void 0 ? void 0 : (_finalInputRef$curren3 = finalInputRef.current) === null || _finalInputRef$curren3 === void 0 ? void 0 : (_finalInputRef$curren4 = _finalInputRef$curren3.focus) === null || _finalInputRef$curren4 === void 0 ? void 0 : _finalInputRef$curren4.call(_finalInputRef$curren3);
333
+ if (shouldCloseOnSelect) handleChangeCalendarBoxState(false);
334
+ }, [props.name, props.onChange, initialName, finalName]);
335
+ const handleOnBlurMaskInput = (event, inputType) => {
336
+ var _props$onBlur;
337
+ props === null || props === void 0 ? void 0 : (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 ? void 0 : _props$onBlur.call(props, event);
338
+ if (inputType === 'initial') {
339
+ var _event$relatedTarget;
340
+ if (((_event$relatedTarget = event.relatedTarget) === null || _event$relatedTarget === void 0 ? void 0 : _event$relatedTarget.id) !== finalInputName) handleChangeCalendarBoxState(false);
341
+ if (calendarBoxOpen) {
342
+ var _selectedDate$inicial2, _selectedDate$inicial3;
343
+ handleChangeActiveDescendant(((_selectedDate$inicial2 = selectedDate.inicial) !== null && _selectedDate$inicial2 !== void 0 ? _selectedDate$inicial2 : (0, _moment.default)()).format(_helpers2.TOKEN_ISO_FORMAT));
344
+ setCalendarDisplayDate((_selectedDate$inicial3 = selectedDate.inicial) !== null && _selectedDate$inicial3 !== void 0 ? _selectedDate$inicial3 : (0, _moment.default)());
345
+ }
346
+ if (_lodash.default.size(initialUnmaskedValue) !== 8) {
347
+ const date = (0, _moment.default)(selectedDate.inicial, _helpers2.TOKEN_ISO_FORMAT);
348
+ if (date.isValid()) {
349
+ setInitialMaskValue(date.format(_helpers2.TOKEN_PTBR_FORMAT));
350
+ }
351
+ }
352
+ }
353
+ if (inputType === 'final') {
354
+ var _event$relatedTarget2;
355
+ if (((_event$relatedTarget2 = event.relatedTarget) === null || _event$relatedTarget2 === void 0 ? void 0 : _event$relatedTarget2.id) !== initialInputName) handleChangeCalendarBoxState(false);
356
+ if (calendarBoxOpen) {
357
+ var _selectedDate$final2, _selectedDate$final3;
358
+ handleChangeActiveDescendant(((_selectedDate$final2 = selectedDate.final) !== null && _selectedDate$final2 !== void 0 ? _selectedDate$final2 : (0, _moment.default)()).format(_helpers2.TOKEN_ISO_FORMAT));
359
+ setCalendarDisplayDate((_selectedDate$final3 = selectedDate.final) !== null && _selectedDate$final3 !== void 0 ? _selectedDate$final3 : (0, _moment.default)());
360
+ }
361
+ if (_lodash.default.size(finalUnmaskedValue) !== 8) {
362
+ const date = (0, _moment.default)(selectedDate.final, _helpers2.TOKEN_ISO_FORMAT);
363
+ if (date.isValid()) {
364
+ setFinalMaskValue(date.format(_helpers2.TOKEN_PTBR_FORMAT));
365
+ }
366
+ }
367
+ }
368
+ };
369
+ const handleOnFocusMaskInput = (event, inputType) => {
370
+ var _props$onFocus;
371
+ props === null || props === void 0 ? void 0 : (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event);
372
+ if (!isReadOnly && !calendarBoxOpen && openCalendarOnFocus) {
373
+ setCalendarBoxOpen(true);
374
+ }
375
+ if (inputType === 'initial') {
376
+ var _selectedDate$inicial4, _selectedDate$inicial5;
377
+ handleChangeActiveDescendant(((_selectedDate$inicial4 = selectedDate.inicial) !== null && _selectedDate$inicial4 !== void 0 ? _selectedDate$inicial4 : (0, _moment.default)()).format(_helpers2.TOKEN_ISO_FORMAT));
378
+ setCalendarDisplayDate((_selectedDate$inicial5 = selectedDate.inicial) !== null && _selectedDate$inicial5 !== void 0 ? _selectedDate$inicial5 : (0, _moment.default)());
379
+ }
380
+ if (inputType === 'final') {
381
+ var _selectedDate$final4, _selectedDate$final5;
382
+ handleChangeActiveDescendant(((_selectedDate$final4 = selectedDate.final) !== null && _selectedDate$final4 !== void 0 ? _selectedDate$final4 : (0, _moment.default)()).format(_helpers2.TOKEN_ISO_FORMAT));
383
+ setCalendarDisplayDate((_selectedDate$final5 = selectedDate.final) !== null && _selectedDate$final5 !== void 0 ? _selectedDate$final5 : (0, _moment.default)());
384
+ }
385
+ };
386
+ const handleOnKeyDownMaskInput = (event, inputType) => {
387
+ var _props$onKeyDown;
388
+ props === null || props === void 0 ? void 0 : (_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 ? void 0 : _props$onKeyDown.call(props, event);
389
+ if (calendarBoxOpen && event.key && !event.shiftKey && !event.altKey && event.key === _types.Keys.enter) {
390
+ event.preventDefault();
391
+ const rawDate = (0, _moment.default)(_lodash.default.toString(activeDescendant), _helpers2.TOKEN_ISO_FORMAT);
392
+ handleChangeUpdateDateState({
393
+ date: rawDate,
394
+ inputType
395
+ });
396
+ }
397
+ };
398
+ const handleOnPaste = event => {
399
+ if (undigitable) {
400
+ event.preventDefault();
401
+ } else {
402
+ var _props$onPaste;
403
+ (_props$onPaste = props.onPaste) === null || _props$onPaste === void 0 ? void 0 : _props$onPaste.call(props, event);
404
+ }
405
+ };
406
+ const handleOnBeforeInput = event => {
407
+ if (undigitable) {
408
+ event.preventDefault();
409
+ } else {
410
+ var _props$onBeforeInput;
411
+ (_props$onBeforeInput = props.onBeforeInput) === null || _props$onBeforeInput === void 0 ? void 0 : _props$onBeforeInput.call(props, event);
412
+ }
413
+ };
414
+ const handleOnKeyDown = event => {
415
+ if (calendarBoxOpen && event.key && !event.shiftKey && !event.altKey && _helpers2.NAVIGATION_KEYS.includes(event.key)) {
416
+ event.preventDefault();
417
+ switch (event.key) {
418
+ case _types.Keys.arrowLeft:
419
+ handleNavigateWithDays(-1);
420
+ break;
421
+ case _types.Keys.arrowRight:
422
+ handleNavigateWithDays(1);
423
+ break;
424
+ case _types.Keys.arrowUp:
425
+ handleNavigateWithDays(-7);
426
+ break;
427
+ case _types.Keys.arrowDown:
428
+ handleNavigateWithDays(7);
429
+ break;
430
+ case _types.Keys.pageUp:
431
+ handleChangeNextMonth();
432
+ break;
433
+ case _types.Keys.pageDown:
434
+ handleChangePreviousMonth();
435
+ break;
436
+ case _types.Keys.home:
437
+ handleNavigateWithWeeks('start');
438
+ break;
439
+ case _types.Keys.end:
440
+ handleNavigateWithWeeks('end');
441
+ break;
442
+ case _types.Keys.escape:
443
+ handleChangeCalendarBoxState(false);
444
+ break;
445
+ default:
446
+ break;
447
+ }
448
+ }
449
+ };
450
+ _react.default.useEffect(() => {
451
+ if (props !== null && props !== void 0 && props.value) {
452
+ const objectValue = props.value;
453
+ const initialDate = (0, _moment.default)(_lodash.default.toString(objectValue[initialName]), _helpers2.TOKEN_ISO_FORMAT);
454
+ const finalDate = (0, _moment.default)(_lodash.default.toString(objectValue[finalName]), _helpers2.TOKEN_ISO_FORMAT);
455
+ setSelectedDate(() => ({
456
+ inicial: initialDate.isValid() ? initialDate : null,
457
+ final: finalDate.isValid() ? finalDate : null
458
+ }));
459
+ setInitialMaskValue(initialDate.format(_helpers2.TOKEN_PTBR_FORMAT));
460
+ setFinalMaskValue(finalDate.format(_helpers2.TOKEN_PTBR_FORMAT));
461
+ }
462
+ }, [props === null || props === void 0 ? void 0 : props.value]);
463
+ const contextValues = _react.default.useMemo(() => ({
464
+ isReadOnly,
465
+ isDisabled,
466
+ undigitable,
467
+ skeletonize,
468
+ dateContainerRef,
469
+ calendarBoxOpen,
470
+ activeDescendant,
471
+ selectedDate,
472
+ initialInputId: initialInputName,
473
+ finalInputId: finalInputName,
474
+ initialInputRef,
475
+ finalInputRef,
476
+ showCalendarButton,
477
+ calendarDisplayDate,
478
+ hasValidationErrors,
479
+ openCalendarOnFocus,
480
+ showPredefinedPeriodsButton,
481
+ showClearDateButton,
482
+ handleChangeSelectedDate,
483
+ handleChangePreviousMonth,
484
+ handleChangeNextMonth,
485
+ handleChangeCalendarBoxState,
486
+ handleChangeActiveDescendant,
487
+ handleChangeCalendarDisplayDate,
488
+ handleChangeUpdateDateState,
489
+ handleOnClickClearSelectedPeriod,
490
+ handleChangeUpdateDateStateWithPredefinedPeriod,
491
+ hasValidPeriodSelected: verifyPeriodSelectedIsValid()
492
+ }), [isReadOnly, isDisabled, undigitable, skeletonize, initialInputName, finalInputName, selectedDate, calendarBoxOpen, activeDescendant, calendarDisplayDate, hasValidationErrors, openCalendarOnFocus, showClearDateButton]);
45
493
  if (unvisible || hideContent) return null;
46
- if (gridLayout) {
47
- return /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
48
- cols: gridLayout
49
- }, /*#__PURE__*/_react.default.createElement(_base.InputBase, _extends({
50
- ref: ref
51
- }, inputProps)));
52
- }
53
- return /*#__PURE__*/_react.default.createElement(_base.InputBase, _extends({
54
- ref: ref
55
- }, inputProps));
494
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
495
+ cols: gridLayout
496
+ }, /*#__PURE__*/_react.default.createElement(_context.DatePeriodFieldContext.Provider, {
497
+ value: contextValues
498
+ }, /*#__PURE__*/_react.default.createElement(BaseDate.Root, {
499
+ ref: inputRootRef,
500
+ "data-testid": "test-date-period-field-root",
501
+ "data-state-error": hasValidationErrors,
502
+ customClassWrapper: customClassWrapper
503
+ }, hasLabel && /*#__PURE__*/_react.default.createElement(BaseDate.Label, {
504
+ "data-testid": "test-date-period-field-label",
505
+ label: label,
506
+ inputId: initialInputName,
507
+ hint: props === null || props === void 0 ? void 0 : props.hint,
508
+ isDisabled: isDisabled,
509
+ isReadOnly: isReadOnly,
510
+ skeletonize: skeletonize,
511
+ required: props === null || props === void 0 ? void 0 : props.required,
512
+ hintPosition: hintPosition,
513
+ themePopover: themePopover,
514
+ popoverAlign: popoverAlign,
515
+ labelUppercase: labelUppercase,
516
+ hasHintMessages: hasHintMessages,
517
+ customClassLabel: customClassLabel
518
+ }), /*#__PURE__*/_react.default.createElement(BaseDate.Container, {
519
+ ref: dateContainerRef,
520
+ "data-testid": "test-date-period-field-container",
521
+ onKeyDown: handleOnKeyDown,
522
+ skeletonize: skeletonize,
523
+ customClassInputContainer: customClassInputContainer
524
+ }, /*#__PURE__*/_react.default.createElement(BaseDate.Input, _extends({}, _lodash.default.omit(rest, ['initialRef', 'finalRef']), {
525
+ ref: (0, _helpers.mergeRefs)(initialInputRef, props === null || props === void 0 ? void 0 : props.initialRef),
526
+ id: initialInputName,
527
+ name: initialInputName,
528
+ value: initialMaskedValue,
529
+ readOnly: isReadOnly,
530
+ disabled: isDisabled,
531
+ customClass: customClass,
532
+ tabIndex: !isReadOnly && !skeletonize ? 0 : -1,
533
+ placeholder: placeholder,
534
+ "aria-autocomplete": "list",
535
+ "aria-activedescendant": activeDescendant,
536
+ "aria-expanded": calendarBoxOpen,
537
+ "aria-controls": initialInputName,
538
+ "aria-labelledby": initialInputName,
539
+ "data-testid": "test-date-period-field-initial-input",
540
+ "data-state-is-period-input": true,
541
+ "data-state-error": hasValidationErrors,
542
+ "data-state-read-only": isReadOnly,
543
+ "data-state-text-align": textAlign,
544
+ "data-state-undigitable": undigitable,
545
+ "data-state-skeletonize": skeletonize,
546
+ onPaste: handleOnPaste,
547
+ onBeforeInput: handleOnBeforeInput,
548
+ onBlur: event => handleOnBlurMaskInput(event, 'initial'),
549
+ onFocus: event => handleOnFocusMaskInput(event, 'initial'),
550
+ onKeyDown: event => handleOnKeyDownMaskInput(event, 'initial')
551
+ })), /*#__PURE__*/_react.default.createElement("span", {
552
+ className: "separator",
553
+ "data-state-disabled": isDisabled,
554
+ "data-state-read-only": isReadOnly,
555
+ onMouseDown: event => {
556
+ event.preventDefault();
557
+ }
558
+ }, /*#__PURE__*/_react.default.createElement(_icons.default, {
559
+ name: "arrow_right",
560
+ size: 10
561
+ })), /*#__PURE__*/_react.default.createElement(BaseDate.Input, _extends({}, _lodash.default.omit(rest, ['initialRef', 'finalRef']), {
562
+ ref: (0, _helpers.mergeRefs)(finalInputRef, props === null || props === void 0 ? void 0 : props.finalRef),
563
+ id: finalInputName,
564
+ name: finalInputName,
565
+ value: finalMaskedValue,
566
+ readOnly: isReadOnly,
567
+ disabled: isDisabled,
568
+ customClass: customClass,
569
+ tabIndex: !isReadOnly && !skeletonize ? 0 : -1,
570
+ placeholder: placeholder,
571
+ "aria-autocomplete": "list",
572
+ "aria-activedescendant": activeDescendant,
573
+ "aria-expanded": calendarBoxOpen,
574
+ "aria-controls": finalInputName,
575
+ "aria-labelledby": finalInputName,
576
+ "data-testid": "test-date-period-field-final-input",
577
+ "data-state-is-period-input": true,
578
+ "data-state-error": hasValidationErrors,
579
+ "data-state-read-only": isReadOnly,
580
+ "data-state-text-align": textAlign,
581
+ "data-state-undigitable": undigitable,
582
+ "data-state-skeletonize": skeletonize,
583
+ onPaste: handleOnPaste,
584
+ onBeforeInput: handleOnBeforeInput,
585
+ onBlur: event => handleOnBlurMaskInput(event, 'final'),
586
+ onFocus: event => handleOnFocusMaskInput(event, 'final'),
587
+ onKeyDown: event => handleOnKeyDownMaskInput(event, 'final')
588
+ })), /*#__PURE__*/_react.default.createElement(_triggers.Triggers, null)), calendarBoxOpen && !hideContent && /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement(_calendarbox.CalendarBox, {
589
+ ref: calendarRef
590
+ }), document.body), hintPosition === 'below' && /*#__PURE__*/_react.default.createElement(_hint.default, {
591
+ customClass: "hint",
592
+ description: props.hint,
593
+ disabled: isDisabled,
594
+ skeletonize: skeletonize,
595
+ visible: hasHintMessages
596
+ }), hasValidationErrors && /*#__PURE__*/_react.default.createElement("span", {
597
+ "data-testid": "test-date-period-field-list-errors",
598
+ className: "error",
599
+ "data-state-skeletonize": skeletonize,
600
+ "aria-describedby": String(label).concat('-errors')
601
+ }, errors === null || errors === void 0 ? void 0 : errors.map((error, index) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
602
+ key: "".concat(index + 1, "-").concat(error)
603
+ }, error, "\xA0")))))), /*#__PURE__*/_react.default.createElement(_tooltip.Tooltip, {
604
+ targetRef: inputRootRef,
605
+ text: tooltip,
606
+ width: tooltipWidth,
607
+ position: tooltipPosition
608
+ }));
56
609
  });
57
610
  Input.displayName = 'DatePeriodFieldInput';
@@ -23,7 +23,7 @@ type UpdateDateStateParams = {
23
23
  typing?: boolean;
24
24
  };
25
25
  type InputHTMLProps = Omit<React__default.ComponentPropsWithoutRef<'input'>, 'type' | 'multiple' | 'value'>;
26
- interface DatePeriodFieldBaseProps extends InputHTMLProps, ITooltipCommonProps {
26
+ interface DatePeriodFieldProps extends InputHTMLProps, ITooltipCommonProps {
27
27
  value?: any;
28
28
  initialName?: string;
29
29
  initialRef?: React__default.MutableRefObject<HTMLInputElement | null>;
@@ -32,6 +32,7 @@ interface DatePeriodFieldBaseProps extends InputHTMLProps, ITooltipCommonProps {
32
32
  hint?: string;
33
33
  label?: string;
34
34
  errors?: string[];
35
+ gridLayout?: string;
35
36
  customClass?: string;
36
37
  customClassLabel?: string;
37
38
  customClassWrapper?: string;
@@ -52,9 +53,6 @@ interface DatePeriodFieldBaseProps extends InputHTMLProps, ITooltipCommonProps {
52
53
  hintPosition?: HintPosition;
53
54
  themePopover?: ColorTheme;
54
55
  popoverAlign?: Extract<Position, 'left' | 'right'>;
55
- }
56
- interface DatePeriodFieldProps extends DatePeriodFieldBaseProps {
57
- gridLayout?: string;
58
56
  permissionAttr?: PermissionAttr;
59
57
  onDeniedActions?: OnDenied;
60
58
  }
@@ -100,4 +98,4 @@ declare enum Keys {
100
98
  enter = "Enter"
101
99
  }
102
100
 
103
- export { DatePeriodContextProps, DatePeriodFieldBaseProps, DatePeriodFieldProps, DatePeriodTypes, InputType, Keys, PeriodOptions, SelectedDateType, UpdateDateStateParams };
101
+ export { DatePeriodContextProps, DatePeriodFieldProps, DatePeriodTypes, InputType, Keys, PeriodOptions, SelectedDateType, UpdateDateStateParams };