@instructure/ui-date-input 9.5.2 → 9.6.1-pr-snapshot-1726659472372
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 +22 -0
- package/es/DateInput2/index.js +149 -77
- package/es/DateInput2/props.js +3 -5
- package/lib/DateInput2/index.js +149 -77
- package/lib/DateInput2/props.js +3 -5
- package/package.json +20 -20
- package/src/DateInput/README.md +1 -1
- package/src/DateInput2/README.md +186 -64
- package/src/DateInput2/index.tsx +151 -88
- package/src/DateInput2/props.ts +32 -32
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput2/index.d.ts +10 -13
- package/types/DateInput2/index.d.ts.map +1 -1
- package/types/DateInput2/props.d.ts +14 -22
- package/types/DateInput2/props.d.ts.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-date-input",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.6.1-pr-snapshot-1726659472372",
|
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",
|
@@ -23,11 +23,11 @@
|
|
23
23
|
},
|
24
24
|
"license": "MIT",
|
25
25
|
"devDependencies": {
|
26
|
-
"@instructure/ui-axe-check": "9.
|
27
|
-
"@instructure/ui-babel-preset": "9.
|
28
|
-
"@instructure/ui-buttons": "9.
|
29
|
-
"@instructure/ui-scripts": "9.
|
30
|
-
"@instructure/ui-test-utils": "9.
|
26
|
+
"@instructure/ui-axe-check": "9.6.1-pr-snapshot-1726659472372",
|
27
|
+
"@instructure/ui-babel-preset": "9.6.1-pr-snapshot-1726659472372",
|
28
|
+
"@instructure/ui-buttons": "9.6.1-pr-snapshot-1726659472372",
|
29
|
+
"@instructure/ui-scripts": "9.6.1-pr-snapshot-1726659472372",
|
30
|
+
"@instructure/ui-test-utils": "9.6.1-pr-snapshot-1726659472372",
|
31
31
|
"@testing-library/jest-dom": "^6.4.6",
|
32
32
|
"@testing-library/react": "^15.0.7",
|
33
33
|
"@testing-library/user-event": "^14.5.2",
|
@@ -35,20 +35,20 @@
|
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
37
|
"@babel/runtime": "^7.24.5",
|
38
|
-
"@instructure/emotion": "9.
|
39
|
-
"@instructure/shared-types": "9.
|
40
|
-
"@instructure/ui-calendar": "9.
|
41
|
-
"@instructure/ui-form-field": "9.
|
42
|
-
"@instructure/ui-i18n": "9.
|
43
|
-
"@instructure/ui-icons": "9.
|
44
|
-
"@instructure/ui-popover": "9.
|
45
|
-
"@instructure/ui-position": "9.
|
46
|
-
"@instructure/ui-prop-types": "9.
|
47
|
-
"@instructure/ui-react-utils": "9.
|
48
|
-
"@instructure/ui-selectable": "9.
|
49
|
-
"@instructure/ui-testable": "9.
|
50
|
-
"@instructure/ui-text-input": "9.
|
51
|
-
"@instructure/ui-utils": "9.
|
38
|
+
"@instructure/emotion": "9.6.1-pr-snapshot-1726659472372",
|
39
|
+
"@instructure/shared-types": "9.6.1-pr-snapshot-1726659472372",
|
40
|
+
"@instructure/ui-calendar": "9.6.1-pr-snapshot-1726659472372",
|
41
|
+
"@instructure/ui-form-field": "9.6.1-pr-snapshot-1726659472372",
|
42
|
+
"@instructure/ui-i18n": "9.6.1-pr-snapshot-1726659472372",
|
43
|
+
"@instructure/ui-icons": "9.6.1-pr-snapshot-1726659472372",
|
44
|
+
"@instructure/ui-popover": "9.6.1-pr-snapshot-1726659472372",
|
45
|
+
"@instructure/ui-position": "9.6.1-pr-snapshot-1726659472372",
|
46
|
+
"@instructure/ui-prop-types": "9.6.1-pr-snapshot-1726659472372",
|
47
|
+
"@instructure/ui-react-utils": "9.6.1-pr-snapshot-1726659472372",
|
48
|
+
"@instructure/ui-selectable": "9.6.1-pr-snapshot-1726659472372",
|
49
|
+
"@instructure/ui-testable": "9.6.1-pr-snapshot-1726659472372",
|
50
|
+
"@instructure/ui-text-input": "9.6.1-pr-snapshot-1726659472372",
|
51
|
+
"@instructure/ui-utils": "9.6.1-pr-snapshot-1726659472372",
|
52
52
|
"moment-timezone": "^0.5.45",
|
53
53
|
"prop-types": "^15.8.1"
|
54
54
|
},
|
package/src/DateInput/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
describes: DateInput
|
3
3
|
---
|
4
4
|
|
5
|
-
>
|
5
|
+
> *Note:* you can now try the updated (but still experimental) [`DateInput2`](/#DateInput2) which is easier to configure for developers, has a better UX, better accessibility features and a year picker. We recommend using that instead of `DateInput` which will be deprecated in the future.
|
6
6
|
|
7
7
|
The `DateInput` component provides a visual interface for inputting date data.
|
8
8
|
|
package/src/DateInput2/README.md
CHANGED
@@ -2,28 +2,37 @@
|
|
2
2
|
describes: DateInput2
|
3
3
|
---
|
4
4
|
|
5
|
-
|
5
|
+
> *Warning*: `DateInput2` is an **experimental** upgrade to the existing [`DateInput`](/#DateInput) component, offering easier configuration, better UX, improved accessibility, and a year picker. While it addresses key limitations of `DateInput`, it's still in the experimental phase, with some missing unit tests and potential API changes.
|
6
6
|
|
7
7
|
### Minimal config
|
8
8
|
|
9
9
|
- ```js
|
10
10
|
class Example extends React.Component {
|
11
|
-
state = {
|
11
|
+
state = { inputValue: '', dateString: '' }
|
12
12
|
|
13
13
|
render() {
|
14
14
|
return (
|
15
|
-
<
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
<div>
|
16
|
+
<DateInput2
|
17
|
+
renderLabel="Choose a date"
|
18
|
+
screenReaderLabels={{
|
19
|
+
calendarIcon: 'Calendar',
|
20
|
+
nextMonthButton: 'Next month',
|
21
|
+
prevMonthButton: 'Previous month'
|
22
|
+
}}
|
23
|
+
value={this.state.inputValue}
|
24
|
+
width="20rem"
|
25
|
+
onChange={(e, inputValue, dateString) => {
|
26
|
+
this.setState({ dateString, inputValue })
|
27
|
+
}}
|
28
|
+
invalidDateErrorMessage="Invalid date"
|
29
|
+
/>
|
30
|
+
<p>
|
31
|
+
Input Value: <code>{this.state.inputValue}</code>
|
32
|
+
<br />
|
33
|
+
UTC Date String: <code>{this.state.dateString}</code>
|
34
|
+
</p>
|
35
|
+
</div>
|
27
36
|
)
|
28
37
|
}
|
29
38
|
}
|
@@ -33,8 +42,58 @@ This component is an updated version of [`DateInput`](/#DateInput) that's easier
|
|
33
42
|
|
34
43
|
- ```js
|
35
44
|
const Example = () => {
|
36
|
-
const [
|
45
|
+
const [inputValue, setInputValue] = useState('')
|
46
|
+
const [dateString, setDateString] = useState('')
|
37
47
|
return (
|
48
|
+
<div>
|
49
|
+
<DateInput2
|
50
|
+
renderLabel="Choose a date"
|
51
|
+
screenReaderLabels={{
|
52
|
+
calendarIcon: 'Calendar',
|
53
|
+
nextMonthButton: 'Next month',
|
54
|
+
prevMonthButton: 'Previous month'
|
55
|
+
}}
|
56
|
+
value={inputValue}
|
57
|
+
width="20rem"
|
58
|
+
onChange={(e, inputValue, dateString) => {
|
59
|
+
setInputValue(inputValue)
|
60
|
+
setDateString(dateString)
|
61
|
+
}}
|
62
|
+
invalidDateErrorMessage="Invalid date"
|
63
|
+
/>
|
64
|
+
<p>
|
65
|
+
Input Value: <code>{inputValue}</code>
|
66
|
+
<br />
|
67
|
+
UTC Date String: <code>{dateString}</code>
|
68
|
+
</p>
|
69
|
+
</div>
|
70
|
+
)
|
71
|
+
}
|
72
|
+
|
73
|
+
render(<Example />)
|
74
|
+
```
|
75
|
+
|
76
|
+
### Parsing and formatting dates
|
77
|
+
|
78
|
+
When typing in a date manually (instead of using the included picker), the component tries to parse the date as you type it in. By default parsing is based on the user's locale which determines the order of day, month and year (e.g.: a user with US locale will have MONTH/DAY/YEAR order, and someone with GB locale will have DAY/MONTH/YEAR order).
|
79
|
+
|
80
|
+
Any of the following separators can be used when typing a date: `,`, `-`, `.`, `/` or a whitespace however on blur the date will be formatted according to the locale and separators will be changed and leading zeros also adjusted.
|
81
|
+
|
82
|
+
If you want different parsing and formatting then the current locale you can use the `dateFormat` prop which accepts either a string with a name of a different locale (so you can use US date format even if the user is France) or a parser and formatter functions.
|
83
|
+
|
84
|
+
The default parser also have a limitation of excluding years before `1000` and after `9999`. These values are invalid by default but not with custom parsers.
|
85
|
+
|
86
|
+
```js
|
87
|
+
---
|
88
|
+
type: example
|
89
|
+
---
|
90
|
+
const Example = () => {
|
91
|
+
const [value, setValue] = useState('')
|
92
|
+
const [value2, setValue2] = useState('')
|
93
|
+
|
94
|
+
return (
|
95
|
+
<div>
|
96
|
+
<p>US locale with german date format:</p>
|
38
97
|
<DateInput2
|
39
98
|
renderLabel="Choose a date"
|
40
99
|
screenReaderLabels={{
|
@@ -42,42 +101,87 @@ This component is an updated version of [`DateInput`](/#DateInput) that's easier
|
|
42
101
|
nextMonthButton: 'Next month',
|
43
102
|
prevMonthButton: 'Previous month'
|
44
103
|
}}
|
45
|
-
value={value}
|
46
104
|
width="20rem"
|
105
|
+
value={value}
|
106
|
+
locale="en-us"
|
107
|
+
dateFormat="de-de"
|
47
108
|
onChange={(e, value) => setValue(value)}
|
48
|
-
invalidDateErrorMessage="Invalid date"
|
49
109
|
/>
|
50
|
-
|
51
|
-
|
110
|
+
<p>US locale with ISO date format:</p>
|
111
|
+
<DateInput2
|
112
|
+
renderLabel="Choose a date"
|
113
|
+
screenReaderLabels={{
|
114
|
+
calendarIcon: 'Calendar',
|
115
|
+
nextMonthButton: 'Next month',
|
116
|
+
prevMonthButton: 'Previous month'
|
117
|
+
}}
|
118
|
+
width="20rem"
|
119
|
+
value={value2}
|
120
|
+
locale="en-us"
|
121
|
+
dateFormat={{
|
122
|
+
parser: (input) => {
|
123
|
+
// split input on '.', whitespace, '/', ',' or '-' using regex: /[.\s/.-]+/
|
124
|
+
// the '+' allows splitting on consecutive delimiters
|
125
|
+
const [year, month, day] = input.split(/[,.\s/.-]+/)
|
126
|
+
const newDate = new Date(year, month-1, day)
|
127
|
+
return isNaN(newDate) ? '' : newDate
|
128
|
+
},
|
129
|
+
formatter: (date) => {
|
130
|
+
// vanilla js formatter but you could use a date library instead
|
131
|
+
const year = date.getFullYear()
|
132
|
+
// month is zero indexed so add 1
|
133
|
+
const month = `${date.getMonth() + 1}`.padStart(2, '0')
|
134
|
+
const day = `${date.getDate()}`.padStart(2, '0')
|
135
|
+
return `${year}-${month}-${day}`
|
136
|
+
}
|
137
|
+
}}
|
138
|
+
onChange={(e, value) => setValue2(value)}
|
139
|
+
/>
|
140
|
+
</div>
|
141
|
+
)
|
142
|
+
}
|
52
143
|
|
53
|
-
|
54
|
-
|
144
|
+
render(<Example />)
|
145
|
+
```
|
146
|
+
|
147
|
+
### Timezones
|
148
|
+
|
149
|
+
In the examples above you can see that the `onChange` callback also return a UTC date string. This means it is timezone adjusted. If the timezone is not set via the `timezone` prop, it is calculated/assumed from the user's machine. So if a user chooses September 10th 2024 with the timezone 'Europe/Budapest', the `onChange` function will return `2024-09-09T22:00:00.000Z` because Budapest is two hours ahead of UTC (summertime).
|
55
150
|
|
56
151
|
### With year picker
|
57
152
|
|
58
153
|
- ```js
|
59
154
|
class Example extends React.Component {
|
60
|
-
state = {
|
155
|
+
state = { inputValue: '', dateString: '' }
|
61
156
|
|
62
157
|
render() {
|
63
158
|
return (
|
64
|
-
<
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
159
|
+
<div>
|
160
|
+
<DateInput2
|
161
|
+
renderLabel="Choose a date"
|
162
|
+
screenReaderLabels={{
|
163
|
+
calendarIcon: 'Calendar',
|
164
|
+
nextMonthButton: 'Next month',
|
165
|
+
prevMonthButton: 'Previous month'
|
166
|
+
}}
|
167
|
+
value={this.state.inputValue}
|
168
|
+
width="20rem"
|
169
|
+
onChange={(e, inputValue, dateString) => {
|
170
|
+
this.setState({ dateString, inputValue })
|
171
|
+
}}
|
172
|
+
invalidDateErrorMessage="Invalid date"
|
173
|
+
withYearPicker={{
|
174
|
+
screenReaderLabel: 'Year picker',
|
175
|
+
startYear: 1900,
|
176
|
+
endYear: 2024
|
177
|
+
}}
|
178
|
+
/>
|
179
|
+
<p>
|
180
|
+
Input Value: <code>{this.state.inputValue}</code>
|
181
|
+
<br />
|
182
|
+
UTC Date String: <code>{this.state.dateString}</code>
|
183
|
+
</p>
|
184
|
+
</div>
|
81
185
|
)
|
82
186
|
}
|
83
187
|
}
|
@@ -87,33 +191,47 @@ This component is an updated version of [`DateInput`](/#DateInput) that's easier
|
|
87
191
|
|
88
192
|
- ```js
|
89
193
|
const Example = () => {
|
90
|
-
const [
|
91
|
-
|
194
|
+
const [inputValue, setInputValue] = useState('')
|
195
|
+
const [dateString, setDateString] = useState('')
|
92
196
|
return (
|
93
|
-
<
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
197
|
+
<div>
|
198
|
+
<DateInput2
|
199
|
+
renderLabel="Choose a date"
|
200
|
+
screenReaderLabels={{
|
201
|
+
calendarIcon: 'Calendar',
|
202
|
+
nextMonthButton: 'Next month',
|
203
|
+
prevMonthButton: 'Previous month'
|
204
|
+
}}
|
205
|
+
value={inputValue}
|
206
|
+
width="20rem"
|
207
|
+
onChange={(e, inputValue, dateString) => {
|
208
|
+
setInputValue(inputValue)
|
209
|
+
setDateString(dateString)
|
210
|
+
}}
|
211
|
+
invalidDateErrorMessage="Invalid date"
|
212
|
+
withYearPicker={{
|
213
|
+
screenReaderLabel: 'Year picker',
|
214
|
+
startYear: 1900,
|
215
|
+
endYear: 2024
|
216
|
+
}}
|
217
|
+
/>
|
218
|
+
<p>
|
219
|
+
Input Value: <code>{inputValue}</code>
|
220
|
+
<br />
|
221
|
+
UTC Date String: <code>{dateString}</code>
|
222
|
+
</p>
|
223
|
+
</div>
|
110
224
|
)
|
111
225
|
}
|
112
226
|
|
113
227
|
render(<Example />)
|
114
228
|
```
|
115
229
|
|
116
|
-
###
|
230
|
+
### Date validation
|
231
|
+
|
232
|
+
By default `DateInput2` only does date validation if the `invalidDateErrorMessage` prop is provided. Validation is triggered on the blur event of the input field. Invalid dates are determined based on [parsing](/#DateInput2/#Parsing%20and%20formatting%20dates).
|
233
|
+
|
234
|
+
If you want to do a more complex validation than the above (e.g. only allow a subset of dates) you can use the `onBlur` and `messages` props.
|
117
235
|
|
118
236
|
```js
|
119
237
|
---
|
@@ -121,18 +239,22 @@ type: example
|
|
121
239
|
---
|
122
240
|
const Example = () => {
|
123
241
|
const [value, setValue] = useState('')
|
242
|
+
const [dateString, setDateString] = useState('')
|
124
243
|
const [messages, setMessages] = useState([])
|
125
244
|
|
126
|
-
const handleDateValidation = (
|
127
|
-
|
245
|
+
const handleDateValidation = (e, inputValue, utcIsoDate) => {
|
246
|
+
const date = new Date(utcIsoDate)
|
247
|
+
console.log(utcIsoDate)
|
248
|
+
// don't validate empty input
|
249
|
+
if (!utcIsoDate && inputValue.length > 0) {
|
128
250
|
setMessages([{
|
129
251
|
type: 'error',
|
130
252
|
text: 'This is not a valid date'
|
131
253
|
}])
|
132
|
-
} else if (
|
254
|
+
} else if (date < new Date('1990-01-01')) {
|
133
255
|
setMessages([{
|
134
256
|
type: 'error',
|
135
|
-
text: '
|
257
|
+
text: 'Select date after January 1, 1990'
|
136
258
|
}])
|
137
259
|
} else {
|
138
260
|
setMessages([])
|
@@ -141,7 +263,7 @@ const Example = () => {
|
|
141
263
|
|
142
264
|
return (
|
143
265
|
<DateInput2
|
144
|
-
renderLabel="Choose a date after January 1,
|
266
|
+
renderLabel="Choose a date after January 1, 1990"
|
145
267
|
screenReaderLabels={{
|
146
268
|
calendarIcon: 'Calendar',
|
147
269
|
nextMonthButton: 'Next month',
|