@instructure/ui-date-time-input 8.23.1-snapshot.9 → 8.24.1-snapshot.17
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 +11 -0
- package/es/DateTimeInput/index.js +53 -12
- package/es/DateTimeInput/props.js +6 -2
- package/lib/DateTimeInput/index.js +53 -12
- package/lib/DateTimeInput/props.js +6 -2
- package/package.json +19 -19
- package/src/DateTimeInput/README.md +80 -15
- package/src/DateTimeInput/index.tsx +48 -15
- package/src/DateTimeInput/props.ts +36 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateTimeInput/index.d.ts +3 -3
- package/types/DateTimeInput/index.d.ts.map +1 -1
- package/types/DateTimeInput/props.d.ts +15 -1
- package/types/DateTimeInput/props.d.ts.map +1 -1
|
@@ -56,6 +56,8 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
56
56
|
static allowedProps = allowedProps
|
|
57
57
|
static defaultProps = {
|
|
58
58
|
layout: 'inline',
|
|
59
|
+
colSpacing: 'medium',
|
|
60
|
+
rowSpacing: 'small',
|
|
59
61
|
timeStep: 30,
|
|
60
62
|
messageFormat: DateTimeInput.DEFAULT_MESSAGE_FORMAT,
|
|
61
63
|
isRequired: false,
|
|
@@ -66,7 +68,6 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
66
68
|
|
|
67
69
|
static contextType = ApplyLocaleContext
|
|
68
70
|
|
|
69
|
-
private _timeInput?: TimeSelect
|
|
70
71
|
ref: Element | null = null // This is used by Tooltip for positioning
|
|
71
72
|
|
|
72
73
|
handleRef = (el: Element | null) => {
|
|
@@ -134,13 +135,29 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
134
135
|
.month(this.state.iso.month())
|
|
135
136
|
.year(this.state.iso.year())
|
|
136
137
|
}
|
|
137
|
-
const newTimeSelectValue =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.
|
|
142
|
-
.
|
|
143
|
-
|
|
138
|
+
const newTimeSelectValue = parsed.toISOString()
|
|
139
|
+
if (this.isDisabledDate(parsed)) {
|
|
140
|
+
let text =
|
|
141
|
+
typeof this.props.disabledDateTimeMessage === 'function'
|
|
142
|
+
? this.props.disabledDateTimeMessage(parsed.toISOString(true))
|
|
143
|
+
: this.props.disabledDateTimeMessage
|
|
144
|
+
if (!text) {
|
|
145
|
+
text =
|
|
146
|
+
typeof this.props.invalidDateTimeMessage === 'function'
|
|
147
|
+
? this.props.invalidDateTimeMessage(parsed.toISOString(true))
|
|
148
|
+
: this.props.invalidDateTimeMessage
|
|
149
|
+
}
|
|
150
|
+
errorMsg = text ? { text, type: 'error' } : undefined
|
|
151
|
+
return {
|
|
152
|
+
iso: parsed.clone(),
|
|
153
|
+
calendarSelectedDate: parsed.clone(),
|
|
154
|
+
dateInputTextChanged: false,
|
|
155
|
+
dateInputText: parsed.format(this.dateFormat),
|
|
156
|
+
message: errorMsg,
|
|
157
|
+
timeSelectValue: newTimeSelectValue,
|
|
158
|
+
renderedDate: parsed.clone()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
144
161
|
return {
|
|
145
162
|
iso: parsed.clone(),
|
|
146
163
|
calendarSelectedDate: parsed.clone(),
|
|
@@ -194,6 +211,22 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
194
211
|
return this.props.dateFormat
|
|
195
212
|
}
|
|
196
213
|
|
|
214
|
+
isDisabledDate(date: Moment) {
|
|
215
|
+
const disabledDates = this.props.disabledDates
|
|
216
|
+
if (!disabledDates) {
|
|
217
|
+
return false
|
|
218
|
+
}
|
|
219
|
+
if (Array.isArray(disabledDates)) {
|
|
220
|
+
for (const aDisabledDate of disabledDates) {
|
|
221
|
+
if (date.isSame(aDisabledDate, 'day')) {
|
|
222
|
+
return true
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return false
|
|
226
|
+
}
|
|
227
|
+
return disabledDates(date.toISOString())
|
|
228
|
+
}
|
|
229
|
+
|
|
197
230
|
// Called when the user enters text into dateInput
|
|
198
231
|
handleDateTextChange = (_event: SyntheticEvent, date: { value: string }) => {
|
|
199
232
|
const dateParsed = this.tryParseDate(date.value)
|
|
@@ -319,10 +352,6 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
319
352
|
}
|
|
320
353
|
}
|
|
321
354
|
|
|
322
|
-
timeInputComponentRef = (node: TimeSelect) => {
|
|
323
|
-
this._timeInput = node
|
|
324
|
-
}
|
|
325
|
-
|
|
326
355
|
handleShowCalendar = (_event: SyntheticEvent) => {
|
|
327
356
|
this.setState({ isShowingCalendar: true })
|
|
328
357
|
}
|
|
@@ -406,6 +435,7 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
406
435
|
isOutsideMonth={!date.isSame(renderedDate, 'month')}
|
|
407
436
|
label={date.format('D MMMM YYYY')} // used by screen readers
|
|
408
437
|
onClick={this.handleDayClick}
|
|
438
|
+
interaction={this.isDisabledDate(date) ? 'disabled' : 'enabled'}
|
|
409
439
|
>
|
|
410
440
|
{date.format('DD')}
|
|
411
441
|
</DateInput.Day>
|
|
@@ -491,16 +521,19 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
491
521
|
timezone,
|
|
492
522
|
messages,
|
|
493
523
|
layout,
|
|
524
|
+
rowSpacing,
|
|
525
|
+
colSpacing,
|
|
494
526
|
isRequired,
|
|
495
527
|
interaction,
|
|
496
528
|
renderWeekdayLabels
|
|
497
529
|
} = this.props
|
|
530
|
+
|
|
498
531
|
return (
|
|
499
532
|
<FormFieldGroup
|
|
500
533
|
description={description}
|
|
501
|
-
colSpacing="medium"
|
|
502
|
-
rowSpacing="small"
|
|
503
534
|
layout={layout}
|
|
535
|
+
rowSpacing={rowSpacing}
|
|
536
|
+
colSpacing={colSpacing}
|
|
504
537
|
vAlign="top"
|
|
505
538
|
elementRef={this.handleRef}
|
|
506
539
|
messages={[
|
|
@@ -509,6 +542,7 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
509
542
|
]}
|
|
510
543
|
>
|
|
511
544
|
<DateInput
|
|
545
|
+
display="block"
|
|
512
546
|
value={this.state.dateInputText}
|
|
513
547
|
onChange={this.handleDateTextChange}
|
|
514
548
|
onBlur={this.handleBlur}
|
|
@@ -544,7 +578,6 @@ class DateTimeInput extends Component<DateTimeInputProps, DateTimeInputState> {
|
|
|
544
578
|
value={this.state.timeSelectValue}
|
|
545
579
|
onChange={this.handleTimeChange}
|
|
546
580
|
onBlur={this.handleBlur}
|
|
547
|
-
ref={this.timeInputComponentRef}
|
|
548
581
|
renderLabel={timeRenderLabel}
|
|
549
582
|
locale={locale}
|
|
550
583
|
format={timeFormat}
|
|
@@ -152,6 +152,14 @@ type DateTimeInputProps = {
|
|
|
152
152
|
* See [FormFieldGroup](#FormFieldGroup) for details.
|
|
153
153
|
**/
|
|
154
154
|
layout?: 'stacked' | 'columns' | 'inline'
|
|
155
|
+
/**
|
|
156
|
+
* Controls the spacing between the inputs when they are in a vertical layout.
|
|
157
|
+
**/
|
|
158
|
+
rowSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
159
|
+
/**
|
|
160
|
+
* Controls the spacing between the inputs when they are in a horizontal layout.
|
|
161
|
+
**/
|
|
162
|
+
colSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
155
163
|
/**
|
|
156
164
|
* An ISO 8601 formatted date string representing the current date-time
|
|
157
165
|
* (must be accompanied by an onChange prop).
|
|
@@ -197,7 +205,7 @@ type DateTimeInputProps = {
|
|
|
197
205
|
* Called when the date-time value has changed.
|
|
198
206
|
* The passed in parameters are:
|
|
199
207
|
* - *event*: The triggering event (which may be from the underlying
|
|
200
|
-
*
|
|
208
|
+
* `DateInput` or `TimeSelect`)
|
|
201
209
|
* - *isoValue*: The new date value in ISO8601 format, undefined if its invalid
|
|
202
210
|
**/
|
|
203
211
|
onChange?: (event: SyntheticEvent, isoValue?: string) => void
|
|
@@ -215,6 +223,17 @@ type DateTimeInputProps = {
|
|
|
215
223
|
* component
|
|
216
224
|
*/
|
|
217
225
|
onBlur?: (e: SyntheticEvent) => void
|
|
226
|
+
/*
|
|
227
|
+
* Specify which date(s) will be shown as disabled in the calendar.
|
|
228
|
+
* You can either supply an array of ISO8601 timeDate strings or
|
|
229
|
+
* a function that will be called for each date shown in the calendar.
|
|
230
|
+
*/
|
|
231
|
+
disabledDates?: string[] | ((isoDateToCheck: string) => boolean)
|
|
232
|
+
/**
|
|
233
|
+
* Error message shown to the user if they enter a date that is disabled.
|
|
234
|
+
* If not specified the component will show the `invalidDateTimeMessage`.
|
|
235
|
+
*/
|
|
236
|
+
disabledDateTimeMessage?: string | ((rawDateValue: string) => string)
|
|
218
237
|
}
|
|
219
238
|
|
|
220
239
|
type DateTimeInputState = {
|
|
@@ -264,6 +283,8 @@ const propTypes: PropValidators<PropKeys> = {
|
|
|
264
283
|
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
265
284
|
messageFormat: PropTypes.string,
|
|
266
285
|
layout: PropTypes.oneOf(['stacked', 'columns', 'inline']),
|
|
286
|
+
rowSpacing: PropTypes.oneOf(['none', 'small', 'medium', 'large']),
|
|
287
|
+
colSpacing: PropTypes.oneOf(['none', 'small', 'medium', 'large']),
|
|
267
288
|
value: controllable(I18nPropTypes.iso8601, 'onChange'),
|
|
268
289
|
defaultValue: I18nPropTypes.iso8601,
|
|
269
290
|
renderWeekdayLabels: PropTypes.arrayOf(
|
|
@@ -273,7 +294,15 @@ const propTypes: PropValidators<PropKeys> = {
|
|
|
273
294
|
onChange: PropTypes.func,
|
|
274
295
|
dateInputRef: PropTypes.func,
|
|
275
296
|
timeInputRef: PropTypes.func,
|
|
276
|
-
onBlur: PropTypes.func
|
|
297
|
+
onBlur: PropTypes.func,
|
|
298
|
+
disabledDates: PropTypes.oneOfType([
|
|
299
|
+
PropTypes.func,
|
|
300
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
301
|
+
]),
|
|
302
|
+
disabledDateTimeMessage: PropTypes.oneOfType([
|
|
303
|
+
PropTypes.string,
|
|
304
|
+
PropTypes.func
|
|
305
|
+
])
|
|
277
306
|
}
|
|
278
307
|
|
|
279
308
|
const allowedProps: AllowedPropKeys = [
|
|
@@ -293,6 +322,8 @@ const allowedProps: AllowedPropKeys = [
|
|
|
293
322
|
'messages',
|
|
294
323
|
'messageFormat',
|
|
295
324
|
'layout',
|
|
325
|
+
'rowSpacing',
|
|
326
|
+
'colSpacing',
|
|
296
327
|
'value',
|
|
297
328
|
'defaultValue',
|
|
298
329
|
'renderWeekdayLabels',
|
|
@@ -300,7 +331,9 @@ const allowedProps: AllowedPropKeys = [
|
|
|
300
331
|
'onChange',
|
|
301
332
|
'dateInputRef',
|
|
302
333
|
'timeInputRef',
|
|
303
|
-
'onBlur'
|
|
334
|
+
'onBlur',
|
|
335
|
+
'disabledDates',
|
|
336
|
+
'disabledDateTimeMessage'
|
|
304
337
|
]
|
|
305
338
|
|
|
306
339
|
export type { DateTimeInputProps, DateTimeInputState }
|