@instructure/ui-date-time-input 8.53.3-snapshot-23 → 8.54.0

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 CHANGED
@@ -3,9 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [8.53.3-snapshot-23](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.53.3-snapshot-23) (2024-03-20)
6
+ # [8.54.0](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.54.0) (2024-03-21)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-date-time-input
8
+
9
+ ### Features
10
+
11
+ * **ui-date-time-input:** make resetting programatically possible ([a474dab](https://github.com/instructure/instructure-ui/commit/a474daba920a16b6704f89e3c825902902ed1c0b))
9
12
 
10
13
 
11
14
 
@@ -51,6 +51,7 @@ let DateTimeInput = (_dec = testable(), _dec(_class = (_class2 = class DateTimeI
51
51
  this.handleRef = el => {
52
52
  this.ref = el;
53
53
  };
54
+ this.reset = () => this.setState(this.recalculateState());
54
55
  // Called when the user enters text into dateInput
55
56
  this.handleDateTextChange = (_event, date) => {
56
57
  const dateParsed = this.tryParseDate(date.value);
@@ -189,10 +190,12 @@ let DateTimeInput = (_dec = testable(), _dec(_class = (_class2 = class DateTimeI
189
190
  this.state = this.recalculateState(props.value || props.defaultValue);
190
191
  }
191
192
  componentDidMount() {
193
+ var _this$props$reset, _this$props3;
192
194
  // we'll need to recalculate the state because the context value is
193
195
  // set at this point (and it might change locale & timezone)
194
196
  const initState = this.recalculateState(this.props.value || this.props.defaultValue);
195
197
  this.setState(initState);
198
+ (_this$props$reset = (_this$props3 = this.props).reset) === null || _this$props$reset === void 0 ? void 0 : _this$props$reset.call(_this$props3, this.reset);
196
199
  }
197
200
  componentDidUpdate(prevProps) {
198
201
  const valueChanged = prevProps.value !== this.props.value || prevProps.defaultValue !== this.props.defaultValue;
@@ -411,27 +414,27 @@ let DateTimeInput = (_dec = testable(), _dec(_class = (_class2 = class DateTimeI
411
414
  });
412
415
  }
413
416
  render() {
414
- const _this$props3 = this.props,
415
- description = _this$props3.description,
416
- datePlaceholder = _this$props3.datePlaceholder,
417
- timePlaceholder = _this$props3.timePlaceholder,
418
- dateRenderLabel = _this$props3.dateRenderLabel,
419
- dateInputRef = _this$props3.dateInputRef,
420
- timeRenderLabel = _this$props3.timeRenderLabel,
421
- timeFormat = _this$props3.timeFormat,
422
- timeStep = _this$props3.timeStep,
423
- timeInputRef = _this$props3.timeInputRef,
424
- locale = _this$props3.locale,
425
- timezone = _this$props3.timezone,
426
- showMessages = _this$props3.showMessages,
427
- messages = _this$props3.messages,
428
- layout = _this$props3.layout,
429
- rowSpacing = _this$props3.rowSpacing,
430
- colSpacing = _this$props3.colSpacing,
431
- isRequired = _this$props3.isRequired,
432
- interaction = _this$props3.interaction,
433
- renderWeekdayLabels = _this$props3.renderWeekdayLabels,
434
- allowNonStepInput = _this$props3.allowNonStepInput;
417
+ const _this$props4 = this.props,
418
+ description = _this$props4.description,
419
+ datePlaceholder = _this$props4.datePlaceholder,
420
+ timePlaceholder = _this$props4.timePlaceholder,
421
+ dateRenderLabel = _this$props4.dateRenderLabel,
422
+ dateInputRef = _this$props4.dateInputRef,
423
+ timeRenderLabel = _this$props4.timeRenderLabel,
424
+ timeFormat = _this$props4.timeFormat,
425
+ timeStep = _this$props4.timeStep,
426
+ timeInputRef = _this$props4.timeInputRef,
427
+ locale = _this$props4.locale,
428
+ timezone = _this$props4.timezone,
429
+ showMessages = _this$props4.showMessages,
430
+ messages = _this$props4.messages,
431
+ layout = _this$props4.layout,
432
+ rowSpacing = _this$props4.rowSpacing,
433
+ colSpacing = _this$props4.colSpacing,
434
+ isRequired = _this$props4.isRequired,
435
+ interaction = _this$props4.interaction,
436
+ renderWeekdayLabels = _this$props4.renderWeekdayLabels,
437
+ allowNonStepInput = _this$props4.allowNonStepInput;
435
438
  return /*#__PURE__*/React.createElement(FormFieldGroup, {
436
439
  description: description,
437
440
  layout: layout,
@@ -67,7 +67,8 @@ const propTypes = {
67
67
  disabledDates: PropTypes.oneOfType([PropTypes.func, PropTypes.arrayOf(PropTypes.string)]),
68
68
  disabledDateTimeMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
69
69
  allowNonStepInput: PropTypes.bool,
70
+ reset: PropTypes.func,
70
71
  initialTimeForNewDate: hourMinuteValidator
71
72
  };
72
- const allowedProps = ['description', 'dateRenderLabel', 'prevMonthLabel', 'nextMonthLabel', 'datePlaceholder', 'timePlaceholder', 'dateFormat', 'interaction', 'timeRenderLabel', 'timeStep', 'timeFormat', 'locale', 'timezone', 'invalidDateTimeMessage', 'showMessages', 'messages', 'messageFormat', 'layout', 'rowSpacing', 'colSpacing', 'value', 'defaultValue', 'renderWeekdayLabels', 'isRequired', 'onChange', 'dateInputRef', 'timeInputRef', 'onBlur', 'disabledDates', 'disabledDateTimeMessage', 'allowNonStepInput'];
73
+ const allowedProps = ['description', 'dateRenderLabel', 'prevMonthLabel', 'nextMonthLabel', 'datePlaceholder', 'timePlaceholder', 'dateFormat', 'interaction', 'timeRenderLabel', 'timeStep', 'timeFormat', 'locale', 'timezone', 'invalidDateTimeMessage', 'showMessages', 'messages', 'messageFormat', 'layout', 'rowSpacing', 'colSpacing', 'value', 'defaultValue', 'renderWeekdayLabels', 'isRequired', 'onChange', 'dateInputRef', 'timeInputRef', 'onBlur', 'disabledDates', 'disabledDateTimeMessage', 'allowNonStepInput', 'reset'];
73
74
  export { propTypes, allowedProps };
@@ -59,6 +59,7 @@ let DateTimeInput = exports.DateTimeInput = (_dec = (0, _testable.testable)(), _
59
59
  this.handleRef = el => {
60
60
  this.ref = el;
61
61
  };
62
+ this.reset = () => this.setState(this.recalculateState());
62
63
  // Called when the user enters text into dateInput
63
64
  this.handleDateTextChange = (_event, date) => {
64
65
  const dateParsed = this.tryParseDate(date.value);
@@ -197,10 +198,12 @@ let DateTimeInput = exports.DateTimeInput = (_dec = (0, _testable.testable)(), _
197
198
  this.state = this.recalculateState(props.value || props.defaultValue);
198
199
  }
199
200
  componentDidMount() {
201
+ var _this$props$reset, _this$props3;
200
202
  // we'll need to recalculate the state because the context value is
201
203
  // set at this point (and it might change locale & timezone)
202
204
  const initState = this.recalculateState(this.props.value || this.props.defaultValue);
203
205
  this.setState(initState);
206
+ (_this$props$reset = (_this$props3 = this.props).reset) === null || _this$props$reset === void 0 ? void 0 : _this$props$reset.call(_this$props3, this.reset);
204
207
  }
205
208
  componentDidUpdate(prevProps) {
206
209
  const valueChanged = prevProps.value !== this.props.value || prevProps.defaultValue !== this.props.defaultValue;
@@ -419,27 +422,27 @@ let DateTimeInput = exports.DateTimeInput = (_dec = (0, _testable.testable)(), _
419
422
  });
420
423
  }
421
424
  render() {
422
- const _this$props3 = this.props,
423
- description = _this$props3.description,
424
- datePlaceholder = _this$props3.datePlaceholder,
425
- timePlaceholder = _this$props3.timePlaceholder,
426
- dateRenderLabel = _this$props3.dateRenderLabel,
427
- dateInputRef = _this$props3.dateInputRef,
428
- timeRenderLabel = _this$props3.timeRenderLabel,
429
- timeFormat = _this$props3.timeFormat,
430
- timeStep = _this$props3.timeStep,
431
- timeInputRef = _this$props3.timeInputRef,
432
- locale = _this$props3.locale,
433
- timezone = _this$props3.timezone,
434
- showMessages = _this$props3.showMessages,
435
- messages = _this$props3.messages,
436
- layout = _this$props3.layout,
437
- rowSpacing = _this$props3.rowSpacing,
438
- colSpacing = _this$props3.colSpacing,
439
- isRequired = _this$props3.isRequired,
440
- interaction = _this$props3.interaction,
441
- renderWeekdayLabels = _this$props3.renderWeekdayLabels,
442
- allowNonStepInput = _this$props3.allowNonStepInput;
425
+ const _this$props4 = this.props,
426
+ description = _this$props4.description,
427
+ datePlaceholder = _this$props4.datePlaceholder,
428
+ timePlaceholder = _this$props4.timePlaceholder,
429
+ dateRenderLabel = _this$props4.dateRenderLabel,
430
+ dateInputRef = _this$props4.dateInputRef,
431
+ timeRenderLabel = _this$props4.timeRenderLabel,
432
+ timeFormat = _this$props4.timeFormat,
433
+ timeStep = _this$props4.timeStep,
434
+ timeInputRef = _this$props4.timeInputRef,
435
+ locale = _this$props4.locale,
436
+ timezone = _this$props4.timezone,
437
+ showMessages = _this$props4.showMessages,
438
+ messages = _this$props4.messages,
439
+ layout = _this$props4.layout,
440
+ rowSpacing = _this$props4.rowSpacing,
441
+ colSpacing = _this$props4.colSpacing,
442
+ isRequired = _this$props4.isRequired,
443
+ interaction = _this$props4.interaction,
444
+ renderWeekdayLabels = _this$props4.renderWeekdayLabels,
445
+ allowNonStepInput = _this$props4.allowNonStepInput;
443
446
  return /*#__PURE__*/_react.default.createElement(_FormFieldGroup.FormFieldGroup, {
444
447
  description: description,
445
448
  layout: layout,
@@ -74,6 +74,7 @@ const propTypes = exports.propTypes = {
74
74
  disabledDates: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.arrayOf(_propTypes.default.string)]),
75
75
  disabledDateTimeMessage: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]),
76
76
  allowNonStepInput: _propTypes.default.bool,
77
+ reset: _propTypes.default.func,
77
78
  initialTimeForNewDate: hourMinuteValidator
78
79
  };
79
- const allowedProps = exports.allowedProps = ['description', 'dateRenderLabel', 'prevMonthLabel', 'nextMonthLabel', 'datePlaceholder', 'timePlaceholder', 'dateFormat', 'interaction', 'timeRenderLabel', 'timeStep', 'timeFormat', 'locale', 'timezone', 'invalidDateTimeMessage', 'showMessages', 'messages', 'messageFormat', 'layout', 'rowSpacing', 'colSpacing', 'value', 'defaultValue', 'renderWeekdayLabels', 'isRequired', 'onChange', 'dateInputRef', 'timeInputRef', 'onBlur', 'disabledDates', 'disabledDateTimeMessage', 'allowNonStepInput'];
80
+ const allowedProps = exports.allowedProps = ['description', 'dateRenderLabel', 'prevMonthLabel', 'nextMonthLabel', 'datePlaceholder', 'timePlaceholder', 'dateFormat', 'interaction', 'timeRenderLabel', 'timeStep', 'timeFormat', 'locale', 'timezone', 'invalidDateTimeMessage', 'showMessages', 'messages', 'messageFormat', 'layout', 'rowSpacing', 'colSpacing', 'value', 'defaultValue', 'renderWeekdayLabels', 'isRequired', 'onChange', 'dateInputRef', 'timeInputRef', 'onBlur', 'disabledDates', 'disabledDateTimeMessage', 'allowNonStepInput', 'reset'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-date-time-input",
3
- "version": "8.53.3-snapshot-23",
3
+ "version": "8.54.0",
4
4
  "description": "A UI component that allows to select date and time.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,30 +23,30 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.53.3-snapshot-23",
27
- "@instructure/ui-test-locator": "8.53.3-snapshot-23",
28
- "@instructure/ui-test-utils": "8.53.3-snapshot-23",
26
+ "@instructure/ui-babel-preset": "8.54.0",
27
+ "@instructure/ui-test-locator": "8.54.0",
28
+ "@instructure/ui-test-utils": "8.54.0",
29
29
  "@testing-library/jest-dom": "^6.1.4",
30
30
  "@testing-library/react": "^14.1.2",
31
31
  "@testing-library/user-event": "^14.5.1"
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.23.2",
35
- "@instructure/console": "8.53.3-snapshot-23",
36
- "@instructure/debounce": "8.53.3-snapshot-23",
37
- "@instructure/emotion": "8.53.3-snapshot-23",
38
- "@instructure/ui-a11y-content": "8.53.3-snapshot-23",
39
- "@instructure/ui-buttons": "8.53.3-snapshot-23",
40
- "@instructure/ui-calendar": "8.53.3-snapshot-23",
41
- "@instructure/ui-date-input": "8.53.3-snapshot-23",
42
- "@instructure/ui-form-field": "8.53.3-snapshot-23",
43
- "@instructure/ui-i18n": "8.53.3-snapshot-23",
44
- "@instructure/ui-icons": "8.53.3-snapshot-23",
45
- "@instructure/ui-prop-types": "8.53.3-snapshot-23",
46
- "@instructure/ui-react-utils": "8.53.3-snapshot-23",
47
- "@instructure/ui-testable": "8.53.3-snapshot-23",
48
- "@instructure/ui-time-select": "8.53.3-snapshot-23",
49
- "@instructure/ui-utils": "8.53.3-snapshot-23",
35
+ "@instructure/console": "8.54.0",
36
+ "@instructure/debounce": "8.54.0",
37
+ "@instructure/emotion": "8.54.0",
38
+ "@instructure/ui-a11y-content": "8.54.0",
39
+ "@instructure/ui-buttons": "8.54.0",
40
+ "@instructure/ui-calendar": "8.54.0",
41
+ "@instructure/ui-date-input": "8.54.0",
42
+ "@instructure/ui-form-field": "8.54.0",
43
+ "@instructure/ui-i18n": "8.54.0",
44
+ "@instructure/ui-icons": "8.54.0",
45
+ "@instructure/ui-prop-types": "8.54.0",
46
+ "@instructure/ui-react-utils": "8.54.0",
47
+ "@instructure/ui-testable": "8.54.0",
48
+ "@instructure/ui-time-select": "8.54.0",
49
+ "@instructure/ui-utils": "8.54.0",
50
50
  "prop-types": "^15.8.1"
51
51
  },
52
52
  "peerDependencies": {
@@ -219,3 +219,69 @@ class Example extends React.Component {
219
219
 
220
220
  render(<Example />)
221
221
  ```
222
+
223
+ #### Programatically reset `DateTimeInput`
224
+
225
+ Due to `onChange` not being called on every typing event, and `value` isn't representing the inner value-state of the component, it's not possible to reset the `DateTimeInput` by setting the `value` to `undefined`. Instead, you can use the `reset` function that is passed to the `DateTimeInput` as a prop.
226
+
227
+ - ```js
228
+ class Example extends React.Component {
229
+ constructor(props) {
230
+ super(props)
231
+ this.state = {
232
+ date: ''
233
+ }
234
+ }
235
+
236
+ resetFn = null
237
+
238
+ render() {
239
+ return (
240
+ <div>
241
+ <DateTimeInput
242
+ description="Pick a date and time"
243
+ datePlaceholder="Choose a date"
244
+ dateRenderLabel="Date"
245
+ timeRenderLabel="Time"
246
+ invalidDateTimeMessage="Invalid date!"
247
+ prevMonthLabel="Previous month"
248
+ nextMonthLabel="Next month"
249
+ value={this.state.date}
250
+ onChange={(e, newDate) => this.setState({ date: newDate })}
251
+ reset={(reset) => (this.resetFn = reset)}
252
+ />
253
+ <Button onClick={() => this.resetFn()}>Clear</Button>
254
+ <p>{this.state.date}</p>
255
+ </div>
256
+ )
257
+ }
258
+ }
259
+ render(<Example />)
260
+ ```
261
+
262
+ - ```js
263
+ const Example = () => {
264
+ const [date, setDate] = useState('')
265
+ const resetFn = useRef()
266
+
267
+ return (
268
+ <div>
269
+ <DateTimeInput
270
+ description="Pick a date and time"
271
+ datePlaceholder="Choose a date"
272
+ dateRenderLabel="Date"
273
+ timeRenderLabel="Time"
274
+ invalidDateTimeMessage="Invalid date!"
275
+ prevMonthLabel="Previous month"
276
+ nextMonthLabel="Next month"
277
+ value={date}
278
+ onChange={(e, newDate) => setDate(newDate)}
279
+ reset={(reset) => (resetFn.current = reset)}
280
+ />
281
+ <Button onClick={() => resetFn.current()}>Clear</Button>
282
+ <p>{date}</p>
283
+ </div>
284
+ )
285
+ }
286
+ render(<Example />)
287
+ ```
@@ -88,6 +88,7 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
88
88
  this.props.value || this.props.defaultValue
89
89
  )
90
90
  this.setState(initState)
91
+ this.props.reset?.(this.reset)
91
92
  }
92
93
 
93
94
  componentDidUpdate(prevProps: Readonly<DateTimeInputProps>): void {
@@ -206,6 +207,8 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
206
207
  }
207
208
  }
208
209
 
210
+ reset = () => this.setState(this.recalculateState())
211
+
209
212
  locale(): string {
210
213
  if (this.props.locale) {
211
214
  return this.props.locale
@@ -247,6 +247,13 @@ type DateTimeInputProps = {
247
247
  * An error is thrown if the time format is not HH:MM.
248
248
  */
249
249
  initialTimeForNewDate?: string
250
+ /**
251
+ * Used for getting the internal reset function of DateTimeInput. If that
252
+ * function is called, the component will reset to its default inner state.
253
+ * The callback function will be called in componentDidMount
254
+ * NOTE: this won't call onChange, so you have to reset the value manually when calling reset
255
+ */
256
+ reset?: (reset: () => void) => void
250
257
  }
251
258
 
252
259
  type DateTimeInputState = {
@@ -339,6 +346,7 @@ const propTypes: PropValidators<PropKeys> = {
339
346
  PropTypes.func
340
347
  ]),
341
348
  allowNonStepInput: PropTypes.bool,
349
+ reset: PropTypes.func,
342
350
  initialTimeForNewDate: hourMinuteValidator
343
351
  }
344
352
 
@@ -373,7 +381,8 @@ const allowedProps: AllowedPropKeys = [
373
381
  'onBlur',
374
382
  'disabledDates',
375
383
  'disabledDateTimeMessage',
376
- 'allowNonStepInput'
384
+ 'allowNonStepInput',
385
+ 'reset'
377
386
  ]
378
387
 
379
388
  export type { DateTimeInputProps, DateTimeInputState }