@instructure/ui-date-time-input 10.2.2-snapshot-7 → 10.2.2-snapshot-9

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,7 +3,7 @@
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
- ## [10.2.2-snapshot-7](https://github.com/instructure/instructure-ui/compare/v10.2.1...v10.2.2-snapshot-7) (2024-09-10)
6
+ ## [10.2.2-snapshot-9](https://github.com/instructure/instructure-ui/compare/v10.2.1...v10.2.2-snapshot-9) (2024-09-12)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-date-time-input
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-date-time-input",
3
- "version": "10.2.2-snapshot-7",
3
+ "version": "10.2.2-snapshot-9",
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,8 +23,8 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "10.2.2-snapshot-7",
27
- "@instructure/ui-test-utils": "10.2.2-snapshot-7",
26
+ "@instructure/ui-babel-preset": "10.2.2-snapshot-9",
27
+ "@instructure/ui-test-utils": "10.2.2-snapshot-9",
28
28
  "@testing-library/jest-dom": "^6.4.6",
29
29
  "@testing-library/react": "^15.0.7",
30
30
  "@testing-library/user-event": "^14.5.2",
@@ -32,20 +32,20 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.24.5",
35
- "@instructure/console": "10.2.2-snapshot-7",
36
- "@instructure/shared-types": "10.2.2-snapshot-7",
37
- "@instructure/ui-a11y-content": "10.2.2-snapshot-7",
38
- "@instructure/ui-buttons": "10.2.2-snapshot-7",
39
- "@instructure/ui-calendar": "10.2.2-snapshot-7",
40
- "@instructure/ui-date-input": "10.2.2-snapshot-7",
41
- "@instructure/ui-form-field": "10.2.2-snapshot-7",
42
- "@instructure/ui-i18n": "10.2.2-snapshot-7",
43
- "@instructure/ui-icons": "10.2.2-snapshot-7",
44
- "@instructure/ui-prop-types": "10.2.2-snapshot-7",
45
- "@instructure/ui-react-utils": "10.2.2-snapshot-7",
46
- "@instructure/ui-testable": "10.2.2-snapshot-7",
47
- "@instructure/ui-time-select": "10.2.2-snapshot-7",
48
- "@instructure/ui-utils": "10.2.2-snapshot-7",
35
+ "@instructure/console": "10.2.2-snapshot-9",
36
+ "@instructure/shared-types": "10.2.2-snapshot-9",
37
+ "@instructure/ui-a11y-content": "10.2.2-snapshot-9",
38
+ "@instructure/ui-buttons": "10.2.2-snapshot-9",
39
+ "@instructure/ui-calendar": "10.2.2-snapshot-9",
40
+ "@instructure/ui-date-input": "10.2.2-snapshot-9",
41
+ "@instructure/ui-form-field": "10.2.2-snapshot-9",
42
+ "@instructure/ui-i18n": "10.2.2-snapshot-9",
43
+ "@instructure/ui-icons": "10.2.2-snapshot-9",
44
+ "@instructure/ui-prop-types": "10.2.2-snapshot-9",
45
+ "@instructure/ui-react-utils": "10.2.2-snapshot-9",
46
+ "@instructure/ui-testable": "10.2.2-snapshot-9",
47
+ "@instructure/ui-time-select": "10.2.2-snapshot-9",
48
+ "@instructure/ui-utils": "10.2.2-snapshot-9",
49
49
  "prop-types": "^15.8.1"
50
50
  },
51
51
  "peerDependencies": {
@@ -19,82 +19,163 @@ The component is localized via its `locale` and `timezone` parameters. Both are
19
19
 
20
20
  #### A DateTimeInput with `columns` layout and a default value:
21
21
 
22
- ```js
23
- ---
24
- type: example
25
- ---
26
- class Example extends React.Component {
27
- render () {
22
+ - ```js
23
+ class Example extends React.Component {
24
+ render() {
25
+ return (
26
+ <div style={{ height: '10rem', width: '40em' }}>
27
+ <DateTimeInput
28
+ description="Pick a date and time"
29
+ datePlaceholder="Choose a date"
30
+ dateRenderLabel="Date"
31
+ timeRenderLabel="Time"
32
+ invalidDateTimeMessage="Invalid date!"
33
+ prevMonthLabel="Previous month"
34
+ nextMonthLabel="Next month"
35
+ defaultValue="2018-01-18T13:30"
36
+ layout="columns"
37
+ />
38
+ </div>
39
+ )
40
+ }
41
+ }
42
+ render(<Example />)
43
+ ```
44
+
45
+ - ```js
46
+ const Example = () => {
28
47
  return (
29
- <div style= { {height: '10rem',width: '40em'}}>
48
+ <div style={{ height: '10rem', width: '40em' }}>
30
49
  <DateTimeInput
31
50
  description="Pick a date and time"
32
51
  datePlaceholder="Choose a date"
33
52
  dateRenderLabel="Date"
34
53
  timeRenderLabel="Time"
35
54
  invalidDateTimeMessage="Invalid date!"
36
- prevMonthLabel='Previous month'
37
- nextMonthLabel='Next month'
55
+ prevMonthLabel="Previous month"
56
+ nextMonthLabel="Next month"
38
57
  defaultValue="2018-01-18T13:30"
39
58
  layout="columns"
40
59
  />
41
- </div>)
60
+ </div>
61
+ )
42
62
  }
43
- }
44
- render(<Example />)
45
- ```
63
+
64
+ render(<Example />)
65
+ ```
46
66
 
47
67
  #### A required DateInput with `stacked` layout that warns if the value in the past:
48
68
 
49
69
  This sample code also allows the user to enter an arbitrary time value by setting `allowNonStepInput` to `true`.
50
70
 
51
- ```js
52
- ---
53
- type: example
54
- ---
55
-
56
- class Example extends React.Component {
57
- constructor (props) {
58
- super(props)
59
- this.state = {
60
- value: undefined,
61
- messages: []
71
+ - ```js
72
+ class Example extends React.Component {
73
+ constructor(props) {
74
+ super(props)
75
+ this.state = {
76
+ value: undefined,
77
+ messages: []
78
+ }
62
79
  }
63
- }
64
80
 
65
- onChange = (e, isoDate) => {
66
- let messages = []
67
- if (!isoDate) {
68
- // this happens if an invalid date is entered
69
- this.setState({ messages:messages, value:undefined })
70
- return
81
+ onChange = (e, isoDate) => {
82
+ let messages = []
83
+ if (!isoDate) {
84
+ // this happens if an invalid date is entered
85
+ this.setState({ messages: messages, value: undefined })
86
+ return
87
+ }
88
+ const now = new Date()
89
+ const newValue = new Date(isoDate)
90
+ if (newValue.valueOf() <= now.valueOf()) {
91
+ messages = [{ text: 'That date-time is in the past', type: 'hint' }]
92
+ }
93
+ this.setState({ value: isoDate, messages })
71
94
  }
72
- const now = new Date()
73
- const newValue = new Date(isoDate)
74
- if ( newValue.valueOf() <= now.valueOf()) {
75
- messages = [{text: 'That date-time is in the past', type: 'hint'}]
95
+
96
+ render() {
97
+ const text = this.state.value
98
+ ? new Date(this.state.value).toString()
99
+ : 'N/A'
100
+ return (
101
+ <div style={{ width: '25em' }}>
102
+ <div style={{ marginBottom: '1em', fontStyle: 'italic' }}>
103
+ You entered:
104
+ <br />
105
+ {text}
106
+ </div>
107
+ <div style={{ height: '14rem' }}>
108
+ <DateTimeInput
109
+ description={
110
+ <ScreenReaderContent>Pick a date and time</ScreenReaderContent>
111
+ }
112
+ datePlaceholder="Choose"
113
+ dateRenderLabel="Date"
114
+ timeRenderLabel="Time"
115
+ prevMonthLabel="Previous month"
116
+ nextMonthLabel="Next month"
117
+ onChange={this.onChange}
118
+ layout="stacked"
119
+ value={this.state.value}
120
+ invalidDateTimeMessage="Invalid date!"
121
+ messages={this.state.messages}
122
+ allowNonStepInput={true}
123
+ isRequired
124
+ />
125
+ </div>
126
+ </div>
127
+ )
76
128
  }
77
- this.setState({ value: isoDate, messages })
78
129
  }
130
+ render(<Example />)
131
+ ```
132
+
133
+ - ```js
134
+ const Example = () => {
135
+ const [value, setValue] = useState(undefined)
136
+ const [messages, setMessages] = useState([])
137
+
138
+ const onChange = (e, isoDate) => {
139
+ let newMessages = []
140
+ if (!isoDate) {
141
+ // this happens if an invalid date is entered
142
+ setValue(undefined)
143
+ setMessages(newMessages)
144
+ return
145
+ }
146
+ const now = new Date()
147
+ const newValue = new Date(isoDate)
148
+ if (newValue.valueOf() <= now.valueOf()) {
149
+ newMessages = [{ text: 'That date-time is in the past', type: 'hint' }]
150
+ }
151
+ setValue(isoDate)
152
+ setMessages(newMessages)
153
+ }
154
+
155
+ const text = value ? new Date(value).toString() : 'N/A'
79
156
 
80
- render () {
81
- const text = this.state.value ? new Date(this.state.value).toString() : 'N/A'
82
157
  return (
83
- <div style={{width: '25em'}}>
84
- <div style={{marginBottom: '1em', fontStyle: 'italic'}}>You entered:<br/>{text}</div>
85
- <div style={{height: '14rem'}}>
158
+ <div style={{ width: '25em' }}>
159
+ <div style={{ marginBottom: '1em', fontStyle: 'italic' }}>
160
+ You entered:
161
+ <br />
162
+ {text}
163
+ </div>
164
+ <div style={{ height: '14rem' }}>
86
165
  <DateTimeInput
87
- description={<ScreenReaderContent>Pick a date and time</ScreenReaderContent>}
166
+ description={
167
+ <ScreenReaderContent>Pick a date and time</ScreenReaderContent>
168
+ }
88
169
  datePlaceholder="Choose"
89
170
  dateRenderLabel="Date"
90
171
  timeRenderLabel="Time"
91
- prevMonthLabel='Previous month'
92
- nextMonthLabel='Next month'
93
- onChange={this.onChange}
172
+ prevMonthLabel="Previous month"
173
+ nextMonthLabel="Next month"
174
+ onChange={onChange}
94
175
  layout="stacked"
95
- value={this.state.value}
176
+ value={value}
96
177
  invalidDateTimeMessage="Invalid date!"
97
- messages={this.state.messages}
178
+ messages={messages}
98
179
  allowNonStepInput={true}
99
180
  isRequired
100
181
  />
@@ -102,9 +183,9 @@ class Example extends React.Component {
102
183
  </div>
103
184
  )
104
185
  }
105
- }
106
- render(<Example />)
107
- ```
186
+
187
+ render(<Example />)
188
+ ```
108
189
 
109
190
  #### A disabled DateTimeInput:
110
191
 
@@ -128,12 +209,35 @@ type: example
128
209
 
129
210
  #### A DateTimeInput in a different locale and timezone where these are set from the React `context`:
130
211
 
131
- ```js
132
- ---
133
- type: example
134
- ---
135
- class Example extends React.Component {
136
- render() {
212
+ - ```js
213
+ class Example extends React.Component {
214
+ render() {
215
+ return (
216
+ <ApplyLocale locale="fr" timezone="Africa/Nairobi">
217
+ <div style={{ height: '12rem', width: '40em' }}>
218
+ <DateTimeInput
219
+ description="Pick a date and time"
220
+ datePlaceholder="Choose a date"
221
+ dateRenderLabel="Date"
222
+ timeRenderLabel="Time"
223
+ prevMonthLabel="Previous month"
224
+ nextMonthLabel="Next month"
225
+ invalidDateTimeMessage={(dvalue) => {
226
+ return `'${dvalue} is not valid.`
227
+ }}
228
+ layout="columns"
229
+ defaultValue="2018-01-18T16:00"
230
+ />
231
+ </div>
232
+ </ApplyLocale>
233
+ )
234
+ }
235
+ }
236
+ render(<Example />)
237
+ ```
238
+
239
+ - ```js
240
+ const Example = () => {
137
241
  return (
138
242
  <ApplyLocale locale="fr" timezone="Africa/Nairobi">
139
243
  <div style={{ height: '12rem', width: '40em' }}>
@@ -142,8 +246,8 @@ class Example extends React.Component {
142
246
  datePlaceholder="Choose a date"
143
247
  dateRenderLabel="Date"
144
248
  timeRenderLabel="Time"
145
- prevMonthLabel='Previous month'
146
- nextMonthLabel='Next month'
249
+ prevMonthLabel="Previous month"
250
+ nextMonthLabel="Next month"
147
251
  invalidDateTimeMessage={(dvalue) => {
148
252
  return `'${dvalue} is not valid.`
149
253
  }}
@@ -151,11 +255,12 @@ class Example extends React.Component {
151
255
  defaultValue="2018-01-18T16:00"
152
256
  />
153
257
  </div>
154
- </ApplyLocale>)
258
+ </ApplyLocale>
259
+ )
155
260
  }
156
- }
157
- render(<Example />)
158
- ```
261
+
262
+ render(<Example />)
263
+ ```
159
264
 
160
265
  #### A `DateTimeInput` with some disabled dates that are supplied via a `string` array:
161
266
 
@@ -182,43 +287,94 @@ type: example
182
287
 
183
288
  #### A `DateTimeInput` with some disabled dates that are supplied via a `function`:
184
289
 
185
- ```js
186
- ---
187
- type: example
188
- ---
189
- const locale = 'en-us'
190
- const timezone = 'America/Denver'
191
-
192
- class Example extends React.Component {
193
- getDisabledDates(isoDateToCheck) {
194
- const parsed = moment.tz(isoDateToCheck, [moment.ISO_8601], locale, timezone)
195
- const now = moment().locale(locale).tz(timezone)
196
- return parsed.isBefore(now)
290
+ - ```js
291
+ const locale = 'en-us'
292
+ const timezone = 'America/Denver'
293
+
294
+ class Example extends React.Component {
295
+ getDisabledDates(isoDateToCheck) {
296
+ const parsed = moment.tz(
297
+ isoDateToCheck,
298
+ [moment.ISO_8601],
299
+ locale,
300
+ timezone
301
+ )
302
+ const now = moment().locale(locale).tz(timezone)
303
+ return parsed.isBefore(now)
304
+ }
305
+ render() {
306
+ return (
307
+ <div style={{ height: '12rem', width: '40em' }}>
308
+ <DateTimeInput
309
+ description="Pick a date and time"
310
+ datePlaceholder="Choose a date"
311
+ dateRenderLabel="Date"
312
+ timeRenderLabel="Time"
313
+ invalidDateTimeMessage={(rawDateValue) =>
314
+ 'Invalid date: ' + rawDateValue
315
+ }
316
+ disabledDateTimeMessage={(rawDateValue) =>
317
+ 'Disabled date: ' + rawDateValue
318
+ }
319
+ prevMonthLabel="Previous month"
320
+ nextMonthLabel="Next month"
321
+ defaultValue="2022-04-08T13:30"
322
+ layout="columns"
323
+ disabledDates={this.getDisabledDates}
324
+ locale={locale}
325
+ timezone={timezone}
326
+ />
327
+ </div>
328
+ )
329
+ }
197
330
  }
198
- render() {
331
+
332
+ render(<Example />)
333
+ ```
334
+
335
+ - ```js
336
+ const Example = () => {
337
+ const locale = 'en-us'
338
+ const timezone = 'America/Denver'
339
+
340
+ const getDisabledDates = (isoDateToCheck) => {
341
+ const parsed = moment.tz(
342
+ isoDateToCheck,
343
+ [moment.ISO_8601],
344
+ locale,
345
+ timezone
346
+ )
347
+ const now = moment().locale(locale).tz(timezone)
348
+ return parsed.isBefore(now)
349
+ }
350
+
199
351
  return (
200
- <div style= { {height: '12rem', width: '40em'}}>
352
+ <div style={{ height: '12rem', width: '40em' }}>
201
353
  <DateTimeInput
202
354
  description="Pick a date and time"
203
355
  datePlaceholder="Choose a date"
204
356
  dateRenderLabel="Date"
205
357
  timeRenderLabel="Time"
206
- invalidDateTimeMessage={(rawDateValue) => 'Invalid date: ' + rawDateValue}
207
- disabledDateTimeMessage={(rawDateValue) => 'Disabled date: ' + rawDateValue}
358
+ invalidDateTimeMessage={(rawDateValue) =>
359
+ 'Invalid date: ' + rawDateValue
360
+ }
361
+ disabledDateTimeMessage={(rawDateValue) =>
362
+ 'Disabled date: ' + rawDateValue
363
+ }
208
364
  prevMonthLabel="Previous month"
209
365
  nextMonthLabel="Next month"
210
366
  defaultValue="2022-04-08T13:30"
211
367
  layout="columns"
212
- disabledDates={this.getDisabledDates}
368
+ disabledDates={getDisabledDates}
213
369
  locale={locale}
214
370
  timezone={timezone}
215
371
  />
216
- </div>)
372
+ </div>
373
+ )
217
374
  }
218
- }
219
375
 
220
- render(<Example />)
221
- ```
376
+ render(<Example />)
377
+ ```
222
378
 
223
379
  #### Programatically reset `DateTimeInput`
224
380