linear-react-components-ui 1.1.21-beta.3 → 1.1.21-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/assets/styles/button.scss +1 -0
- package/lib/assets/styles/calendar.scss +64 -30
- package/lib/assets/styles/datepicker.scss +26 -6
- package/lib/assets/styles/periodpicker.scss +60 -20
- package/lib/assets/styles/sidenav.scss +1 -1
- package/lib/assets/styles/tabs.scss +48 -18
- package/lib/buttons/DefaultButton.js +6 -3
- package/lib/buttons/types.d.ts +1 -0
- package/lib/calendar/DangerCalendar.d.ts +1 -0
- package/lib/calendar/InfoCalendar.d.ts +1 -0
- package/lib/calendar/PrimaryCalendar.d.ts +1 -0
- package/lib/calendar/SuccessCalendar.d.ts +1 -0
- package/lib/calendar/WarningCalendar.d.ts +1 -0
- package/lib/calendar/base/Day.d.ts +1 -0
- package/lib/calendar/base/Day.js +6 -2
- package/lib/calendar/base/Month.d.ts +2 -1
- package/lib/calendar/base/Month.js +2 -0
- package/lib/calendar/base/Week.d.ts +1 -0
- package/lib/calendar/base/index.d.ts +1 -0
- package/lib/calendar/base/index.js +61 -13
- package/lib/calendar/index.d.ts +1 -0
- package/lib/calendar/types.d.ts +5 -0
- package/lib/dialog/base/Content.js +5 -4
- package/lib/dialog/base/Header.js +0 -1
- package/lib/dialog/base/index.js +26 -3
- package/lib/drawer/Drawer.js +1 -1
- package/lib/dropdown/Popup.d.ts +2 -2
- package/lib/dropdown/Popup.js +38 -17
- package/lib/dropdown/types.d.ts +7 -3
- package/lib/dropdown/withDropdown.js +5 -4
- package/lib/form/Field.js +11 -2
- package/lib/form/FieldArray.js +11 -2
- package/lib/form/FieldNumber.js +10 -1
- package/lib/form/FieldPeriod.js +15 -12
- package/lib/form/index.d.ts +1 -1
- package/lib/form/index.js +30 -5
- package/lib/form/types.d.ts +13 -1
- package/lib/form/withFieldHOC.js +4 -2
- package/lib/inputs/base/InputTextBase.js +9 -2
- package/lib/inputs/base/types.d.ts +2 -0
- package/lib/inputs/date/Dialog.js +5 -4
- package/lib/inputs/date/Dropdown.js +13 -7
- package/lib/inputs/date/helpers.d.ts +31 -11
- package/lib/inputs/date/helpers.js +32 -15
- package/lib/inputs/date/index.js +142 -102
- package/lib/inputs/date/types.d.ts +8 -6
- package/lib/inputs/mask/BaseMask.d.ts +1 -1
- package/lib/inputs/mask/BaseMask.js +6 -4
- package/lib/inputs/mask/helpers.d.ts +6 -53
- package/lib/inputs/mask/helpers.js +15 -35
- package/lib/inputs/mask/types.d.ts +1 -0
- package/lib/inputs/number/BaseNumber.d.ts +1 -1
- package/lib/inputs/number/BaseNumber.js +9 -2
- package/lib/inputs/number/Currency.d.ts +1 -1
- package/lib/inputs/number/Currency.js +11 -4
- package/lib/inputs/period/Dialog.d.ts +1 -1
- package/lib/inputs/period/Dialog.js +5 -3
- package/lib/inputs/period/Dropdown.js +16 -8
- package/lib/inputs/period/PeriodList.js +3 -12
- package/lib/inputs/period/index.js +210 -74
- package/lib/inputs/period/types.d.ts +10 -8
- package/lib/inputs/select/ActionButtons.js +3 -2
- package/lib/inputs/select/Dropdown.js +4 -2
- package/lib/inputs/select/multiple/index.js +10 -4
- package/lib/inputs/select/simple/index.js +10 -4
- package/lib/inputs/select/types.d.ts +4 -0
- package/lib/inputs/types.d.ts +1 -0
- package/lib/popover/PopoverText.d.ts +1 -0
- package/lib/popover/PopoverTitle.d.ts +1 -0
- package/lib/popover/index.d.ts +3 -5
- package/lib/popover/index.js +21 -15
- package/lib/popover/types.d.ts +11 -0
- package/lib/tabs/DropdownTabs.js +21 -7
- package/lib/tabs/Menu.d.ts +1 -1
- package/lib/tabs/Menu.js +4 -2
- package/lib/tabs/MenuTabs.js +16 -5
- package/lib/tabs/context.d.ts +1 -1
- package/lib/tabs/context.js +6 -4
- package/lib/tabs/index.d.ts +1 -1
- package/lib/tabs/index.js +13 -6
- package/lib/tabs/types.d.ts +8 -1
- package/lib/toolbar/types.d.ts +2 -1
- package/package.json +1 -1
package/lib/inputs/date/index.js
CHANGED
|
@@ -6,21 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _moment = _interopRequireDefault(require("moment"));
|
|
9
|
-
var
|
|
10
|
-
var _Dropdown = _interopRequireDefault(require("./Dropdown"));
|
|
11
|
-
var _calendar = _interopRequireDefault(require("../../calendar"));
|
|
12
|
-
require("../../assets/styles/datepicker.scss");
|
|
13
|
-
var contants = _interopRequireWildcard(require("../../internals/constants"));
|
|
9
|
+
var _gridlayout = _interopRequireDefault(require("../../gridlayout"));
|
|
14
10
|
var _buttons = _interopRequireDefault(require("../../buttons"));
|
|
15
|
-
var
|
|
11
|
+
var _calendar = _interopRequireDefault(require("../../calendar"));
|
|
16
12
|
var _Dialog = _interopRequireDefault(require("./Dialog"));
|
|
13
|
+
var _Dropdown = _interopRequireDefault(require("./Dropdown"));
|
|
17
14
|
var _helpers = require("./helpers");
|
|
15
|
+
require("../../assets/styles/datepicker.scss");
|
|
16
|
+
var _BaseMask = _interopRequireDefault(require("../mask/BaseMask"));
|
|
18
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
20
|
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); }
|
|
22
|
-
const CALENDAR_BUTTON_WIDTH = 24;
|
|
23
|
-
const CALENDAR_MIN_WIDTH = 250;
|
|
24
21
|
const DatePicker = props => {
|
|
25
22
|
const {
|
|
26
23
|
showButtonOpen = true,
|
|
@@ -33,75 +30,110 @@ const DatePicker = props => {
|
|
|
33
30
|
name = '',
|
|
34
31
|
inputRef: inputRefProp,
|
|
35
32
|
dialogSize = {
|
|
36
|
-
width: '
|
|
37
|
-
height: '
|
|
38
|
-
}
|
|
33
|
+
width: '384px',
|
|
34
|
+
height: '384px'
|
|
35
|
+
},
|
|
36
|
+
gridLayout,
|
|
37
|
+
shouldCloseOnEsc = true,
|
|
38
|
+
isDateTimeField = false
|
|
39
39
|
} = props;
|
|
40
|
+
const maskFormat = !isDateTimeField ? '00/00/0000' : Date;
|
|
41
|
+
const patternFormat = !isDateTimeField ? undefined : 'DD/MM/YYYY HH:mm';
|
|
42
|
+
const brFormatter = !isDateTimeField ? _helpers.PT_BR_FORMAT : _helpers.PT_BR_FORMAT_DATETIME;
|
|
43
|
+
const usFormatter = !isDateTimeField ? _helpers.EN_US_FORMAT : _helpers.EN_US_FORMAT_DATETIME;
|
|
40
44
|
const [valueState, setValueState] = (0, _react.useState)(value ? (0, _helpers.getMomentValue)(value) : undefined);
|
|
41
|
-
const [valueFromProps, setValueFromProps] = (0, _react.useState)(value);
|
|
42
45
|
const [showCalendar, setShowCalendar] = (0, _react.useState)(false);
|
|
46
|
+
const [valueFromProps, setValueFromProps] = (0, _react.useState)((0, _moment.default)(value, patternFormat).format());
|
|
43
47
|
const [inputDimensions, setInputDimensions] = (0, _react.useState)();
|
|
44
|
-
const [
|
|
48
|
+
const [calendarOnDialog, setCalendarOnDialog] = (0, _react.useState)(false);
|
|
45
49
|
const [onDenied, setOnDenied] = (0, _react.useState)({
|
|
46
50
|
disabled: false,
|
|
47
51
|
readOnly: false,
|
|
48
52
|
unvisible: false,
|
|
49
53
|
hideContent: false
|
|
50
54
|
});
|
|
51
|
-
const
|
|
55
|
+
const inputDateRef = (0, _react.useRef)();
|
|
52
56
|
const buttonOpenRef = (0, _react.useRef)();
|
|
53
57
|
const dropdownContainer = (0, _react.useRef)();
|
|
54
|
-
const
|
|
58
|
+
const currentDateButtonRef = (0, _react.useRef)();
|
|
59
|
+
const calendarContainerRef = (0, _react.useRef)(null);
|
|
60
|
+
const datePickerContainerRef = (0, _react.useRef)(null);
|
|
55
61
|
const onScreenResize = () => {
|
|
56
|
-
setInputDimensions(
|
|
62
|
+
setInputDimensions(inputDateRef?.current?.getBoundingClientRect());
|
|
63
|
+
};
|
|
64
|
+
const onCloseDateDialog = () => {
|
|
65
|
+
setShowCalendar(false);
|
|
66
|
+
if (showCalendarInDialog) {
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
setCalendarOnDialog(false);
|
|
69
|
+
inputDateRef.current?.focus();
|
|
70
|
+
}, 100);
|
|
71
|
+
}
|
|
57
72
|
};
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
} = event;
|
|
62
|
-
if (!dropdownContainer || target === inputRef.current || target === buttonOpenRef.current) return;
|
|
63
|
-
if (target !== dropdownContainer.current && dropdownContainer && dropdownContainer.current && !dropdownContainer.current.contains(target) && buttonOpenRef && !buttonOpenRef?.current?.contains(target)) {
|
|
73
|
+
const onCloseWithoutBlur = event => {
|
|
74
|
+
const focusOnAnotherField = !datePickerContainerRef.current?.contains(event.relatedTarget);
|
|
75
|
+
if (!showCalendarInDialog && showCalendar && focusOnAnotherField) {
|
|
64
76
|
setShowCalendar(false);
|
|
65
77
|
}
|
|
66
78
|
};
|
|
79
|
+
const onKeyDownPress = event => {
|
|
80
|
+
if (shouldCloseOnEsc && showCalendar && event && event.key && event.key === 'Escape') {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
setShowCalendar(false);
|
|
83
|
+
inputDateRef.current?.focus();
|
|
84
|
+
}
|
|
85
|
+
if (showCalendar && showCalendarInDialog && event && event.key && event.key === 'Tab') {
|
|
86
|
+
const buttonForNavigateCalendar = calendarContainerRef.current?.getElementsByClassName('navbutton');
|
|
87
|
+
const datePicked = calendarContainerRef.current?.getElementsByClassName('-selectedday');
|
|
88
|
+
const buttonDatePicked = datePicked[0].firstChild;
|
|
89
|
+
const buttonsForFocus = Array.from([...buttonForNavigateCalendar, buttonDatePicked]);
|
|
90
|
+
const firstElement = buttonsForFocus[0];
|
|
91
|
+
const lastElement = buttonsForFocus[buttonsForFocus.length - 1];
|
|
92
|
+
if (event.shiftKey && document.activeElement === firstElement) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
lastElement.focus();
|
|
95
|
+
} else if (!event.shiftKey && document.activeElement === lastElement) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
firstElement.focus();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
event.stopPropagation();
|
|
101
|
+
};
|
|
102
|
+
const keepPositionCalendarByScroll = () => {
|
|
103
|
+
const inputDateDimensions = inputDateRef.current?.getBoundingClientRect();
|
|
104
|
+
const positionTop = inputDateDimensions && inputDateDimensions.bottom;
|
|
105
|
+
if (dropdownContainer && dropdownContainer.current && inputDateDimensions) {
|
|
106
|
+
dropdownContainer.current.style.top = String(positionTop).concat('px');
|
|
107
|
+
}
|
|
108
|
+
};
|
|
67
109
|
const openCalendar = () => {
|
|
68
110
|
setShowCalendar(true);
|
|
69
|
-
if (
|
|
70
|
-
|
|
111
|
+
if (inputDateRef.current) {
|
|
112
|
+
inputDateRef.current.focus();
|
|
113
|
+
setInputDimensions(inputDateRef.current?.getBoundingClientRect());
|
|
71
114
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} = event;
|
|
77
|
-
setInsideDropdown(false);
|
|
78
|
-
if (dropdownContainer !== undefined && dropdownContainer.current) {
|
|
79
|
-
if (target === dropdownContainer.current || dropdownContainer.current.contains(target)) {
|
|
80
|
-
setInsideDropdown(true);
|
|
81
|
-
}
|
|
115
|
+
if (showCalendarInDialog) {
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
currentDateButtonRef.current?.focus();
|
|
118
|
+
}, 100);
|
|
82
119
|
}
|
|
83
120
|
};
|
|
84
121
|
const onInputFocus = e => {
|
|
85
122
|
if (props.onFocus) props.onFocus(e);
|
|
86
|
-
if (openOnFocus)
|
|
123
|
+
if (openOnFocus && !showCalendar && !calendarOnDialog) {
|
|
124
|
+
openCalendar();
|
|
125
|
+
}
|
|
87
126
|
};
|
|
88
127
|
const onInputBlur = e => {
|
|
89
128
|
if (props.onBlur) props.onBlur(e);
|
|
90
|
-
if (!insideDropdown) setShowCalendar(false);
|
|
91
|
-
};
|
|
92
|
-
const onInputKeyDown = event => {
|
|
93
|
-
if (Number(event.code) === contants.keyCodes.TAB) {
|
|
94
|
-
setInsideDropdown(false);
|
|
95
|
-
setShowCalendar(false);
|
|
96
|
-
}
|
|
97
129
|
};
|
|
98
130
|
const isValidDate = date => {
|
|
99
131
|
if (typeof date === 'object' && !(date instanceof Date)) {
|
|
100
|
-
const initialValid = (0, _moment.default)(date.initial,
|
|
101
|
-
const finalValid = (0, _moment.default)(date.final,
|
|
132
|
+
const initialValid = (0, _moment.default)(date.initial, brFormatter, true).isValid();
|
|
133
|
+
const finalValid = (0, _moment.default)(date.final, brFormatter, true).isValid();
|
|
102
134
|
return initialValid && finalValid;
|
|
103
135
|
}
|
|
104
|
-
return (0, _moment.default)(date,
|
|
136
|
+
return (0, _moment.default)(date, brFormatter, true).isValid();
|
|
105
137
|
};
|
|
106
138
|
const onInputChange = function (event) {
|
|
107
139
|
let valueInput = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
@@ -109,7 +141,7 @@ const DatePicker = props => {
|
|
|
109
141
|
const date = event.target.value ?? '';
|
|
110
142
|
if (props.onChange) {
|
|
111
143
|
if (isValidDate(date)) {
|
|
112
|
-
const newValue = (0, _moment.default)(date,
|
|
144
|
+
const newValue = (0, _moment.default)(date, brFormatter).format(usFormatter);
|
|
113
145
|
const obj = {
|
|
114
146
|
target: {
|
|
115
147
|
value: newValue,
|
|
@@ -131,101 +163,106 @@ const DatePicker = props => {
|
|
|
131
163
|
}
|
|
132
164
|
}
|
|
133
165
|
};
|
|
134
|
-
const setValue =
|
|
135
|
-
|
|
136
|
-
let e = arguments.length > 1 ? arguments[1] : undefined;
|
|
137
|
-
if (showCalendar && setFocusOnSelect) inputRef.current?.focus();
|
|
166
|
+
const setValue = (valueParam, e) => {
|
|
167
|
+
if (showCalendar && setFocusOnSelect) inputDateRef.current?.focus();
|
|
138
168
|
if (props.onComplete) props.onComplete(e, valueParam);
|
|
139
169
|
if (props.onChange) onInputChange({
|
|
140
170
|
target: {
|
|
141
|
-
value: valueParam,
|
|
171
|
+
value: valueParam ?? '',
|
|
142
172
|
name
|
|
143
173
|
}
|
|
144
174
|
}, valueParam);
|
|
145
175
|
if (shouldCloseOnSelect) setShowCalendar(false);
|
|
146
|
-
setValueState((0, _moment.default)(valueParam,
|
|
176
|
+
setValueState((0, _moment.default)(valueParam, brFormatter));
|
|
147
177
|
};
|
|
148
178
|
const shouldDisable = () => props.disabled || onDenied && (onDenied.disabled || onDenied.hideContent);
|
|
149
179
|
const getButtonOpen = () => {
|
|
150
180
|
if (!showButtonOpen) return undefined;
|
|
151
181
|
return /*#__PURE__*/_react.default.createElement(_buttons.default, {
|
|
152
|
-
key: "button-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
182
|
+
key: "button-open-date-picker",
|
|
183
|
+
disabled: shouldDisable(),
|
|
184
|
+
tabIndex: -1,
|
|
185
|
+
customClass: "calendar-button",
|
|
186
|
+
iconName: "calendar",
|
|
187
|
+
title: showCalendar ? 'Fechar Calendário' : 'Abrir Calendário',
|
|
158
188
|
onClick: () => {
|
|
159
|
-
|
|
189
|
+
if (showCalendar) {
|
|
190
|
+
setShowCalendar(false);
|
|
191
|
+
} else openCalendar();
|
|
160
192
|
},
|
|
161
|
-
customClass: "calendar-button",
|
|
162
|
-
tabIndex: -1,
|
|
163
193
|
targetRef: ref => {
|
|
164
194
|
buttonOpenRef.current = ref;
|
|
165
|
-
}
|
|
166
|
-
disabled: shouldDisable()
|
|
195
|
+
}
|
|
167
196
|
});
|
|
168
197
|
};
|
|
169
198
|
const getCalendar = (valueCalendar, calendarColorStyle) => /*#__PURE__*/_react.default.createElement(_calendar.default, {
|
|
199
|
+
colorStyle: calendarColorStyle,
|
|
170
200
|
currentDate: valueCalendar !== undefined ? valueCalendar : (0, _moment.default)(),
|
|
171
201
|
onDateChange: date => {
|
|
172
|
-
setValue(date.format(
|
|
202
|
+
setValue(date.format(brFormatter), undefined);
|
|
203
|
+
if (showCalendarInDialog) setCalendarOnDialog(false);
|
|
173
204
|
},
|
|
174
|
-
|
|
205
|
+
currentDateButton: buttonElement => currentDateButtonRef.current = buttonElement,
|
|
206
|
+
calendarContainer: calendarContainer => {
|
|
207
|
+
calendarContainerRef.current = calendarContainer;
|
|
208
|
+
}
|
|
175
209
|
});
|
|
176
|
-
const
|
|
210
|
+
const getCalendarComponent = () => {
|
|
177
211
|
if (onDenied && onDenied.readOnly) return null;
|
|
178
212
|
if (showCalendarInDialog) {
|
|
179
213
|
return /*#__PURE__*/_react.default.createElement(_Dialog.default, {
|
|
180
214
|
dialogSize: dialogSize,
|
|
181
|
-
handlerClose:
|
|
215
|
+
handlerClose: onCloseDateDialog
|
|
182
216
|
}, getCalendar(valueState, props?.calendarColorStyle));
|
|
183
217
|
}
|
|
184
218
|
return /*#__PURE__*/_react.default.createElement(_Dropdown.default, {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
width: inputDimensions ? inputDimensions.width + (showButtonOpen ? CALENDAR_BUTTON_WIDTH : 0) : '',
|
|
219
|
+
showButtonOpen: showButtonOpen,
|
|
220
|
+
inputDimensions: inputDimensions,
|
|
221
|
+
containerRef: datePickerContainerRef,
|
|
189
222
|
dropdownRef: el => {
|
|
190
223
|
dropdownContainer.current = el;
|
|
191
224
|
}
|
|
192
225
|
}, getCalendar(valueState, props?.calendarColorStyle));
|
|
193
226
|
};
|
|
194
227
|
(0, _react.useEffect)(() => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
} else {
|
|
199
|
-
|
|
228
|
+
if (value && (0, _moment.default)(value, usFormatter).format() !== 'Invalid date' && (0, _moment.default)(valueFromProps, usFormatter).format() !== (0, _moment.default)(value, usFormatter).format()) {
|
|
229
|
+
setValueState((0, _moment.default)(value, usFormatter));
|
|
230
|
+
setValueFromProps(value);
|
|
231
|
+
} else if (!value && value !== valueFromProps) {
|
|
232
|
+
setValueState(undefined);
|
|
233
|
+
setValueFromProps(value);
|
|
200
234
|
}
|
|
201
|
-
}, [
|
|
235
|
+
}, [value]);
|
|
202
236
|
(0, _react.useEffect)(() => {
|
|
203
237
|
window.addEventListener('resize', onScreenResize);
|
|
204
|
-
document.addEventListener('
|
|
205
|
-
|
|
206
|
-
if (
|
|
238
|
+
document.addEventListener('keydown', onKeyDownPress);
|
|
239
|
+
if (inputDateRef.current) onScreenResize();
|
|
240
|
+
if (showCalendar && showCalendarInDialog) setCalendarOnDialog(true);
|
|
207
241
|
return () => {
|
|
208
242
|
window.removeEventListener('resize', onScreenResize);
|
|
209
|
-
document.removeEventListener('
|
|
210
|
-
document.removeEventListener('mousemove', onMouseMove);
|
|
243
|
+
document.removeEventListener('keydown', onKeyDownPress);
|
|
211
244
|
};
|
|
212
|
-
|
|
213
|
-
// TODO: Procurar solução melhor.
|
|
214
|
-
// setTimeout(() => { this.onScreenResize(); }, 300);
|
|
215
|
-
}, [inputRef.current]);
|
|
245
|
+
}, [inputDateRef.current, showCalendar]);
|
|
216
246
|
(0, _react.useEffect)(() => {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}, [value]);
|
|
247
|
+
document.addEventListener('scroll', keepPositionCalendarByScroll);
|
|
248
|
+
document.getElementById('modal-dialog-content')?.addEventListener('scroll', keepPositionCalendarByScroll);
|
|
249
|
+
return () => {
|
|
250
|
+
document.removeEventListener('scroll', keepPositionCalendarByScroll);
|
|
251
|
+
document.getElementById('modal-dialog-content')?.removeEventListener('scroll', keepPositionCalendarByScroll);
|
|
252
|
+
};
|
|
253
|
+
}, []);
|
|
225
254
|
if (onDenied && onDenied.unvisible) return null;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
255
|
+
const component = () => /*#__PURE__*/_react.default.createElement("div", {
|
|
256
|
+
ref: datePickerContainerRef,
|
|
257
|
+
onBlur: onCloseWithoutBlur,
|
|
258
|
+
className: "datepicker-container"
|
|
259
|
+
}, /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({}, props, {
|
|
260
|
+
gridLayout: undefined,
|
|
261
|
+
isDateTimeField: isDateTimeField,
|
|
262
|
+
value: !valueState ? ' ' : valueState.format(brFormatter),
|
|
263
|
+
mask: maskFormat,
|
|
264
|
+
pattern: patternFormat,
|
|
265
|
+
blocks: !isDateTimeField ? {} : _helpers.blocksDateTimeFormat,
|
|
229
266
|
onComplete: e => {
|
|
230
267
|
if (e) {
|
|
231
268
|
setValue(e.target?.maskedValue, e);
|
|
@@ -235,17 +272,20 @@ const DatePicker = props => {
|
|
|
235
272
|
onFocus: e => {
|
|
236
273
|
onInputFocus(e);
|
|
237
274
|
},
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (date) onInputChange(e, e.target.value);
|
|
275
|
+
onChange: (e, date) => {
|
|
276
|
+
if (date) onInputChange(e, date);
|
|
241
277
|
},
|
|
242
278
|
inputRef: el => {
|
|
243
|
-
|
|
279
|
+
inputDateRef.current = el;
|
|
244
280
|
if (inputRefProp) inputRefProp.current = el;
|
|
245
281
|
},
|
|
246
282
|
rightElements: getButtonOpen(),
|
|
247
283
|
required: required,
|
|
248
284
|
handlerSetOnDenied: () => setOnDenied(onDenied)
|
|
249
|
-
})), showCalendar &&
|
|
285
|
+
})), showCalendar && getCalendarComponent());
|
|
286
|
+
return !gridLayout ? component() : /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
|
|
287
|
+
customClass: "-withinput",
|
|
288
|
+
cols: gridLayout
|
|
289
|
+
}, component());
|
|
250
290
|
};
|
|
251
291
|
var _default = exports.default = DatePicker;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import { ReactNode, RefObject } from 'react';
|
|
2
2
|
import { ColorStyles } from '../../@types/ColorStyles.js';
|
|
3
3
|
import { PermissionAttr } from '../../@types/PermissionAttr.js';
|
|
4
4
|
import { CustomInputEvent } from '../base/types.js';
|
|
@@ -9,10 +9,11 @@ import '../../@types/Position.js';
|
|
|
9
9
|
|
|
10
10
|
interface IDatePickerProps {
|
|
11
11
|
value?: string;
|
|
12
|
+
openOnFocus?: boolean;
|
|
12
13
|
showButtonOpen?: boolean;
|
|
14
|
+
shouldCloseOnEsc?: boolean;
|
|
13
15
|
shouldCloseOnSelect?: boolean;
|
|
14
16
|
setFocusOnSelect?: boolean;
|
|
15
|
-
openOnFocus?: boolean;
|
|
16
17
|
showCalendarInDialog?: boolean;
|
|
17
18
|
inputRef?: React.MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null>;
|
|
18
19
|
dialogSize?: {
|
|
@@ -37,18 +38,19 @@ interface IDatePickerProps {
|
|
|
37
38
|
disabled?: boolean;
|
|
38
39
|
permissionAttr?: PermissionAttr;
|
|
39
40
|
label?: string;
|
|
41
|
+
gridLayout?: string;
|
|
40
42
|
hint?: string | string[];
|
|
41
43
|
hintPosition?: 'below' | 'onLabelRight';
|
|
42
44
|
themePopover?: 'light' | 'dark';
|
|
43
45
|
popoverAlign?: 'right' | 'left';
|
|
46
|
+
isDateTimeField?: boolean;
|
|
44
47
|
}
|
|
45
48
|
interface IDateDropdownProps {
|
|
46
49
|
children: ReactNode | ReactNode[];
|
|
47
50
|
dropdownRef: (el: HTMLDivElement) => void;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
minWidth: number | string;
|
|
51
|
+
containerRef: RefObject<HTMLDivElement | HTMLElement>;
|
|
52
|
+
showButtonOpen: boolean;
|
|
53
|
+
inputDimensions?: DOMRect;
|
|
52
54
|
}
|
|
53
55
|
interface IDateDialogProps {
|
|
54
56
|
children: ReactNode | ReactNode[];
|
|
@@ -7,6 +7,6 @@ import '../../@types/Period.js';
|
|
|
7
7
|
import '../../internals/types.js';
|
|
8
8
|
import '../../@types/Position.js';
|
|
9
9
|
|
|
10
|
-
declare const BaseMask: ({ value: valueProp, defaultValue, inputRef, onChange, onComplete, permissionAttr, mask, ...rest }: IBaseMaskProps) => JSX.Element;
|
|
10
|
+
declare const BaseMask: ({ value: valueProp, defaultValue, inputRef, onChange, onComplete, permissionAttr, mask, isDateTimeField, ...rest }: IBaseMaskProps) => JSX.Element;
|
|
11
11
|
|
|
12
12
|
export { BaseMask as default };
|
|
@@ -10,7 +10,7 @@ var _format_number = require("../number/format_number");
|
|
|
10
10
|
var _reactImask = require("react-imask");
|
|
11
11
|
var _permissionValidations = require("../../permissionValidations");
|
|
12
12
|
var _helpers = require("./helpers");
|
|
13
|
-
const _excluded = ["value", "defaultValue", "inputRef", "onChange", "onComplete", "permissionAttr", "mask"];
|
|
13
|
+
const _excluded = ["value", "defaultValue", "inputRef", "onChange", "onComplete", "permissionAttr", "mask", "isDateTimeField"];
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -102,7 +102,8 @@ const BaseMask = _ref => {
|
|
|
102
102
|
onChange,
|
|
103
103
|
onComplete,
|
|
104
104
|
permissionAttr,
|
|
105
|
-
mask
|
|
105
|
+
mask,
|
|
106
|
+
isDateTimeField
|
|
106
107
|
} = _ref,
|
|
107
108
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
108
109
|
const onDenied = (0, _permissionValidations.actionsOnPermissionDenied)(options, permissionAttr);
|
|
@@ -112,14 +113,15 @@ const BaseMask = _ref => {
|
|
|
112
113
|
} = onDenied;
|
|
113
114
|
const disableCallbacks = disabled || readOnly;
|
|
114
115
|
const maskOptions = (0, _helpers.getMaskOptions)(_objectSpread({
|
|
115
|
-
mask
|
|
116
|
+
mask,
|
|
117
|
+
isDateTimeField
|
|
116
118
|
}, rest));
|
|
117
119
|
const {
|
|
118
120
|
ref,
|
|
119
121
|
setValue,
|
|
120
122
|
setTypedValue,
|
|
121
123
|
maskRef
|
|
122
|
-
} = (0, _reactImask.useIMask)(maskOptions, {
|
|
124
|
+
} = (0, _reactImask.useIMask)(_objectSpread({}, maskOptions), {
|
|
123
125
|
defaultValue: defaultValue,
|
|
124
126
|
onAccept: (_, r) => {
|
|
125
127
|
if (!disableCallbacks && onChange) {
|
|
@@ -1,61 +1,14 @@
|
|
|
1
|
-
import { TextAlign } from '../../@types/Align.js';
|
|
2
|
-
import { OnDenied, PermissionAttr } from '../../@types/PermissionAttr.js';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { CustomInputEvent } from '../base/types.js';
|
|
5
1
|
import { IBaseMaskProps } from './types.js';
|
|
2
|
+
import { ReactMaskOpts } from 'react-imask';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '../../@types/Align.js';
|
|
5
|
+
import '../../@types/PermissionAttr.js';
|
|
6
|
+
import '../base/types.js';
|
|
6
7
|
import '../../@types/Period.js';
|
|
7
8
|
import '../../internals/types.js';
|
|
8
9
|
import '../../@types/Position.js';
|
|
9
10
|
|
|
10
|
-
declare const getMaskOptions: ({ isDateField, placeholderChar, min, max, lazy, pattern, radix, thousandsSeparator, mapToRadix, scale, normalizeZeros, padFractionalZeros, rightElements, leftElements, ...rest }: IBaseMaskProps) =>
|
|
11
|
-
value?: string | number | undefined;
|
|
12
|
-
onBlur?: ((e: CustomInputEvent) => void) | undefined;
|
|
13
|
-
onKeyDown?: ((e: CustomInputEvent | React.KeyboardEvent<Element>) => void) | undefined;
|
|
14
|
-
defaultValue?: string | undefined;
|
|
15
|
-
isNumeric?: boolean | undefined;
|
|
16
|
-
blocks?: any;
|
|
17
|
-
handlerSetOnDenied?: ((onDeniedValue: OnDenied) => void) | undefined;
|
|
18
|
-
onChange?: ((e: CustomInputEvent, maskValue?: string | undefined, date?: string | undefined) => void) | undefined;
|
|
19
|
-
onComplete?: ((e: CustomInputEvent, maskValue?: string | undefined, date?: string | undefined) => void) | undefined;
|
|
20
|
-
inputRef?: React.MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null> | ((ref: HTMLInputElement | HTMLTextAreaElement | null) => void) | undefined;
|
|
21
|
-
permissionAttr?: PermissionAttr | undefined;
|
|
22
|
-
errorMessages?: string[] | undefined;
|
|
23
|
-
rounded?: boolean | undefined;
|
|
24
|
-
textAlign?: TextAlign | undefined;
|
|
25
|
-
customClassForInputContent?: string | undefined;
|
|
26
|
-
label?: string | undefined;
|
|
27
|
-
name?: string | undefined;
|
|
28
|
-
customClassForLabel?: string | undefined;
|
|
29
|
-
customClass?: string | undefined;
|
|
30
|
-
gridLayout?: string | undefined;
|
|
31
|
-
placeHolder?: string | undefined;
|
|
32
|
-
readOnly?: boolean | undefined;
|
|
33
|
-
labelUppercase?: boolean | undefined;
|
|
34
|
-
disabled?: boolean | undefined;
|
|
35
|
-
unmask?: boolean | undefined;
|
|
36
|
-
onFocus?: ((e: CustomInputEvent) => void) | undefined;
|
|
37
|
-
required?: boolean | undefined;
|
|
38
|
-
returnFormattedValueOnBlur?: boolean | undefined;
|
|
39
|
-
returnFormattedValueOnKeyDown?: boolean | undefined;
|
|
40
|
-
autoCompleteMask?: "left" | "right" | undefined;
|
|
41
|
-
definitions?: any;
|
|
42
|
-
mask?: any;
|
|
43
|
-
hint?: string | string[] | undefined;
|
|
44
|
-
hintPosition?: "below" | "onLabelRight" | undefined;
|
|
45
|
-
themePopover?: "light" | "dark" | undefined;
|
|
46
|
-
popoverAlign?: "left" | "right" | undefined;
|
|
47
|
-
placeholderChar: string;
|
|
48
|
-
min: any;
|
|
49
|
-
max: any;
|
|
50
|
-
lazy: boolean;
|
|
51
|
-
pattern: string;
|
|
52
|
-
radix: string;
|
|
53
|
-
thousandsSeparator: string;
|
|
54
|
-
mapToRadix: string[];
|
|
55
|
-
scale: number;
|
|
56
|
-
normalizeZeros: boolean;
|
|
57
|
-
padFractionalZeros: boolean;
|
|
58
|
-
};
|
|
11
|
+
declare const getMaskOptions: ({ isDateField, placeholderChar, min, max, lazy, pattern, radix, thousandsSeparator, mapToRadix, scale, normalizeZeros, padFractionalZeros, rightElements, leftElements, isDateTimeField, ...rest }: IBaseMaskProps) => ReactMaskOpts;
|
|
59
12
|
declare function CPFValidation(cpf?: string, returnMessage?: (msg: string) => void): void | "CPF inválido";
|
|
60
13
|
declare function CNPJValidation(cnpj?: string, returnMessage?: (msg: string) => void): void | "CNPJ inválido";
|
|
61
14
|
|
|
@@ -7,8 +7,10 @@ exports.CNPJValidation = CNPJValidation;
|
|
|
7
7
|
exports.CPFValidation = CPFValidation;
|
|
8
8
|
exports.getMaskOptions = void 0;
|
|
9
9
|
var _lodash = require("lodash");
|
|
10
|
-
|
|
10
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
11
|
+
const _excluded = ["isDateField", "placeholderChar", "min", "max", "lazy", "pattern", "radix", "thousandsSeparator", "mapToRadix", "scale", "normalizeZeros", "padFractionalZeros", "rightElements", "leftElements", "isDateTimeField"];
|
|
11
12
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
14
|
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; }
|
|
13
15
|
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; }
|
|
14
16
|
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; }
|
|
@@ -32,42 +34,11 @@ const getMaskOptions = _ref => {
|
|
|
32
34
|
normalizeZeros = true,
|
|
33
35
|
padFractionalZeros = true,
|
|
34
36
|
rightElements,
|
|
35
|
-
leftElements
|
|
37
|
+
leftElements,
|
|
38
|
+
isDateTimeField
|
|
36
39
|
} = _ref,
|
|
37
40
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
38
|
-
|
|
39
|
-
// if (isDateField) {
|
|
40
|
-
// return {
|
|
41
|
-
// mask: Date,
|
|
42
|
-
// min: min || new Date(1900, 0, 1),
|
|
43
|
-
// max: max || new Date(9999, 0, 1),
|
|
44
|
-
// pattern: momentFormat,
|
|
45
|
-
// lazy,
|
|
46
|
-
// format: (date: moment.MomentInput) => moment(date).format(momentFormat),
|
|
47
|
-
// parse: (str) => moment(str, momentFormat).toDate(),
|
|
48
|
-
// blocks: {
|
|
49
|
-
// DD: {
|
|
50
|
-
// mask: IMask.MaskedRange,
|
|
51
|
-
// from: 1,
|
|
52
|
-
// to: 31,
|
|
53
|
-
// maxLength: 2,
|
|
54
|
-
// },
|
|
55
|
-
// MM: {
|
|
56
|
-
// mask: IMask.MaskedRange,
|
|
57
|
-
// from: 1,
|
|
58
|
-
// to: 12,
|
|
59
|
-
// maxLength: 2,
|
|
60
|
-
// },
|
|
61
|
-
// YYYY: {
|
|
62
|
-
// mask: IMask.MaskedRange,
|
|
63
|
-
// from: 1900,
|
|
64
|
-
// to: 9999,
|
|
65
|
-
// },
|
|
66
|
-
// },
|
|
67
|
-
// } satisfies ReactMaskOpts;
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
|
-
return _objectSpread({
|
|
41
|
+
const options = _objectSpread({
|
|
71
42
|
placeholderChar: placeholderChar === '' ? ' ' : placeholderChar,
|
|
72
43
|
min,
|
|
73
44
|
max,
|
|
@@ -80,6 +51,15 @@ const getMaskOptions = _ref => {
|
|
|
80
51
|
normalizeZeros,
|
|
81
52
|
padFractionalZeros
|
|
82
53
|
}, rest);
|
|
54
|
+
if (isDateTimeField) {
|
|
55
|
+
options.format = date => {
|
|
56
|
+
return (0, _moment.default)(date).format(momentFormat);
|
|
57
|
+
};
|
|
58
|
+
options.parse = str => {
|
|
59
|
+
return (0, _moment.default)(str, momentFormat);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return options;
|
|
83
63
|
};
|
|
84
64
|
exports.getMaskOptions = getMaskOptions;
|
|
85
65
|
const allEqualDigits = input => input.split('').every(char => char === input[0]);
|
|
@@ -12,6 +12,6 @@ import '../../drawer/types.js';
|
|
|
12
12
|
import '../../@types/Icon.js';
|
|
13
13
|
import '../../icons/helper.js';
|
|
14
14
|
|
|
15
|
-
declare const BaseNumber: (props: IBaseNumberProps) => JSX.Element;
|
|
15
|
+
declare const BaseNumber: ({ value, ...props }: IBaseNumberProps) => JSX.Element;
|
|
16
16
|
|
|
17
17
|
export { BaseNumber as default };
|
|
@@ -7,8 +7,11 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _BaseMask = _interopRequireDefault(require("../mask/BaseMask"));
|
|
9
9
|
var _format_number = require("./format_number");
|
|
10
|
+
const _excluded = ["value"];
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
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); }
|
|
13
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
14
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
12
15
|
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; }
|
|
13
16
|
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; }
|
|
14
17
|
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; }
|
|
@@ -54,13 +57,17 @@ const getEventProps = props => {
|
|
|
54
57
|
}
|
|
55
58
|
};
|
|
56
59
|
};
|
|
57
|
-
const BaseNumber =
|
|
60
|
+
const BaseNumber = _ref => {
|
|
61
|
+
let {
|
|
62
|
+
value
|
|
63
|
+
} = _ref,
|
|
64
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
58
65
|
const eventProps = _objectSpread(_objectSpread({}, props), {}, {
|
|
59
66
|
returnFormattedValueOnBlur: true,
|
|
60
67
|
returnFormattedValueOnKeyDown: true
|
|
61
68
|
});
|
|
62
69
|
return /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({
|
|
63
|
-
value: (0, _format_number.numberToPtBR)(
|
|
70
|
+
value: (0, _format_number.numberToPtBR)(value ?? 0),
|
|
64
71
|
thousandsSeparator: ".",
|
|
65
72
|
radix: ",",
|
|
66
73
|
mask: Number,
|