@instructure/ui-date-input 11.7.3 → 11.7.4-pr-snapshot-1781695314229
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE.md +1 -0
- package/{lib/DateInput/v1/styles.js → babel.config.cjs} +12 -28
- package/es/DateInput/v1/index.js +3 -3
- package/es/DateInput/v2/index.js +9 -4
- package/es/exports/a.js +3 -2
- package/es/exports/b.js +3 -2
- package/package.json +18 -23
- package/src/DateInput/v1/index.tsx +3 -2
- package/src/DateInput/v2/index.tsx +7 -6
- package/src/exports/a.ts +2 -2
- package/src/exports/b.ts +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput/v1/index.d.ts +1 -0
- package/types/DateInput/v1/index.d.ts.map +1 -1
- package/types/DateInput/v2/index.d.ts.map +1 -1
- package/types/exports/a.d.ts +2 -2
- package/types/exports/a.d.ts.map +1 -1
- package/types/exports/b.d.ts +2 -2
- package/types/exports/b.d.ts.map +1 -1
- package/lib/DateInput/v1/index.js +0 -426
- package/lib/DateInput/v1/props.js +0 -31
- package/lib/DateInput/v2/index.js +0 -291
- package/lib/DateInput/v2/props.js +0 -5
- package/lib/DateInput2/v1/index.js +0 -290
- package/lib/DateInput2/v1/props.js +0 -5
- package/lib/exports/a.js +0 -19
- package/lib/exports/b.js +0 -19
- package/lib/package.json +0 -1
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.DateInput = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _latest = require("@instructure/ui-calendar/latest");
|
|
9
|
-
var _latest2 = require("@instructure/ui-buttons/latest");
|
|
10
|
-
var _uiIcons = require("@instructure/ui-icons");
|
|
11
|
-
var _latest3 = require("@instructure/ui-popover/latest");
|
|
12
|
-
var _latest4 = require("@instructure/ui-text-input/latest");
|
|
13
|
-
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
14
|
-
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
15
|
-
var _getLocale = require("@instructure/ui-i18n/lib/getLocale.js");
|
|
16
|
-
var _getTimezone = require("@instructure/ui-i18n/lib/getTimezone.js");
|
|
17
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
18
|
-
/*
|
|
19
|
-
* The MIT License (MIT)
|
|
20
|
-
*
|
|
21
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
22
|
-
*
|
|
23
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
24
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
25
|
-
* in the Software without restriction, including without limitation the rights
|
|
26
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
27
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
28
|
-
* furnished to do so, subject to the following conditions:
|
|
29
|
-
*
|
|
30
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
31
|
-
* copies or substantial portions of the Software.
|
|
32
|
-
*
|
|
33
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
39
|
-
* SOFTWARE.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
function parseLocaleDate(dateString = '', locale, timeZone) {
|
|
43
|
-
// This function may seem complicated but it basically does one thing:
|
|
44
|
-
// Given a dateString, a locale and a timeZone. The dateString is assumed to be formatted according
|
|
45
|
-
// to the locale. So if the locale is `en-us` the dateString is expected to be in the format of M/D/YYYY.
|
|
46
|
-
// The dateString is also assumed to be in the given timeZone, so "1/1/2020" in "America/Los_Angeles" timezone is
|
|
47
|
-
// expected to be "2020-01-01T08:00:00.000Z" in UTC time.
|
|
48
|
-
// This function tries to parse the dateString taking these variables into account and return a javascript Date object
|
|
49
|
-
// that is adjusted to be in UTC.
|
|
50
|
-
|
|
51
|
-
// Split string on '.', whitespace, '/', ',' or '-' using regex: /[.\s/.-]+/.
|
|
52
|
-
// The '+' allows splitting on consecutive delimiters.
|
|
53
|
-
// `.filter(Boolean)` is needed because some locales have a delimeter at the end (e.g.: hungarian dates are formatted as `2024. 09. 19.`)
|
|
54
|
-
const splitDate = dateString.split(/[,.\s/.-]+/).filter(Boolean);
|
|
55
|
-
|
|
56
|
-
// create a locale formatted new date to later extract the order and delimeter information
|
|
57
|
-
const localeDate = new Intl.DateTimeFormat(locale).formatToParts(new Date());
|
|
58
|
-
let index = 0;
|
|
59
|
-
let day, month, year;
|
|
60
|
-
localeDate.forEach(part => {
|
|
61
|
-
if (part.type === 'month') {
|
|
62
|
-
month = parseInt(splitDate[index], 10);
|
|
63
|
-
index++;
|
|
64
|
-
} else if (part.type === 'day') {
|
|
65
|
-
day = parseInt(splitDate[index], 10);
|
|
66
|
-
index++;
|
|
67
|
-
} else if (part.type === 'year') {
|
|
68
|
-
year = parseInt(splitDate[index], 10);
|
|
69
|
-
index++;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// sensible limitations
|
|
74
|
-
if (!year || !month || !day || year < 1000 || year > 9999) return null;
|
|
75
|
-
|
|
76
|
-
// create utc date from year, month (zero indexed) and day
|
|
77
|
-
const date = new Date(Date.UTC(year, month - 1, day));
|
|
78
|
-
|
|
79
|
-
// Format date string in the provided timezone. The locale here is irrelevant, we only care about how to time is adjusted for the timezone.
|
|
80
|
-
const parts = new Intl.DateTimeFormat('en-US', {
|
|
81
|
-
timeZone,
|
|
82
|
-
year: 'numeric',
|
|
83
|
-
month: '2-digit',
|
|
84
|
-
day: '2-digit',
|
|
85
|
-
hour: '2-digit',
|
|
86
|
-
minute: '2-digit',
|
|
87
|
-
second: '2-digit',
|
|
88
|
-
hour12: false
|
|
89
|
-
}).formatToParts(date);
|
|
90
|
-
|
|
91
|
-
// Extract the date and time parts from the formatted string
|
|
92
|
-
const dateStringInTimezone = parts.reduce((acc, part) => {
|
|
93
|
-
return part.type === 'literal' ? acc : {
|
|
94
|
-
...acc,
|
|
95
|
-
[part.type]: part.value
|
|
96
|
-
};
|
|
97
|
-
}, {});
|
|
98
|
-
|
|
99
|
-
// Create a date string in the format 'YYYY-MM-DDTHH:mm:ss'
|
|
100
|
-
const dateInTimezone = `${dateStringInTimezone.year}-${dateStringInTimezone.month}-${dateStringInTimezone.day}T${dateStringInTimezone.hour}:${dateStringInTimezone.minute}:${dateStringInTimezone.second}`;
|
|
101
|
-
|
|
102
|
-
// Calculate time difference for timezone offset
|
|
103
|
-
const timeDiff = new Date(dateInTimezone + 'Z').getTime() - date.getTime();
|
|
104
|
-
const utcTime = new Date(date.getTime() - timeDiff);
|
|
105
|
-
// Return the UTC Date corresponding to the time in the specified timezone
|
|
106
|
-
return utcTime;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
---
|
|
111
|
-
category: components
|
|
112
|
-
---
|
|
113
|
-
**/
|
|
114
|
-
const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
115
|
-
renderLabel,
|
|
116
|
-
screenReaderLabels,
|
|
117
|
-
isRequired = false,
|
|
118
|
-
interaction = 'enabled',
|
|
119
|
-
isInline = false,
|
|
120
|
-
value,
|
|
121
|
-
messages,
|
|
122
|
-
width,
|
|
123
|
-
onChange,
|
|
124
|
-
onBlur,
|
|
125
|
-
withYearPicker,
|
|
126
|
-
invalidDateErrorMessage,
|
|
127
|
-
locale,
|
|
128
|
-
timezone,
|
|
129
|
-
placeholder,
|
|
130
|
-
dateFormat,
|
|
131
|
-
onRequestValidateDate,
|
|
132
|
-
disabledDates,
|
|
133
|
-
renderCalendarIcon,
|
|
134
|
-
margin,
|
|
135
|
-
inputRef,
|
|
136
|
-
...rest
|
|
137
|
-
}, ref) => {
|
|
138
|
-
const userLocale = locale || (0, _getLocale.getLocale)();
|
|
139
|
-
const userTimezone = timezone || (0, _getTimezone.getTimezone)();
|
|
140
|
-
const [inputMessages, setInputMessages] = (0, _react.useState)(messages || []);
|
|
141
|
-
const [showPopover, setShowPopover] = (0, _react.useState)(false);
|
|
142
|
-
(0, _react.useEffect)(() => {
|
|
143
|
-
// don't set input messages if there is an internal error set already
|
|
144
|
-
if (inputMessages.find(m => m.text === invalidDateErrorMessage)) return;
|
|
145
|
-
setInputMessages(messages || []);
|
|
146
|
-
}, [messages]);
|
|
147
|
-
(0, _react.useEffect)(() => {
|
|
148
|
-
const [, utcIsoDate] = parseDate(value);
|
|
149
|
-
// clear error messages if date becomes valid
|
|
150
|
-
if (utcIsoDate || !value) {
|
|
151
|
-
setInputMessages(messages || []);
|
|
152
|
-
}
|
|
153
|
-
}, [value]);
|
|
154
|
-
const parseDate = (dateString = '') => {
|
|
155
|
-
let date = null;
|
|
156
|
-
if (dateFormat) {
|
|
157
|
-
if (typeof dateFormat === 'string') {
|
|
158
|
-
// use dateFormat instead of the user locale
|
|
159
|
-
date = parseLocaleDate(dateString, dateFormat, userTimezone);
|
|
160
|
-
} else if (dateFormat.parser) {
|
|
161
|
-
date = dateFormat.parser(dateString);
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
// no dateFormat prop passed, use locale for formatting
|
|
165
|
-
date = parseLocaleDate(dateString, userLocale, userTimezone);
|
|
166
|
-
}
|
|
167
|
-
return date ? [formatDate(date), date.toISOString()] : ['', ''];
|
|
168
|
-
};
|
|
169
|
-
const formatDate = (date, timeZone = userTimezone) => {
|
|
170
|
-
// use formatter function if provided
|
|
171
|
-
if (typeof dateFormat !== 'string' && dateFormat?.formatter) {
|
|
172
|
-
return dateFormat.formatter(date);
|
|
173
|
-
}
|
|
174
|
-
// if dateFormat set to a locale, use that, otherwise default to the user's locale
|
|
175
|
-
return date.toLocaleDateString(typeof dateFormat === 'string' ? dateFormat : userLocale, {
|
|
176
|
-
timeZone,
|
|
177
|
-
calendar: 'gregory',
|
|
178
|
-
numberingSystem: 'latn'
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
const getDateFormatHint = () => {
|
|
182
|
-
const exampleDate = new Date('2024-09-01');
|
|
183
|
-
const formattedDate = formatDate(exampleDate, 'UTC'); // exampleDate is in UTC so format it as such
|
|
184
|
-
|
|
185
|
-
// Create a regular expression to find the exact match of the number
|
|
186
|
-
const regex = n => {
|
|
187
|
-
return new RegExp(`(?<!\\d)0*${n}(?!\\d)`, 'g');
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// Replace the matched number with the same number of dashes
|
|
191
|
-
const year = '2024';
|
|
192
|
-
const month = '9';
|
|
193
|
-
const day = '1';
|
|
194
|
-
return formattedDate.replace(regex(year), match => 'Y'.repeat(match.length)).replace(regex(month), match => 'M'.repeat(match.length)).replace(regex(day), match => 'D'.repeat(match.length));
|
|
195
|
-
};
|
|
196
|
-
const handleInputChange = (e, newValue) => {
|
|
197
|
-
const [, utcIsoDate] = parseDate(newValue);
|
|
198
|
-
onChange?.(e, newValue, utcIsoDate);
|
|
199
|
-
};
|
|
200
|
-
const handleDateSelected = (dateString, _momentDate, e) => {
|
|
201
|
-
setShowPopover(false);
|
|
202
|
-
const newValue = formatDate(new Date(dateString));
|
|
203
|
-
onChange?.(e, newValue, dateString);
|
|
204
|
-
onRequestValidateDate?.(e, newValue, dateString);
|
|
205
|
-
};
|
|
206
|
-
const handleBlur = e => {
|
|
207
|
-
const [localeDate, utcIsoDate] = parseDate(value);
|
|
208
|
-
if (localeDate) {
|
|
209
|
-
if (localeDate !== value) {
|
|
210
|
-
onChange?.(e, localeDate, utcIsoDate);
|
|
211
|
-
}
|
|
212
|
-
} else if (value && invalidDateErrorMessage) {
|
|
213
|
-
setInputMessages([{
|
|
214
|
-
type: 'error',
|
|
215
|
-
text: invalidDateErrorMessage
|
|
216
|
-
}]);
|
|
217
|
-
}
|
|
218
|
-
onRequestValidateDate?.(e, value || '', utcIsoDate);
|
|
219
|
-
onBlur?.(e, value || '', utcIsoDate);
|
|
220
|
-
};
|
|
221
|
-
const selectedDate = parseDate(value)[1];
|
|
222
|
-
return (0, _jsxRuntime.jsx)(_latest4.TextInput, {
|
|
223
|
-
...(0, _passthroughProps.passthroughProps)(rest),
|
|
224
|
-
ref: ref,
|
|
225
|
-
inputRef: inputRef,
|
|
226
|
-
renderLabel: renderLabel,
|
|
227
|
-
"aria-label": (0, _callRenderProp.callRenderProp)(renderLabel),
|
|
228
|
-
onChange: handleInputChange,
|
|
229
|
-
onBlur: handleBlur,
|
|
230
|
-
isRequired: isRequired,
|
|
231
|
-
value: value,
|
|
232
|
-
placeholder: placeholder ?? getDateFormatHint(),
|
|
233
|
-
width: width,
|
|
234
|
-
display: isInline ? 'inline-block' : 'block',
|
|
235
|
-
messages: inputMessages,
|
|
236
|
-
interaction: interaction,
|
|
237
|
-
margin: margin,
|
|
238
|
-
renderAfterInput: (0, _jsxRuntime.jsx)(_latest3.Popover, {
|
|
239
|
-
renderTrigger: (0, _jsxRuntime.jsx)(_latest2.IconButton, {
|
|
240
|
-
size: "condensedMedium",
|
|
241
|
-
withBackground: false,
|
|
242
|
-
withBorder: false,
|
|
243
|
-
screenReaderLabel: screenReaderLabels.calendarIcon,
|
|
244
|
-
interaction: interaction,
|
|
245
|
-
children: renderCalendarIcon ? (0, _callRenderProp.callRenderProp)(renderCalendarIcon) : (0, _jsxRuntime.jsx)(_uiIcons.CalendarInstUIIcon, {
|
|
246
|
-
color: "baseColor"
|
|
247
|
-
})
|
|
248
|
-
}),
|
|
249
|
-
isShowingContent: showPopover,
|
|
250
|
-
onShowContent: () => setShowPopover(true),
|
|
251
|
-
onHideContent: () => setShowPopover(false),
|
|
252
|
-
on: "click",
|
|
253
|
-
shouldContainFocus: true,
|
|
254
|
-
shouldReturnFocus: true,
|
|
255
|
-
shouldCloseOnDocumentClick: true,
|
|
256
|
-
screenReaderLabel: screenReaderLabels.datePickerDialog,
|
|
257
|
-
children: (0, _jsxRuntime.jsx)(_latest.Calendar, {
|
|
258
|
-
withYearPicker: withYearPicker,
|
|
259
|
-
onDateSelected: handleDateSelected,
|
|
260
|
-
selectedDate: selectedDate,
|
|
261
|
-
selectedLabel: screenReaderLabels.selectedLabel,
|
|
262
|
-
disabledDates: disabledDates,
|
|
263
|
-
visibleMonth: selectedDate,
|
|
264
|
-
locale: userLocale,
|
|
265
|
-
timezone: userTimezone,
|
|
266
|
-
renderNextMonthButton: (0, _jsxRuntime.jsx)(_latest2.IconButton, {
|
|
267
|
-
size: "small",
|
|
268
|
-
withBackground: false,
|
|
269
|
-
withBorder: false,
|
|
270
|
-
renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
|
|
271
|
-
color: "baseColor"
|
|
272
|
-
}),
|
|
273
|
-
screenReaderLabel: screenReaderLabels.nextMonthButton
|
|
274
|
-
}),
|
|
275
|
-
renderPrevMonthButton: (0, _jsxRuntime.jsx)(_latest2.IconButton, {
|
|
276
|
-
size: "small",
|
|
277
|
-
withBackground: false,
|
|
278
|
-
withBorder: false,
|
|
279
|
-
renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronLeftInstUIIcon, {
|
|
280
|
-
color: "baseColor"
|
|
281
|
-
}),
|
|
282
|
-
screenReaderLabel: screenReaderLabels.prevMonthButton
|
|
283
|
-
})
|
|
284
|
-
})
|
|
285
|
-
})
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
// TODO this is probably needed?
|
|
290
|
-
DateInput.displayName = 'DateInput';
|
|
291
|
-
var _default = exports.default = DateInput;
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.DateInput2 = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _v11_ = require("@instructure/ui-calendar/v11_6");
|
|
9
|
-
var _v11_2 = require("@instructure/ui-buttons/v11_6");
|
|
10
|
-
var _uiIcons = require("@instructure/ui-icons");
|
|
11
|
-
var _v11_3 = require("@instructure/ui-popover/v11_6");
|
|
12
|
-
var _v11_4 = require("@instructure/ui-text-input/v11_6");
|
|
13
|
-
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
14
|
-
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
15
|
-
var _getLocale = require("@instructure/ui-i18n/lib/getLocale.js");
|
|
16
|
-
var _getTimezone = require("@instructure/ui-i18n/lib/getTimezone.js");
|
|
17
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
18
|
-
/*
|
|
19
|
-
* The MIT License (MIT)
|
|
20
|
-
*
|
|
21
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
22
|
-
*
|
|
23
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
24
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
25
|
-
* in the Software without restriction, including without limitation the rights
|
|
26
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
27
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
28
|
-
* furnished to do so, subject to the following conditions:
|
|
29
|
-
*
|
|
30
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
31
|
-
* copies or substantial portions of the Software.
|
|
32
|
-
*
|
|
33
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
39
|
-
* SOFTWARE.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
function parseLocaleDate(dateString = '', locale, timeZone) {
|
|
43
|
-
// This function may seem complicated but it basically does one thing:
|
|
44
|
-
// Given a dateString, a locale and a timeZone. The dateString is assumed to be formatted according
|
|
45
|
-
// to the locale. So if the locale is `en-us` the dateString is expected to be in the format of M/D/YYYY.
|
|
46
|
-
// The dateString is also assumed to be in the given timeZone, so "1/1/2020" in "America/Los_Angeles" timezone is
|
|
47
|
-
// expected to be "2020-01-01T08:00:00.000Z" in UTC time.
|
|
48
|
-
// This function tries to parse the dateString taking these variables into account and return a javascript Date object
|
|
49
|
-
// that is adjusted to be in UTC.
|
|
50
|
-
|
|
51
|
-
// Split string on '.', whitespace, '/', ',' or '-' using regex: /[.\s/.-]+/.
|
|
52
|
-
// The '+' allows splitting on consecutive delimiters.
|
|
53
|
-
// `.filter(Boolean)` is needed because some locales have a delimeter at the end (e.g.: hungarian dates are formatted as `2024. 09. 19.`)
|
|
54
|
-
const splitDate = dateString.split(/[,.\s/.-]+/).filter(Boolean);
|
|
55
|
-
|
|
56
|
-
// create a locale formatted new date to later extract the order and delimeter information
|
|
57
|
-
const localeDate = new Intl.DateTimeFormat(locale).formatToParts(new Date());
|
|
58
|
-
let index = 0;
|
|
59
|
-
let day, month, year;
|
|
60
|
-
localeDate.forEach(part => {
|
|
61
|
-
if (part.type === 'month') {
|
|
62
|
-
month = parseInt(splitDate[index], 10);
|
|
63
|
-
index++;
|
|
64
|
-
} else if (part.type === 'day') {
|
|
65
|
-
day = parseInt(splitDate[index], 10);
|
|
66
|
-
index++;
|
|
67
|
-
} else if (part.type === 'year') {
|
|
68
|
-
year = parseInt(splitDate[index], 10);
|
|
69
|
-
index++;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// sensible limitations
|
|
74
|
-
if (!year || !month || !day || year < 1000 || year > 9999) return null;
|
|
75
|
-
|
|
76
|
-
// create utc date from year, month (zero indexed) and day
|
|
77
|
-
const date = new Date(Date.UTC(year, month - 1, day));
|
|
78
|
-
|
|
79
|
-
// Format date string in the provided timezone. The locale here is irrelevant, we only care about how to time is adjusted for the timezone.
|
|
80
|
-
const parts = new Intl.DateTimeFormat('en-US', {
|
|
81
|
-
timeZone,
|
|
82
|
-
year: 'numeric',
|
|
83
|
-
month: '2-digit',
|
|
84
|
-
day: '2-digit',
|
|
85
|
-
hour: '2-digit',
|
|
86
|
-
minute: '2-digit',
|
|
87
|
-
second: '2-digit',
|
|
88
|
-
hour12: false
|
|
89
|
-
}).formatToParts(date);
|
|
90
|
-
|
|
91
|
-
// Extract the date and time parts from the formatted string
|
|
92
|
-
const dateStringInTimezone = parts.reduce((acc, part) => {
|
|
93
|
-
return part.type === 'literal' ? acc : {
|
|
94
|
-
...acc,
|
|
95
|
-
[part.type]: part.value
|
|
96
|
-
};
|
|
97
|
-
}, {});
|
|
98
|
-
|
|
99
|
-
// Create a date string in the format 'YYYY-MM-DDTHH:mm:ss'
|
|
100
|
-
const dateInTimezone = `${dateStringInTimezone.year}-${dateStringInTimezone.month}-${dateStringInTimezone.day}T${dateStringInTimezone.hour}:${dateStringInTimezone.minute}:${dateStringInTimezone.second}`;
|
|
101
|
-
|
|
102
|
-
// Calculate time difference for timezone offset
|
|
103
|
-
const timeDiff = new Date(dateInTimezone + 'Z').getTime() - date.getTime();
|
|
104
|
-
const utcTime = new Date(date.getTime() - timeDiff);
|
|
105
|
-
// Return the UTC Date corresponding to the time in the specified timezone
|
|
106
|
-
return utcTime;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
---
|
|
111
|
-
category: components
|
|
112
|
-
---
|
|
113
|
-
**/
|
|
114
|
-
const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
115
|
-
renderLabel,
|
|
116
|
-
screenReaderLabels,
|
|
117
|
-
isRequired = false,
|
|
118
|
-
interaction = 'enabled',
|
|
119
|
-
isInline = false,
|
|
120
|
-
value,
|
|
121
|
-
messages,
|
|
122
|
-
width,
|
|
123
|
-
onChange,
|
|
124
|
-
onBlur,
|
|
125
|
-
withYearPicker,
|
|
126
|
-
invalidDateErrorMessage,
|
|
127
|
-
locale,
|
|
128
|
-
timezone,
|
|
129
|
-
placeholder,
|
|
130
|
-
dateFormat,
|
|
131
|
-
onRequestValidateDate,
|
|
132
|
-
disabledDates,
|
|
133
|
-
renderCalendarIcon,
|
|
134
|
-
margin,
|
|
135
|
-
inputRef,
|
|
136
|
-
...rest
|
|
137
|
-
}, ref) => {
|
|
138
|
-
const userLocale = locale || (0, _getLocale.getLocale)();
|
|
139
|
-
const userTimezone = timezone || (0, _getTimezone.getTimezone)();
|
|
140
|
-
const [inputMessages, setInputMessages] = (0, _react.useState)(messages || []);
|
|
141
|
-
const [showPopover, setShowPopover] = (0, _react.useState)(false);
|
|
142
|
-
(0, _react.useEffect)(() => {
|
|
143
|
-
// don't set input messages if there is an internal error set already
|
|
144
|
-
if (inputMessages.find(m => m.text === invalidDateErrorMessage)) return;
|
|
145
|
-
setInputMessages(messages || []);
|
|
146
|
-
}, [messages]);
|
|
147
|
-
(0, _react.useEffect)(() => {
|
|
148
|
-
const [, utcIsoDate] = parseDate(value);
|
|
149
|
-
// clear error messages if date becomes valid
|
|
150
|
-
if (utcIsoDate || !value) {
|
|
151
|
-
setInputMessages(messages || []);
|
|
152
|
-
}
|
|
153
|
-
}, [value]);
|
|
154
|
-
const parseDate = (dateString = '') => {
|
|
155
|
-
let date = null;
|
|
156
|
-
if (dateFormat) {
|
|
157
|
-
if (typeof dateFormat === 'string') {
|
|
158
|
-
// use dateFormat instead of the user locale
|
|
159
|
-
date = parseLocaleDate(dateString, dateFormat, userTimezone);
|
|
160
|
-
} else if (dateFormat.parser) {
|
|
161
|
-
date = dateFormat.parser(dateString);
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
// no dateFormat prop passed, use locale for formatting
|
|
165
|
-
date = parseLocaleDate(dateString, userLocale, userTimezone);
|
|
166
|
-
}
|
|
167
|
-
return date ? [formatDate(date), date.toISOString()] : ['', ''];
|
|
168
|
-
};
|
|
169
|
-
const formatDate = (date, timeZone = userTimezone) => {
|
|
170
|
-
// use formatter function if provided
|
|
171
|
-
if (typeof dateFormat !== 'string' && dateFormat?.formatter) {
|
|
172
|
-
return dateFormat.formatter(date);
|
|
173
|
-
}
|
|
174
|
-
// if dateFormat set to a locale, use that, otherwise default to the user's locale
|
|
175
|
-
return date.toLocaleDateString(typeof dateFormat === 'string' ? dateFormat : userLocale, {
|
|
176
|
-
timeZone,
|
|
177
|
-
calendar: 'gregory',
|
|
178
|
-
numberingSystem: 'latn'
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
const getDateFormatHint = () => {
|
|
182
|
-
const exampleDate = new Date('2024-09-01');
|
|
183
|
-
const formattedDate = formatDate(exampleDate, 'UTC'); // exampleDate is in UTC so format it as such
|
|
184
|
-
|
|
185
|
-
// Create a regular expression to find the exact match of the number
|
|
186
|
-
const regex = n => {
|
|
187
|
-
return new RegExp(`(?<!\\d)0*${n}(?!\\d)`, 'g');
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// Replace the matched number with the same number of dashes
|
|
191
|
-
const year = '2024';
|
|
192
|
-
const month = '9';
|
|
193
|
-
const day = '1';
|
|
194
|
-
return formattedDate.replace(regex(year), match => 'Y'.repeat(match.length)).replace(regex(month), match => 'M'.repeat(match.length)).replace(regex(day), match => 'D'.repeat(match.length));
|
|
195
|
-
};
|
|
196
|
-
const handleInputChange = (e, newValue) => {
|
|
197
|
-
const [, utcIsoDate] = parseDate(newValue);
|
|
198
|
-
onChange?.(e, newValue, utcIsoDate);
|
|
199
|
-
};
|
|
200
|
-
const handleDateSelected = (dateString, _momentDate, e) => {
|
|
201
|
-
setShowPopover(false);
|
|
202
|
-
const newValue = formatDate(new Date(dateString));
|
|
203
|
-
onChange?.(e, newValue, dateString);
|
|
204
|
-
onRequestValidateDate?.(e, newValue, dateString);
|
|
205
|
-
};
|
|
206
|
-
const handleBlur = e => {
|
|
207
|
-
const [localeDate, utcIsoDate] = parseDate(value);
|
|
208
|
-
if (localeDate) {
|
|
209
|
-
if (localeDate !== value) {
|
|
210
|
-
onChange?.(e, localeDate, utcIsoDate);
|
|
211
|
-
}
|
|
212
|
-
} else if (value && invalidDateErrorMessage) {
|
|
213
|
-
setInputMessages([{
|
|
214
|
-
type: 'error',
|
|
215
|
-
text: invalidDateErrorMessage
|
|
216
|
-
}]);
|
|
217
|
-
}
|
|
218
|
-
onRequestValidateDate?.(e, value || '', utcIsoDate);
|
|
219
|
-
onBlur?.(e, value || '', utcIsoDate);
|
|
220
|
-
};
|
|
221
|
-
const selectedDate = parseDate(value)[1];
|
|
222
|
-
return (0, _jsxRuntime.jsx)(_v11_4.TextInput, {
|
|
223
|
-
...(0, _passthroughProps.passthroughProps)(rest),
|
|
224
|
-
ref: ref,
|
|
225
|
-
inputRef: inputRef,
|
|
226
|
-
"aria-label": (0, _callRenderProp.callRenderProp)(renderLabel),
|
|
227
|
-
renderLabel: renderLabel,
|
|
228
|
-
onChange: handleInputChange,
|
|
229
|
-
onBlur: handleBlur,
|
|
230
|
-
isRequired: isRequired,
|
|
231
|
-
value: value,
|
|
232
|
-
placeholder: placeholder ?? getDateFormatHint(),
|
|
233
|
-
width: width,
|
|
234
|
-
display: isInline ? 'inline-block' : 'block',
|
|
235
|
-
messages: inputMessages,
|
|
236
|
-
interaction: interaction,
|
|
237
|
-
margin: margin,
|
|
238
|
-
renderAfterInput: (0, _jsxRuntime.jsx)(_v11_3.Popover, {
|
|
239
|
-
renderTrigger: (0, _jsxRuntime.jsx)(_v11_2.IconButton, {
|
|
240
|
-
withBackground: false,
|
|
241
|
-
withBorder: false,
|
|
242
|
-
screenReaderLabel: screenReaderLabels.calendarIcon,
|
|
243
|
-
interaction: interaction,
|
|
244
|
-
children: renderCalendarIcon ? (0, _callRenderProp.callRenderProp)(renderCalendarIcon) : (0, _jsxRuntime.jsx)(_uiIcons.CalendarInstUIIcon, {
|
|
245
|
-
color: "baseColor"
|
|
246
|
-
})
|
|
247
|
-
}),
|
|
248
|
-
isShowingContent: showPopover,
|
|
249
|
-
onShowContent: () => setShowPopover(true),
|
|
250
|
-
onHideContent: () => setShowPopover(false),
|
|
251
|
-
on: "click",
|
|
252
|
-
shouldContainFocus: true,
|
|
253
|
-
shouldReturnFocus: true,
|
|
254
|
-
shouldCloseOnDocumentClick: true,
|
|
255
|
-
screenReaderLabel: screenReaderLabels.datePickerDialog,
|
|
256
|
-
children: (0, _jsxRuntime.jsx)(_v11_.Calendar, {
|
|
257
|
-
withYearPicker: withYearPicker,
|
|
258
|
-
onDateSelected: handleDateSelected,
|
|
259
|
-
selectedDate: selectedDate,
|
|
260
|
-
selectedLabel: screenReaderLabels.selectedLabel,
|
|
261
|
-
disabledDates: disabledDates,
|
|
262
|
-
visibleMonth: selectedDate,
|
|
263
|
-
locale: userLocale,
|
|
264
|
-
timezone: userTimezone,
|
|
265
|
-
renderNextMonthButton: (0, _jsxRuntime.jsx)(_v11_2.IconButton, {
|
|
266
|
-
size: "small",
|
|
267
|
-
withBackground: false,
|
|
268
|
-
withBorder: false,
|
|
269
|
-
renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
|
|
270
|
-
color: "baseColor"
|
|
271
|
-
}),
|
|
272
|
-
screenReaderLabel: screenReaderLabels.nextMonthButton
|
|
273
|
-
}),
|
|
274
|
-
renderPrevMonthButton: (0, _jsxRuntime.jsx)(_v11_2.IconButton, {
|
|
275
|
-
size: "small",
|
|
276
|
-
withBackground: false,
|
|
277
|
-
withBorder: false,
|
|
278
|
-
renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronLeftInstUIIcon, {
|
|
279
|
-
color: "baseColor"
|
|
280
|
-
}),
|
|
281
|
-
screenReaderLabel: screenReaderLabels.prevMonthButton
|
|
282
|
-
})
|
|
283
|
-
})
|
|
284
|
-
})
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// TODO this is probably needed?
|
|
289
|
-
DateInput2.displayName = 'DateInput2';
|
|
290
|
-
var _default = exports.default = DateInput2;
|
package/lib/exports/a.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "DateInput", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _v.DateInput;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "DateInput2", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _v2.DateInput2;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _v = require("../DateInput/v1");
|
|
19
|
-
var _v2 = require("../DateInput2/v1");
|
package/lib/exports/b.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "DateInput", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _v.DateInput;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "DateInput2", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _v2.DateInput2;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _v = require("../DateInput/v2");
|
|
19
|
-
var _v2 = require("../DateInput2/v1");
|
package/lib/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|