@commercetools-uikit/date-time-input 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ <!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
2
+ <!-- This file is created by the `yarn generate-readme` script. -->
3
+
4
+ # DateTimeInput
5
+
6
+ ## Description
7
+
8
+ The `DateTimeInput` component allows the user to select a date. This component also supports multiple date selection.
9
+
10
+ It formats the selected date depending on the current locale.
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ yarn add @commercetools-uikit/date-time-input
16
+ ```
17
+
18
+ ```
19
+ npm --save install @commercetools-uikit/date-time-input
20
+ ```
21
+
22
+ Additionally install the peer dependencies (if not present)
23
+
24
+ ```
25
+ yarn add moment react react-intl
26
+ ```
27
+
28
+ ```
29
+ npm --save install moment react react-intl
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```jsx
35
+ import DateTimeInput from '@commercetools-uikit/date-time-input';
36
+
37
+ const Example = () => (
38
+ <DateTimeInput
39
+ placeholder="Select a date..."
40
+ timeZone="Europe/Berlin"
41
+ value="2018-10-04T09:00:00.000Z"
42
+ onChange={() => {}}
43
+ />
44
+ );
45
+
46
+ export default Example;
47
+ ```
48
+
49
+ ## Properties
50
+
51
+ | Props | Type | Required | Default | Description |
52
+ | ------------------------- | -------------------------------------------------------------------------------------------- | :------: | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53
+ | `aria-invalid` | `boolean` | | | Indicate if the value entered in the input is invalid. |
54
+ | `aria-errormessage` | `string` | | | HTML ID of an element containing an error message related to the input. |
55
+ | `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | | Horizontal size limit of the input field. |
56
+ | `value` | `string` | ✅ | | The selected date, must either be an empty string or a date formatted in ISO 8601 (e.g. "2018-10-04T09:00:00.000Z"). |
57
+ | `onChange` | `Function`<br/>[See signature.](#signature-onchange) | | | Called when the date changes. Called with an event containing an empty string (no value) or a string in this format: "YYYY-MM-DD". |
58
+ | `onFocus` | `FocusEventHandler` | | | Called when the date input gains focus. |
59
+ | `onBlur` | `Function`<br/>[See signature.](#signature-onblur) | | | Called when the date input loses focus. |
60
+ | `timeZone` | `string` | ✅ | | Specifies the time zone in which the calendar and selected values are shown. It also influences how entered dates and times are parsed.&#xA;Get list of timezone with `moment.tz.names()` [See moment docs](https://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/) |
61
+ | `id` | `string` | | | Used as the HTML `id` attribute. |
62
+ | `name` | `string` | | | Used as the HTML `name` attribute. |
63
+ | `placeholder` | `string` | | | Placeholder value to show in the input field |
64
+ | `isCondensed` | `boolean` | | | Use this property to reduce the paddings of the component for a ui compact variant |
65
+ | `isDisabled` | `boolean` | | | Disables the date picker |
66
+ | `isReadOnly` | `boolean` | | | Disables the date picker menu and sets the input field as read-only |
67
+ | `hasError` | `boolean` | | | Indicates the input field has an error |
68
+ | `hasWarning` | `boolean` | | | Indicates the input field has a warning |
69
+ | `defaultDaySelectionTime` | `string` | | | The time that will be used by default when a user selects a calendar day.&#xA;It must follow the “HH:mm” pattern (eg: 04:30, 13:25, 23:59) |
70
+
71
+ ## Signatures
72
+
73
+ ### Signature `onChange`
74
+
75
+ ```ts
76
+ (event: TCustomEvent) => void
77
+ ```
78
+
79
+ ### Signature `onBlur`
80
+
81
+ ```ts
82
+ (event: TCustomEvent) => void
83
+ ```
84
+
85
+ ### `props.timeZone`
86
+
87
+ The `timeZone` specifies which time zone the calendar uses, which time zone the selected value is shown in and which time zone entered dates and times are parsed in. For example, given the value is `2018-10-18T00:00:00.000Z` and the`timeZone`is set to`Europe/Berlin`, then entering "13:00" as the time results in the`onChange`being called with`2018-10-15T11:00:00.000Z` (as the time zone offset for that date is two hours).
@@ -0,0 +1,3 @@
1
+ export * from "./declarations/src/index.js";
2
+ export { default } from "./declarations/src/index.js";
3
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC1kYXRlLXRpbWUtaW5wdXQuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
@@ -0,0 +1,433 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
6
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
7
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
8
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
9
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
10
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
11
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
12
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
13
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
14
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
15
+ var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
16
+ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
17
+ var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
18
+ var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
19
+ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
20
+ var _pt = require('prop-types');
21
+ var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
22
+ var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
23
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
24
+ var react$1 = require('react');
25
+ var Downshift = require('downshift');
26
+ var reactIntl = require('react-intl');
27
+ var Constraints = require('@commercetools-uikit/constraints');
28
+ var utils = require('@commercetools-uikit/utils');
29
+ var calendarTimeUtils = require('@commercetools-uikit/calendar-time-utils');
30
+ var calendarUtils = require('@commercetools-uikit/calendar-utils');
31
+ var react = require('@emotion/react');
32
+ var designSystem = require('@commercetools-uikit/design-system');
33
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
34
+
35
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
36
+
37
+ var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
38
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
39
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
40
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
41
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
42
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
43
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
44
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
45
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
46
+ var _pt__default = /*#__PURE__*/_interopDefault(_pt);
47
+ var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
48
+ var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
49
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
50
+ var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
51
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
52
+
53
+ const getInputStyles = () => /*#__PURE__*/react.css("width:100%;text-align:center;border:0;border-top:1px solid ", designSystem.designTokens.colorNeutral90, ";padding:10px 0;outline:0;font-size:", designSystem.designTokens.fontSize30, ";margin-top:", designSystem.designTokens.spacing20, ";color:", designSystem.designTokens.colorSolid, ";:disabled{background-color:", designSystem.designTokens.colorSurface, ";}" + (process.env.NODE_ENV === "production" ? "" : ";label:getInputStyles;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRpbWUtaW5wdXQudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1nQyIsImZpbGUiOiJ0aW1lLWlucHV0LnRzeCIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHR5cGVzPVwiQGVtb3Rpb24vcmVhY3QvdHlwZXMvY3NzLXByb3BcIiAvPlxuaW1wb3J0IHR5cGUgeyBLZXlib2FyZEV2ZW50SGFuZGxlciwgUmVmT2JqZWN0IH0gZnJvbSAncmVhY3QnO1xuaW1wb3J0IHsgY3NzIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnO1xuaW1wb3J0IHsgZGVzaWduVG9rZW5zIH0gZnJvbSAnQGNvbW1lcmNldG9vbHMtdWlraXQvZGVzaWduLXN5c3RlbSc7XG5pbXBvcnQgdHlwZSB7IFREYXRlVGltZUlucHV0UHJvcHMgfSBmcm9tICcuL2RhdGUtdGltZS1pbnB1dCc7XG5cbmNvbnN0IGdldElucHV0U3R5bGVzID0gKCkgPT4gY3NzYFxuICB3aWR0aDogMTAwJTtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBib3JkZXI6IDA7XG4gIGJvcmRlci10b3A6IDFweCBzb2xpZCAke2Rlc2lnblRva2Vucy5jb2xvck5ldXRyYWw5MH07XG4gIHBhZGRpbmc6IDEwcHggMDtcbiAgb3V0bGluZTogMDtcbiAgZm9udC1zaXplOiAke2Rlc2lnblRva2Vucy5mb250U2l6ZTMwfTtcbiAgbWFyZ2luLXRvcDogJHtkZXNpZ25Ub2tlbnMuc3BhY2luZzIwfTtcbiAgY29sb3I6ICR7ZGVzaWduVG9rZW5zLmNvbG9yU29saWR9O1xuXG4gIDpkaXNhYmxlZCB7XG4gICAgLyogRml4ZXMgYmFja2dyb3VuZCBjb2xvciBpbiBGaXJlZm94ICovXG4gICAgYmFja2dyb3VuZC1jb2xvcjogJHtkZXNpZ25Ub2tlbnMuY29sb3JTdXJmYWNlfTtcbiAgfVxuYDtcblxudHlwZSBURGF0ZUNhbGVuZGFyVGltZUlucHV0UHJvcHMgPSB7XG4gIHRpbWVJbnB1dFJlZjogUmVmT2JqZWN0PEhUTUxJbnB1dEVsZW1lbnQ+O1xuICBvbktleURvd246IEtleWJvYXJkRXZlbnRIYW5kbGVyPEhUTUxJbnB1dEVsZW1lbnQ+O1xufSAmIFBpY2s8XG4gIFREYXRlVGltZUlucHV0UHJvcHMsXG4gICdpc0Rpc2FibGVkJyB8ICdvbkNoYW5nZScgfCAndmFsdWUnIHwgJ3BsYWNlaG9sZGVyJ1xuPjtcblxuY29uc3QgRGF0ZUNhbGVuZGFyVGltZUlucHV0ID0gKHByb3BzOiBURGF0ZUNhbGVuZGFyVGltZUlucHV0UHJvcHMpID0+IChcbiAgPGlucHV0XG4gICAgZGlzYWJsZWQ9e3Byb3BzLmlzRGlzYWJsZWR9XG4gICAgcmVmPXtwcm9wcy50aW1lSW5wdXRSZWZ9XG4gICAgdHlwZT1cInRleHRcIlxuICAgIHZhbHVlPXtwcm9wcy52YWx1ZX1cbiAgICBvbkNoYW5nZT17cHJvcHMub25DaGFuZ2V9XG4gICAgb25LZXlEb3duPXtwcm9wcy5vbktleURvd259XG4gICAgcGxhY2Vob2xkZXI9e3Byb3BzLnBsYWNlaG9sZGVyfVxuICAgIGNzcz17Z2V0SW5wdXRTdHlsZXMoKX1cbiAgLz5cbik7XG5cbkRhdGVDYWxlbmRhclRpbWVJbnB1dC5kaXNwbGF5TmFtZSA9ICdEYXRlQ2FsZW5kYXJUaW1lSW5wdXQnO1xuXG5leHBvcnQgZGVmYXVsdCBEYXRlQ2FsZW5kYXJUaW1lSW5wdXQ7XG4iXX0= */");
54
+ const DateCalendarTimeInput = props => jsxRuntime.jsx("input", {
55
+ disabled: props.isDisabled,
56
+ ref: props.timeInputRef,
57
+ type: "text",
58
+ value: props.value,
59
+ onChange: props.onChange,
60
+ onKeyDown: props.onKeyDown,
61
+ placeholder: props.placeholder,
62
+ css: getInputStyles()
63
+ });
64
+ DateCalendarTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
65
+ timeInputRef: _pt__default["default"].any.isRequired,
66
+ onKeyDown: _pt__default["default"].func.isRequired
67
+ } : {};
68
+ DateCalendarTimeInput.displayName = 'DateCalendarTimeInput';
69
+ var TimeInput = DateCalendarTimeInput;
70
+
71
+ function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
72
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
73
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
74
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
75
+ const activationTypes = [Downshift__default["default"].stateChangeTypes.keyDownEnter, Downshift__default["default"].stateChangeTypes.clickItem];
76
+ const preventDownshiftDefault = event => {
77
+ event.nativeEvent.preventDownshiftDefault = true;
78
+ };
79
+
80
+ // This keeps the menu open when the user focuses the time input (thereby
81
+ // blurring the regular input/toggle button)
82
+ const createBlurHandler = function (timeInputRef) {
83
+ let cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
84
+ return event => {
85
+ event.persist();
86
+ if (event.relatedTarget === timeInputRef.current) {
87
+ preventDownshiftDefault(event);
88
+ }
89
+ cb();
90
+ };
91
+ };
92
+ let DateTimeInput = /*#__PURE__*/function (_Component) {
93
+ function DateTimeInput() {
94
+ var _this;
95
+ _classCallCheck(this, DateTimeInput);
96
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
97
+ args[_key] = arguments[_key];
98
+ }
99
+ _this = _callSuper(this, DateTimeInput, [...args]);
100
+ _this.inputRef = /*#__PURE__*/react$1.createRef();
101
+ _this.timeInputRef = /*#__PURE__*/react$1.createRef();
102
+ _this.state = {
103
+ calendarDate: calendarTimeUtils.getToday(_this.props.timeZone),
104
+ suggestedItems: [],
105
+ highlightedIndex: _this.props.value === '' ? null : calendarTimeUtils.getDateInMonth(_this.props.value, _this.props.timeZone) - 1,
106
+ timeString: _this.props.defaultDaySelectionTime ? calendarTimeUtils.formatDefaultTime(_this.props.defaultDaySelectionTime, _this.props.intl.locale) : ''
107
+ };
108
+ _this.jumpMonths = function (amount) {
109
+ let dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
110
+ _this.setState(prevState => {
111
+ const nextDate = calendarTimeUtils.changeMonth(prevState.calendarDate, _this.props.timeZone, amount);
112
+ return {
113
+ calendarDate: nextDate,
114
+ highlightedIndex: dayToHighlight
115
+ };
116
+ });
117
+ };
118
+ _this.showToday = () => {
119
+ const today = calendarTimeUtils.getToday(_this.props.timeZone);
120
+ _this.setState(prevState => ({
121
+ calendarDate: today,
122
+ highlightedIndex: (prevState.suggestedItems || []).length + calendarTimeUtils.getDateInMonth(today, _this.props.timeZone) - 1
123
+ }), () => _this.inputRef.current?.focus());
124
+ };
125
+ _this.handleBlur = () => {
126
+ if (_this.props.onBlur) _this.props.onBlur({
127
+ target: {
128
+ id: _this.props.id,
129
+ name: _this.props.name
130
+ }
131
+ });
132
+ };
133
+ _this.handleTimeChange = event => {
134
+ const parsedTime = utils.parseTime(event.target.value);
135
+ _this.setState({
136
+ timeString: event.target.value
137
+ });
138
+
139
+ // We can't update the parent when there is no value
140
+ if (_this.props.value === '') return;
141
+ let date = calendarTimeUtils.getStartOf(_this.props.value, _this.props.timeZone);
142
+ if (parsedTime) {
143
+ date = calendarTimeUtils.changeTime(date, _this.props.timeZone, parsedTime);
144
+ }
145
+ _this.emit(date);
146
+ };
147
+ _this.emit = value => _this.props.onChange?.({
148
+ target: {
149
+ id: _this.props.id,
150
+ name: _this.props.name,
151
+ // when cleared the value is null, but we always want it to be an
152
+ // empty string when there is no value.
153
+ value: value || ''
154
+ }
155
+ });
156
+ return _this;
157
+ }
158
+ _inherits(DateTimeInput, _Component);
159
+ return _createClass(DateTimeInput, [{
160
+ key: "render",
161
+ value: function render() {
162
+ if (!this.props.isReadOnly) {
163
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'DateTimeInput: `onChange` is required when input is not read only.') : void 0;
164
+ }
165
+ return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
166
+ max: this.props.horizontalConstraint,
167
+ children: jsxRuntime.jsx(Downshift__default["default"]
168
+ // Setting the key to the timeZone conveniently forces a rerender
169
+ // when the time-zone changes. Otherwise we'd need to make
170
+ // inputValue a controlled property so that we can update
171
+ // the displayed value as downshift seems to ignore an updated
172
+ // itemToString function.
173
+ , {
174
+ inputId: this.props.id,
175
+ itemToString: calendarTimeUtils.createItemDateTimeToString(this.props.intl.locale, this.props.timeZone),
176
+ selectedItem: this.props.value === '' ? null : this.props.value,
177
+ highlightedIndex: this.state.highlightedIndex,
178
+ onChange: this.emit,
179
+ stateReducer: (_, changes) => {
180
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
181
+ return _objectSpread(_objectSpread({}, changes), {}, {
182
+ isOpen: true
183
+ });
184
+ }
185
+ return changes;
186
+ },
187
+ onStateChange: changes => {
188
+ this.setState(prevState => {
189
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
190
+ return {
191
+ startDate: changes.isOpen ? prevState.startDate : null,
192
+ inputValue: changes.inputValue || prevState.inputValue,
193
+ timeString: changes.selectedItem ? calendarTimeUtils.formatTime(changes.selectedItem, this.props.intl.locale, this.props.timeZone) : prevState.timeString
194
+ };
195
+ }
196
+ if (changes.hasOwnProperty('inputValue')) {
197
+ const suggestedItems = calendarTimeUtils.createSuggestedItems(changes.inputValue, this.props.timeZone);
198
+ return {
199
+ suggestedItems,
200
+ highlightedIndex: suggestedItems.length > 0 ? 0 : null
201
+ };
202
+ }
203
+ if (changes.hasOwnProperty('isOpen')) {
204
+ return {
205
+ inputValue: changes.inputValue || prevState.inputValue,
206
+ startDate: changes.isOpen ? prevState.startDate : null,
207
+ // set time input value to time from value when menu is opened
208
+ // or to the current timeString which equals to defaultDaySelectionTime prop
209
+ timeString: changes.isOpen && this.props.value !== '' ? calendarTimeUtils.formatTime(this.props.value, this.props.intl.locale, this.props.timeZone) : this.state.timeString,
210
+ // ensure calendar always opens on selected item, or on
211
+ // current month when there is no selected item
212
+ calendarDate: this.props.value === '' ? calendarTimeUtils.getToday(this.props.timeZone) : this.props.value
213
+ };
214
+ }
215
+ if (changes.hasOwnProperty('highlightedIndex')) {
216
+ return {
217
+ highlightedIndex: changes.highlightedIndex
218
+ };
219
+ }
220
+ return null;
221
+ }, () => {
222
+ if (_includesInstanceProperty__default["default"](activationTypes).call(activationTypes, changes.type)) {
223
+ this.timeInputRef.current?.focus();
224
+ this.timeInputRef.current?.setSelectionRange(0, this.state.timeString.length);
225
+ }
226
+ });
227
+ },
228
+ children: _ref => {
229
+ var _context;
230
+ let getInputProps = _ref.getInputProps,
231
+ getMenuProps = _ref.getMenuProps,
232
+ getItemProps = _ref.getItemProps,
233
+ getToggleButtonProps = _ref.getToggleButtonProps,
234
+ clearSelection = _ref.clearSelection,
235
+ highlightedIndex = _ref.highlightedIndex,
236
+ openMenu = _ref.openMenu,
237
+ closeMenu = _ref.closeMenu,
238
+ setHighlightedIndex = _ref.setHighlightedIndex,
239
+ selectedItem = _ref.selectedItem,
240
+ inputValue = _ref.inputValue,
241
+ isOpen = _ref.isOpen;
242
+ const suggestedItems = this.state.suggestedItems;
243
+ const calendarItems = calendarTimeUtils.createCalendarItems(this.state.calendarDate, this.state.timeString, this.props.timeZone);
244
+ const paddingDayCount = calendarTimeUtils.getPaddingDayCount(this.state.calendarDate, this.props.intl.locale, this.props.timeZone);
245
+ const paddingDays = _fillInstanceProperty__default["default"](_context = Array(paddingDayCount)).call(_context, undefined);
246
+ const weekdays = calendarTimeUtils.getWeekdayNames(this.props.intl.locale);
247
+ const today = calendarTimeUtils.getToday(this.props.timeZone);
248
+ const isTimeInputVisible = Boolean(this.props.value) && this.props.value !== '';
249
+ return jsxRuntime.jsxs("div", {
250
+ onFocus: this.props.onFocus,
251
+ onBlur: this.handleBlur,
252
+ children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
253
+ inputRef: this.inputRef,
254
+ inputProps: getInputProps(_objectSpread({
255
+ /* ARIA */
256
+ 'aria-invalid': this.props['aria-invalid'],
257
+ 'aria-errormessage': this.props['aria-errormessage'],
258
+ // Unset the aria-labelledby as it interfers with the link
259
+ // between the <label for> and the <input id>.
260
+ 'aria-labelledby': undefined,
261
+ name: this.props.name,
262
+ placeholder: typeof this.props.placeholder === 'string' ? this.props.placeholder : calendarTimeUtils.getLocalizedDateTimeFormatPattern(this.props.intl.locale, 'full'),
263
+ onMouseEnter: () => {
264
+ // we remove the highlight so that the user can use the
265
+ // arrow keys to move the cursor when hovering
266
+ if (isOpen) setHighlightedIndex(-1);
267
+ },
268
+ onKeyDown: event => {
269
+ if (this.props.isReadOnly) {
270
+ preventDownshiftDefault(event);
271
+ return;
272
+ }
273
+ // parse input when user presses enter on regular input,
274
+ // close menu and notify parent
275
+ if (event.key === 'Enter' && highlightedIndex === null) {
276
+ preventDownshiftDefault(event);
277
+ const parsedDate = calendarTimeUtils.parseInputText(inputValue, this.props.intl.locale, this.props.timeZone);
278
+
279
+ // If there is no parsed date, don't clear and submit. Instead, give
280
+ // the user a chance to fix the value.
281
+ if (!parsedDate) return;
282
+ this.emit(parsedDate);
283
+ closeMenu();
284
+ }
285
+ // ArrowDown
286
+ if (event.key === 'ArrowDown') {
287
+ if (Number(highlightedIndex) + 1 >= calendarItems.length) {
288
+ // if it's the end of the month
289
+ // then bypass normal arrow navigation
290
+ preventDownshiftDefault(event);
291
+ // then jump to start of next month
292
+ this.jumpMonths(1, 0);
293
+ }
294
+ }
295
+ // ArrowUp
296
+ if (event.key === 'ArrowUp') {
297
+ const previousDay = calendarTimeUtils.getPreviousDay(calendarItems[Number(highlightedIndex)]);
298
+ if (Number(highlightedIndex) <= 0) {
299
+ // if it's the start of the month
300
+ // then bypass normal arrow navigation
301
+ preventDownshiftDefault(event);
302
+ const numberOfDaysOfPrevMonth = calendarTimeUtils.getDaysInMonth(previousDay, this.props.timeZone);
303
+ // then jump to the last day of the previous month
304
+ this.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
305
+ }
306
+ }
307
+ },
308
+ onClick: this.props.isReadOnly ? undefined : openMenu,
309
+ // validate the input on blur, and emit the value if it's valid
310
+ onBlur: createBlurHandler(this.timeInputRef, () => {
311
+ const inputValue = this.inputRef.current?.value || '';
312
+ const parsedDate = calendarTimeUtils.parseInputText(inputValue, this.props.intl.locale, this.props.timeZone);
313
+ if (inputValue.length > 0 && !parsedDate) return;
314
+ this.emit(parsedDate);
315
+ }),
316
+ onChange: event => {
317
+ // keep timeInput and regular input in sync when user
318
+ // types into regular input
319
+ if (!isOpen) return;
320
+ const time = event.target.value?.split(' ')[1];
321
+ if (!time) return;
322
+ const parsedTime = utils.parseTime(time);
323
+ this.setState(() => {
324
+ if (!parsedTime) return {
325
+ timeString: ''
326
+ };
327
+ let date = calendarTimeUtils.getToday(this.props.timeZone);
328
+ if (parsedTime) {
329
+ date = calendarTimeUtils.changeTime(date, this.props.timeZone, parsedTime);
330
+ }
331
+ return {
332
+ timeString: calendarTimeUtils.formatTime(date, this.props.intl.locale, this.props.timeZone)
333
+ };
334
+ });
335
+ }
336
+ }, utils.filterDataAttributes(this.props))),
337
+ hasSelection: Boolean(selectedItem),
338
+ onClear: clearSelection,
339
+ isOpen: isOpen,
340
+ isCondensed: this.props.isCondensed,
341
+ isDisabled: this.props.isDisabled,
342
+ isReadOnly: this.props.isReadOnly,
343
+ toggleButtonProps: getToggleButtonProps({
344
+ onBlur: createBlurHandler(this.timeInputRef)
345
+ }),
346
+ hasError: this.props.hasError,
347
+ hasWarning: this.props.hasWarning
348
+ }), isOpen && !this.props.isDisabled && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
349
+ hasFooter: true,
350
+ hasError: this.props.hasError,
351
+ hasWarning: this.props.hasWarning,
352
+ children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
353
+ monthLabel: calendarTimeUtils.getMonthCalendarLabel(this.state.calendarDate, this.props.intl.locale),
354
+ yearLabel: calendarTimeUtils.getYearCalendarLabel(this.state.calendarDate, this.props.intl.locale),
355
+ onPrevMonthClick: () => this.jumpMonths(-1),
356
+ onTodayClick: this.showToday,
357
+ onNextMonthClick: () => this.jumpMonths(1),
358
+ onPrevYearClick: () => this.jumpMonths(-12),
359
+ onNextYearClick: () => this.jumpMonths(12)
360
+ }), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
361
+ children: [_mapInstanceProperty__default["default"](weekdays).call(weekdays, weekday => jsxRuntime.jsx(calendarUtils.CalendarDay, {
362
+ type: "heading",
363
+ children: weekday
364
+ }, weekday)), _mapInstanceProperty__default["default"](paddingDays).call(paddingDays, (_, index) => jsxRuntime.jsx(calendarUtils.CalendarDay, {
365
+ type: "spacing"
366
+ }, index)), _mapInstanceProperty__default["default"](calendarItems).call(calendarItems, (item, index) => jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
367
+ isToday: calendarTimeUtils.isSameDay(today, item)
368
+ }, getItemProps({
369
+ disabled: this.props.isDisabled,
370
+ item,
371
+ onMouseOut: () => {
372
+ setHighlightedIndex(-1);
373
+ }
374
+ })), {}, {
375
+ isHighlighted: suggestedItems.length + index === highlightedIndex,
376
+ isSelected: calendarTimeUtils.isSameDay(item, this.props.value),
377
+ children: calendarTimeUtils.getCalendarDayLabel(item, this.props.timeZone)
378
+ }), item))]
379
+ }), jsxRuntime.jsx(TimeInput, {
380
+ isDisabled: !isTimeInputVisible,
381
+ timeInputRef: this.timeInputRef,
382
+ placeholder: calendarTimeUtils.getLocalizedDateTimeFormatPattern(this.props.intl.locale, 'time'),
383
+ value: this.state.timeString,
384
+ onChange: this.handleTimeChange,
385
+ onKeyDown: event => {
386
+ if (event.key === 'ArrowUp') {
387
+ setHighlightedIndex(-1);
388
+ this.inputRef.current?.focus();
389
+ return;
390
+ }
391
+ if (event.key === 'Enter') {
392
+ setHighlightedIndex(-1);
393
+ this.inputRef.current?.focus();
394
+ this.inputRef.current?.setSelectionRange(0, 100);
395
+ closeMenu();
396
+ }
397
+ }
398
+ })]
399
+ }))]
400
+ });
401
+ }
402
+ }, `${this.props.timeZone}:${this.props.intl.locale}`)
403
+ });
404
+ }
405
+ }]);
406
+ }(react$1.Component);
407
+ DateTimeInput.displayName = 'DateTimeInput';
408
+ DateTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
409
+ 'aria-invalid': _pt__default["default"].bool,
410
+ 'aria-errormessage': _pt__default["default"].string,
411
+ horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
412
+ value: _pt__default["default"].string.isRequired,
413
+ onChange: _pt__default["default"].func,
414
+ onFocus: _pt__default["default"].func,
415
+ onBlur: _pt__default["default"].func,
416
+ timeZone: _pt__default["default"].string.isRequired,
417
+ id: _pt__default["default"].string,
418
+ name: _pt__default["default"].string,
419
+ placeholder: _pt__default["default"].string,
420
+ isCondensed: _pt__default["default"].bool,
421
+ isDisabled: _pt__default["default"].bool,
422
+ isReadOnly: _pt__default["default"].bool,
423
+ hasError: _pt__default["default"].bool,
424
+ hasWarning: _pt__default["default"].bool,
425
+ defaultDaySelectionTime: _pt__default["default"].string
426
+ } : {};
427
+ var dateTimeInput = reactIntl.injectIntl(DateTimeInput);
428
+
429
+ // NOTE: This string will be replaced on build time with the package version.
430
+ var version = "19.25.1";
431
+
432
+ exports["default"] = dateTimeInput;
433
+ exports.version = version;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-uikit-date-time-input.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-uikit-date-time-input.cjs.dev.js");
7
+ }