@commercetools-uikit/date-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,91 @@
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
+ # DateInput
5
+
6
+ ## Description
7
+
8
+ The \`DateInput\` component allows the user to select a date. It formats the selected date depending on the users' locale.
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ yarn add @commercetools-uikit/date-input
14
+ ```
15
+
16
+ ```
17
+ npm --save install @commercetools-uikit/date-input
18
+ ```
19
+
20
+ Additionally install the peer dependencies (if not present)
21
+
22
+ ```
23
+ yarn add moment react react-intl
24
+ ```
25
+
26
+ ```
27
+ npm --save install moment react react-intl
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```jsx
33
+ import DateInput from '@commercetools-uikit/date-input';
34
+
35
+ const Example = () => (
36
+ <DateInput
37
+ placeholder="Select a date..."
38
+ value="2017-12-31"
39
+ onChange={() => {}}
40
+ />
41
+ );
42
+
43
+ export default Example;
44
+ ```
45
+
46
+ ## Properties
47
+
48
+ | Props | Type | Required | Default | Description |
49
+ | ---------------------- | -------------------------------------------------------------------------------------------- | :------: | ------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
50
+ | `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. |
51
+ | `value` | `string` | ✅ | | The selected date, must either be an empty string or a date formatted as "YYYY-MM-DD". |
52
+ | `onChange` | `Function`<br/>[See signature.](#signature-onchange) | | | Called when the date changes. Called with an event containing either an empty string (no value) or a string in this format: "YYYY-MM-DD". |
53
+ | `onFocus` | `FocusEventHandler` | | | Called when the date input gains focus. |
54
+ | `onBlur` | `Function`<br/>[See signature.](#signature-onblur) | | | Called when the date input loses focus. |
55
+ | `id` | `string` | | | Used as the HTML `id` attribute. |
56
+ | `aria-invalid` | `boolean` | | | Indicate if the value entered in the input is invalid. |
57
+ | `aria-errormessage` | `string` | | | HTML ID of an element containing an error message related to the input. |
58
+ | `name` | `string` | | | Used as the HTML `name` attribute. |
59
+ | `placeholder` | `string` | | | Placeholder value to show in the input field |
60
+ | `isCondensed` | `boolean` | | | Use this property to reduce the paddings of the component for a ui compact variant |
61
+ | `isDisabled` | `boolean` | | | Disables the date picker |
62
+ | `isReadOnly` | `boolean` | | | Disables the date picker menu and makes input field read-only |
63
+ | `hasError` | `boolean` | | | Indicates the input field has an error |
64
+ | `hasWarning` | `boolean` | | | Indicates the input field has a warning |
65
+ | `minValue` | `string` | | | A minimum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD". |
66
+ | `maxValue` | `string` | | | A maximum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD". |
67
+
68
+ ## Signatures
69
+
70
+ ### Signature `onChange`
71
+
72
+ ```ts
73
+ (event: TCustomEvent) => void
74
+ ```
75
+
76
+ ### Signature `onBlur`
77
+
78
+ ```ts
79
+ (event: TCustomEvent) => void
80
+ ```
81
+
82
+ ## Static methods
83
+
84
+ ### `DateInput.isEmpty`
85
+
86
+ Returns `true` when the value is considered empty, which is when the value is an empty string.
87
+
88
+ ```js
89
+ DateInput.isEmpty(''); // -> true
90
+ DateInput.isEmpty('2018-09-20'); // -> false
91
+ ```
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC1kYXRlLWlucHV0LmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -0,0 +1,312 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
6
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
7
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
8
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
9
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
10
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
11
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
12
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
13
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
14
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
15
+ var _pt = require('prop-types');
16
+ var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
17
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
18
+ var react = require('react');
19
+ var Downshift = require('downshift');
20
+ var reactIntl = require('react-intl');
21
+ var Constraints = require('@commercetools-uikit/constraints');
22
+ var utils = require('@commercetools-uikit/utils');
23
+ var calendarUtils = require('@commercetools-uikit/calendar-utils');
24
+ var calendarTimeUtils = require('@commercetools-uikit/calendar-time-utils');
25
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
26
+
27
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
28
+
29
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
30
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
31
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
32
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
33
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
34
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
35
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
36
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
37
+ var _pt__default = /*#__PURE__*/_interopDefault(_pt);
38
+ var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
39
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
40
+ var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
41
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
42
+
43
+ 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; }
44
+ 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; }
45
+ const preventDownshiftDefault = event => {
46
+ event.nativeEvent.preventDownshiftDefault = true;
47
+ };
48
+ const DateInput = props => {
49
+ const intl = reactIntl.useIntl();
50
+ const _useState = react.useState(props.value || calendarUtils.getToday()),
51
+ _useState2 = _slicedToArray(_useState, 2),
52
+ calendarDate = _useState2[0],
53
+ setCalendarDate = _useState2[1];
54
+ const _useState3 = react.useState([]),
55
+ _useState4 = _slicedToArray(_useState3, 2),
56
+ suggestedItems = _useState4[0],
57
+ setSuggestedItems = _useState4[1];
58
+ const _useState5 = react.useState(props.value === '' ? null : calendarUtils.getDateInMonth(props.value) - 1),
59
+ _useState6 = _slicedToArray(_useState5, 2),
60
+ highlightedIndex = _useState6[0],
61
+ setHighlightedIndex = _useState6[1];
62
+ const inputRef = react.useRef(null);
63
+ if (!props.isReadOnly) {
64
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof props.onChange === 'function', 'DateInput: `onChange` is required when input is not read only.') : void 0;
65
+ }
66
+ const onChange = props.onChange;
67
+ const emit = react.useCallback(value => onChange?.({
68
+ target: {
69
+ id: props.id,
70
+ name: props.name,
71
+ // when cleared the value is null, but we always want it to be an
72
+ // empty string when there is no value.
73
+ value: value || ''
74
+ }
75
+ }), [onChange, props.id, props.name]);
76
+ const handleChange = react.useCallback(date => {
77
+ inputRef.current?.setSelectionRange(0, 100);
78
+ emit(date);
79
+ }, [inputRef, emit]);
80
+ const onBlur = props.onBlur;
81
+ const handleBlur = react.useCallback(() => {
82
+ if (onBlur) onBlur({
83
+ target: {
84
+ id: props.id,
85
+ name: props.name
86
+ }
87
+ });
88
+ }, [onBlur, props.id, props.name]);
89
+ const showToday = () => {
90
+ const today = calendarUtils.getToday();
91
+ setCalendarDate(today);
92
+ setHighlightedIndex(suggestedItems.length + calendarUtils.getDateInMonth(today) - 1);
93
+ inputRef.current?.focus();
94
+ };
95
+ const jumpMonth = function (amount) {
96
+ let dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
97
+ const nextDate = calendarUtils.changeMonth(calendarDate, amount);
98
+ setCalendarDate(nextDate);
99
+ setHighlightedIndex(dayToHighlight);
100
+ };
101
+
102
+ /**
103
+ * If the user manually enters a value in the text-input field,
104
+ * attempt to parse the value and emit it to the consumer if it's valid and in range.
105
+ */
106
+ const onInputBlur = event => {
107
+ const inputValue = event.target.value || '';
108
+ const date = calendarUtils.parseInputToDate(inputValue, intl.locale);
109
+ const inRange = calendarUtils.getIsDateInRange(date, props.minValue, props.maxValue);
110
+ if (inputValue.length === 0) emit(inputValue);
111
+ if (!date || !inRange) return;
112
+ emit(date);
113
+ };
114
+ return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
115
+ max: props.horizontalConstraint,
116
+ children: jsxRuntime.jsx(Downshift__default["default"], {
117
+ inputId: props.id,
118
+ itemToString: calendarUtils.createItemToString(intl.locale),
119
+ selectedItem: props.value === '' ? null : props.value,
120
+ highlightedIndex: highlightedIndex,
121
+ onChange: handleChange,
122
+ onStateChange: changes => {
123
+ if (changes.hasOwnProperty('inputValue')) {
124
+ // input changed because user typed
125
+ if (changes.type === Downshift__default["default"].stateChangeTypes.changeInput) {
126
+ const date = calendarUtils.parseInputToDate(changes.inputValue, intl.locale);
127
+ if (date === '') {
128
+ setSuggestedItems([]);
129
+ setHighlightedIndex(null);
130
+ } else {
131
+ setSuggestedItems([date]);
132
+ if (calendarUtils.getIsDateInRange(date, props.minValue, props.maxValue)) {
133
+ setHighlightedIndex(calendarUtils.getDateInMonth(date) - 1);
134
+ }
135
+ setCalendarDate(date);
136
+ }
137
+ } else {
138
+ // input changed because user selected a date
139
+ setSuggestedItems([]);
140
+ setHighlightedIndex(null);
141
+ }
142
+ /**
143
+ * Asides the inputValue, we also have other ways to enter calendar inputs like the mouse move event to enter calender values.
144
+ * We check the downshift changes property to be sure it has highlightedIndex That is not null before updating it,
145
+ * otherwise it may override the initially set highlightedIndex from the inputValue and set it to null.
146
+ */
147
+ } else if (changes.hasOwnProperty('highlightedIndex')) {
148
+ setHighlightedIndex(changes.highlightedIndex);
149
+ }
150
+ },
151
+ children: _ref => {
152
+ var _context;
153
+ let getInputProps = _ref.getInputProps,
154
+ getMenuProps = _ref.getMenuProps,
155
+ getItemProps = _ref.getItemProps,
156
+ getToggleButtonProps = _ref.getToggleButtonProps,
157
+ clearSelection = _ref.clearSelection,
158
+ downshiftHighlightedIndex = _ref.highlightedIndex,
159
+ openMenu = _ref.openMenu,
160
+ setDownshiftHighlightedIndex = _ref.setHighlightedIndex,
161
+ selectedItem = _ref.selectedItem,
162
+ isOpen = _ref.isOpen,
163
+ inputValue = _ref.inputValue;
164
+ const calendarItems = calendarUtils.createCalendarItems(calendarDate);
165
+ const paddingDayCount = calendarUtils.getPaddingDayCount(calendarDate, intl.locale);
166
+ const paddingDays = _fillInstanceProperty__default["default"](_context = Array(paddingDayCount)).call(_context, undefined);
167
+ const weekdays = calendarUtils.getWeekdayNames(intl.locale);
168
+ const today = calendarUtils.getToday();
169
+ return jsxRuntime.jsxs("div", {
170
+ onFocus: props.onFocus,
171
+ onBlur: handleBlur,
172
+ children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
173
+ inputRef: inputRef,
174
+ inputProps: getInputProps(_objectSpread({
175
+ /* ARIA */
176
+ 'aria-invalid': props['aria-invalid'],
177
+ 'aria-errormessage': props['aria-errormessage'],
178
+ // Unset the aria-labelledby as it interfers with the link
179
+ // between the <label for> and the <input id>.
180
+ 'aria-labelledby': undefined,
181
+ name: props.name,
182
+ placeholder: typeof props.placeholder === 'string' ? props.placeholder : calendarTimeUtils.getLocalizedDateTimeFormatPattern(intl.locale),
183
+ onMouseEnter: () => {
184
+ // we remove the highlight so that the user can use the
185
+ // arrow keys to move the cursor when hovering
186
+ // @ts-ignore
187
+ if (isOpen) setDownshiftHighlightedIndex(null);
188
+ },
189
+ onKeyDown: event => {
190
+ if (props.isReadOnly) {
191
+ preventDownshiftDefault(event);
192
+ return;
193
+ }
194
+ if (event.key === 'Enter' && inputValue?.trim() === '') {
195
+ clearSelection();
196
+ }
197
+ // ArrowDown
198
+ if (event.key === 'ArrowDown') {
199
+ const nextDayToHighlight = calendarUtils.getNextDay(calendarItems[Number(highlightedIndex)]);
200
+ if (!calendarUtils.getIsDateInRange(nextDayToHighlight, props.minValue, props.maxValue)) {
201
+ // if the date to highlight is disabled
202
+ // then do nothing
203
+ preventDownshiftDefault(event);
204
+ return;
205
+ }
206
+ if (Number(highlightedIndex) + 1 >= calendarItems.length) {
207
+ // if it's the end of the month
208
+ // then bypass normal arrow navigation
209
+ preventDownshiftDefault(event);
210
+ // then jump to start of next month
211
+ jumpMonth(1, 0);
212
+ }
213
+ }
214
+ // ArrowUp
215
+ if (event.key === 'ArrowUp') {
216
+ const previousDay = calendarUtils.getPreviousDay(calendarItems[Number(highlightedIndex)]);
217
+ if (!calendarUtils.getIsDateInRange(previousDay, props.minValue, props.maxValue)) {
218
+ // if the date to highlight is disabled
219
+ // then do nothing
220
+ preventDownshiftDefault(event);
221
+ return;
222
+ }
223
+ if (Number(highlightedIndex) <= 0) {
224
+ // if it's the start of the month
225
+ // then bypass normal arrow navigation
226
+ preventDownshiftDefault(event);
227
+ const numberOfDaysOfPrevMonth = calendarUtils.getDaysInMonth(previousDay);
228
+ // then jump to the last day of the previous month
229
+ jumpMonth(-1, numberOfDaysOfPrevMonth - 1);
230
+ }
231
+ }
232
+ },
233
+ onBlur: onInputBlur,
234
+ // we only do this for readOnly because the input
235
+ // doesn't ignore these events, unlike when its disabled
236
+ onClick: props.isReadOnly ? undefined : openMenu
237
+ }, utils.filterDataAttributes(props))),
238
+ hasSelection: Boolean(selectedItem),
239
+ onClear: clearSelection,
240
+ isOpen: isOpen,
241
+ isDisabled: props.isDisabled,
242
+ isReadOnly: props.isReadOnly,
243
+ isCondensed: props.isCondensed,
244
+ toggleButtonProps: getToggleButtonProps(),
245
+ hasError: props.hasError,
246
+ hasWarning: props.hasWarning
247
+ }), isOpen && !props.isDisabled && !props.isReadOnly && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
248
+ hasError: props.hasError,
249
+ hasWarning: props.hasWarning,
250
+ children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
251
+ monthLabel: calendarUtils.getMonthCalendarLabel(calendarDate, intl.locale),
252
+ yearLabel: calendarUtils.getYearCalendarLabel(calendarDate, intl.locale),
253
+ onPrevMonthClick: () => jumpMonth(-1),
254
+ onTodayClick: showToday,
255
+ onNextMonthClick: () => jumpMonth(1),
256
+ onPrevYearClick: () => jumpMonth(-12),
257
+ onNextYearClick: () => jumpMonth(12)
258
+ }), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
259
+ children: [_mapInstanceProperty__default["default"](weekdays).call(weekdays, weekday => jsxRuntime.jsx(calendarUtils.CalendarDay, {
260
+ type: "heading",
261
+ children: weekday
262
+ }, weekday)), _mapInstanceProperty__default["default"](paddingDays).call(paddingDays, (_, index) => jsxRuntime.jsx(calendarUtils.CalendarDay, {
263
+ type: "spacing"
264
+ }, index)), _mapInstanceProperty__default["default"](calendarItems).call(calendarItems, (item, index) => jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
265
+ isToday: calendarUtils.isSameDay(today, item)
266
+ }, getItemProps({
267
+ disabled: !calendarUtils.getIsDateInRange(item, props.minValue, props.maxValue),
268
+ item,
269
+ onMouseOut: () => {
270
+ // @ts-ignore
271
+ setDownshiftHighlightedIndex(null);
272
+ }
273
+ })), {}, {
274
+ isHighlighted: index === downshiftHighlightedIndex,
275
+ isSelected: calendarUtils.isSameDay(item, props.value),
276
+ children: calendarUtils.getCalendarDayLabel(item)
277
+ }), item))]
278
+ })]
279
+ }))]
280
+ });
281
+ }
282
+ }, intl.locale)
283
+ });
284
+ };
285
+ DateInput.propTypes = process.env.NODE_ENV !== "production" ? {
286
+ horizontalConstraint: _pt__default["default"].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
287
+ value: _pt__default["default"].string.isRequired,
288
+ onChange: _pt__default["default"].func,
289
+ onFocus: _pt__default["default"].func,
290
+ onBlur: _pt__default["default"].func,
291
+ id: _pt__default["default"].string,
292
+ 'aria-invalid': _pt__default["default"].bool,
293
+ 'aria-errormessage': _pt__default["default"].string,
294
+ name: _pt__default["default"].string,
295
+ placeholder: _pt__default["default"].string,
296
+ isCondensed: _pt__default["default"].bool,
297
+ isDisabled: _pt__default["default"].bool,
298
+ isReadOnly: _pt__default["default"].bool,
299
+ hasError: _pt__default["default"].bool,
300
+ hasWarning: _pt__default["default"].bool,
301
+ minValue: _pt__default["default"].string,
302
+ maxValue: _pt__default["default"].string
303
+ } : {};
304
+ DateInput.displayName = 'DateInput';
305
+ DateInput.isEmpty = value => value === '';
306
+ var DateInput$1 = DateInput;
307
+
308
+ // NOTE: This string will be replaced on build time with the package version.
309
+ var version = "19.25.1";
310
+
311
+ exports["default"] = DateInput$1;
312
+ 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-input.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-uikit-date-input.cjs.dev.js");
7
+ }
@@ -0,0 +1,291 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
6
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
7
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
8
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
9
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
10
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
11
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
12
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
13
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
14
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
15
+ require('prop-types');
16
+ var _fillInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/fill');
17
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
18
+ var react = require('react');
19
+ var Downshift = require('downshift');
20
+ var reactIntl = require('react-intl');
21
+ var Constraints = require('@commercetools-uikit/constraints');
22
+ var utils = require('@commercetools-uikit/utils');
23
+ var calendarUtils = require('@commercetools-uikit/calendar-utils');
24
+ var calendarTimeUtils = require('@commercetools-uikit/calendar-time-utils');
25
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
26
+
27
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
28
+
29
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
30
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
31
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
32
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
33
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
34
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
35
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
36
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
37
+ var _fillInstanceProperty__default = /*#__PURE__*/_interopDefault(_fillInstanceProperty);
38
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
39
+ var Downshift__default = /*#__PURE__*/_interopDefault(Downshift);
40
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
41
+
42
+ 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; }
43
+ 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; }
44
+ const preventDownshiftDefault = event => {
45
+ event.nativeEvent.preventDownshiftDefault = true;
46
+ };
47
+ const DateInput = props => {
48
+ const intl = reactIntl.useIntl();
49
+ const _useState = react.useState(props.value || calendarUtils.getToday()),
50
+ _useState2 = _slicedToArray(_useState, 2),
51
+ calendarDate = _useState2[0],
52
+ setCalendarDate = _useState2[1];
53
+ const _useState3 = react.useState([]),
54
+ _useState4 = _slicedToArray(_useState3, 2),
55
+ suggestedItems = _useState4[0],
56
+ setSuggestedItems = _useState4[1];
57
+ const _useState5 = react.useState(props.value === '' ? null : calendarUtils.getDateInMonth(props.value) - 1),
58
+ _useState6 = _slicedToArray(_useState5, 2),
59
+ highlightedIndex = _useState6[0],
60
+ setHighlightedIndex = _useState6[1];
61
+ const inputRef = react.useRef(null);
62
+ if (!props.isReadOnly) ;
63
+ const onChange = props.onChange;
64
+ const emit = react.useCallback(value => onChange?.({
65
+ target: {
66
+ id: props.id,
67
+ name: props.name,
68
+ // when cleared the value is null, but we always want it to be an
69
+ // empty string when there is no value.
70
+ value: value || ''
71
+ }
72
+ }), [onChange, props.id, props.name]);
73
+ const handleChange = react.useCallback(date => {
74
+ inputRef.current?.setSelectionRange(0, 100);
75
+ emit(date);
76
+ }, [inputRef, emit]);
77
+ const onBlur = props.onBlur;
78
+ const handleBlur = react.useCallback(() => {
79
+ if (onBlur) onBlur({
80
+ target: {
81
+ id: props.id,
82
+ name: props.name
83
+ }
84
+ });
85
+ }, [onBlur, props.id, props.name]);
86
+ const showToday = () => {
87
+ const today = calendarUtils.getToday();
88
+ setCalendarDate(today);
89
+ setHighlightedIndex(suggestedItems.length + calendarUtils.getDateInMonth(today) - 1);
90
+ inputRef.current?.focus();
91
+ };
92
+ const jumpMonth = function (amount) {
93
+ let dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
94
+ const nextDate = calendarUtils.changeMonth(calendarDate, amount);
95
+ setCalendarDate(nextDate);
96
+ setHighlightedIndex(dayToHighlight);
97
+ };
98
+
99
+ /**
100
+ * If the user manually enters a value in the text-input field,
101
+ * attempt to parse the value and emit it to the consumer if it's valid and in range.
102
+ */
103
+ const onInputBlur = event => {
104
+ const inputValue = event.target.value || '';
105
+ const date = calendarUtils.parseInputToDate(inputValue, intl.locale);
106
+ const inRange = calendarUtils.getIsDateInRange(date, props.minValue, props.maxValue);
107
+ if (inputValue.length === 0) emit(inputValue);
108
+ if (!date || !inRange) return;
109
+ emit(date);
110
+ };
111
+ return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
112
+ max: props.horizontalConstraint,
113
+ children: jsxRuntime.jsx(Downshift__default["default"], {
114
+ inputId: props.id,
115
+ itemToString: calendarUtils.createItemToString(intl.locale),
116
+ selectedItem: props.value === '' ? null : props.value,
117
+ highlightedIndex: highlightedIndex,
118
+ onChange: handleChange,
119
+ onStateChange: changes => {
120
+ if (changes.hasOwnProperty('inputValue')) {
121
+ // input changed because user typed
122
+ if (changes.type === Downshift__default["default"].stateChangeTypes.changeInput) {
123
+ const date = calendarUtils.parseInputToDate(changes.inputValue, intl.locale);
124
+ if (date === '') {
125
+ setSuggestedItems([]);
126
+ setHighlightedIndex(null);
127
+ } else {
128
+ setSuggestedItems([date]);
129
+ if (calendarUtils.getIsDateInRange(date, props.minValue, props.maxValue)) {
130
+ setHighlightedIndex(calendarUtils.getDateInMonth(date) - 1);
131
+ }
132
+ setCalendarDate(date);
133
+ }
134
+ } else {
135
+ // input changed because user selected a date
136
+ setSuggestedItems([]);
137
+ setHighlightedIndex(null);
138
+ }
139
+ /**
140
+ * Asides the inputValue, we also have other ways to enter calendar inputs like the mouse move event to enter calender values.
141
+ * We check the downshift changes property to be sure it has highlightedIndex That is not null before updating it,
142
+ * otherwise it may override the initially set highlightedIndex from the inputValue and set it to null.
143
+ */
144
+ } else if (changes.hasOwnProperty('highlightedIndex')) {
145
+ setHighlightedIndex(changes.highlightedIndex);
146
+ }
147
+ },
148
+ children: _ref => {
149
+ var _context;
150
+ let getInputProps = _ref.getInputProps,
151
+ getMenuProps = _ref.getMenuProps,
152
+ getItemProps = _ref.getItemProps,
153
+ getToggleButtonProps = _ref.getToggleButtonProps,
154
+ clearSelection = _ref.clearSelection,
155
+ downshiftHighlightedIndex = _ref.highlightedIndex,
156
+ openMenu = _ref.openMenu,
157
+ setDownshiftHighlightedIndex = _ref.setHighlightedIndex,
158
+ selectedItem = _ref.selectedItem,
159
+ isOpen = _ref.isOpen,
160
+ inputValue = _ref.inputValue;
161
+ const calendarItems = calendarUtils.createCalendarItems(calendarDate);
162
+ const paddingDayCount = calendarUtils.getPaddingDayCount(calendarDate, intl.locale);
163
+ const paddingDays = _fillInstanceProperty__default["default"](_context = Array(paddingDayCount)).call(_context, undefined);
164
+ const weekdays = calendarUtils.getWeekdayNames(intl.locale);
165
+ const today = calendarUtils.getToday();
166
+ return jsxRuntime.jsxs("div", {
167
+ onFocus: props.onFocus,
168
+ onBlur: handleBlur,
169
+ children: [jsxRuntime.jsx(calendarUtils.CalendarBody, {
170
+ inputRef: inputRef,
171
+ inputProps: getInputProps(_objectSpread({
172
+ /* ARIA */
173
+ 'aria-invalid': props['aria-invalid'],
174
+ 'aria-errormessage': props['aria-errormessage'],
175
+ // Unset the aria-labelledby as it interfers with the link
176
+ // between the <label for> and the <input id>.
177
+ 'aria-labelledby': undefined,
178
+ name: props.name,
179
+ placeholder: typeof props.placeholder === 'string' ? props.placeholder : calendarTimeUtils.getLocalizedDateTimeFormatPattern(intl.locale),
180
+ onMouseEnter: () => {
181
+ // we remove the highlight so that the user can use the
182
+ // arrow keys to move the cursor when hovering
183
+ // @ts-ignore
184
+ if (isOpen) setDownshiftHighlightedIndex(null);
185
+ },
186
+ onKeyDown: event => {
187
+ if (props.isReadOnly) {
188
+ preventDownshiftDefault(event);
189
+ return;
190
+ }
191
+ if (event.key === 'Enter' && inputValue?.trim() === '') {
192
+ clearSelection();
193
+ }
194
+ // ArrowDown
195
+ if (event.key === 'ArrowDown') {
196
+ const nextDayToHighlight = calendarUtils.getNextDay(calendarItems[Number(highlightedIndex)]);
197
+ if (!calendarUtils.getIsDateInRange(nextDayToHighlight, props.minValue, props.maxValue)) {
198
+ // if the date to highlight is disabled
199
+ // then do nothing
200
+ preventDownshiftDefault(event);
201
+ return;
202
+ }
203
+ if (Number(highlightedIndex) + 1 >= calendarItems.length) {
204
+ // if it's the end of the month
205
+ // then bypass normal arrow navigation
206
+ preventDownshiftDefault(event);
207
+ // then jump to start of next month
208
+ jumpMonth(1, 0);
209
+ }
210
+ }
211
+ // ArrowUp
212
+ if (event.key === 'ArrowUp') {
213
+ const previousDay = calendarUtils.getPreviousDay(calendarItems[Number(highlightedIndex)]);
214
+ if (!calendarUtils.getIsDateInRange(previousDay, props.minValue, props.maxValue)) {
215
+ // if the date to highlight is disabled
216
+ // then do nothing
217
+ preventDownshiftDefault(event);
218
+ return;
219
+ }
220
+ if (Number(highlightedIndex) <= 0) {
221
+ // if it's the start of the month
222
+ // then bypass normal arrow navigation
223
+ preventDownshiftDefault(event);
224
+ const numberOfDaysOfPrevMonth = calendarUtils.getDaysInMonth(previousDay);
225
+ // then jump to the last day of the previous month
226
+ jumpMonth(-1, numberOfDaysOfPrevMonth - 1);
227
+ }
228
+ }
229
+ },
230
+ onBlur: onInputBlur,
231
+ // we only do this for readOnly because the input
232
+ // doesn't ignore these events, unlike when its disabled
233
+ onClick: props.isReadOnly ? undefined : openMenu
234
+ }, utils.filterDataAttributes(props))),
235
+ hasSelection: Boolean(selectedItem),
236
+ onClear: clearSelection,
237
+ isOpen: isOpen,
238
+ isDisabled: props.isDisabled,
239
+ isReadOnly: props.isReadOnly,
240
+ isCondensed: props.isCondensed,
241
+ toggleButtonProps: getToggleButtonProps(),
242
+ hasError: props.hasError,
243
+ hasWarning: props.hasWarning
244
+ }), isOpen && !props.isDisabled && !props.isReadOnly && jsxRuntime.jsxs(calendarUtils.CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
245
+ hasError: props.hasError,
246
+ hasWarning: props.hasWarning,
247
+ children: [jsxRuntime.jsx(calendarUtils.CalendarHeader, {
248
+ monthLabel: calendarUtils.getMonthCalendarLabel(calendarDate, intl.locale),
249
+ yearLabel: calendarUtils.getYearCalendarLabel(calendarDate, intl.locale),
250
+ onPrevMonthClick: () => jumpMonth(-1),
251
+ onTodayClick: showToday,
252
+ onNextMonthClick: () => jumpMonth(1),
253
+ onPrevYearClick: () => jumpMonth(-12),
254
+ onNextYearClick: () => jumpMonth(12)
255
+ }), jsxRuntime.jsxs(calendarUtils.CalendarContent, {
256
+ children: [_mapInstanceProperty__default["default"](weekdays).call(weekdays, weekday => jsxRuntime.jsx(calendarUtils.CalendarDay, {
257
+ type: "heading",
258
+ children: weekday
259
+ }, weekday)), _mapInstanceProperty__default["default"](paddingDays).call(paddingDays, (_, index) => jsxRuntime.jsx(calendarUtils.CalendarDay, {
260
+ type: "spacing"
261
+ }, index)), _mapInstanceProperty__default["default"](calendarItems).call(calendarItems, (item, index) => jsxRuntime.jsx(calendarUtils.CalendarDay, _objectSpread(_objectSpread({
262
+ isToday: calendarUtils.isSameDay(today, item)
263
+ }, getItemProps({
264
+ disabled: !calendarUtils.getIsDateInRange(item, props.minValue, props.maxValue),
265
+ item,
266
+ onMouseOut: () => {
267
+ // @ts-ignore
268
+ setDownshiftHighlightedIndex(null);
269
+ }
270
+ })), {}, {
271
+ isHighlighted: index === downshiftHighlightedIndex,
272
+ isSelected: calendarUtils.isSameDay(item, props.value),
273
+ children: calendarUtils.getCalendarDayLabel(item)
274
+ }), item))]
275
+ })]
276
+ }))]
277
+ });
278
+ }
279
+ }, intl.locale)
280
+ });
281
+ };
282
+ DateInput.propTypes = {};
283
+ DateInput.displayName = 'DateInput';
284
+ DateInput.isEmpty = value => value === '';
285
+ var DateInput$1 = DateInput;
286
+
287
+ // NOTE: This string will be replaced on build time with the package version.
288
+ var version = "19.25.1";
289
+
290
+ exports["default"] = DateInput$1;
291
+ exports.version = version;
@@ -0,0 +1,291 @@
1
+ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
2
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
3
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
4
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
5
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
6
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
7
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
8
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
9
+ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
10
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
11
+ import _pt from 'prop-types';
12
+ import _fillInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/fill';
13
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
14
+ import { useState, useRef, useCallback } from 'react';
15
+ import Downshift from 'downshift';
16
+ import { useIntl } from 'react-intl';
17
+ import Constraints from '@commercetools-uikit/constraints';
18
+ import { warning, filterDataAttributes } from '@commercetools-uikit/utils';
19
+ import { getToday, getDateInMonth, createItemToString, parseInputToDate, getIsDateInRange, createCalendarItems, getPaddingDayCount, getWeekdayNames, CalendarBody, getNextDay, getPreviousDay, getDaysInMonth, CalendarMenu, CalendarHeader, getMonthCalendarLabel, getYearCalendarLabel, CalendarContent, CalendarDay, isSameDay, getCalendarDayLabel, changeMonth } from '@commercetools-uikit/calendar-utils';
20
+ import { getLocalizedDateTimeFormatPattern } from '@commercetools-uikit/calendar-time-utils';
21
+ import { jsx, jsxs } from '@emotion/react/jsx-runtime';
22
+
23
+ function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
24
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
25
+ const preventDownshiftDefault = event => {
26
+ event.nativeEvent.preventDownshiftDefault = true;
27
+ };
28
+ const DateInput = props => {
29
+ const intl = useIntl();
30
+ const _useState = useState(props.value || getToday()),
31
+ _useState2 = _slicedToArray(_useState, 2),
32
+ calendarDate = _useState2[0],
33
+ setCalendarDate = _useState2[1];
34
+ const _useState3 = useState([]),
35
+ _useState4 = _slicedToArray(_useState3, 2),
36
+ suggestedItems = _useState4[0],
37
+ setSuggestedItems = _useState4[1];
38
+ const _useState5 = useState(props.value === '' ? null : getDateInMonth(props.value) - 1),
39
+ _useState6 = _slicedToArray(_useState5, 2),
40
+ highlightedIndex = _useState6[0],
41
+ setHighlightedIndex = _useState6[1];
42
+ const inputRef = useRef(null);
43
+ if (!props.isReadOnly) {
44
+ process.env.NODE_ENV !== "production" ? warning(typeof props.onChange === 'function', 'DateInput: `onChange` is required when input is not read only.') : void 0;
45
+ }
46
+ const onChange = props.onChange;
47
+ const emit = useCallback(value => onChange?.({
48
+ target: {
49
+ id: props.id,
50
+ name: props.name,
51
+ // when cleared the value is null, but we always want it to be an
52
+ // empty string when there is no value.
53
+ value: value || ''
54
+ }
55
+ }), [onChange, props.id, props.name]);
56
+ const handleChange = useCallback(date => {
57
+ inputRef.current?.setSelectionRange(0, 100);
58
+ emit(date);
59
+ }, [inputRef, emit]);
60
+ const onBlur = props.onBlur;
61
+ const handleBlur = useCallback(() => {
62
+ if (onBlur) onBlur({
63
+ target: {
64
+ id: props.id,
65
+ name: props.name
66
+ }
67
+ });
68
+ }, [onBlur, props.id, props.name]);
69
+ const showToday = () => {
70
+ const today = getToday();
71
+ setCalendarDate(today);
72
+ setHighlightedIndex(suggestedItems.length + getDateInMonth(today) - 1);
73
+ inputRef.current?.focus();
74
+ };
75
+ const jumpMonth = function (amount) {
76
+ let dayToHighlight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
77
+ const nextDate = changeMonth(calendarDate, amount);
78
+ setCalendarDate(nextDate);
79
+ setHighlightedIndex(dayToHighlight);
80
+ };
81
+
82
+ /**
83
+ * If the user manually enters a value in the text-input field,
84
+ * attempt to parse the value and emit it to the consumer if it's valid and in range.
85
+ */
86
+ const onInputBlur = event => {
87
+ const inputValue = event.target.value || '';
88
+ const date = parseInputToDate(inputValue, intl.locale);
89
+ const inRange = getIsDateInRange(date, props.minValue, props.maxValue);
90
+ if (inputValue.length === 0) emit(inputValue);
91
+ if (!date || !inRange) return;
92
+ emit(date);
93
+ };
94
+ return jsx(Constraints.Horizontal, {
95
+ max: props.horizontalConstraint,
96
+ children: jsx(Downshift, {
97
+ inputId: props.id,
98
+ itemToString: createItemToString(intl.locale),
99
+ selectedItem: props.value === '' ? null : props.value,
100
+ highlightedIndex: highlightedIndex,
101
+ onChange: handleChange,
102
+ onStateChange: changes => {
103
+ if (changes.hasOwnProperty('inputValue')) {
104
+ // input changed because user typed
105
+ if (changes.type === Downshift.stateChangeTypes.changeInput) {
106
+ const date = parseInputToDate(changes.inputValue, intl.locale);
107
+ if (date === '') {
108
+ setSuggestedItems([]);
109
+ setHighlightedIndex(null);
110
+ } else {
111
+ setSuggestedItems([date]);
112
+ if (getIsDateInRange(date, props.minValue, props.maxValue)) {
113
+ setHighlightedIndex(getDateInMonth(date) - 1);
114
+ }
115
+ setCalendarDate(date);
116
+ }
117
+ } else {
118
+ // input changed because user selected a date
119
+ setSuggestedItems([]);
120
+ setHighlightedIndex(null);
121
+ }
122
+ /**
123
+ * Asides the inputValue, we also have other ways to enter calendar inputs like the mouse move event to enter calender values.
124
+ * We check the downshift changes property to be sure it has highlightedIndex That is not null before updating it,
125
+ * otherwise it may override the initially set highlightedIndex from the inputValue and set it to null.
126
+ */
127
+ } else if (changes.hasOwnProperty('highlightedIndex')) {
128
+ setHighlightedIndex(changes.highlightedIndex);
129
+ }
130
+ },
131
+ children: _ref => {
132
+ var _context;
133
+ let getInputProps = _ref.getInputProps,
134
+ getMenuProps = _ref.getMenuProps,
135
+ getItemProps = _ref.getItemProps,
136
+ getToggleButtonProps = _ref.getToggleButtonProps,
137
+ clearSelection = _ref.clearSelection,
138
+ downshiftHighlightedIndex = _ref.highlightedIndex,
139
+ openMenu = _ref.openMenu,
140
+ setDownshiftHighlightedIndex = _ref.setHighlightedIndex,
141
+ selectedItem = _ref.selectedItem,
142
+ isOpen = _ref.isOpen,
143
+ inputValue = _ref.inputValue;
144
+ const calendarItems = createCalendarItems(calendarDate);
145
+ const paddingDayCount = getPaddingDayCount(calendarDate, intl.locale);
146
+ const paddingDays = _fillInstanceProperty(_context = Array(paddingDayCount)).call(_context, undefined);
147
+ const weekdays = getWeekdayNames(intl.locale);
148
+ const today = getToday();
149
+ return jsxs("div", {
150
+ onFocus: props.onFocus,
151
+ onBlur: handleBlur,
152
+ children: [jsx(CalendarBody, {
153
+ inputRef: inputRef,
154
+ inputProps: getInputProps(_objectSpread({
155
+ /* ARIA */
156
+ 'aria-invalid': props['aria-invalid'],
157
+ 'aria-errormessage': props['aria-errormessage'],
158
+ // Unset the aria-labelledby as it interfers with the link
159
+ // between the <label for> and the <input id>.
160
+ 'aria-labelledby': undefined,
161
+ name: props.name,
162
+ placeholder: typeof props.placeholder === 'string' ? props.placeholder : getLocalizedDateTimeFormatPattern(intl.locale),
163
+ onMouseEnter: () => {
164
+ // we remove the highlight so that the user can use the
165
+ // arrow keys to move the cursor when hovering
166
+ // @ts-ignore
167
+ if (isOpen) setDownshiftHighlightedIndex(null);
168
+ },
169
+ onKeyDown: event => {
170
+ if (props.isReadOnly) {
171
+ preventDownshiftDefault(event);
172
+ return;
173
+ }
174
+ if (event.key === 'Enter' && inputValue?.trim() === '') {
175
+ clearSelection();
176
+ }
177
+ // ArrowDown
178
+ if (event.key === 'ArrowDown') {
179
+ const nextDayToHighlight = getNextDay(calendarItems[Number(highlightedIndex)]);
180
+ if (!getIsDateInRange(nextDayToHighlight, props.minValue, props.maxValue)) {
181
+ // if the date to highlight is disabled
182
+ // then do nothing
183
+ preventDownshiftDefault(event);
184
+ return;
185
+ }
186
+ if (Number(highlightedIndex) + 1 >= calendarItems.length) {
187
+ // if it's the end of the month
188
+ // then bypass normal arrow navigation
189
+ preventDownshiftDefault(event);
190
+ // then jump to start of next month
191
+ jumpMonth(1, 0);
192
+ }
193
+ }
194
+ // ArrowUp
195
+ if (event.key === 'ArrowUp') {
196
+ const previousDay = getPreviousDay(calendarItems[Number(highlightedIndex)]);
197
+ if (!getIsDateInRange(previousDay, props.minValue, props.maxValue)) {
198
+ // if the date to highlight is disabled
199
+ // then do nothing
200
+ preventDownshiftDefault(event);
201
+ return;
202
+ }
203
+ if (Number(highlightedIndex) <= 0) {
204
+ // if it's the start of the month
205
+ // then bypass normal arrow navigation
206
+ preventDownshiftDefault(event);
207
+ const numberOfDaysOfPrevMonth = getDaysInMonth(previousDay);
208
+ // then jump to the last day of the previous month
209
+ jumpMonth(-1, numberOfDaysOfPrevMonth - 1);
210
+ }
211
+ }
212
+ },
213
+ onBlur: onInputBlur,
214
+ // we only do this for readOnly because the input
215
+ // doesn't ignore these events, unlike when its disabled
216
+ onClick: props.isReadOnly ? undefined : openMenu
217
+ }, filterDataAttributes(props))),
218
+ hasSelection: Boolean(selectedItem),
219
+ onClear: clearSelection,
220
+ isOpen: isOpen,
221
+ isDisabled: props.isDisabled,
222
+ isReadOnly: props.isReadOnly,
223
+ isCondensed: props.isCondensed,
224
+ toggleButtonProps: getToggleButtonProps(),
225
+ hasError: props.hasError,
226
+ hasWarning: props.hasWarning
227
+ }), isOpen && !props.isDisabled && !props.isReadOnly && jsxs(CalendarMenu, _objectSpread(_objectSpread({}, getMenuProps()), {}, {
228
+ hasError: props.hasError,
229
+ hasWarning: props.hasWarning,
230
+ children: [jsx(CalendarHeader, {
231
+ monthLabel: getMonthCalendarLabel(calendarDate, intl.locale),
232
+ yearLabel: getYearCalendarLabel(calendarDate, intl.locale),
233
+ onPrevMonthClick: () => jumpMonth(-1),
234
+ onTodayClick: showToday,
235
+ onNextMonthClick: () => jumpMonth(1),
236
+ onPrevYearClick: () => jumpMonth(-12),
237
+ onNextYearClick: () => jumpMonth(12)
238
+ }), jsxs(CalendarContent, {
239
+ children: [_mapInstanceProperty(weekdays).call(weekdays, weekday => jsx(CalendarDay, {
240
+ type: "heading",
241
+ children: weekday
242
+ }, weekday)), _mapInstanceProperty(paddingDays).call(paddingDays, (_, index) => jsx(CalendarDay, {
243
+ type: "spacing"
244
+ }, index)), _mapInstanceProperty(calendarItems).call(calendarItems, (item, index) => jsx(CalendarDay, _objectSpread(_objectSpread({
245
+ isToday: isSameDay(today, item)
246
+ }, getItemProps({
247
+ disabled: !getIsDateInRange(item, props.minValue, props.maxValue),
248
+ item,
249
+ onMouseOut: () => {
250
+ // @ts-ignore
251
+ setDownshiftHighlightedIndex(null);
252
+ }
253
+ })), {}, {
254
+ isHighlighted: index === downshiftHighlightedIndex,
255
+ isSelected: isSameDay(item, props.value),
256
+ children: getCalendarDayLabel(item)
257
+ }), item))]
258
+ })]
259
+ }))]
260
+ });
261
+ }
262
+ }, intl.locale)
263
+ });
264
+ };
265
+ DateInput.propTypes = process.env.NODE_ENV !== "production" ? {
266
+ horizontalConstraint: _pt.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
267
+ value: _pt.string.isRequired,
268
+ onChange: _pt.func,
269
+ onFocus: _pt.func,
270
+ onBlur: _pt.func,
271
+ id: _pt.string,
272
+ 'aria-invalid': _pt.bool,
273
+ 'aria-errormessage': _pt.string,
274
+ name: _pt.string,
275
+ placeholder: _pt.string,
276
+ isCondensed: _pt.bool,
277
+ isDisabled: _pt.bool,
278
+ isReadOnly: _pt.bool,
279
+ hasError: _pt.bool,
280
+ hasWarning: _pt.bool,
281
+ minValue: _pt.string,
282
+ maxValue: _pt.string
283
+ } : {};
284
+ DateInput.displayName = 'DateInput';
285
+ DateInput.isEmpty = value => value === '';
286
+ var DateInput$1 = DateInput;
287
+
288
+ // NOTE: This string will be replaced on build time with the package version.
289
+ var version = "19.25.1";
290
+
291
+ export { DateInput$1 as default, version };
@@ -0,0 +1,84 @@
1
+ import { type FocusEventHandler } from 'react';
2
+ type TCustomEvent = {
3
+ target: {
4
+ id?: string;
5
+ name?: string;
6
+ value?: string;
7
+ };
8
+ };
9
+ export type TDateInput = {
10
+ /**
11
+ * Horizontal size limit of the input field.
12
+ */
13
+ horizontalConstraint?: 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
14
+ /**
15
+ * The selected date, must either be an empty string or a date formatted as "YYYY-MM-DD".
16
+ */
17
+ value: string;
18
+ /**
19
+ * Called when the date changes. Called with an event containing either an empty string (no value) or a string in this format: "YYYY-MM-DD".
20
+ */
21
+ onChange?: (event: TCustomEvent) => void;
22
+ /**
23
+ * Called when the date input gains focus.
24
+ */
25
+ onFocus?: FocusEventHandler<HTMLDivElement>;
26
+ /**
27
+ * Called when the date input loses focus.
28
+ */
29
+ onBlur?: (event: TCustomEvent) => void;
30
+ /**
31
+ * Used as the HTML `id` attribute.
32
+ */
33
+ id?: string;
34
+ /**
35
+ * Indicate if the value entered in the input is invalid.
36
+ */
37
+ 'aria-invalid'?: boolean;
38
+ /**
39
+ * HTML ID of an element containing an error message related to the input.
40
+ */
41
+ 'aria-errormessage'?: string;
42
+ /**
43
+ * Used as the HTML `name` attribute.
44
+ */
45
+ name?: string;
46
+ /**
47
+ * Placeholder value to show in the input field
48
+ */
49
+ placeholder?: string;
50
+ /**
51
+ * Use this property to reduce the paddings of the component for a ui compact variant
52
+ */
53
+ isCondensed?: boolean;
54
+ /**
55
+ * Disables the date picker
56
+ */
57
+ isDisabled?: boolean;
58
+ /**
59
+ * Disables the date picker menu and makes input field read-only
60
+ */
61
+ isReadOnly?: boolean;
62
+ /**
63
+ * Indicates the input field has an error
64
+ */
65
+ hasError?: boolean;
66
+ /**
67
+ * Indicates the input field has a warning
68
+ */
69
+ hasWarning?: boolean;
70
+ /**
71
+ * A minimum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD".
72
+ */
73
+ minValue?: string;
74
+ /**
75
+ * A maximum selectable date. Must either be an empty string or a date formatted as "YYYY-MM-DD".
76
+ */
77
+ maxValue?: string;
78
+ };
79
+ declare const DateInput: {
80
+ (props: TDateInput): import("@emotion/react/jsx-runtime").JSX.Element;
81
+ displayName: string;
82
+ isEmpty(value?: string): value is "";
83
+ };
84
+ export default DateInput;
@@ -0,0 +1 @@
1
+ export type { TDateInput } from "./date-input.js";
@@ -0,0 +1,3 @@
1
+ export { default } from "./date-input.js";
2
+ export { default as version } from "./version.js";
3
+ export * from "./export-types.js";
@@ -0,0 +1,2 @@
1
+ declare const _default: "__@UI_KIT_PACKAGE/VERSION_OF_RELEASE__";
2
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@commercetools-uikit/date-input",
3
+ "description": "The `DateInput` component allows the user to select a date. It formats the selected date depending on the users' locale.",
4
+ "version": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
5
+ "bugs": "https://github.com/commercetools/ui-kit/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/commercetools/ui-kit.git",
9
+ "directory": "packages/components/inputs/date-input"
10
+ },
11
+ "homepage": "https://uikit.commercetools.com",
12
+ "keywords": [
13
+ "javascript",
14
+ "typescript",
15
+ "design-system",
16
+ "react",
17
+ "uikit"
18
+ ],
19
+ "license": "MIT",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "sideEffects": false,
24
+ "main": "dist/commercetools-uikit-date-input.cjs.js",
25
+ "module": "dist/commercetools-uikit-date-input.esm.js",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "dependencies": {
30
+ "@babel/runtime": "^7.20.13",
31
+ "@babel/runtime-corejs3": "^7.20.13",
32
+ "@commercetools-uikit/accessible-button": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
33
+ "@commercetools-uikit/calendar-time-utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
34
+ "@commercetools-uikit/calendar-utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
35
+ "@commercetools-uikit/constraints": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
36
+ "@commercetools-uikit/design-system": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
37
+ "@commercetools-uikit/hooks": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
38
+ "@commercetools-uikit/icons": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
39
+ "@commercetools-uikit/secondary-icon-button": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
40
+ "@commercetools-uikit/select-utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
41
+ "@commercetools-uikit/spacings-inline": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
42
+ "@commercetools-uikit/text": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
43
+ "@commercetools-uikit/tooltip": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
44
+ "@commercetools-uikit/utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
45
+ "@emotion/react": "^11.10.5",
46
+ "@emotion/styled": "^11.10.5",
47
+ "downshift": "6.1.12",
48
+ "prop-types": "15.8.1",
49
+ "react-is": "17.0.2",
50
+ "warning": "4.0.3"
51
+ },
52
+ "devDependencies": {
53
+ "moment": "2.30.1",
54
+ "react": "17.0.2",
55
+ "react-intl": "^6.3.2"
56
+ },
57
+ "peerDependencies": {
58
+ "moment": "2.x",
59
+ "react": "17.x",
60
+ "react-intl": "6.x"
61
+ }
62
+ }