@commercetools-uikit/date-time-input 0.0.0-canary-2021830134526
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 +21 -0
- package/README.md +72 -0
- package/dist/commercetools-uikit-date-time-input.cjs.dev.js +573 -0
- package/dist/commercetools-uikit-date-time-input.cjs.js +7 -0
- package/dist/commercetools-uikit-date-time-input.cjs.prod.js +493 -0
- package/dist/commercetools-uikit-date-time-input.esm.js +549 -0
- package/package.json +67 -0
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,72 @@
|
|
|
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
|
+
| `intl` | `object` | ✅ | | |
|
|
54
|
+
| `intl.locale` | `string` | ✅ | | |
|
|
55
|
+
| `intl.formatMessage` | `func` | ✅ | | |
|
|
56
|
+
| `horizontalConstraint` | `enum`<br/>Possible values:<br/>`6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | | Horizontal size limit of the input field. |
|
|
57
|
+
| `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"). |
|
|
58
|
+
| `onChange` | `func` | ✅ | | Called when the date changes. Called with an event containing an empty string (no value) or a string in this format: "YYYY-MM-DD".
<br />
Signature: `(event) => void` |
|
|
59
|
+
| `onFocus` | `func` | | | Called when the date input gains focus. |
|
|
60
|
+
| `onBlur` | `func` | | | Called when the date input loses focus. |
|
|
61
|
+
| `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. |
|
|
62
|
+
| `id` | `string` | | | Used as the HTML `id` attribute. |
|
|
63
|
+
| `name` | `string` | | | Used as the HTML `name` attribute. |
|
|
64
|
+
| `placeholder` | `string` | | | Placeholder value to show in the input field |
|
|
65
|
+
| `isDisabled` | `bool` | | | Disables the date picker |
|
|
66
|
+
| `isReadOnly` | `bool` | | | Disables the date picker menu and sets the input field as read-only |
|
|
67
|
+
| `hasError` | `bool` | | | Indicates the input field has an error |
|
|
68
|
+
| `hasWarning` | `bool` | | | Indicates the input field has a warning |
|
|
69
|
+
|
|
70
|
+
### `props.timeZone`
|
|
71
|
+
|
|
72
|
+
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,573 @@
|
|
|
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 _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
18
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
19
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
20
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
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 PropTypes = require('prop-types');
|
|
26
|
+
var Downshift = require('downshift');
|
|
27
|
+
var reactIntl = require('react-intl');
|
|
28
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
29
|
+
var utils = require('@commercetools-uikit/utils');
|
|
30
|
+
var calendarTimeUtils = require('@commercetools-uikit/calendar-time-utils');
|
|
31
|
+
var calendarUtils = require('@commercetools-uikit/calendar-utils');
|
|
32
|
+
var react = require('@emotion/react');
|
|
33
|
+
var designSystem = require('@commercetools-uikit/design-system');
|
|
34
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
35
|
+
|
|
36
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
37
|
+
|
|
38
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
39
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
40
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
41
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
43
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
44
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
45
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
46
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
47
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
48
|
+
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
49
|
+
var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
|
|
50
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
51
|
+
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
52
|
+
var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
|
|
53
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
54
|
+
|
|
55
|
+
var getInputStyles = function getInputStyles() {
|
|
56
|
+
return /*#__PURE__*/react.css("width:100%;text-align:center;border:0;border-top:1px solid ", designSystem.customProperties.colorNeutral90, ";padding:10px 0;outline:0;font-size:", designSystem.customProperties.fontSizeDefault, ";margin-top:", designSystem.customProperties.spacingS, ";color:", designSystem.customProperties.colorSolid, ";:disabled{background-color:", designSystem.customProperties.colorSurface, ";}" + (process.env.NODE_ENV === "production" ? "" : ";label:getInputStyles;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRpbWUtaW5wdXQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSWdDIiwiZmlsZSI6InRpbWUtaW5wdXQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1xuaW1wb3J0IHsgY3NzIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnO1xuaW1wb3J0IHsgY3VzdG9tUHJvcGVydGllcyBhcyB2YXJzIH0gZnJvbSAnQGNvbW1lcmNldG9vbHMtdWlraXQvZGVzaWduLXN5c3RlbSc7XG5cbmNvbnN0IGdldElucHV0U3R5bGVzID0gKCkgPT4gY3NzYFxuICB3aWR0aDogMTAwJTtcbiAgdGV4dC1hbGlnbjogY2VudGVyO1xuICBib3JkZXI6IDA7XG4gIGJvcmRlci10b3A6IDFweCBzb2xpZCAke3ZhcnMuY29sb3JOZXV0cmFsOTB9O1xuICBwYWRkaW5nOiAxMHB4IDA7XG4gIG91dGxpbmU6IDA7XG4gIGZvbnQtc2l6ZTogJHt2YXJzLmZvbnRTaXplRGVmYXVsdH07XG4gIG1hcmdpbi10b3A6ICR7dmFycy5zcGFjaW5nU307XG4gIGNvbG9yOiAke3ZhcnMuY29sb3JTb2xpZH07XG5cbiAgOmRpc2FibGVkIHtcbiAgICAvKiBGaXhlcyBiYWNrZ3JvdW5kIGNvbG9yIGluIEZpcmVmb3ggKi9cbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAke3ZhcnMuY29sb3JTdXJmYWNlfTtcbiAgfVxuYDtcbmNvbnN0IERhdGVDYWxlbmRhclRpbWVJbnB1dCA9IChwcm9wcykgPT4gKFxuICA8aW5wdXRcbiAgICBkaXNhYmxlZD17cHJvcHMuaXNEaXNhYmxlZH1cbiAgICByZWY9e3Byb3BzLnRpbWVJbnB1dFJlZn1cbiAgICB0eXBlPVwidGV4dFwiXG4gICAgdmFsdWU9e3Byb3BzLnZhbHVlfVxuICAgIG9uQ2hhbmdlPXtwcm9wcy5vbkNoYW5nZX1cbiAgICBvbktleURvd249e3Byb3BzLm9uS2V5RG93bn1cbiAgICBwbGFjZWhvbGRlcj17cHJvcHMucGxhY2Vob2xkZXJ9XG4gICAgY3NzPXtnZXRJbnB1dFN0eWxlcygpfVxuICAvPlxuKTtcblxuRGF0ZUNhbGVuZGFyVGltZUlucHV0LmRpc3BsYXlOYW1lID0gJ0RhdGVDYWxlbmRhclRpbWVJbnB1dCc7XG5cbkRhdGVDYWxlbmRhclRpbWVJbnB1dC5wcm9wVHlwZXMgPSB7XG4gIGlzRGlzYWJsZWQ6IFByb3BUeXBlcy5ib29sLmlzUmVxdWlyZWQsXG4gIHRpbWVJbnB1dFJlZjogUHJvcFR5cGVzLm9iamVjdC5pc1JlcXVpcmVkLFxuICBvbktleURvd246IFByb3BUeXBlcy5mdW5jLmlzUmVxdWlyZWQsXG4gIG9uQ2hhbmdlOiBQcm9wVHlwZXMuZnVuYy5pc1JlcXVpcmVkLFxuICB2YWx1ZTogUHJvcFR5cGVzLnN0cmluZy5pc1JlcXVpcmVkLFxuICBwbGFjZWhvbGRlcjogUHJvcFR5cGVzLnN0cmluZyxcbn07XG5cbmV4cG9ydCBkZWZhdWx0IERhdGVDYWxlbmRhclRpbWVJbnB1dDtcbiJdfQ== */");
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var DateCalendarTimeInput = function DateCalendarTimeInput(props) {
|
|
60
|
+
return jsxRuntime.jsx("input", {
|
|
61
|
+
disabled: props.isDisabled,
|
|
62
|
+
ref: props.timeInputRef,
|
|
63
|
+
type: "text",
|
|
64
|
+
value: props.value,
|
|
65
|
+
onChange: props.onChange,
|
|
66
|
+
onKeyDown: props.onKeyDown,
|
|
67
|
+
placeholder: props.placeholder,
|
|
68
|
+
css: getInputStyles()
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
DateCalendarTimeInput.displayName = 'DateCalendarTimeInput';
|
|
73
|
+
DateCalendarTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
74
|
+
isDisabled: PropTypes__default['default'].bool.isRequired,
|
|
75
|
+
timeInputRef: PropTypes__default['default'].object.isRequired,
|
|
76
|
+
onKeyDown: PropTypes__default['default'].func.isRequired,
|
|
77
|
+
onChange: PropTypes__default['default'].func.isRequired,
|
|
78
|
+
value: PropTypes__default['default'].string.isRequired,
|
|
79
|
+
placeholder: PropTypes__default['default'].string
|
|
80
|
+
} : {};
|
|
81
|
+
var TimeInput = DateCalendarTimeInput;
|
|
82
|
+
|
|
83
|
+
var messages = reactIntl.defineMessages({
|
|
84
|
+
placeholder: {
|
|
85
|
+
id: 'UIKit.DateTimeInput.placeholder',
|
|
86
|
+
description: 'Placeholder for date time input',
|
|
87
|
+
defaultMessage: 'MM/DD/YYYY - HH:mm AM/PM'
|
|
88
|
+
},
|
|
89
|
+
timePlaceholder: {
|
|
90
|
+
id: 'UIKit.DateTimeInput.timePlaceholder',
|
|
91
|
+
description: 'Placeholder for time input at bottom of date-time-input',
|
|
92
|
+
defaultMessage: 'HH:mm AM/PM'
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default['default'](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default['default'](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
97
|
+
|
|
98
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context5; _forEachInstanceProperty__default['default'](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
|
|
99
|
+
|
|
100
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
101
|
+
|
|
102
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default['default'](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
103
|
+
var activationTypes = [Downshift__default['default'].stateChangeTypes.keyDownEnter, Downshift__default['default'].stateChangeTypes.clickItem];
|
|
104
|
+
|
|
105
|
+
var preventDownshiftDefault = function preventDownshiftDefault(event) {
|
|
106
|
+
// eslint-disable-next-line no-param-reassign
|
|
107
|
+
event.nativeEvent.preventDownshiftDefault = true;
|
|
108
|
+
}; // This keeps the menu open when the user focuses the time input (thereby
|
|
109
|
+
// blurring the regular input/toggle button)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
var createBlurHandler = function createBlurHandler(timeInputRef) {
|
|
113
|
+
return function (event) {
|
|
114
|
+
event.persist();
|
|
115
|
+
|
|
116
|
+
if (event.relatedTarget === timeInputRef.current) {
|
|
117
|
+
preventDownshiftDefault(event);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
var DateTimeInput = /*#__PURE__*/function (_Component) {
|
|
123
|
+
_inherits(DateTimeInput, _Component);
|
|
124
|
+
|
|
125
|
+
var _super = _createSuper(DateTimeInput);
|
|
126
|
+
|
|
127
|
+
function DateTimeInput() {
|
|
128
|
+
var _context;
|
|
129
|
+
|
|
130
|
+
var _this;
|
|
131
|
+
|
|
132
|
+
_classCallCheck(this, DateTimeInput);
|
|
133
|
+
|
|
134
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
135
|
+
args[_key] = arguments[_key];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
_this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context = [this]).call(_context, args));
|
|
139
|
+
_this.inputRef = /*#__PURE__*/react$1.createRef();
|
|
140
|
+
_this.timeInputRef = /*#__PURE__*/react$1.createRef();
|
|
141
|
+
_this.state = {
|
|
142
|
+
calendarDate: calendarTimeUtils.getToday(_this.props.timeZone),
|
|
143
|
+
suggestedItems: [],
|
|
144
|
+
highlightedIndex: _this.props.value === '' ? null : calendarTimeUtils.getDateInMonth(_this.props.value, _this.props.timeZone) - 1,
|
|
145
|
+
timeString: ''
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
_this.jumpMonths = function (amount) {
|
|
149
|
+
var dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
150
|
+
|
|
151
|
+
_this.setState(function (prevState) {
|
|
152
|
+
var nextDate = calendarTimeUtils.changeMonth(prevState.calendarDate, _this.props.timeZone, amount);
|
|
153
|
+
return {
|
|
154
|
+
calendarDate: nextDate,
|
|
155
|
+
highlightedIndex: dayToHighlight
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
_this.showToday = function () {
|
|
161
|
+
var today = calendarTimeUtils.getToday(_this.props.timeZone);
|
|
162
|
+
|
|
163
|
+
_this.setState(function (prevState) {
|
|
164
|
+
return {
|
|
165
|
+
calendarDate: today,
|
|
166
|
+
highlightedIndex: prevState.suggestedItems.length + calendarTimeUtils.getDateInMonth(today, _this.props.timeZone) - 1
|
|
167
|
+
};
|
|
168
|
+
}, function () {
|
|
169
|
+
return _this.inputRef.current.focus();
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
_this.handleBlur = function () {
|
|
174
|
+
if (_this.props.onBlur) _this.props.onBlur({
|
|
175
|
+
target: {
|
|
176
|
+
id: _this.props.id,
|
|
177
|
+
name: _this.props.name
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
_this.handleTimeChange = function (event) {
|
|
183
|
+
var parsedTime = utils.parseTime(event.target.value);
|
|
184
|
+
|
|
185
|
+
_this.setState({
|
|
186
|
+
timeString: event.target.value
|
|
187
|
+
}); // We can't update the parent when there is no value
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
if (_this.props.value === '') return;
|
|
191
|
+
var date = calendarTimeUtils.getStartOf(_this.props.value, _this.props.timeZone);
|
|
192
|
+
|
|
193
|
+
if (parsedTime) {
|
|
194
|
+
date = calendarTimeUtils.changeTime(date, _this.props.timeZone, parsedTime);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
_this.emit(date);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
_this.emit = function (value) {
|
|
201
|
+
return _this.props.onChange({
|
|
202
|
+
target: {
|
|
203
|
+
id: _this.props.id,
|
|
204
|
+
name: _this.props.name,
|
|
205
|
+
// when cleared the value is null, but we always want it to be an
|
|
206
|
+
// empty string when there is no value.
|
|
207
|
+
value: value || ''
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
return _this;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
_createClass(DateTimeInput, [{
|
|
216
|
+
key: "render",
|
|
217
|
+
value: function render() {
|
|
218
|
+
var _context2,
|
|
219
|
+
_this2 = this;
|
|
220
|
+
|
|
221
|
+
return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
|
|
222
|
+
max: this.props.horizontalConstraint,
|
|
223
|
+
children: jsxRuntime.jsx(Downshift__default['default'] // Setting the key to the timeZone conveniently forces a rerender
|
|
224
|
+
// when the time-zone changes. Otherwise we'd need to make
|
|
225
|
+
// inputValue a controlled property so that we can update
|
|
226
|
+
// the displayed value as downshift seems to ignore an updated
|
|
227
|
+
// itemToString function.
|
|
228
|
+
, {
|
|
229
|
+
inputId: this.props.id,
|
|
230
|
+
itemToString: calendarTimeUtils.createItemDateTimeToString(this.props.intl.locale, this.props.timeZone),
|
|
231
|
+
selectedItem: this.props.value === '' ? null : this.props.value,
|
|
232
|
+
highlightedIndex: this.state.highlightedIndex,
|
|
233
|
+
onChange: this.emit,
|
|
234
|
+
stateReducer: function stateReducer(state, changes) {
|
|
235
|
+
if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
|
|
236
|
+
return _objectSpread(_objectSpread({}, changes), {}, {
|
|
237
|
+
isOpen: true
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return changes;
|
|
242
|
+
},
|
|
243
|
+
onStateChange: function onStateChange(changes) {
|
|
244
|
+
/* eslint-disable no-prototype-builtins */
|
|
245
|
+
_this2.setState(function (prevState) {
|
|
246
|
+
if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
|
|
247
|
+
return {
|
|
248
|
+
startDate: changes.isOpen ? prevState.startDate : null,
|
|
249
|
+
inputValue: changes.inputValue || prevState.inputValue,
|
|
250
|
+
timeString: changes.selectedItem ? calendarTimeUtils.formatTime(changes.selectedItem, _this2.props.intl.locale, _this2.props.timeZone) : prevState.timeString
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (changes.hasOwnProperty('inputValue')) {
|
|
255
|
+
var suggestedItems = calendarTimeUtils.createSuggestedItems(changes.inputValue, _this2.props.timeZone);
|
|
256
|
+
return {
|
|
257
|
+
suggestedItems: suggestedItems,
|
|
258
|
+
highlightedIndex: suggestedItems.length > 0 ? 0 : null
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (changes.hasOwnProperty('isOpen')) {
|
|
263
|
+
return {
|
|
264
|
+
inputValue: changes.inputValue || prevState.inputValue,
|
|
265
|
+
startDate: changes.isOpen ? prevState.startDate : null,
|
|
266
|
+
// set time input value to time from value when menu is opened
|
|
267
|
+
timeString: changes.isOpen && _this2.props.value !== '' ? calendarTimeUtils.formatTime(_this2.props.value, _this2.props.intl.locale, _this2.props.timeZone) : '',
|
|
268
|
+
// ensure calendar always opens on selected item, or on
|
|
269
|
+
// current month when there is no selected item
|
|
270
|
+
calendarDate: _this2.props.value === '' ? calendarTimeUtils.getToday() : _this2.props.value
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (changes.hasOwnProperty('highlightedIndex')) {
|
|
275
|
+
return {
|
|
276
|
+
highlightedIndex: changes.highlightedIndex
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return null;
|
|
281
|
+
}, function () {
|
|
282
|
+
if (_includesInstanceProperty__default['default'](activationTypes).call(activationTypes, changes.type)) {
|
|
283
|
+
_this2.timeInputRef.current.focus();
|
|
284
|
+
|
|
285
|
+
_this2.timeInputRef.current.setSelectionRange(0, _this2.state.timeString.length);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
/* eslint-enable no-prototype-builtins */
|
|
289
|
+
|
|
290
|
+
},
|
|
291
|
+
children: function children(_ref) {
|
|
292
|
+
var _context3;
|
|
293
|
+
|
|
294
|
+
var getInputProps = _ref.getInputProps,
|
|
295
|
+
getMenuProps = _ref.getMenuProps,
|
|
296
|
+
getItemProps = _ref.getItemProps,
|
|
297
|
+
getToggleButtonProps = _ref.getToggleButtonProps,
|
|
298
|
+
clearSelection = _ref.clearSelection,
|
|
299
|
+
highlightedIndex = _ref.highlightedIndex,
|
|
300
|
+
openMenu = _ref.openMenu,
|
|
301
|
+
closeMenu = _ref.closeMenu,
|
|
302
|
+
setHighlightedIndex = _ref.setHighlightedIndex,
|
|
303
|
+
selectedItem = _ref.selectedItem,
|
|
304
|
+
inputValue = _ref.inputValue,
|
|
305
|
+
isOpen = _ref.isOpen;
|
|
306
|
+
var suggestedItems = _this2.state.suggestedItems;
|
|
307
|
+
var calendarItems = calendarTimeUtils.createCalendarItems(_this2.state.calendarDate, _this2.state.timeString, _this2.props.intl, _this2.props.timeZone);
|
|
308
|
+
var paddingDayCount = calendarTimeUtils.getPaddingDayCount(_this2.state.calendarDate, _this2.props.intl.locale, _this2.props.timeZone);
|
|
309
|
+
|
|
310
|
+
var paddingDays = _fillInstanceProperty__default['default'](_context3 = Array(paddingDayCount)).call(_context3);
|
|
311
|
+
|
|
312
|
+
var weekdays = calendarTimeUtils.getWeekdayNames(_this2.props.intl.locale);
|
|
313
|
+
var today = calendarTimeUtils.getToday();
|
|
314
|
+
var isTimeInputVisible = Boolean(_this2.props.value) && _this2.props.value !== '';
|
|
315
|
+
return jsxRuntime.jsxs("div", {
|
|
316
|
+
onFocus: _this2.props.onFocus,
|
|
317
|
+
onBlur: _this2.handleBlur,
|
|
318
|
+
children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
|
|
319
|
+
inputRef: _this2.inputRef,
|
|
320
|
+
inputProps: getInputProps(_objectSpread({
|
|
321
|
+
// Unset the aria-labelledby as it interfers with the link
|
|
322
|
+
// between the <label for> and the <input id>.
|
|
323
|
+
'aria-labelledby': undefined,
|
|
324
|
+
name: _this2.props.name,
|
|
325
|
+
placeholder: typeof _this2.props.placeholder === 'string' ? _this2.props.placeholder : _this2.props.intl.formatMessage(messages.placeholder),
|
|
326
|
+
onMouseEnter: function onMouseEnter() {
|
|
327
|
+
// we remove the highlight so that the user can use the
|
|
328
|
+
// arrow keys to move the cursor when hovering
|
|
329
|
+
if (isOpen) setHighlightedIndex(null);
|
|
330
|
+
},
|
|
331
|
+
onKeyDown: function onKeyDown(event) {
|
|
332
|
+
if (_this2.props.isReadOnly) {
|
|
333
|
+
preventDownshiftDefault(event);
|
|
334
|
+
return;
|
|
335
|
+
} // parse input when user presses enter on regular input,
|
|
336
|
+
// close menu and notify parent
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
if (event.key === 'Enter' && highlightedIndex === null) {
|
|
340
|
+
preventDownshiftDefault(event);
|
|
341
|
+
var parsedDate = calendarTimeUtils.parseInputText(inputValue, _this2.props.intl.locale, _this2.props.timeZone);
|
|
342
|
+
|
|
343
|
+
_this2.emit(parsedDate);
|
|
344
|
+
|
|
345
|
+
closeMenu();
|
|
346
|
+
} // ArrowDown
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
if (event.keyCode === 40) {
|
|
350
|
+
if (highlightedIndex + 1 >= calendarItems.length) {
|
|
351
|
+
// if it's the end of the month
|
|
352
|
+
// then bypass normal arrow navigation
|
|
353
|
+
preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
|
|
354
|
+
// then jump to start of next month
|
|
355
|
+
|
|
356
|
+
_this2.jumpMonths(1, 0);
|
|
357
|
+
}
|
|
358
|
+
} // ArrowUp
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
if (event.keyCode === 38) {
|
|
362
|
+
var previousDay = calendarTimeUtils.getPreviousDay(calendarItems[highlightedIndex]);
|
|
363
|
+
|
|
364
|
+
if (highlightedIndex <= 0) {
|
|
365
|
+
// if it's the start of the month
|
|
366
|
+
// then bypass normal arrow navigation
|
|
367
|
+
preventDownshiftDefault(event); // eslint-disable-line no-param-reassign
|
|
368
|
+
|
|
369
|
+
var numberOfDaysOfPrevMonth = calendarTimeUtils.getDaysInMonth(previousDay); // then jump to the last day of the previous month
|
|
370
|
+
|
|
371
|
+
_this2.jumpMonths(-1, numberOfDaysOfPrevMonth - 1);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
onClick: _this2.props.isReadOnly ? undefined : openMenu,
|
|
376
|
+
onBlur: createBlurHandler(_this2.timeInputRef),
|
|
377
|
+
onChange: function onChange(event) {
|
|
378
|
+
// keep timeInput and regular input in sync when user
|
|
379
|
+
// types into regular input
|
|
380
|
+
if (!isOpen) return;
|
|
381
|
+
var time = event.target.value.split(' ')[1];
|
|
382
|
+
if (!time) return;
|
|
383
|
+
var parsedTime = utils.parseTime(time);
|
|
384
|
+
|
|
385
|
+
_this2.setState(function () {
|
|
386
|
+
if (!parsedTime) return {
|
|
387
|
+
timeString: ''
|
|
388
|
+
};
|
|
389
|
+
var date = calendarTimeUtils.getToday(_this2.props.timeZone);
|
|
390
|
+
|
|
391
|
+
if (parsedTime) {
|
|
392
|
+
date = calendarTimeUtils.changeTime(date, _this2.props.timeZone, parsedTime);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
timeString: calendarTimeUtils.formatTime(date, _this2.props.intl.locale, _this2.props.timeZone)
|
|
397
|
+
};
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}, utils.filterDataAttributes(_this2.props))),
|
|
401
|
+
hasSelection: Boolean(selectedItem),
|
|
402
|
+
onClear: clearSelection,
|
|
403
|
+
isOpen: isOpen,
|
|
404
|
+
isDisabled: _this2.props.isDisabled,
|
|
405
|
+
isReadOnly: _this2.props.isReadOnly,
|
|
406
|
+
toggleButtonProps: getToggleButtonProps({
|
|
407
|
+
onBlur: createBlurHandler(_this2.timeInputRef)
|
|
408
|
+
}),
|
|
409
|
+
hasError: _this2.props.hasError,
|
|
410
|
+
hasWarning: _this2.props.hasWarning
|
|
411
|
+
}), isOpen && !_this2.props.isDisabled && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
|
|
412
|
+
hasFooter: true,
|
|
413
|
+
hasError: _this2.props.hasError,
|
|
414
|
+
hasWarning: _this2.props.hasWarning,
|
|
415
|
+
children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
|
|
416
|
+
monthLabel: calendarTimeUtils.getMonthCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
417
|
+
yearLabel: calendarTimeUtils.getYearCalendarLabel(_this2.state.calendarDate, _this2.props.intl.locale),
|
|
418
|
+
onPrevMonthClick: function onPrevMonthClick() {
|
|
419
|
+
return _this2.jumpMonths(-1);
|
|
420
|
+
},
|
|
421
|
+
onTodayClick: _this2.showToday,
|
|
422
|
+
onNextMonthClick: function onNextMonthClick() {
|
|
423
|
+
return _this2.jumpMonths(1);
|
|
424
|
+
},
|
|
425
|
+
onPrevYearClick: function onPrevYearClick() {
|
|
426
|
+
return _this2.jumpMonths(-12);
|
|
427
|
+
},
|
|
428
|
+
onNextYearClick: function onNextYearClick() {
|
|
429
|
+
return _this2.jumpMonths(12);
|
|
430
|
+
}
|
|
431
|
+
}), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
|
|
432
|
+
children: [_mapInstanceProperty__default['default'](weekdays).call(weekdays, function (weekday) {
|
|
433
|
+
return jsxRuntime.jsx(calendarUtils.CalendarDay, {
|
|
434
|
+
type: "heading",
|
|
435
|
+
children: weekday
|
|
436
|
+
}, weekday);
|
|
437
|
+
}), _mapInstanceProperty__default['default'](paddingDays).call(paddingDays, function (day, index) {
|
|
438
|
+
return jsxRuntime.jsx(calendarUtils.CalendarDay, {
|
|
439
|
+
type: "spacing"
|
|
440
|
+
}, index);
|
|
441
|
+
}), _mapInstanceProperty__default['default'](calendarItems).call(calendarItems, function (item, index) {
|
|
442
|
+
return jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
|
|
443
|
+
isToday: calendarTimeUtils.isSameDay(today, item)
|
|
444
|
+
}, getItemProps({
|
|
445
|
+
disabled: _this2.props.isDisabled,
|
|
446
|
+
item: item,
|
|
447
|
+
onMouseOut: function onMouseOut() {
|
|
448
|
+
setHighlightedIndex(null);
|
|
449
|
+
}
|
|
450
|
+
})), {}, {
|
|
451
|
+
isHighlighted: suggestedItems.length + index === highlightedIndex,
|
|
452
|
+
isSelected: calendarTimeUtils.isSameDay(item, _this2.props.value),
|
|
453
|
+
children: calendarTimeUtils.getCalendarDayLabel(item, _this2.props.timeZone)
|
|
454
|
+
}), item);
|
|
455
|
+
})]
|
|
456
|
+
}), jsxRuntime.jsx(TimeInput, {
|
|
457
|
+
isDisabled: !isTimeInputVisible,
|
|
458
|
+
timeInputRef: _this2.timeInputRef,
|
|
459
|
+
placeholder: _this2.props.intl.formatMessage(messages.timePlaceholder),
|
|
460
|
+
value: _this2.state.timeString,
|
|
461
|
+
onChange: _this2.handleTimeChange,
|
|
462
|
+
onKeyDown: function onKeyDown(event) {
|
|
463
|
+
if (event.key === 'ArrowUp') {
|
|
464
|
+
setHighlightedIndex(null);
|
|
465
|
+
|
|
466
|
+
_this2.inputRef.current.focus();
|
|
467
|
+
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (event.key === 'Enter') {
|
|
472
|
+
setHighlightedIndex(null);
|
|
473
|
+
|
|
474
|
+
_this2.inputRef.current.focus();
|
|
475
|
+
|
|
476
|
+
_this2.inputRef.current.setSelectionRange(0, 100);
|
|
477
|
+
|
|
478
|
+
closeMenu();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
})]
|
|
482
|
+
}))]
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}, _concatInstanceProperty__default['default'](_context2 = "".concat(this.props.timeZone, ":")).call(_context2, this.props.intl.locale))
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}]);
|
|
489
|
+
|
|
490
|
+
return DateTimeInput;
|
|
491
|
+
}(react$1.Component);
|
|
492
|
+
|
|
493
|
+
DateTimeInput.displayName = 'DateTimeInput';
|
|
494
|
+
DateTimeInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
495
|
+
intl: PropTypes__default['default'].shape({
|
|
496
|
+
locale: PropTypes__default['default'].string.isRequired,
|
|
497
|
+
formatMessage: PropTypes__default['default'].func.isRequired
|
|
498
|
+
}).isRequired,
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Horizontal size limit of the input field.
|
|
502
|
+
*/
|
|
503
|
+
horizontalConstraint: PropTypes__default['default'].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* The selected date, must either be an empty string or a date formatted in ISO 8601 (e.g. "2018-10-04T09:00:00.000Z").
|
|
507
|
+
*/
|
|
508
|
+
value: PropTypes__default['default'].string.isRequired,
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Called when the date changes. Called with an event containing an empty string (no value) or a string in this format: "YYYY-MM-DD".
|
|
512
|
+
* <br />
|
|
513
|
+
* Signature: `(event) => void`
|
|
514
|
+
*/
|
|
515
|
+
onChange: PropTypes__default['default'].func.isRequired,
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Called when the date input gains focus.
|
|
519
|
+
*/
|
|
520
|
+
onFocus: PropTypes__default['default'].func,
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Called when the date input loses focus.
|
|
524
|
+
*/
|
|
525
|
+
onBlur: PropTypes__default['default'].func,
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Specifies the time zone in which the calendar and selected values are shown. It also influences how entered dates and times are parsed.
|
|
529
|
+
*/
|
|
530
|
+
timeZone: PropTypes__default['default'].string.isRequired,
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Used as the HTML `id` attribute.
|
|
534
|
+
*/
|
|
535
|
+
id: PropTypes__default['default'].string,
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Used as the HTML `name` attribute.
|
|
539
|
+
*/
|
|
540
|
+
name: PropTypes__default['default'].string,
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Placeholder value to show in the input field
|
|
544
|
+
*/
|
|
545
|
+
placeholder: PropTypes__default['default'].string,
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Disables the date picker
|
|
549
|
+
*/
|
|
550
|
+
isDisabled: PropTypes__default['default'].bool,
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Disables the date picker menu and sets the input field as read-only
|
|
554
|
+
*/
|
|
555
|
+
isReadOnly: PropTypes__default['default'].bool,
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Indicates the input field has an error
|
|
559
|
+
*/
|
|
560
|
+
hasError: PropTypes__default['default'].bool,
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Indicates the input field has a warning
|
|
564
|
+
*/
|
|
565
|
+
hasWarning: PropTypes__default['default'].bool
|
|
566
|
+
} : {};
|
|
567
|
+
var dateTimeInput = reactIntl.injectIntl(DateTimeInput);
|
|
568
|
+
|
|
569
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
570
|
+
var version = '0.0.0-canary-2021830134526';
|
|
571
|
+
|
|
572
|
+
exports['default'] = dateTimeInput;
|
|
573
|
+
exports.version = version;
|