@instructure/ui-calendar 8.51.0 → 8.51.1-snapshot-5
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/Calendar/__new-tests__/Calendar.test.js +76 -0
- package/es/Calendar/index.js +191 -26
- package/es/Calendar/props.js +13 -7
- package/lib/Calendar/__new-tests__/Calendar.test.js +79 -0
- package/lib/Calendar/index.js +193 -26
- package/lib/Calendar/props.js +13 -7
- package/package.json +21 -17
- package/src/Calendar/README.md +51 -0
- package/src/Calendar/__new-tests__/Calendar.test.tsx +83 -0
- package/src/Calendar/index.tsx +241 -29
- package/src/Calendar/props.ts +98 -31
- package/tsconfig.build.json +54 -16
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Calendar/__new-tests__/Calendar.test.d.ts +2 -0
- package/types/Calendar/__new-tests__/Calendar.test.d.ts.map +1 -0
- package/types/Calendar/index.d.ts +56 -18
- package/types/Calendar/index.d.ts.map +1 -1
- package/types/Calendar/props.d.ts +65 -20
- package/types/Calendar/props.d.ts.map +1 -1
package/src/Calendar/index.tsx
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
|
-
import React, { Children, Component, ReactElement } from 'react'
|
|
26
|
+
import React, { Children, Component, ReactElement, MouseEvent } from 'react'
|
|
27
27
|
|
|
28
28
|
import { View } from '@instructure/ui-view'
|
|
29
29
|
import {
|
|
@@ -34,18 +34,29 @@ import {
|
|
|
34
34
|
import { createChainedFunction } from '@instructure/ui-utils'
|
|
35
35
|
import { logError as error } from '@instructure/console'
|
|
36
36
|
import { uid } from '@instructure/uid'
|
|
37
|
+
import { AccessibleContent } from '@instructure/ui-a11y-content'
|
|
37
38
|
|
|
38
39
|
import { testable } from '@instructure/ui-testable'
|
|
39
40
|
|
|
40
41
|
import { withStyle, jsx } from '@instructure/emotion'
|
|
41
42
|
|
|
43
|
+
import { Locale, DateTime, ApplyLocaleContext } from '@instructure/ui-i18n'
|
|
44
|
+
import type { Moment } from '@instructure/ui-i18n'
|
|
45
|
+
|
|
42
46
|
import generateStyle from './styles'
|
|
43
47
|
import generateComponentTheme from './theme'
|
|
44
48
|
|
|
45
49
|
import { Day } from './Day'
|
|
46
50
|
|
|
47
51
|
import { propTypes, allowedProps } from './props'
|
|
48
|
-
import type { CalendarProps } from './props'
|
|
52
|
+
import type { CalendarProps, CalendarState } from './props'
|
|
53
|
+
import { Renderable } from '@instructure/shared-types'
|
|
54
|
+
|
|
55
|
+
import { IconButton } from '@instructure/ui-buttons'
|
|
56
|
+
import {
|
|
57
|
+
IconArrowOpenStartSolid,
|
|
58
|
+
IconArrowOpenEndSolid
|
|
59
|
+
} from '@instructure/ui-icons'
|
|
49
60
|
|
|
50
61
|
/**
|
|
51
62
|
---
|
|
@@ -54,9 +65,11 @@ category: components
|
|
|
54
65
|
**/
|
|
55
66
|
@withStyle(generateStyle, generateComponentTheme)
|
|
56
67
|
@testable()
|
|
57
|
-
class Calendar extends Component<CalendarProps> {
|
|
68
|
+
class Calendar extends Component<CalendarProps, CalendarState> {
|
|
58
69
|
static readonly componentId = 'Calendar'
|
|
59
70
|
|
|
71
|
+
declare context: React.ContextType<typeof ApplyLocaleContext>
|
|
72
|
+
static contextType = ApplyLocaleContext
|
|
60
73
|
static Day = Day
|
|
61
74
|
static DAY_COUNT = 42 // 6 weeks visible
|
|
62
75
|
|
|
@@ -68,12 +81,20 @@ class Calendar extends Component<CalendarProps> {
|
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
ref: Element | null = null
|
|
71
|
-
private _weekdayHeaderIds =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
)
|
|
84
|
+
private _weekdayHeaderIds = (
|
|
85
|
+
this.props.renderWeekdayLabels || this.defaultWeekdays
|
|
86
|
+
).reduce((ids: Record<number, string>, _label, i) => {
|
|
87
|
+
return { ...ids, [i]: uid(`weekday-header-${i}`) }
|
|
88
|
+
}, {})
|
|
89
|
+
constructor(props: CalendarProps) {
|
|
90
|
+
super(props)
|
|
91
|
+
|
|
92
|
+
this.state = this.calculateState(
|
|
93
|
+
this.locale(),
|
|
94
|
+
this.timezone(),
|
|
95
|
+
props.currentDate
|
|
96
|
+
)
|
|
97
|
+
}
|
|
77
98
|
|
|
78
99
|
handleRef = (el: Element | null) => {
|
|
79
100
|
this.ref = el
|
|
@@ -83,26 +104,97 @@ class Calendar extends Component<CalendarProps> {
|
|
|
83
104
|
this.props.makeStyles?.()
|
|
84
105
|
}
|
|
85
106
|
|
|
86
|
-
componentDidUpdate() {
|
|
107
|
+
componentDidUpdate(prevProps: CalendarProps) {
|
|
87
108
|
this.props.makeStyles?.()
|
|
109
|
+
|
|
110
|
+
const isUpdated =
|
|
111
|
+
prevProps.locale !== this.props.locale ||
|
|
112
|
+
prevProps.timezone !== this.props.timezone
|
|
113
|
+
|
|
114
|
+
if (isUpdated) {
|
|
115
|
+
this.setState(() => {
|
|
116
|
+
return {
|
|
117
|
+
...this.calculateState(
|
|
118
|
+
this.locale(),
|
|
119
|
+
this.timezone(),
|
|
120
|
+
this.props.currentDate
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
}
|
|
88
125
|
}
|
|
89
126
|
|
|
127
|
+
calculateState = (
|
|
128
|
+
locale: string,
|
|
129
|
+
timezone: string,
|
|
130
|
+
currentDate?: string
|
|
131
|
+
) => ({
|
|
132
|
+
renderedDate: currentDate
|
|
133
|
+
? DateTime.parse(currentDate, locale, timezone)
|
|
134
|
+
: DateTime.now(locale, timezone),
|
|
135
|
+
today: currentDate
|
|
136
|
+
? DateTime.parse(currentDate, locale, timezone)
|
|
137
|
+
: DateTime.now(locale, timezone)
|
|
138
|
+
})
|
|
139
|
+
|
|
90
140
|
get role() {
|
|
91
141
|
return this.props.role === 'listbox' ? this.props.role : undefined
|
|
92
142
|
}
|
|
93
143
|
|
|
144
|
+
renderMonthNavigationButtons = () => {
|
|
145
|
+
const { renderNextMonthButton, renderPrevMonthButton } = this.props
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
prevButton: renderPrevMonthButton ? (
|
|
149
|
+
callRenderProp(renderPrevMonthButton)
|
|
150
|
+
) : (
|
|
151
|
+
<IconButton
|
|
152
|
+
size="small"
|
|
153
|
+
withBackground={false}
|
|
154
|
+
withBorder={false}
|
|
155
|
+
renderIcon={<IconArrowOpenStartSolid color="primary" />}
|
|
156
|
+
screenReaderLabel="Previous month"
|
|
157
|
+
/>
|
|
158
|
+
),
|
|
159
|
+
nextButton: renderNextMonthButton ? (
|
|
160
|
+
callRenderProp(renderNextMonthButton)
|
|
161
|
+
) : (
|
|
162
|
+
<IconButton
|
|
163
|
+
size="small"
|
|
164
|
+
withBackground={false}
|
|
165
|
+
withBorder={false}
|
|
166
|
+
renderIcon={<IconArrowOpenEndSolid color="primary" />}
|
|
167
|
+
screenReaderLabel="Next month"
|
|
168
|
+
/>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
handleMonthChange = (direction: 'prev' | 'next') => (e: React.MouseEvent) => {
|
|
174
|
+
const { onRequestRenderNextMonth, onRequestRenderPrevMonth } = this.props
|
|
175
|
+
const { renderedDate } = this.state
|
|
176
|
+
const newDate = renderedDate.clone()
|
|
177
|
+
if (direction === 'prev') {
|
|
178
|
+
if (onRequestRenderPrevMonth) {
|
|
179
|
+
onRequestRenderPrevMonth(e)
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
newDate.subtract({ months: 1 })
|
|
183
|
+
} else {
|
|
184
|
+
if (onRequestRenderNextMonth) {
|
|
185
|
+
onRequestRenderNextMonth(e)
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
newDate.add({ months: 1 })
|
|
189
|
+
}
|
|
190
|
+
this.setState({ renderedDate: newDate })
|
|
191
|
+
}
|
|
192
|
+
|
|
94
193
|
renderHeader() {
|
|
95
|
-
const {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
onRequestRenderNextMonth,
|
|
100
|
-
onRequestRenderPrevMonth,
|
|
101
|
-
styles
|
|
102
|
-
} = this.props
|
|
103
|
-
|
|
104
|
-
const nextButton: ReactElement = callRenderProp(renderNextMonthButton)
|
|
105
|
-
const prevButton: ReactElement = callRenderProp(renderPrevMonthButton)
|
|
194
|
+
const { renderNavigationLabel, styles } = this.props
|
|
195
|
+
const { renderedDate } = this.state
|
|
196
|
+
const { prevButton, nextButton } = this.renderMonthNavigationButtons()
|
|
197
|
+
|
|
106
198
|
const cloneButton = (
|
|
107
199
|
button: ReactElement,
|
|
108
200
|
onClick?: (e: React.MouseEvent) => void
|
|
@@ -121,9 +213,16 @@ class Calendar extends Component<CalendarProps> {
|
|
|
121
213
|
|
|
122
214
|
return (
|
|
123
215
|
<div css={style}>
|
|
124
|
-
{prevButton && cloneButton(prevButton,
|
|
125
|
-
{
|
|
126
|
-
|
|
216
|
+
{prevButton && cloneButton(prevButton, this.handleMonthChange('prev'))}
|
|
217
|
+
{renderNavigationLabel ? (
|
|
218
|
+
callRenderProp(renderNavigationLabel)
|
|
219
|
+
) : (
|
|
220
|
+
<span>
|
|
221
|
+
<div>{renderedDate.format('MMMM')}</div>
|
|
222
|
+
<div>{renderedDate.format('YYYY')}</div>
|
|
223
|
+
</span>
|
|
224
|
+
)}
|
|
225
|
+
{nextButton && cloneButton(nextButton, this.handleMonthChange('next'))}
|
|
127
226
|
</div>
|
|
128
227
|
)
|
|
129
228
|
}
|
|
@@ -138,9 +237,10 @@ class Calendar extends Component<CalendarProps> {
|
|
|
138
237
|
}
|
|
139
238
|
|
|
140
239
|
renderWeekdayHeaders() {
|
|
141
|
-
const {
|
|
240
|
+
const { styles } = this.props
|
|
241
|
+
const renderWeekdayLabels =
|
|
242
|
+
this.props.renderWeekdayLabels || this.defaultWeekdays
|
|
142
243
|
const { length } = renderWeekdayLabels
|
|
143
|
-
|
|
144
244
|
error(
|
|
145
245
|
length === 7,
|
|
146
246
|
`[Calendar] \`renderWeekdayLabels\` should be an array with 7 labels (one for each weekday). ${length} provided.`
|
|
@@ -163,9 +263,46 @@ class Calendar extends Component<CalendarProps> {
|
|
|
163
263
|
)
|
|
164
264
|
}
|
|
165
265
|
|
|
266
|
+
get defaultWeekdays() {
|
|
267
|
+
const shortDayNames = DateTime.getLocalDayNamesOfTheWeek(
|
|
268
|
+
this.locale(),
|
|
269
|
+
'short'
|
|
270
|
+
)
|
|
271
|
+
const longDayNames = DateTime.getLocalDayNamesOfTheWeek(
|
|
272
|
+
this.locale(),
|
|
273
|
+
'long'
|
|
274
|
+
)
|
|
275
|
+
return [
|
|
276
|
+
<AccessibleContent key={1} alt={longDayNames[0]}>
|
|
277
|
+
{shortDayNames[0]}
|
|
278
|
+
</AccessibleContent>,
|
|
279
|
+
<AccessibleContent key={2} alt={longDayNames[1]}>
|
|
280
|
+
{shortDayNames[1]}
|
|
281
|
+
</AccessibleContent>,
|
|
282
|
+
<AccessibleContent key={3} alt={longDayNames[2]}>
|
|
283
|
+
{shortDayNames[2]}
|
|
284
|
+
</AccessibleContent>,
|
|
285
|
+
<AccessibleContent key={4} alt={longDayNames[3]}>
|
|
286
|
+
{shortDayNames[3]}
|
|
287
|
+
</AccessibleContent>,
|
|
288
|
+
<AccessibleContent key={5} alt={longDayNames[4]}>
|
|
289
|
+
{shortDayNames[4]}
|
|
290
|
+
</AccessibleContent>,
|
|
291
|
+
<AccessibleContent key={6} alt={longDayNames[5]}>
|
|
292
|
+
{shortDayNames[5]}
|
|
293
|
+
</AccessibleContent>,
|
|
294
|
+
<AccessibleContent key={7} alt={longDayNames[6]}>
|
|
295
|
+
{shortDayNames[6]}
|
|
296
|
+
</AccessibleContent>
|
|
297
|
+
] as Renderable<never>[]
|
|
298
|
+
}
|
|
299
|
+
|
|
166
300
|
renderDays() {
|
|
167
|
-
const children =
|
|
168
|
-
const
|
|
301
|
+
const { children } = this.props
|
|
302
|
+
const childrenArr = Children.toArray(
|
|
303
|
+
children ? children : this.renderDefaultdays()
|
|
304
|
+
) as ReactElement[]
|
|
305
|
+
const { length } = childrenArr
|
|
169
306
|
const role = this.role === 'listbox' ? 'presentation' : undefined
|
|
170
307
|
|
|
171
308
|
error(
|
|
@@ -173,7 +310,7 @@ class Calendar extends Component<CalendarProps> {
|
|
|
173
310
|
`[Calendar] should have exactly ${Calendar.DAY_COUNT} children. ${length} provided.`
|
|
174
311
|
)
|
|
175
312
|
|
|
176
|
-
return
|
|
313
|
+
return childrenArr
|
|
177
314
|
.reduce((days: ReactElement[][], day, i) => {
|
|
178
315
|
const index = Math.floor(i / 7)
|
|
179
316
|
if (!days[index]) days.push([])
|
|
@@ -195,6 +332,81 @@ class Calendar extends Component<CalendarProps> {
|
|
|
195
332
|
))
|
|
196
333
|
}
|
|
197
334
|
|
|
335
|
+
locale(): string {
|
|
336
|
+
if (this.props.locale) {
|
|
337
|
+
return this.props.locale
|
|
338
|
+
} else if (this.context && this.context.locale) {
|
|
339
|
+
return this.context.locale
|
|
340
|
+
}
|
|
341
|
+
return Locale.browserLocale()
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
timezone() {
|
|
345
|
+
if (this.props.timezone) {
|
|
346
|
+
return this.props.timezone
|
|
347
|
+
} else if (this.context && this.context.timezone) {
|
|
348
|
+
return this.context.timezone
|
|
349
|
+
}
|
|
350
|
+
return DateTime.browserTimeZone()
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// date is returned es a ISO string, like 2021-09-14T22:00:00.000Z
|
|
354
|
+
handleDayClick = (event: MouseEvent<any>, { date }: { date: string }) => {
|
|
355
|
+
if (this.props.onDateSelected) {
|
|
356
|
+
const parsedDate = DateTime.parse(date, this.locale(), this.timezone())
|
|
357
|
+
this.props.onDateSelected(parsedDate.toISOString(), parsedDate, event)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
isDisabledDate(date: Moment) {
|
|
362
|
+
const disabledDates = this.props.disabledDates
|
|
363
|
+
if (!disabledDates) {
|
|
364
|
+
return false
|
|
365
|
+
}
|
|
366
|
+
if (Array.isArray(disabledDates)) {
|
|
367
|
+
for (const aDisabledDate of disabledDates) {
|
|
368
|
+
if (date.isSame(aDisabledDate, 'day')) {
|
|
369
|
+
return true
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return false
|
|
373
|
+
}
|
|
374
|
+
return disabledDates(date.toISOString())
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
renderDefaultdays() {
|
|
378
|
+
const { selectedDate } = this.props
|
|
379
|
+
const { renderedDate, today } = this.state
|
|
380
|
+
// Sets it to the first local day of the week counting back from the start of the month.
|
|
381
|
+
// Note that first day depends on the locale, e.g. it's Sunday in the US and
|
|
382
|
+
// Monday in most of the EU.
|
|
383
|
+
const currDate = DateTime.getFirstDayOfWeek(
|
|
384
|
+
renderedDate.clone().startOf('month')
|
|
385
|
+
)
|
|
386
|
+
const arr: Moment[] = []
|
|
387
|
+
for (let i = 0; i < Calendar.DAY_COUNT; i++) {
|
|
388
|
+
arr.push(currDate.clone())
|
|
389
|
+
currDate.add({ days: 1 })
|
|
390
|
+
}
|
|
391
|
+
return arr.map((date) => {
|
|
392
|
+
const dateStr = date.toISOString()
|
|
393
|
+
return (
|
|
394
|
+
<Calendar.Day
|
|
395
|
+
key={dateStr}
|
|
396
|
+
date={dateStr}
|
|
397
|
+
isSelected={selectedDate ? date.isSame(selectedDate, 'day') : false}
|
|
398
|
+
isToday={date.isSame(today, 'day')}
|
|
399
|
+
isOutsideMonth={!date.isSame(renderedDate, 'month')}
|
|
400
|
+
label={date.format('D MMMM YYYY')} // used by screen readers
|
|
401
|
+
onClick={this.handleDayClick}
|
|
402
|
+
interaction={this.isDisabledDate(date) ? 'disabled' : 'enabled'}
|
|
403
|
+
>
|
|
404
|
+
{date.format('DD')}
|
|
405
|
+
</Calendar.Day>
|
|
406
|
+
)
|
|
407
|
+
})
|
|
408
|
+
}
|
|
409
|
+
|
|
198
410
|
render() {
|
|
199
411
|
const passthroughProps = View.omitViewProps(
|
|
200
412
|
omitProps(this.props, Calendar.allowedProps),
|
package/src/Calendar/props.ts
CHANGED
|
@@ -37,13 +37,65 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
|
37
37
|
import React, { ReactElement } from 'react'
|
|
38
38
|
import type { CalendarDayProps } from './Day/props'
|
|
39
39
|
import { Renderable } from '@instructure/shared-types'
|
|
40
|
+
import type { Moment } from '@instructure/ui-i18n'
|
|
40
41
|
|
|
41
42
|
type CalendarOwnProps = {
|
|
43
|
+
/**
|
|
44
|
+
* The element to render as the `Calendar` root, `span` by default
|
|
45
|
+
*/
|
|
46
|
+
as?: AsElementType
|
|
42
47
|
/**
|
|
43
48
|
* children of type `<Calendar.Day />` There should be exactly 42 provided (6
|
|
44
49
|
* weeks).
|
|
45
50
|
*/
|
|
46
51
|
children?: ReactElement<CalendarDayProps>[]
|
|
52
|
+
/**
|
|
53
|
+
* ISO date string for the current date if necessary. Defaults to the current
|
|
54
|
+
* date in the user's timezone.
|
|
55
|
+
*/
|
|
56
|
+
currentDate?: string
|
|
57
|
+
/*
|
|
58
|
+
* Specify which date(s) will be shown as disabled in the calendar.
|
|
59
|
+
* You can either supply an array of ISO8601 timeDate strings or
|
|
60
|
+
* a function that will be called for each date shown in the calendar.
|
|
61
|
+
*/
|
|
62
|
+
disabledDates?: string[] | ((isoDateToCheck: string) => boolean)
|
|
63
|
+
/**
|
|
64
|
+
* A standard language identifier.
|
|
65
|
+
*
|
|
66
|
+
* See [Moment.js](https://momentjs.com/timezone/docs/#/using-timezones/parsing-in-zone/) for
|
|
67
|
+
* more details.
|
|
68
|
+
*
|
|
69
|
+
* This property can also be set via a context property and if both are set
|
|
70
|
+
* then the component property takes precedence over the context property.
|
|
71
|
+
*
|
|
72
|
+
* The web browser's locale will be used if no value is set via a component
|
|
73
|
+
* property or a context property.
|
|
74
|
+
**/
|
|
75
|
+
locale?: string
|
|
76
|
+
/**
|
|
77
|
+
* Callback fired when a day has been selected.
|
|
78
|
+
*/
|
|
79
|
+
onDateSelected?: (
|
|
80
|
+
dateString: string,
|
|
81
|
+
momentDate: Moment,
|
|
82
|
+
e: React.MouseEvent
|
|
83
|
+
) => void
|
|
84
|
+
/**
|
|
85
|
+
* Callback fired when the next month button is clicked in the navigation
|
|
86
|
+
* header, requesting to render the next month.
|
|
87
|
+
*/
|
|
88
|
+
onRequestRenderNextMonth?: (e: React.MouseEvent) => void
|
|
89
|
+
/**
|
|
90
|
+
* Callback fired when the previous month button is clicked in the navigation
|
|
91
|
+
* header, requesting to render the previous month.
|
|
92
|
+
*/
|
|
93
|
+
onRequestRenderPrevMonth?: (e: React.MouseEvent) => void
|
|
94
|
+
/**
|
|
95
|
+
* Content to render in the navigation header. The recommendation is to include
|
|
96
|
+
* the name of the current rendered month along with the year.
|
|
97
|
+
*/
|
|
98
|
+
renderNavigationLabel?: Renderable
|
|
47
99
|
/**
|
|
48
100
|
* A button to render in the navigation header. The recommendation is to
|
|
49
101
|
* compose it with the [IconButton](#IconButton) component by setting the `size`
|
|
@@ -58,11 +110,6 @@ type CalendarOwnProps = {
|
|
|
58
110
|
* `renderIcon` to [IconArrowOpenStart](#iconography).
|
|
59
111
|
*/
|
|
60
112
|
renderPrevMonthButton?: Renderable
|
|
61
|
-
/**
|
|
62
|
-
* Content to render in the navigation header. The recommendation is to include
|
|
63
|
-
* the name of the current rendered month along with the year.
|
|
64
|
-
*/
|
|
65
|
-
renderNavigationLabel?: Renderable
|
|
66
113
|
/**
|
|
67
114
|
* An array of labels containing the name of each day of the week. The visible
|
|
68
115
|
* portion of the label should be abbreviated (no longer than three characters).
|
|
@@ -72,26 +119,29 @@ type CalendarOwnProps = {
|
|
|
72
119
|
* full day name for assistive technologies and the children containing the
|
|
73
120
|
* abbreviation. ex. `[<AccessibleContent alt="Sunday">Sun</AccessibleContent>, ...]`
|
|
74
121
|
*/
|
|
75
|
-
renderWeekdayLabels
|
|
76
|
-
/**
|
|
77
|
-
* Callback fired when the next month button is clicked in the navigation
|
|
78
|
-
* header, requesting to render the next month.
|
|
79
|
-
*/
|
|
80
|
-
onRequestRenderNextMonth?: (e: React.MouseEvent) => void
|
|
122
|
+
renderWeekdayLabels?: Renderable[]
|
|
81
123
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
124
|
+
* The role of the underlying table. This can be set to 'listbox' when
|
|
125
|
+
* assistive technologies need to read the `<Calendar.Day />` children as a list.
|
|
84
126
|
*/
|
|
85
|
-
|
|
127
|
+
role?: 'table' | 'listbox'
|
|
86
128
|
/**
|
|
87
|
-
*
|
|
129
|
+
* ISO date string for the selected date. It needs onDateSelected to be specified too.
|
|
88
130
|
*/
|
|
89
|
-
|
|
131
|
+
selectedDate?: string
|
|
90
132
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
133
|
+
* A timezone identifier in the format: *Area/Location*
|
|
134
|
+
*
|
|
135
|
+
* See [List of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for the list
|
|
136
|
+
* of possible options.
|
|
137
|
+
*
|
|
138
|
+
* This property can also be set via a context property and if both are set
|
|
139
|
+
* then the component property takes precedence over the context property.
|
|
140
|
+
*
|
|
141
|
+
* The web browser's timezone will be used if no value is set via a component
|
|
142
|
+
* property or a context property.
|
|
93
143
|
*/
|
|
94
|
-
|
|
144
|
+
timezone?: string
|
|
95
145
|
}
|
|
96
146
|
|
|
97
147
|
type PropKeys = keyof CalendarOwnProps
|
|
@@ -107,30 +157,47 @@ type CalendarStyle = ComponentStyle<
|
|
|
107
157
|
>
|
|
108
158
|
|
|
109
159
|
const propTypes: PropValidators<PropKeys> = {
|
|
160
|
+
as: PropTypes.elementType,
|
|
110
161
|
children: ChildrenPropTypes.oneOf([Day]),
|
|
162
|
+
currentDate: PropTypes.string,
|
|
163
|
+
disabledDates: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
|
|
164
|
+
locale: PropTypes.string,
|
|
165
|
+
onDateSelected: PropTypes.func,
|
|
166
|
+
onRequestRenderNextMonth: PropTypes.func,
|
|
167
|
+
onRequestRenderPrevMonth: PropTypes.func,
|
|
168
|
+
renderNavigationLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
111
169
|
renderNextMonthButton: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
112
170
|
renderPrevMonthButton: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
113
|
-
renderNavigationLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
114
171
|
renderWeekdayLabels: PropTypes.arrayOf(
|
|
115
172
|
PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
role: PropTypes.oneOf(['table', 'listbox'])
|
|
173
|
+
),
|
|
174
|
+
role: PropTypes.oneOf(['table', 'listbox']),
|
|
175
|
+
selectedDate: PropTypes.string,
|
|
176
|
+
timezone: PropTypes.string
|
|
121
177
|
}
|
|
122
178
|
|
|
123
179
|
const allowedProps: AllowedPropKeys = [
|
|
180
|
+
'as',
|
|
124
181
|
'children',
|
|
182
|
+
'currentDate',
|
|
183
|
+
'disabledDates',
|
|
184
|
+
'locale',
|
|
185
|
+
'onDateSelected',
|
|
186
|
+
'onRequestRenderNextMonth',
|
|
187
|
+
'onRequestRenderPrevMonth',
|
|
188
|
+
'renderNavigationLabel',
|
|
125
189
|
'renderNextMonthButton',
|
|
126
190
|
'renderPrevMonthButton',
|
|
127
|
-
'renderNavigationLabel',
|
|
128
191
|
'renderWeekdayLabels',
|
|
129
|
-
'
|
|
130
|
-
'
|
|
131
|
-
'
|
|
132
|
-
'role'
|
|
192
|
+
'role',
|
|
193
|
+
'selectedDate',
|
|
194
|
+
'timezone'
|
|
133
195
|
]
|
|
134
196
|
|
|
135
|
-
|
|
197
|
+
type CalendarState = {
|
|
198
|
+
renderedDate: Moment
|
|
199
|
+
today: Moment
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type { CalendarProps, CalendarStyle, CalendarState }
|
|
136
203
|
export { propTypes, allowedProps }
|
package/tsconfig.build.json
CHANGED
|
@@ -7,21 +7,59 @@
|
|
|
7
7
|
},
|
|
8
8
|
"include": ["src"],
|
|
9
9
|
"references": [
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{
|
|
10
|
+
{
|
|
11
|
+
"path": "../ui-babel-preset/tsconfig.build.json"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"path": "../ui-color-utils/tsconfig.build.json"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../ui-test-locator/tsconfig.build.json"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../ui-test-utils/tsconfig.build.json"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "../ui-themes/tsconfig.build.json"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../console/tsconfig.build.json"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "../emotion/tsconfig.build.json"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"path": "../shared-types/tsconfig.build.json"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"path": "../ui-a11y-content/tsconfig.build.json"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"path": "../ui-i18n/tsconfig.build.json"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"path": "../ui-prop-types/tsconfig.build.json"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"path": "../ui-react-utils/tsconfig.build.json"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"path": "../ui-testable/tsconfig.build.json"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"path": "../ui-utils/tsconfig.build.json"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"path": "../ui-view/tsconfig.build.json"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"path": "../uid/tsconfig.build.json"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"path": "../ui-buttons/tsconfig.build.json"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"path": "../ui-icons/tsconfig.build.json"
|
|
63
|
+
}
|
|
26
64
|
]
|
|
27
65
|
}
|