@semcore/date-picker 3.4.5 → 3.4.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.
- package/CHANGELOG.md +8 -2
- package/lib/cjs/DatePicker.js +32 -9
- package/lib/cjs/DatePicker.js.map +1 -1
- package/lib/cjs/DateRangePicker.js +23 -0
- package/lib/cjs/DateRangePicker.js.map +1 -1
- package/lib/cjs/MonthPicker.js +33 -3
- package/lib/cjs/MonthPicker.js.map +1 -1
- package/lib/cjs/MonthRangePicker.js +33 -3
- package/lib/cjs/MonthRangePicker.js.map +1 -1
- package/lib/cjs/components/Calendar.js +20 -18
- package/lib/cjs/components/Calendar.js.map +1 -1
- package/lib/cjs/components/InputTrigger.js +820 -0
- package/lib/cjs/components/InputTrigger.js.map +1 -0
- package/lib/cjs/components/PickerAbstract.js +36 -15
- package/lib/cjs/components/PickerAbstract.js.map +1 -1
- package/lib/cjs/components/RangePickerAbstract.js +34 -13
- package/lib/cjs/components/RangePickerAbstract.js.map +1 -1
- package/lib/cjs/components/index.js +52 -32
- package/lib/cjs/components/index.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/style/date-picker.shadow.css +48 -0
- package/lib/es6/DatePicker.js +33 -10
- package/lib/es6/DatePicker.js.map +1 -1
- package/lib/es6/DateRangePicker.js +24 -1
- package/lib/es6/DateRangePicker.js.map +1 -1
- package/lib/es6/MonthPicker.js +33 -4
- package/lib/es6/MonthPicker.js.map +1 -1
- package/lib/es6/MonthRangePicker.js +33 -4
- package/lib/es6/MonthRangePicker.js.map +1 -1
- package/lib/es6/components/Calendar.js +20 -18
- package/lib/es6/components/Calendar.js.map +1 -1
- package/lib/es6/components/InputTrigger.js +803 -0
- package/lib/es6/components/InputTrigger.js.map +1 -0
- package/lib/es6/components/PickerAbstract.js +36 -15
- package/lib/es6/components/PickerAbstract.js.map +1 -1
- package/lib/es6/components/RangePickerAbstract.js +34 -13
- package/lib/es6/components/RangePickerAbstract.js.map +1 -1
- package/lib/es6/components/index.js +48 -30
- package/lib/es6/components/index.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/style/date-picker.shadow.css +48 -0
- package/lib/types/index.d.ts +64 -2
- package/package.json +10 -5
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
6
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
8
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
9
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
10
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
11
|
+
import { sstyled as _sstyled } from "@semcore/core";
|
|
12
|
+
import { assignProps as _assignProps7 } from "@semcore/core";
|
|
13
|
+
import { assignProps as _assignProps6 } from "@semcore/core";
|
|
14
|
+
import { assignProps as _assignProps5 } from "@semcore/core";
|
|
15
|
+
import { assignProps as _assignProps4 } from "@semcore/core";
|
|
16
|
+
import { assignProps as _assignProps3 } from "@semcore/core";
|
|
17
|
+
import { assignProps as _assignProps2 } from "@semcore/core";
|
|
18
|
+
import { assignProps as _assignProps } from "@semcore/core";
|
|
19
|
+
var _excluded = ["children", "id", "role", "aria-haspopup", "aria-label", "style"],
|
|
20
|
+
_excluded2 = ["children", "id", "role", "aria-haspopup", "aria-label", "style"],
|
|
21
|
+
_excluded3 = ["value", "onChange", "onDisplayedPeriodChange", "locale", "w"],
|
|
22
|
+
_excluded4 = ["value", "locale", "onDisplayedPeriodChange"],
|
|
23
|
+
_excluded5 = ["value", "locale", "onDisplayedPeriodChange"],
|
|
24
|
+
_excluded6 = ["date", "onDateChange", "onDisplayedPeriodChange", "locale", "styles", "parts", "disabledDates", "forwardRef", "placeholders", "labelPrefix", "__excludeProps", "Root"];
|
|
25
|
+
|
|
26
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
27
|
+
|
|
28
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
+
|
|
30
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
31
|
+
|
|
32
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
33
|
+
|
|
34
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
35
|
+
|
|
36
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
|
+
|
|
38
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
|
+
|
|
40
|
+
import React from 'react';
|
|
41
|
+
import BaseTrigger from '@semcore/base-trigger';
|
|
42
|
+
import InputMask from '@semcore/input-mask';
|
|
43
|
+
import { Flex, Box } from '@semcore/flex-box';
|
|
44
|
+
import Calendar from '@semcore/icon/Calendar/m';
|
|
45
|
+
import createComponent, { Root, sstyled, Component } from '@semcore/core';
|
|
46
|
+
import NeighborLocation from '@semcore/neighbor-location';
|
|
47
|
+
import includesDate from '../utils/includesDate';
|
|
48
|
+
import dayjs from 'dayjs';
|
|
49
|
+
|
|
50
|
+
/*__reshadow-styles__:"../style/date-picker.shadow.css"*/
|
|
51
|
+
var style = (
|
|
52
|
+
/*__reshadow_css_start__*/
|
|
53
|
+
_sstyled.insert(
|
|
54
|
+
/*__inner_css_start__*/
|
|
55
|
+
".___SPopper_1rxcc_gg_{padding:16px;outline:0}.___SPopper_1rxcc_gg_::-moz-focus-inner{border:none;padding:0}.___SPopper_1rxcc_gg_:active,.___SPopper_1rxcc_gg_:focus,.___SPopper_1rxcc_gg_:hover{outline:0;text-decoration:none}.___SPopper_1rxcc_gg_:focus{box-shadow:0 0 0 3px rgba(0, 143, 248, 0.2)}.___SHeader_1rxcc_gg_{display:flex;align-items:center}.___STitle_1rxcc_gg_{font-size:14px;color:#191b23;height:32px;width:100%;display:flex;justify-content:center;align-items:center}.___SToday_1rxcc_gg_{display:flex;margin-top:12px;justify-content:center}.___SPeriod_1rxcc_gg_{display:flex;flex-direction:column;margin-bottom:8px}.___SDateRange_1rxcc_gg_:active .___SOutline_1rxcc_gg_,.___SDateRange_1rxcc_gg_:hover .___SOutline_1rxcc_gg_,.___SDateRange_1rxcc_gg_.__active_1rxcc_gg_ .___SOutline_1rxcc_gg_,.___SDateRange_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_:active .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_:hover .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_.__active_1rxcc_gg_ .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SOutline_1rxcc_gg_{background-color:rgba(138,142,155,.3)}.___SDateRange_1rxcc_gg_:active .___SOutline_1rxcc_gg_,.___SDateRange_1rxcc_gg_:focus-within .___SOutline_1rxcc_gg_,.___SDateRange_1rxcc_gg_:hover .___SOutline_1rxcc_gg_,.___SDateRange_1rxcc_gg_.__active_1rxcc_gg_ .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_:active .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_:focus-within .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_:hover .___SOutline_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_.__active_1rxcc_gg_ .___SOutline_1rxcc_gg_{background-color:rgba(138,142,155,.3)}.___SIndicator_1rxcc_gg_{color:#6c6e79}.___SHumanizedDate_1rxcc_gg_{position:absolute;pointer-events:none}.___SDateRange_1rxcc_gg_ .___SMask_1rxcc_gg_,.___SDateRange_1rxcc_gg_ .___SValue_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_ .___SMask_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_ .___SValue_1rxcc_gg_{opacity:0}.___SSingleDateInput_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SHumanizedDate_1rxcc_gg_{opacity:0;z-index:-1000}.___SSingleDateInput_1rxcc_gg_:focus-within .___SHumanizedDate_1rxcc_gg_{opacity:0;z-index:-1000}.___SSingleDateInput_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SMask_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SValue_1rxcc_gg_{opacity:1}.___SSingleDateInput_1rxcc_gg_:focus-within .___SMask_1rxcc_gg_,.___SSingleDateInput_1rxcc_gg_:focus-within .___SValue_1rxcc_gg_{opacity:1}.___SDateRange_1rxcc_gg_ .___SValue_1rxcc_gg_{opacity:0}.___SDateRange_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SHumanizedDate_1rxcc_gg_{opacity:0;z-index:-1000}.___SDateRange_1rxcc_gg_:focus-within .___SHumanizedDate_1rxcc_gg_{opacity:0;z-index:-1000}.___SDateRange_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SMask_1rxcc_gg_,.___SDateRange_1rxcc_gg_.__focus-within_1rxcc_gg_ .___SValue_1rxcc_gg_{opacity:1}.___SDateRange_1rxcc_gg_:focus-within .___SMask_1rxcc_gg_,.___SDateRange_1rxcc_gg_:focus-within .___SValue_1rxcc_gg_{opacity:1}.___SInputMask_1rxcc_gg_.__noHumanizedDate_1rxcc_gg_ .___SMask_1rxcc_gg_,.___SInputMask_1rxcc_gg_.__noHumanizedDate_1rxcc_gg_ .___SValue_1rxcc_gg_{opacity:1}"
|
|
56
|
+
/*__inner_css_end__*/
|
|
57
|
+
, "1rxcc_gg_")
|
|
58
|
+
/*__reshadow_css_end__*/
|
|
59
|
+
, {
|
|
60
|
+
"__SPopper": "___SPopper_1rxcc_gg_",
|
|
61
|
+
"__SHeader": "___SHeader_1rxcc_gg_",
|
|
62
|
+
"__STitle": "___STitle_1rxcc_gg_",
|
|
63
|
+
"__SToday": "___SToday_1rxcc_gg_",
|
|
64
|
+
"__SPeriod": "___SPeriod_1rxcc_gg_",
|
|
65
|
+
"__SDateRange": "___SDateRange_1rxcc_gg_",
|
|
66
|
+
"__SOutline": "___SOutline_1rxcc_gg_",
|
|
67
|
+
"_active": "__active_1rxcc_gg_",
|
|
68
|
+
"_focus-within": "__focus-within_1rxcc_gg_",
|
|
69
|
+
"__SSingleDateInput": "___SSingleDateInput_1rxcc_gg_",
|
|
70
|
+
"__SIndicator": "___SIndicator_1rxcc_gg_",
|
|
71
|
+
"__SHumanizedDate": "___SHumanizedDate_1rxcc_gg_",
|
|
72
|
+
"__SMask": "___SMask_1rxcc_gg_",
|
|
73
|
+
"__SValue": "___SValue_1rxcc_gg_",
|
|
74
|
+
"__SInputMask": "___SInputMask_1rxcc_gg_",
|
|
75
|
+
"_noHumanizedDate": "__noHumanizedDate_1rxcc_gg_"
|
|
76
|
+
});
|
|
77
|
+
import assignProps from '@semcore/utils/lib/assignProps';
|
|
78
|
+
var defaultAllowedParts = {
|
|
79
|
+
year: true,
|
|
80
|
+
month: true,
|
|
81
|
+
day: true
|
|
82
|
+
};
|
|
83
|
+
var defaultPlaceholders = {
|
|
84
|
+
year: 'Y',
|
|
85
|
+
month: 'M',
|
|
86
|
+
day: 'D'
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var InputTriggerRoot = /*#__PURE__*/function (_Component) {
|
|
90
|
+
_inherits(InputTriggerRoot, _Component);
|
|
91
|
+
|
|
92
|
+
var _super = _createSuper(InputTriggerRoot);
|
|
93
|
+
|
|
94
|
+
function InputTriggerRoot() {
|
|
95
|
+
_classCallCheck(this, InputTriggerRoot);
|
|
96
|
+
|
|
97
|
+
return _super.apply(this, arguments);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_createClass(InputTriggerRoot, [{
|
|
101
|
+
key: "getSingleDateInputProps",
|
|
102
|
+
value: function getSingleDateInputProps() {
|
|
103
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
104
|
+
var _this$asProps = this.asProps,
|
|
105
|
+
children = _this$asProps.children,
|
|
106
|
+
id = _this$asProps.id,
|
|
107
|
+
role = _this$asProps.role,
|
|
108
|
+
ariaHasPopup = _this$asProps['aria-haspopup'],
|
|
109
|
+
ariaLabel = _this$asProps['aria-label'],
|
|
110
|
+
style = _this$asProps.style,
|
|
111
|
+
otherProps = _objectWithoutProperties(_this$asProps, _excluded);
|
|
112
|
+
|
|
113
|
+
return otherProps;
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "getDateRangeProps",
|
|
117
|
+
value: function getDateRangeProps() {
|
|
118
|
+
var _this$asProps2 = this.asProps,
|
|
119
|
+
children = _this$asProps2.children,
|
|
120
|
+
id = _this$asProps2.id,
|
|
121
|
+
role = _this$asProps2.role,
|
|
122
|
+
ariaHasPopup = _this$asProps2['aria-haspopup'],
|
|
123
|
+
ariaLabel = _this$asProps2['aria-label'],
|
|
124
|
+
style = _this$asProps2.style,
|
|
125
|
+
otherProps = _objectWithoutProperties(_this$asProps2, _excluded2);
|
|
126
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
return otherProps;
|
|
130
|
+
}
|
|
131
|
+
}, {
|
|
132
|
+
key: "render",
|
|
133
|
+
value: function render() {
|
|
134
|
+
var _ref = this.asProps,
|
|
135
|
+
_ref8;
|
|
136
|
+
|
|
137
|
+
var SInputTrigger = Box;
|
|
138
|
+
var _this$asProps3 = this.asProps,
|
|
139
|
+
Children = _this$asProps3.Children,
|
|
140
|
+
style = _this$asProps3.style;
|
|
141
|
+
return _ref8 = sstyled(style), /*#__PURE__*/React.createElement(SInputTrigger, _ref8.cn("SInputTrigger", _objectSpread({}, _assignProps({
|
|
142
|
+
"aria-label": "Date field",
|
|
143
|
+
"__excludeProps": ['onChange', 'value', 'role']
|
|
144
|
+
}, _ref))), /*#__PURE__*/React.createElement(Children, _ref8.cn("Children", {})));
|
|
145
|
+
}
|
|
146
|
+
}]);
|
|
147
|
+
|
|
148
|
+
return InputTriggerRoot;
|
|
149
|
+
}(Component);
|
|
150
|
+
|
|
151
|
+
_defineProperty(InputTriggerRoot, "displayName", 'InputTrigger');
|
|
152
|
+
|
|
153
|
+
_defineProperty(InputTriggerRoot, "style", style);
|
|
154
|
+
|
|
155
|
+
var SingleDateInputRoot = /*#__PURE__*/function (_Component2) {
|
|
156
|
+
_inherits(SingleDateInputRoot, _Component2);
|
|
157
|
+
|
|
158
|
+
var _super2 = _createSuper(SingleDateInputRoot);
|
|
159
|
+
|
|
160
|
+
function SingleDateInputRoot() {
|
|
161
|
+
_classCallCheck(this, SingleDateInputRoot);
|
|
162
|
+
|
|
163
|
+
return _super2.apply(this, arguments);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_createClass(SingleDateInputRoot, [{
|
|
167
|
+
key: "getMaskedInputProps",
|
|
168
|
+
value: function getMaskedInputProps() {
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
170
|
+
var _this$asProps4 = this.asProps,
|
|
171
|
+
value = _this$asProps4.value,
|
|
172
|
+
onChange = _this$asProps4.onChange,
|
|
173
|
+
onDisplayedPeriodChange = _this$asProps4.onDisplayedPeriodChange,
|
|
174
|
+
locale = _this$asProps4.locale,
|
|
175
|
+
w = _this$asProps4.w,
|
|
176
|
+
otherProps = _objectWithoutProperties(_this$asProps4, _excluded3);
|
|
177
|
+
|
|
178
|
+
return _objectSpread({
|
|
179
|
+
date: value,
|
|
180
|
+
onDateChange: onChange,
|
|
181
|
+
onDisplayedPeriodChange: onDisplayedPeriodChange,
|
|
182
|
+
locale: locale
|
|
183
|
+
}, otherProps);
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
key: "render",
|
|
187
|
+
value: function render() {
|
|
188
|
+
var _ref2 = this.asProps,
|
|
189
|
+
_ref9;
|
|
190
|
+
|
|
191
|
+
var _this$asProps5 = this.asProps,
|
|
192
|
+
Children = _this$asProps5.Children,
|
|
193
|
+
forwardRef = _this$asProps5.forwardRef,
|
|
194
|
+
styles = _this$asProps5.styles;
|
|
195
|
+
var SSingleDateInput = InputMask;
|
|
196
|
+
return _ref9 = sstyled(styles), /*#__PURE__*/React.createElement(SSingleDateInput, _ref9.cn("SSingleDateInput", _objectSpread({}, _assignProps2({
|
|
197
|
+
"ref": forwardRef,
|
|
198
|
+
"__excludeProps": ['onChange', 'style']
|
|
199
|
+
}, _ref2))), /*#__PURE__*/React.createElement(NeighborLocation, _ref9.cn("NeighborLocation", {}), /*#__PURE__*/React.createElement(Children, _ref9.cn("Children", {}))));
|
|
200
|
+
}
|
|
201
|
+
}]);
|
|
202
|
+
|
|
203
|
+
return SingleDateInputRoot;
|
|
204
|
+
}(Component);
|
|
205
|
+
|
|
206
|
+
_defineProperty(SingleDateInputRoot, "displayName", 'SingleDateInput');
|
|
207
|
+
|
|
208
|
+
_defineProperty(SingleDateInputRoot, "style", style);
|
|
209
|
+
|
|
210
|
+
_defineProperty(SingleDateInputRoot, "defaultProps", {
|
|
211
|
+
children: function children() {
|
|
212
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SingleDateInput.Indicator, null), /*#__PURE__*/React.createElement(SingleDateInput.MaskedInput, null));
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
var DateRangeRoot = /*#__PURE__*/function (_Component3) {
|
|
217
|
+
_inherits(DateRangeRoot, _Component3);
|
|
218
|
+
|
|
219
|
+
var _super3 = _createSuper(DateRangeRoot);
|
|
220
|
+
|
|
221
|
+
function DateRangeRoot() {
|
|
222
|
+
var _this;
|
|
223
|
+
|
|
224
|
+
_classCallCheck(this, DateRangeRoot);
|
|
225
|
+
|
|
226
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
227
|
+
args[_key] = arguments[_key];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
_this = _super3.call.apply(_super3, [this].concat(args));
|
|
231
|
+
|
|
232
|
+
_defineProperty(_assertThisInitialized(_this), "fromRef", /*#__PURE__*/React.createRef());
|
|
233
|
+
|
|
234
|
+
_defineProperty(_assertThisInitialized(_this), "toRef", /*#__PURE__*/React.createRef());
|
|
235
|
+
|
|
236
|
+
_defineProperty(_assertThisInitialized(_this), "handleFromChange", function (value, event) {
|
|
237
|
+
var _this$asProps$value$, _this$asProps$value, _this$asProps$value$2, _this$asProps$value2;
|
|
238
|
+
|
|
239
|
+
var onChange = _this.asProps.onChange;
|
|
240
|
+
var prevValue = [(_this$asProps$value$ = (_this$asProps$value = _this.asProps.value) === null || _this$asProps$value === void 0 ? void 0 : _this$asProps$value[0]) !== null && _this$asProps$value$ !== void 0 ? _this$asProps$value$ : null, (_this$asProps$value$2 = (_this$asProps$value2 = _this.asProps.value) === null || _this$asProps$value2 === void 0 ? void 0 : _this$asProps$value2[1]) !== null && _this$asProps$value$2 !== void 0 ? _this$asProps$value$2 : null];
|
|
241
|
+
onChange([value, prevValue[1]], event);
|
|
242
|
+
|
|
243
|
+
if (value) {
|
|
244
|
+
if (!_this.toRef.current) return;
|
|
245
|
+
|
|
246
|
+
_this.toRef.current.focus();
|
|
247
|
+
|
|
248
|
+
setTimeout(function () {
|
|
249
|
+
if (!_this.toRef.current) return;
|
|
250
|
+
|
|
251
|
+
_this.toRef.current.setSelectionRange(0, 0);
|
|
252
|
+
}, 0);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
_defineProperty(_assertThisInitialized(_this), "handleToChange", function (value, event) {
|
|
257
|
+
var _this$asProps$value$3, _this$asProps$value3, _this$asProps$value$4, _this$asProps$value4;
|
|
258
|
+
|
|
259
|
+
var onChange = _this.asProps.onChange;
|
|
260
|
+
var prevValue = [(_this$asProps$value$3 = (_this$asProps$value3 = _this.asProps.value) === null || _this$asProps$value3 === void 0 ? void 0 : _this$asProps$value3[0]) !== null && _this$asProps$value$3 !== void 0 ? _this$asProps$value$3 : null, (_this$asProps$value$4 = (_this$asProps$value4 = _this.asProps.value) === null || _this$asProps$value4 === void 0 ? void 0 : _this$asProps$value4[1]) !== null && _this$asProps$value$4 !== void 0 ? _this$asProps$value$4 : null];
|
|
261
|
+
onChange([prevValue[0], value], event);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
_defineProperty(_assertThisInitialized(_this), "handleFromKeydown", function (event) {
|
|
265
|
+
if (!_this.toRef.current) return;
|
|
266
|
+
if (!_this.fromRef.current) return;
|
|
267
|
+
|
|
268
|
+
if (event.code === 'ArrowRight' && _this.fromRef.current.selectionStart === _this.fromRef.current.value.length && _this.fromRef.current.selectionEnd === _this.fromRef.current.value.length) {
|
|
269
|
+
_this.toRef.current.focus();
|
|
270
|
+
|
|
271
|
+
setTimeout(function () {
|
|
272
|
+
_this.toRef.current.setSelectionRange(0, 0);
|
|
273
|
+
}, 0);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
_defineProperty(_assertThisInitialized(_this), "handleToKeydown", function (event) {
|
|
278
|
+
if (!_this.toRef.current) return;
|
|
279
|
+
if (!_this.fromRef.current) return;
|
|
280
|
+
|
|
281
|
+
if (event.code === 'Backspace' && !_this.toRef.current.value) {
|
|
282
|
+
var value = _this.fromRef.current.value;
|
|
283
|
+
|
|
284
|
+
_this.fromRef.current.focus();
|
|
285
|
+
|
|
286
|
+
setTimeout(function () {
|
|
287
|
+
_this.fromRef.current.setSelectionRange(value.length, value.length);
|
|
288
|
+
}, 0);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (event.code === 'ArrowLeft' && _this.toRef.current.selectionStart === 0 && _this.toRef.current.selectionEnd === 0) {
|
|
292
|
+
var _value = _this.fromRef.current.value;
|
|
293
|
+
|
|
294
|
+
_this.fromRef.current.focus();
|
|
295
|
+
|
|
296
|
+
setTimeout(function () {
|
|
297
|
+
_this.fromRef.current.setSelectionRange(_value.length, _value.length);
|
|
298
|
+
}, 0);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
return _this;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
_createClass(DateRangeRoot, [{
|
|
306
|
+
key: "getFromMaskedInputProps",
|
|
307
|
+
value: function getFromMaskedInputProps() {
|
|
308
|
+
var _this$asProps6 = this.asProps,
|
|
309
|
+
value = _this$asProps6.value,
|
|
310
|
+
locale = _this$asProps6.locale,
|
|
311
|
+
onDisplayedPeriodChange = _this$asProps6.onDisplayedPeriodChange,
|
|
312
|
+
otherProps = _objectWithoutProperties(_this$asProps6, _excluded4);
|
|
313
|
+
|
|
314
|
+
return assignProps({
|
|
315
|
+
ref: this.fromRef,
|
|
316
|
+
date: value === null || value === void 0 ? void 0 : value[0],
|
|
317
|
+
onDateChange: this.handleFromChange,
|
|
318
|
+
onKeyDown: this.handleFromKeydown,
|
|
319
|
+
locale: locale,
|
|
320
|
+
flex: 1,
|
|
321
|
+
onDisplayedPeriodChange: onDisplayedPeriodChange
|
|
322
|
+
}, otherProps);
|
|
323
|
+
}
|
|
324
|
+
}, {
|
|
325
|
+
key: "getToMaskedInputProps",
|
|
326
|
+
value: function getToMaskedInputProps() {
|
|
327
|
+
var _this$asProps7 = this.asProps,
|
|
328
|
+
value = _this$asProps7.value,
|
|
329
|
+
locale = _this$asProps7.locale,
|
|
330
|
+
onDisplayedPeriodChange = _this$asProps7.onDisplayedPeriodChange,
|
|
331
|
+
otherProps = _objectWithoutProperties(_this$asProps7, _excluded5);
|
|
332
|
+
|
|
333
|
+
return assignProps({
|
|
334
|
+
ref: this.toRef,
|
|
335
|
+
date: value === null || value === void 0 ? void 0 : value[1],
|
|
336
|
+
onDateChange: this.handleToChange,
|
|
337
|
+
onKeyDown: this.handleToKeydown,
|
|
338
|
+
locale: locale,
|
|
339
|
+
flex: 1,
|
|
340
|
+
onDisplayedPeriodChange: onDisplayedPeriodChange
|
|
341
|
+
}, otherProps);
|
|
342
|
+
}
|
|
343
|
+
}, {
|
|
344
|
+
key: "render",
|
|
345
|
+
value: function render() {
|
|
346
|
+
var _ref3 = this.asProps,
|
|
347
|
+
_ref10;
|
|
348
|
+
|
|
349
|
+
var SDateRange = InputMask;
|
|
350
|
+
var _this$asProps8 = this.asProps,
|
|
351
|
+
Children = _this$asProps8.Children,
|
|
352
|
+
styles = _this$asProps8.styles,
|
|
353
|
+
w = _this$asProps8.w;
|
|
354
|
+
return _ref10 = sstyled(styles), /*#__PURE__*/React.createElement(SDateRange, _ref10.cn("SDateRange", _objectSpread({}, _assignProps3({
|
|
355
|
+
"__excludeProps": ['onChange', 'value'],
|
|
356
|
+
"w": w
|
|
357
|
+
}, _ref3))), /*#__PURE__*/React.createElement(Children, _ref10.cn("Children", {})));
|
|
358
|
+
}
|
|
359
|
+
}]);
|
|
360
|
+
|
|
361
|
+
return DateRangeRoot;
|
|
362
|
+
}(Component);
|
|
363
|
+
|
|
364
|
+
_defineProperty(DateRangeRoot, "displayName", 'DateRange');
|
|
365
|
+
|
|
366
|
+
_defineProperty(DateRangeRoot, "style", style);
|
|
367
|
+
|
|
368
|
+
_defineProperty(DateRangeRoot, "defaultProps", {
|
|
369
|
+
children: function children() {
|
|
370
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DateRange.Indicator, null), /*#__PURE__*/React.createElement(DateRange.FromMaskedInput, null), /*#__PURE__*/React.createElement(DateRange.RangeSep, null), /*#__PURE__*/React.createElement(DateRange.ToMaskedInput, null));
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
var FromMaskedInput = function FromMaskedInput(props) {
|
|
375
|
+
var _ref4 = arguments[0],
|
|
376
|
+
_ref11;
|
|
377
|
+
|
|
378
|
+
var SFromMaskedInput = MaskedInput;
|
|
379
|
+
return _ref11 = sstyled(props.styles), /*#__PURE__*/React.createElement(SFromMaskedInput, _ref11.cn("SFromMaskedInput", _objectSpread({}, _assignProps4({
|
|
380
|
+
"labelPrefix": "from date"
|
|
381
|
+
}, _ref4))));
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
var ToMaskedInput = function ToMaskedInput(props) {
|
|
385
|
+
var _ref5 = arguments[0],
|
|
386
|
+
_ref12;
|
|
387
|
+
|
|
388
|
+
var SToMaskedInput = MaskedInput;
|
|
389
|
+
return _ref12 = sstyled(props.styles), /*#__PURE__*/React.createElement(SToMaskedInput, _ref12.cn("SToMaskedInput", _objectSpread({}, _assignProps5({
|
|
390
|
+
"labelPrefix": "to date"
|
|
391
|
+
}, _ref5))));
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
var Indicator = function Indicator(props) {
|
|
395
|
+
var _ref6 = arguments[0],
|
|
396
|
+
_ref13;
|
|
397
|
+
|
|
398
|
+
var SIndicator = InputMask.Addon;
|
|
399
|
+
return _ref13 = sstyled(props.styles), /*#__PURE__*/React.createElement(SIndicator, _ref13.cn("SIndicator", _objectSpread({}, _assignProps6({
|
|
400
|
+
"tag": Calendar,
|
|
401
|
+
"aria-hidden": "true",
|
|
402
|
+
"tabIndex": -1
|
|
403
|
+
}, _ref6))));
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
var RangeSep = function RangeSep(props) {
|
|
407
|
+
var _ref7 = arguments[0],
|
|
408
|
+
_ref14;
|
|
409
|
+
|
|
410
|
+
var SRangeSep = InputMask.Addon;
|
|
411
|
+
return _ref14 = sstyled(props.styles), /*#__PURE__*/React.createElement(SRangeSep, _ref14.cn("SRangeSep", _objectSpread({}, _assignProps7({
|
|
412
|
+
"tag": Flex,
|
|
413
|
+
"alignItems": "center",
|
|
414
|
+
"justifyContent": "center",
|
|
415
|
+
"pl": 0,
|
|
416
|
+
"flex": "0"
|
|
417
|
+
}, _ref7))), "-");
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
var MaskedInput = function MaskedInput(_ref16) {
|
|
421
|
+
var _ref15;
|
|
422
|
+
|
|
423
|
+
var outerValue = _ref16.date,
|
|
424
|
+
onDateChange = _ref16.onDateChange,
|
|
425
|
+
onDisplayedPeriodChange = _ref16.onDisplayedPeriodChange,
|
|
426
|
+
locale = _ref16.locale,
|
|
427
|
+
styles = _ref16.styles,
|
|
428
|
+
_ref16$parts = _ref16.parts,
|
|
429
|
+
allowedParts = _ref16$parts === void 0 ? defaultAllowedParts : _ref16$parts,
|
|
430
|
+
disabledDates = _ref16.disabledDates,
|
|
431
|
+
forwardRef = _ref16.forwardRef,
|
|
432
|
+
_ref16$placeholders = _ref16.placeholders,
|
|
433
|
+
placeholders = _ref16$placeholders === void 0 ? defaultPlaceholders : _ref16$placeholders,
|
|
434
|
+
_ref16$labelPrefix = _ref16.labelPrefix,
|
|
435
|
+
labelPrefix = _ref16$labelPrefix === void 0 ? 'Date' : _ref16$labelPrefix,
|
|
436
|
+
__excludeProps = _ref16.__excludeProps,
|
|
437
|
+
_root = _ref16.Root,
|
|
438
|
+
otherProps = _objectWithoutProperties(_ref16, _excluded6);
|
|
439
|
+
|
|
440
|
+
if (placeholders.year.length !== 1 || placeholders.month.length !== 1 || placeholders.day.length !== 1) {
|
|
441
|
+
// eslint-disable-next-line no-console
|
|
442
|
+
console.error({
|
|
443
|
+
placeholders: placeholders
|
|
444
|
+
});
|
|
445
|
+
throw new Error("InputTrigger placeholder prop should contain fields year, month and day each one with string value of single character length. [see above what was received] (".concat(placeholders, ")"), placeholders);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
var _React$useMemo = React.useMemo(function () {
|
|
449
|
+
var _sep;
|
|
450
|
+
|
|
451
|
+
var exampleDate = new Date(2000, 4, 29);
|
|
452
|
+
var options = {
|
|
453
|
+
year: 'numeric',
|
|
454
|
+
month: '2-digit',
|
|
455
|
+
day: '2-digit'
|
|
456
|
+
};
|
|
457
|
+
var dateTimeFormat = new Intl.DateTimeFormat(locale, options);
|
|
458
|
+
var sep = undefined;
|
|
459
|
+
var order = [];
|
|
460
|
+
var parts = dateTimeFormat.formatToParts(exampleDate);
|
|
461
|
+
|
|
462
|
+
var _iterator = _createForOfIteratorHelper(parts),
|
|
463
|
+
_step;
|
|
464
|
+
|
|
465
|
+
try {
|
|
466
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
467
|
+
var part = _step.value;
|
|
468
|
+
|
|
469
|
+
if (!sep && part.type === 'literal') {
|
|
470
|
+
sep = part.value;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (order.length < 3 && ['day', 'month', 'year'].includes(part.type) && allowedParts[part.type]) {
|
|
474
|
+
order.push(part.type);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
} catch (err) {
|
|
478
|
+
_iterator.e(err);
|
|
479
|
+
} finally {
|
|
480
|
+
_iterator.f();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
sep = (_sep = sep) !== null && _sep !== void 0 ? _sep : ' ';
|
|
484
|
+
return {
|
|
485
|
+
sep: sep,
|
|
486
|
+
order: order
|
|
487
|
+
};
|
|
488
|
+
}, [locale, allowedParts]),
|
|
489
|
+
sep = _React$useMemo.sep,
|
|
490
|
+
order = _React$useMemo.order;
|
|
491
|
+
|
|
492
|
+
var outer = React.useMemo(function () {
|
|
493
|
+
var validDate = outerValue && outerValue instanceof Date && !Number.isNaN(outerValue.getTime());
|
|
494
|
+
if (!validDate) return null;
|
|
495
|
+
return {
|
|
496
|
+
year: outerValue.getFullYear().toString().padStart(4, '0'),
|
|
497
|
+
month: (outerValue.getMonth() + 1).toString().padStart(2, '0'),
|
|
498
|
+
day: outerValue.getDate().toString().padStart(2, '0')
|
|
499
|
+
};
|
|
500
|
+
}, [outerValue]);
|
|
501
|
+
var stringifyValue = React.useCallback(function (value) {
|
|
502
|
+
if (!value) return null;
|
|
503
|
+
if (!value.year && !value.month && !value.day) return null;
|
|
504
|
+
var result = [];
|
|
505
|
+
|
|
506
|
+
var _iterator2 = _createForOfIteratorHelper(order),
|
|
507
|
+
_step2;
|
|
508
|
+
|
|
509
|
+
try {
|
|
510
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
511
|
+
var part = _step2.value;
|
|
512
|
+
if (!allowedParts[part]) continue;
|
|
513
|
+
if (part === 'year' && value.year) result.push(value.year);
|
|
514
|
+
if (part === 'month' && value.month) result.push(value.month);
|
|
515
|
+
if (part === 'day' && value.day) result.push(value.day);
|
|
516
|
+
}
|
|
517
|
+
} catch (err) {
|
|
518
|
+
_iterator2.e(err);
|
|
519
|
+
} finally {
|
|
520
|
+
_iterator2.f();
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
return result.join(sep);
|
|
524
|
+
}, [order, allowedParts]);
|
|
525
|
+
|
|
526
|
+
var _React$useState = React.useState(outer),
|
|
527
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
528
|
+
internalValue = _React$useState2[0],
|
|
529
|
+
setInternalValue = _React$useState2[1];
|
|
530
|
+
|
|
531
|
+
var value = React.useMemo(function () {
|
|
532
|
+
return stringifyValue(internalValue);
|
|
533
|
+
}, [stringifyValue, internalValue]);
|
|
534
|
+
var lastKnownOuterValue = React.useRef(outer);
|
|
535
|
+
React.useEffect(function () {
|
|
536
|
+
var _lastKnownOuterValue$, _lastKnownOuterValue$2, _lastKnownOuterValue$3;
|
|
537
|
+
|
|
538
|
+
if (((_lastKnownOuterValue$ = lastKnownOuterValue.current) === null || _lastKnownOuterValue$ === void 0 ? void 0 : _lastKnownOuterValue$.day) !== (outer === null || outer === void 0 ? void 0 : outer.day) || ((_lastKnownOuterValue$2 = lastKnownOuterValue.current) === null || _lastKnownOuterValue$2 === void 0 ? void 0 : _lastKnownOuterValue$2.month) !== (outer === null || outer === void 0 ? void 0 : outer.month) || ((_lastKnownOuterValue$3 = lastKnownOuterValue.current) === null || _lastKnownOuterValue$3 === void 0 ? void 0 : _lastKnownOuterValue$3.year) !== (outer === null || outer === void 0 ? void 0 : outer.year)) {
|
|
539
|
+
setInternalValue(outer);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
lastKnownOuterValue.current = outer;
|
|
543
|
+
}, [outer, setInternalValue]);
|
|
544
|
+
var pipeMask = React.useCallback(function (value) {
|
|
545
|
+
var placeholdersOnly = true;
|
|
546
|
+
|
|
547
|
+
for (var i = 0; i < value.length; i++) {
|
|
548
|
+
if (value[i] !== '_' && value[i] !== sep) {
|
|
549
|
+
placeholdersOnly = false;
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (placeholdersOnly) {
|
|
555
|
+
return '';
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
var getOffsetTo = function getOffsetTo(partName) {
|
|
559
|
+
var partsBefore = order.slice(0, order.indexOf(partName));
|
|
560
|
+
var offset = 0;
|
|
561
|
+
|
|
562
|
+
var _iterator3 = _createForOfIteratorHelper(partsBefore),
|
|
563
|
+
_step3;
|
|
564
|
+
|
|
565
|
+
try {
|
|
566
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
567
|
+
var part = _step3.value;
|
|
568
|
+
if (part === 'year' && allowedParts.year) offset += 4;
|
|
569
|
+
if (part === 'month' && allowedParts.month) offset += 2;
|
|
570
|
+
if (part === 'day' && allowedParts.day) offset += 2;
|
|
571
|
+
}
|
|
572
|
+
} catch (err) {
|
|
573
|
+
_iterator3.e(err);
|
|
574
|
+
} finally {
|
|
575
|
+
_iterator3.f();
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
offset += partsBefore.length * sep.length;
|
|
579
|
+
return offset;
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
var indexesOfPipedChars = [];
|
|
583
|
+
var parsed = {};
|
|
584
|
+
var parts = value.split(sep);
|
|
585
|
+
|
|
586
|
+
for (var partName in placeholders) {
|
|
587
|
+
parsed[partName] = placeholders[partName];
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
for (var _i = 0; _i < order.length; _i++) {
|
|
591
|
+
parsed[order[_i]] = parts[_i];
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
var year = parsed.year,
|
|
595
|
+
month = parsed.month,
|
|
596
|
+
day = parsed.day;
|
|
597
|
+
|
|
598
|
+
if (allowedParts.month) {
|
|
599
|
+
if (month[0] !== '_' && parseInt(month[0], 10) > 1) {
|
|
600
|
+
month = "0".concat(month[0]);
|
|
601
|
+
indexesOfPipedChars.push(getOffsetTo('month'));
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (month === '00') month = '01';
|
|
605
|
+
if (month[0] !== '_' && month[1] !== '_' && parseInt(month, 10) > 12) return false;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (allowedParts.day) {
|
|
609
|
+
if (day[0] !== '_' && parseInt(day[0], 10) > 3) {
|
|
610
|
+
day = "0".concat(day[0]);
|
|
611
|
+
indexesOfPipedChars.push(getOffsetTo('day'));
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (day === '00') day = '01';
|
|
615
|
+
if (day[0] !== '_' && day[1] !== '_' && parseInt(day, 10) > 31) return false;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
year = year.split('').map(function (_char) {
|
|
619
|
+
return _char === '_' ? placeholders.year : _char;
|
|
620
|
+
}).join('');
|
|
621
|
+
month = month.split('').map(function (_char2) {
|
|
622
|
+
return _char2 === '_' ? placeholders.month : _char2;
|
|
623
|
+
}).join('');
|
|
624
|
+
day = day.split('').map(function (_char3) {
|
|
625
|
+
return _char3 === '_' ? placeholders.day : _char3;
|
|
626
|
+
}).join('');
|
|
627
|
+
var yearFulfilled = !allowedParts.year || year && year.length >= 4 && !year.includes(placeholders.year);
|
|
628
|
+
var monthFulfilled = !allowedParts.month || month && month.length === 2 && !month.includes(placeholders.month);
|
|
629
|
+
var dayFulfilled = !allowedParts.day || day && day.length === 2 && !day.includes(placeholders.day);
|
|
630
|
+
var fulfilled = yearFulfilled && monthFulfilled && dayFulfilled;
|
|
631
|
+
|
|
632
|
+
if (fulfilled) {
|
|
633
|
+
var date = new Date();
|
|
634
|
+
date.setFullYear(allowedParts.year ? parseInt(year, 10) : 0);
|
|
635
|
+
date.setMonth(allowedParts.month ? parseInt(month, 10) - 1 : 0);
|
|
636
|
+
date.setDate(allowedParts.day ? parseInt(day, 10) : 1);
|
|
637
|
+
|
|
638
|
+
if (disabledDates && disabledDates.some(includesDate(dayjs(date), 'date'))) {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (allowedParts.day) {
|
|
643
|
+
if (date.getDate() !== parseInt(day, 10)) return false;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
var result = [];
|
|
648
|
+
|
|
649
|
+
var _iterator4 = _createForOfIteratorHelper(order),
|
|
650
|
+
_step4;
|
|
651
|
+
|
|
652
|
+
try {
|
|
653
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
654
|
+
var part = _step4.value;
|
|
655
|
+
if (part === 'year') result.push(year);
|
|
656
|
+
if (part === 'month') result.push(month);
|
|
657
|
+
if (part === 'day') result.push(day);
|
|
658
|
+
}
|
|
659
|
+
} catch (err) {
|
|
660
|
+
_iterator4.e(err);
|
|
661
|
+
} finally {
|
|
662
|
+
_iterator4.f();
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
return {
|
|
666
|
+
value: result.join(sep),
|
|
667
|
+
indexesOfPipedChars: indexesOfPipedChars
|
|
668
|
+
};
|
|
669
|
+
}, [placeholders, sep, order, allowedParts, disabledDates]);
|
|
670
|
+
var handleChange = React.useCallback(function (value) {
|
|
671
|
+
var parsed = {};
|
|
672
|
+
|
|
673
|
+
for (var partName in placeholders) {
|
|
674
|
+
parsed[partName] = placeholders[partName];
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
var parts = value.split(sep);
|
|
678
|
+
|
|
679
|
+
for (var i = 0; i < order.length; i++) {
|
|
680
|
+
parsed[order[i]] = parts[i];
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
var year = parsed.year,
|
|
684
|
+
month = parsed.month,
|
|
685
|
+
day = parsed.day;
|
|
686
|
+
setInternalValue({
|
|
687
|
+
year: year,
|
|
688
|
+
month: month,
|
|
689
|
+
day: day
|
|
690
|
+
});
|
|
691
|
+
var yearFulfilled = !allowedParts.year || year && year.length >= 4 && !year.includes(placeholders.year);
|
|
692
|
+
var monthFulfilled = !allowedParts.month || month && month.length === 2 && !month.includes(placeholders.month);
|
|
693
|
+
var dayFulfilled = !allowedParts.day || day && day.length === 2 && !day.includes(placeholders.day);
|
|
694
|
+
var fulfilled = yearFulfilled && monthFulfilled && dayFulfilled;
|
|
695
|
+
|
|
696
|
+
if (fulfilled) {
|
|
697
|
+
var date = new Date();
|
|
698
|
+
date.setFullYear(allowedParts.year ? parseInt(year, 10) : 0);
|
|
699
|
+
date.setMonth(allowedParts.month ? parseInt(month, 10) - 1 : 0);
|
|
700
|
+
date.setDate(allowedParts.day ? parseInt(day, 10) : 1);
|
|
701
|
+
onDateChange(date);
|
|
702
|
+
lastKnownOuterValue.current = {
|
|
703
|
+
year: year,
|
|
704
|
+
month: month,
|
|
705
|
+
day: day
|
|
706
|
+
};
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (lastKnownOuterValue.current !== null) {
|
|
711
|
+
onDateChange(null);
|
|
712
|
+
lastKnownOuterValue.current = null;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (yearFulfilled && allowedParts.year) {
|
|
716
|
+
var _date = new Date();
|
|
717
|
+
|
|
718
|
+
_date.setFullYear(parseInt(year, 10));
|
|
719
|
+
|
|
720
|
+
if (monthFulfilled && allowedParts.month) {
|
|
721
|
+
_date.setMonth(parseInt(month, 10) - 1);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
onDisplayedPeriodChange(_date);
|
|
725
|
+
}
|
|
726
|
+
}, [onDateChange, setInternalValue, placeholders, onDisplayedPeriodChange, order, allowedParts]);
|
|
727
|
+
var mask = React.useMemo(function () {
|
|
728
|
+
var result = [];
|
|
729
|
+
|
|
730
|
+
var _iterator5 = _createForOfIteratorHelper(order),
|
|
731
|
+
_step5;
|
|
732
|
+
|
|
733
|
+
try {
|
|
734
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
735
|
+
var part = _step5.value;
|
|
736
|
+
if (part === 'year') result.push(placeholders.year + placeholders.year + placeholders.year + placeholders.year);
|
|
737
|
+
if (part === 'month') result.push(placeholders.month + placeholders.month);
|
|
738
|
+
if (part === 'day') result.push(placeholders.day + placeholders.day);
|
|
739
|
+
}
|
|
740
|
+
} catch (err) {
|
|
741
|
+
_iterator5.e(err);
|
|
742
|
+
} finally {
|
|
743
|
+
_iterator5.f();
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
return result.join(sep);
|
|
747
|
+
}, [sep, order, placeholders]);
|
|
748
|
+
var aliases = React.useMemo(function () {
|
|
749
|
+
var _ref17;
|
|
750
|
+
|
|
751
|
+
return _ref17 = {}, _defineProperty(_ref17, placeholders.year, /\d/), _defineProperty(_ref17, placeholders.month, /\d/), _defineProperty(_ref17, placeholders.day, /\d/), _ref17;
|
|
752
|
+
}, [placeholders]);
|
|
753
|
+
var maskOnlySymbols = React.useMemo(function () {
|
|
754
|
+
var _ref18;
|
|
755
|
+
|
|
756
|
+
return _ref18 = {}, _defineProperty(_ref18, placeholders.year, true), _defineProperty(_ref18, placeholders.month, true), _defineProperty(_ref18, placeholders.day, true), _defineProperty(_ref18, sep, true), _ref18;
|
|
757
|
+
}, [sep, placeholders]);
|
|
758
|
+
var humanizedDate = React.useMemo(function () {
|
|
759
|
+
var validDate = outerValue && outerValue instanceof Date && !Number.isNaN(outerValue.getTime());
|
|
760
|
+
if (!validDate) return null;
|
|
761
|
+
return new Intl.DateTimeFormat(locale, {
|
|
762
|
+
year: allowedParts.year ? 'numeric' : undefined,
|
|
763
|
+
month: allowedParts.month ? 'short' : undefined,
|
|
764
|
+
day: allowedParts.day ? '2-digit' : undefined
|
|
765
|
+
}).format(outerValue);
|
|
766
|
+
}, [outerValue, locale, allowedParts]);
|
|
767
|
+
var SHumanizedDate = 'div';
|
|
768
|
+
var handleInputRef = React.useCallback(function (node) {
|
|
769
|
+
if (!node || node.tagName !== 'INPUT') return;
|
|
770
|
+
if (typeof forwardRef === 'function') forwardRef(node);else forwardRef.current = node;
|
|
771
|
+
}, [forwardRef]);
|
|
772
|
+
return _ref15 = sstyled(styles), /*#__PURE__*/React.createElement(InputMask.Value, _extends({
|
|
773
|
+
title: "".concat(labelPrefix, " ").concat(mask),
|
|
774
|
+
mask: mask,
|
|
775
|
+
aliases: aliases,
|
|
776
|
+
maskOnlySymbols: maskOnlySymbols,
|
|
777
|
+
placeholder: mask
|
|
778
|
+
}, otherProps, {
|
|
779
|
+
ref: handleInputRef,
|
|
780
|
+
pipe: pipeMask,
|
|
781
|
+
value: value,
|
|
782
|
+
onChange: handleChange,
|
|
783
|
+
noHumanizedDate: !humanizedDate
|
|
784
|
+
}), humanizedDate && /*#__PURE__*/React.createElement(SHumanizedDate, _ref15.cn("SHumanizedDate", {}), humanizedDate));
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
var SingleDateInput = createComponent(SingleDateInputRoot, {
|
|
788
|
+
Indicator: Indicator,
|
|
789
|
+
MaskedInput: MaskedInput
|
|
790
|
+
});
|
|
791
|
+
var DateRange = createComponent(DateRangeRoot, {
|
|
792
|
+
Indicator: Indicator,
|
|
793
|
+
RangeSep: RangeSep,
|
|
794
|
+
FromMaskedInput: FromMaskedInput,
|
|
795
|
+
ToMaskedInput: ToMaskedInput
|
|
796
|
+
});
|
|
797
|
+
var InputTrigger = createComponent(InputTriggerRoot, {
|
|
798
|
+
Addon: BaseTrigger.Addon,
|
|
799
|
+
SingleDateInput: SingleDateInput,
|
|
800
|
+
DateRange: DateRange
|
|
801
|
+
});
|
|
802
|
+
export default InputTrigger;
|
|
803
|
+
//# sourceMappingURL=InputTrigger.js.map
|