@instructure/ui-date-input 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = exports.DateInput = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
7
  var _react = require("react");
10
8
  var _latest = require("@instructure/ui-calendar/latest");
11
9
  var _latest2 = require("@instructure/ui-buttons/latest");
@@ -17,7 +15,6 @@ var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProp
17
15
  var _getLocale = require("@instructure/ui-i18n/lib/getLocale.js");
18
16
  var _getTimezone = require("@instructure/ui-i18n/lib/getTimezone.js");
19
17
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
20
- var _CalendarInstUIIcon, _ChevronRightInstUIIc, _ChevronLeftInstUIIco;
21
18
  /*
22
19
  * The MIT License (MIT)
23
20
  *
@@ -41,6 +38,7 @@ var _CalendarInstUIIcon, _ChevronRightInstUIIc, _ChevronLeftInstUIIco;
41
38
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42
39
  * SOFTWARE.
43
40
  */
41
+
44
42
  function parseLocaleDate(dateString = '', locale, timeZone) {
45
43
  // This function may seem complicated but it basically does one thing:
46
44
  // Given a dateString, a locale and a timeZone. The dateString is assumed to be formatted according
@@ -139,23 +137,15 @@ const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
139
137
  }, ref) => {
140
138
  const userLocale = locale || (0, _getLocale.getLocale)();
141
139
  const userTimezone = timezone || (0, _getTimezone.getTimezone)();
142
- const _useState = (0, _react.useState)(messages || []),
143
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
144
- inputMessages = _useState2[0],
145
- setInputMessages = _useState2[1];
146
- const _useState3 = (0, _react.useState)(false),
147
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
148
- showPopover = _useState4[0],
149
- setShowPopover = _useState4[1];
140
+ const [inputMessages, setInputMessages] = (0, _react.useState)(messages || []);
141
+ const [showPopover, setShowPopover] = (0, _react.useState)(false);
150
142
  (0, _react.useEffect)(() => {
151
143
  // don't set input messages if there is an internal error set already
152
144
  if (inputMessages.find(m => m.text === invalidDateErrorMessage)) return;
153
145
  setInputMessages(messages || []);
154
146
  }, [messages]);
155
147
  (0, _react.useEffect)(() => {
156
- const _parseDate = parseDate(value),
157
- _parseDate2 = (0, _slicedToArray2.default)(_parseDate, 2),
158
- utcIsoDate = _parseDate2[1];
148
+ const [, utcIsoDate] = parseDate(value);
159
149
  // clear error messages if date becomes valid
160
150
  if (utcIsoDate || !value) {
161
151
  setInputMessages(messages || []);
@@ -178,7 +168,7 @@ const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
178
168
  };
179
169
  const formatDate = (date, timeZone = userTimezone) => {
180
170
  // use formatter function if provided
181
- if (typeof dateFormat !== 'string' && dateFormat !== null && dateFormat !== void 0 && dateFormat.formatter) {
171
+ if (typeof dateFormat !== 'string' && dateFormat?.formatter) {
182
172
  return dateFormat.formatter(date);
183
173
  }
184
174
  // if dateFormat set to a locale, use that, otherwise default to the user's locale
@@ -204,25 +194,20 @@ const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
204
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));
205
195
  };
206
196
  const handleInputChange = (e, newValue) => {
207
- const _parseDate3 = parseDate(newValue),
208
- _parseDate4 = (0, _slicedToArray2.default)(_parseDate3, 2),
209
- utcIsoDate = _parseDate4[1];
210
- onChange === null || onChange === void 0 ? void 0 : onChange(e, newValue, utcIsoDate);
197
+ const [, utcIsoDate] = parseDate(newValue);
198
+ onChange?.(e, newValue, utcIsoDate);
211
199
  };
212
200
  const handleDateSelected = (dateString, _momentDate, e) => {
213
201
  setShowPopover(false);
214
202
  const newValue = formatDate(new Date(dateString));
215
- onChange === null || onChange === void 0 ? void 0 : onChange(e, newValue, dateString);
216
- onRequestValidateDate === null || onRequestValidateDate === void 0 ? void 0 : onRequestValidateDate(e, newValue, dateString);
203
+ onChange?.(e, newValue, dateString);
204
+ onRequestValidateDate?.(e, newValue, dateString);
217
205
  };
218
206
  const handleBlur = e => {
219
- const _parseDate5 = parseDate(value),
220
- _parseDate6 = (0, _slicedToArray2.default)(_parseDate5, 2),
221
- localeDate = _parseDate6[0],
222
- utcIsoDate = _parseDate6[1];
207
+ const [localeDate, utcIsoDate] = parseDate(value);
223
208
  if (localeDate) {
224
209
  if (localeDate !== value) {
225
- onChange === null || onChange === void 0 ? void 0 : onChange(e, localeDate, utcIsoDate);
210
+ onChange?.(e, localeDate, utcIsoDate);
226
211
  }
227
212
  } else if (value && invalidDateErrorMessage) {
228
213
  setInputMessages([{
@@ -230,8 +215,8 @@ const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
230
215
  text: invalidDateErrorMessage
231
216
  }]);
232
217
  }
233
- onRequestValidateDate === null || onRequestValidateDate === void 0 ? void 0 : onRequestValidateDate(e, value || '', utcIsoDate);
234
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(e, value || '', utcIsoDate);
218
+ onRequestValidateDate?.(e, value || '', utcIsoDate);
219
+ onBlur?.(e, value || '', utcIsoDate);
235
220
  };
236
221
  const selectedDate = parseDate(value)[1];
237
222
  return (0, _jsxRuntime.jsx)(_latest4.TextInput, {
@@ -244,7 +229,7 @@ const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
244
229
  onBlur: handleBlur,
245
230
  isRequired: isRequired,
246
231
  value: value,
247
- placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : getDateFormatHint(),
232
+ placeholder: placeholder ?? getDateFormatHint(),
248
233
  width: width,
249
234
  display: isInline ? 'inline-block' : 'block',
250
235
  messages: inputMessages,
@@ -257,9 +242,9 @@ const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
257
242
  withBorder: false,
258
243
  screenReaderLabel: screenReaderLabels.calendarIcon,
259
244
  interaction: interaction,
260
- children: renderCalendarIcon ? (0, _callRenderProp.callRenderProp)(renderCalendarIcon) : _CalendarInstUIIcon || (_CalendarInstUIIcon = (0, _jsxRuntime.jsx)(_uiIcons.CalendarInstUIIcon, {
245
+ children: renderCalendarIcon ? (0, _callRenderProp.callRenderProp)(renderCalendarIcon) : (0, _jsxRuntime.jsx)(_uiIcons.CalendarInstUIIcon, {
261
246
  color: "baseColor"
262
- }))
247
+ })
263
248
  }),
264
249
  isShowingContent: showPopover,
265
250
  onShowContent: () => setShowPopover(true),
@@ -281,18 +266,18 @@ const DateInput = exports.DateInput = /*#__PURE__*/(0, _react.forwardRef)(({
281
266
  size: "small",
282
267
  withBackground: false,
283
268
  withBorder: false,
284
- renderIcon: _ChevronRightInstUIIc || (_ChevronRightInstUIIc = (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
269
+ renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
285
270
  color: "baseColor"
286
- })),
271
+ }),
287
272
  screenReaderLabel: screenReaderLabels.nextMonthButton
288
273
  }),
289
274
  renderPrevMonthButton: (0, _jsxRuntime.jsx)(_latest2.IconButton, {
290
275
  size: "small",
291
276
  withBackground: false,
292
277
  withBorder: false,
293
- renderIcon: _ChevronLeftInstUIIco || (_ChevronLeftInstUIIco = (0, _jsxRuntime.jsx)(_uiIcons.ChevronLeftInstUIIcon, {
278
+ renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronLeftInstUIIcon, {
294
279
  color: "baseColor"
295
- })),
280
+ }),
296
281
  screenReaderLabel: screenReaderLabels.prevMonthButton
297
282
  })
298
283
  })
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = exports.DateInput2 = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
7
  var _react = require("react");
10
8
  var _v11_ = require("@instructure/ui-calendar/v11_6");
11
9
  var _v11_2 = require("@instructure/ui-buttons/v11_6");
@@ -17,7 +15,6 @@ var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProp
17
15
  var _getLocale = require("@instructure/ui-i18n/lib/getLocale.js");
18
16
  var _getTimezone = require("@instructure/ui-i18n/lib/getTimezone.js");
19
17
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
20
- var _CalendarInstUIIcon, _ChevronRightInstUIIc, _ChevronLeftInstUIIco;
21
18
  /*
22
19
  * The MIT License (MIT)
23
20
  *
@@ -41,6 +38,7 @@ var _CalendarInstUIIcon, _ChevronRightInstUIIc, _ChevronLeftInstUIIco;
41
38
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42
39
  * SOFTWARE.
43
40
  */
41
+
44
42
  function parseLocaleDate(dateString = '', locale, timeZone) {
45
43
  // This function may seem complicated but it basically does one thing:
46
44
  // Given a dateString, a locale and a timeZone. The dateString is assumed to be formatted according
@@ -139,23 +137,15 @@ const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
139
137
  }, ref) => {
140
138
  const userLocale = locale || (0, _getLocale.getLocale)();
141
139
  const userTimezone = timezone || (0, _getTimezone.getTimezone)();
142
- const _useState = (0, _react.useState)(messages || []),
143
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
144
- inputMessages = _useState2[0],
145
- setInputMessages = _useState2[1];
146
- const _useState3 = (0, _react.useState)(false),
147
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
148
- showPopover = _useState4[0],
149
- setShowPopover = _useState4[1];
140
+ const [inputMessages, setInputMessages] = (0, _react.useState)(messages || []);
141
+ const [showPopover, setShowPopover] = (0, _react.useState)(false);
150
142
  (0, _react.useEffect)(() => {
151
143
  // don't set input messages if there is an internal error set already
152
144
  if (inputMessages.find(m => m.text === invalidDateErrorMessage)) return;
153
145
  setInputMessages(messages || []);
154
146
  }, [messages]);
155
147
  (0, _react.useEffect)(() => {
156
- const _parseDate = parseDate(value),
157
- _parseDate2 = (0, _slicedToArray2.default)(_parseDate, 2),
158
- utcIsoDate = _parseDate2[1];
148
+ const [, utcIsoDate] = parseDate(value);
159
149
  // clear error messages if date becomes valid
160
150
  if (utcIsoDate || !value) {
161
151
  setInputMessages(messages || []);
@@ -178,7 +168,7 @@ const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
178
168
  };
179
169
  const formatDate = (date, timeZone = userTimezone) => {
180
170
  // use formatter function if provided
181
- if (typeof dateFormat !== 'string' && dateFormat !== null && dateFormat !== void 0 && dateFormat.formatter) {
171
+ if (typeof dateFormat !== 'string' && dateFormat?.formatter) {
182
172
  return dateFormat.formatter(date);
183
173
  }
184
174
  // if dateFormat set to a locale, use that, otherwise default to the user's locale
@@ -204,25 +194,20 @@ const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
204
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));
205
195
  };
206
196
  const handleInputChange = (e, newValue) => {
207
- const _parseDate3 = parseDate(newValue),
208
- _parseDate4 = (0, _slicedToArray2.default)(_parseDate3, 2),
209
- utcIsoDate = _parseDate4[1];
210
- onChange === null || onChange === void 0 ? void 0 : onChange(e, newValue, utcIsoDate);
197
+ const [, utcIsoDate] = parseDate(newValue);
198
+ onChange?.(e, newValue, utcIsoDate);
211
199
  };
212
200
  const handleDateSelected = (dateString, _momentDate, e) => {
213
201
  setShowPopover(false);
214
202
  const newValue = formatDate(new Date(dateString));
215
- onChange === null || onChange === void 0 ? void 0 : onChange(e, newValue, dateString);
216
- onRequestValidateDate === null || onRequestValidateDate === void 0 ? void 0 : onRequestValidateDate(e, newValue, dateString);
203
+ onChange?.(e, newValue, dateString);
204
+ onRequestValidateDate?.(e, newValue, dateString);
217
205
  };
218
206
  const handleBlur = e => {
219
- const _parseDate5 = parseDate(value),
220
- _parseDate6 = (0, _slicedToArray2.default)(_parseDate5, 2),
221
- localeDate = _parseDate6[0],
222
- utcIsoDate = _parseDate6[1];
207
+ const [localeDate, utcIsoDate] = parseDate(value);
223
208
  if (localeDate) {
224
209
  if (localeDate !== value) {
225
- onChange === null || onChange === void 0 ? void 0 : onChange(e, localeDate, utcIsoDate);
210
+ onChange?.(e, localeDate, utcIsoDate);
226
211
  }
227
212
  } else if (value && invalidDateErrorMessage) {
228
213
  setInputMessages([{
@@ -230,8 +215,8 @@ const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
230
215
  text: invalidDateErrorMessage
231
216
  }]);
232
217
  }
233
- onRequestValidateDate === null || onRequestValidateDate === void 0 ? void 0 : onRequestValidateDate(e, value || '', utcIsoDate);
234
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(e, value || '', utcIsoDate);
218
+ onRequestValidateDate?.(e, value || '', utcIsoDate);
219
+ onBlur?.(e, value || '', utcIsoDate);
235
220
  };
236
221
  const selectedDate = parseDate(value)[1];
237
222
  return (0, _jsxRuntime.jsx)(_v11_4.TextInput, {
@@ -244,7 +229,7 @@ const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
244
229
  onBlur: handleBlur,
245
230
  isRequired: isRequired,
246
231
  value: value,
247
- placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : getDateFormatHint(),
232
+ placeholder: placeholder ?? getDateFormatHint(),
248
233
  width: width,
249
234
  display: isInline ? 'inline-block' : 'block',
250
235
  messages: inputMessages,
@@ -256,9 +241,9 @@ const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
256
241
  withBorder: false,
257
242
  screenReaderLabel: screenReaderLabels.calendarIcon,
258
243
  interaction: interaction,
259
- children: renderCalendarIcon ? (0, _callRenderProp.callRenderProp)(renderCalendarIcon) : _CalendarInstUIIcon || (_CalendarInstUIIcon = (0, _jsxRuntime.jsx)(_uiIcons.CalendarInstUIIcon, {
244
+ children: renderCalendarIcon ? (0, _callRenderProp.callRenderProp)(renderCalendarIcon) : (0, _jsxRuntime.jsx)(_uiIcons.CalendarInstUIIcon, {
260
245
  color: "baseColor"
261
- }))
246
+ })
262
247
  }),
263
248
  isShowingContent: showPopover,
264
249
  onShowContent: () => setShowPopover(true),
@@ -280,18 +265,18 @@ const DateInput2 = exports.DateInput2 = /*#__PURE__*/(0, _react.forwardRef)(({
280
265
  size: "small",
281
266
  withBackground: false,
282
267
  withBorder: false,
283
- renderIcon: _ChevronRightInstUIIc || (_ChevronRightInstUIIc = (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
268
+ renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {
284
269
  color: "baseColor"
285
- })),
270
+ }),
286
271
  screenReaderLabel: screenReaderLabels.nextMonthButton
287
272
  }),
288
273
  renderPrevMonthButton: (0, _jsxRuntime.jsx)(_v11_2.IconButton, {
289
274
  size: "small",
290
275
  withBackground: false,
291
276
  withBorder: false,
292
- renderIcon: _ChevronLeftInstUIIco || (_ChevronLeftInstUIIco = (0, _jsxRuntime.jsx)(_uiIcons.ChevronLeftInstUIIcon, {
277
+ renderIcon: (0, _jsxRuntime.jsx)(_uiIcons.ChevronLeftInstUIIcon, {
293
278
  color: "baseColor"
294
- })),
279
+ }),
295
280
  screenReaderLabel: screenReaderLabels.prevMonthButton
296
281
  })
297
282
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-date-input",
3
- "version": "11.7.3-snapshot-7",
3
+ "version": "11.7.3-snapshot-26",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -14,29 +14,29 @@
14
14
  "bugs": "https://github.com/instructure/instructure-ui/issues",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "^7.27.6",
18
- "moment-timezone": "^0.6.0",
19
- "@instructure/shared-types": "11.7.3-snapshot-7",
20
- "@instructure/ui-calendar": "11.7.3-snapshot-7",
21
- "@instructure/emotion": "11.7.3-snapshot-7",
22
- "@instructure/ui-form-field": "11.7.3-snapshot-7",
23
- "@instructure/ui-i18n": "11.7.3-snapshot-7",
24
- "@instructure/ui-icons": "11.7.3-snapshot-7",
25
- "@instructure/ui-popover": "11.7.3-snapshot-7",
26
- "@instructure/ui-position": "11.7.3-snapshot-7",
27
- "@instructure/ui-react-utils": "11.7.3-snapshot-7",
28
- "@instructure/ui-selectable": "11.7.3-snapshot-7",
29
- "@instructure/ui-text-input": "11.7.3-snapshot-7",
30
- "@instructure/ui-utils": "11.7.3-snapshot-7"
17
+ "@babel/runtime": "^7.29.2",
18
+ "moment-timezone": "^0.6.2",
19
+ "@instructure/emotion": "11.7.3-snapshot-26",
20
+ "@instructure/shared-types": "11.7.3-snapshot-26",
21
+ "@instructure/ui-form-field": "11.7.3-snapshot-26",
22
+ "@instructure/ui-i18n": "11.7.3-snapshot-26",
23
+ "@instructure/ui-calendar": "11.7.3-snapshot-26",
24
+ "@instructure/ui-icons": "11.7.3-snapshot-26",
25
+ "@instructure/ui-popover": "11.7.3-snapshot-26",
26
+ "@instructure/ui-position": "11.7.3-snapshot-26",
27
+ "@instructure/ui-react-utils": "11.7.3-snapshot-26",
28
+ "@instructure/ui-selectable": "11.7.3-snapshot-26",
29
+ "@instructure/ui-text-input": "11.7.3-snapshot-26",
30
+ "@instructure/ui-utils": "11.7.3-snapshot-26"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@testing-library/jest-dom": "^6.6.3",
34
34
  "@testing-library/react": "15.0.7",
35
35
  "@testing-library/user-event": "^14.6.1",
36
36
  "vitest": "^3.2.2",
37
- "@instructure/ui-babel-preset": "11.7.3-snapshot-7",
38
- "@instructure/ui-buttons": "11.7.3-snapshot-7",
39
- "@instructure/ui-scripts": "11.7.3-snapshot-7"
37
+ "@instructure/ui-buttons": "11.7.3-snapshot-26",
38
+ "@instructure/ui-scripts": "11.7.3-snapshot-26",
39
+ "@instructure/ui-babel-preset": "11.7.3-snapshot-26"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": ">=18 <=19"