@coreui/react-pro 4.8.0 → 4.9.0-next.1
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/README.md +1 -1
- package/dist/components/alert/CAlert.d.ts +1 -1
- package/dist/components/avatar/CAvatar.d.ts +1 -1
- package/dist/components/badge/CBadge.d.ts +1 -1
- package/dist/components/button/CButton.d.ts +1 -1
- package/dist/components/calendar/index.d.ts +2 -0
- package/dist/components/calendar/utils.d.ts +22 -0
- package/dist/components/callout/CCallout.d.ts +1 -1
- package/dist/components/card/CCard.d.ts +1 -1
- package/dist/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +3 -3
- package/dist/components/date-range-picker/utils.d.ts +1 -0
- package/dist/components/dropdown/CDropdown.d.ts +1 -1
- package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
- package/dist/components/element-cover/CElementCover.d.ts +0 -4
- package/dist/components/element-cover/index.d.ts +2 -0
- package/dist/components/form/CFormCheck.d.ts +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/list-group/CListGroupItem.d.ts +4 -5
- package/dist/components/multi-select/CMultiSelect.d.ts +1 -13
- package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
- package/dist/components/multi-select/types.d.ts +14 -0
- package/dist/components/multi-select/utils.d.ts +6 -0
- package/dist/components/navbar/CNavbar.d.ts +1 -1
- package/dist/components/offcanvas/COffcanvas.d.ts +7 -1
- package/dist/components/picker/CPicker.d.ts +1 -1
- package/dist/components/placeholder/CPlaceholder.d.ts +1 -1
- package/dist/components/popover/CPopover.d.ts +1 -1
- package/dist/components/progress/CProgressBar.d.ts +1 -1
- package/dist/components/smart-table/CSmartTableBody.d.ts +6 -5
- package/dist/components/smart-table/CSmartTableHead.d.ts +6 -3
- package/dist/components/smart-table/CSmartTableInterface.d.ts +38 -59
- package/dist/components/smart-table/types.d.ts +53 -0
- package/dist/components/smart-table/utils.d.ts +16 -0
- package/dist/components/spinner/CSpinner.d.ts +1 -1
- package/dist/components/table/CTable.d.ts +2 -18
- package/dist/components/table/CTableBody.d.ts +1 -1
- package/dist/components/table/CTableDataCell.d.ts +1 -1
- package/dist/components/table/CTableFoot.d.ts +1 -1
- package/dist/components/table/CTableHead.d.ts +1 -1
- package/dist/components/table/CTableHeaderCell.d.ts +1 -1
- package/dist/components/table/CTableRow.d.ts +1 -1
- package/dist/components/table/types.d.ts +17 -0
- package/dist/components/table/utils.d.ts +5 -0
- package/dist/components/time-picker/types.d.ts +15 -0
- package/dist/components/time-picker/utils.d.ts +23 -0
- package/dist/components/toast/CToast.d.ts +1 -1
- package/dist/components/toast/CToastClose.d.ts +1 -1
- package/dist/components/tooltip/CTooltip.d.ts +1 -1
- package/dist/components/virtual-scroller/CVirtualScroller.d.ts +0 -8
- package/dist/components/widgets/CWidgetStatsA.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsB.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsC.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsF.d.ts +1 -1
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useForkedRef.d.ts +7 -0
- package/dist/hooks/useStateWithCallback.d.ts +2 -0
- package/dist/index.es.js +1171 -1109
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1171 -1108
- package/dist/index.js.map +1 -1
- package/dist/props.d.ts +8 -0
- package/dist/types.d.ts +7 -0
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/isObjectInArray.d.ts +2 -0
- package/package.json +11 -11
- package/src/components/accordion/CAccordionBody.tsx +1 -0
- package/src/components/accordion/CAccordionCollapse.tsx +1 -0
- package/src/components/alert/CAlert.tsx +3 -2
- package/src/components/avatar/CAvatar.tsx +2 -8
- package/src/components/backdrop/CBackdrop.tsx +2 -2
- package/src/components/badge/CBadge.tsx +2 -10
- package/src/components/button/CButton.tsx +3 -1
- package/src/components/calendar/CCalendar.tsx +351 -240
- package/src/components/calendar/index.ts +3 -0
- package/src/{utils/calendar.ts → components/calendar/utils.ts} +1 -47
- package/src/components/callout/CCallout.tsx +2 -1
- package/src/components/card/CCard.tsx +2 -1
- package/src/components/carousel/CCarousel.tsx +1 -1
- package/src/components/carousel/CCarouselItem.tsx +1 -1
- package/src/components/collapse/CCollapse.tsx +1 -1
- package/src/components/date-picker/CDatePicker.tsx +1 -1
- package/src/components/date-range-picker/CDateRangePicker.tsx +4 -4
- package/src/components/date-range-picker/utils.ts +49 -0
- package/src/components/dropdown/CDropdown.tsx +3 -2
- package/src/components/dropdown/CDropdownItem.tsx +1 -2
- package/src/components/dropdown/CDropdownMenu.tsx +2 -1
- package/src/components/dropdown/CDropdownToggle.tsx +5 -4
- package/src/components/element-cover/CElementCover.tsx +16 -22
- package/src/components/element-cover/index.ts +3 -0
- package/src/components/form/CFormCheck.tsx +3 -3
- package/src/components/form/CFormControlValidation.tsx +0 -1
- package/src/components/form/CFormControlWrapper.tsx +0 -1
- package/src/components/form/CFormInput.tsx +8 -4
- package/src/components/form/CFormRange.tsx +1 -2
- package/src/components/form/CFormSelect.tsx +1 -2
- package/src/components/form/CFormTextarea.tsx +1 -2
- package/src/components/index.ts +1 -0
- package/src/components/list-group/CListGroupItem.tsx +8 -8
- package/src/components/list-group/CListGroupItem.tsx~HEAD +3 -1
- package/src/components/modal/CModal.tsx +2 -2
- package/src/components/modal/CModalHeader.tsx +3 -2
- package/src/components/multi-select/CMultiSelect.tsx +15 -74
- package/src/components/multi-select/CMultiSelectNativeSelect.tsx +1 -1
- package/src/components/multi-select/CMultiSelectOptions.tsx +2 -2
- package/src/components/multi-select/CMultiSelectSelection.tsx +1 -1
- package/src/components/multi-select/types.ts +15 -0
- package/src/components/multi-select/utils.ts +92 -0
- package/src/components/nav/CNavItem.tsx +1 -0
- package/src/components/nav/CNavLink.tsx +4 -3
- package/src/components/navbar/CNavbar.tsx +2 -1
- package/src/components/offcanvas/COffcanvas.tsx +38 -19
- package/src/components/picker/CPicker.tsx +1 -1
- package/src/components/placeholder/CPlaceholder.tsx +2 -1
- package/src/components/popover/CPopover.tsx +2 -1
- package/src/components/progress/CProgress.tsx +1 -0
- package/src/components/progress/CProgressBar.tsx +2 -1
- package/src/components/sidebar/CSidebar.tsx +3 -2
- package/src/components/smart-table/CSmartTable.tsx +263 -257
- package/src/components/smart-table/CSmartTableBody.tsx +98 -107
- package/src/components/smart-table/CSmartTableCleaner.tsx +1 -1
- package/src/components/smart-table/CSmartTableFilter.tsx +1 -3
- package/src/components/smart-table/CSmartTableHead.tsx +56 -103
- package/src/components/smart-table/CSmartTableInterface.tsx +49 -71
- package/src/components/smart-table/CSmartTableItemsPerPageSelector.tsx +1 -2
- package/src/components/smart-table/types.ts +65 -0
- package/src/components/smart-table/utils.ts +199 -0
- package/src/components/spinner/CSpinner.tsx +2 -1
- package/src/components/table/CTable.tsx +25 -59
- package/src/components/table/CTableBody.tsx +2 -1
- package/src/components/table/CTableDataCell.tsx +2 -1
- package/src/components/table/CTableFoot.tsx +2 -1
- package/src/components/table/CTableHead.tsx +2 -1
- package/src/components/table/CTableHeaderCell.tsx +2 -1
- package/src/components/table/CTableRow.tsx +2 -1
- package/src/components/table/types.ts +20 -0
- package/src/components/table/utils.ts +29 -0
- package/src/components/tabs/CTabPane.tsx +2 -1
- package/src/components/time-picker/CTimePicker.tsx +48 -23
- package/src/components/time-picker/CTimePickerRollCol.tsx +1 -1
- package/src/components/time-picker/types.ts +15 -0
- package/src/{utils/time.ts → components/time-picker/utils.ts} +43 -2
- package/src/components/toast/CToast.tsx +4 -4
- package/src/components/toast/CToastClose.tsx +2 -2
- package/src/components/toast/CToaster.tsx +2 -1
- package/src/components/tooltip/CTooltip.tsx +3 -2
- package/src/components/virtual-scroller/CVirtualScroller.tsx +32 -55
- package/src/components/widgets/CWidgetStatsA.tsx +3 -3
- package/src/components/widgets/CWidgetStatsB.tsx +4 -4
- package/src/components/widgets/CWidgetStatsC.tsx +4 -4
- package/src/components/widgets/CWidgetStatsD.tsx +4 -5
- package/src/components/widgets/CWidgetStatsE.tsx +1 -2
- package/src/components/widgets/CWidgetStatsF.tsx +3 -4
- package/src/{components/Types.tsx → props.ts} +1 -68
- package/src/types.ts +68 -0
- package/src/utils/index.ts +2 -3
- package/src/utils/isObjectInArray.ts +14 -0
- package/src/components/multi-select/CMultiSelectCleaner.tsx +0 -18
- package/src/utils/getNextSibling.ts +0 -18
- package/src/utils/getPreviousSibling.ts +0 -18
- /package/src/{utils/hooks → hooks}/index.ts +0 -0
- /package/src/{utils/hooks → hooks}/useForkedRef.ts +0 -0
- /package/src/{utils/hooks → hooks}/useStateWithCallback.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef, ReactNode, useEffect, useRef, useState } from 'react'
|
|
1
|
+
import React, { forwardRef, KeyboardEvent, ReactNode, useEffect, useRef, useState } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
@@ -18,8 +18,9 @@ import {
|
|
|
18
18
|
isToday,
|
|
19
19
|
isStartDate,
|
|
20
20
|
isEndDate,
|
|
21
|
-
} from '
|
|
22
|
-
|
|
21
|
+
} from './utils'
|
|
22
|
+
|
|
23
|
+
import { useStateWithCallback } from '../../hooks'
|
|
23
24
|
|
|
24
25
|
export interface CCalendarProps {
|
|
25
26
|
/**
|
|
@@ -146,15 +147,299 @@ export interface CCalendarProps {
|
|
|
146
147
|
onViewChanged?: (view: string) => void
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
const Calendar = (props: {
|
|
151
|
+
addMonths: number
|
|
152
|
+
calendarDate: Date
|
|
153
|
+
dayFormat?: 'numeric' | '2-digit' | ((date: Date) => string | number)
|
|
154
|
+
disabledDates?: Date[] | Date[][] | (Date | Date[])[]
|
|
155
|
+
endDate: Date | null
|
|
156
|
+
firstDayOfWeek: number
|
|
157
|
+
hoverDate: Date | null
|
|
158
|
+
locale: string
|
|
159
|
+
maxDate: Date | null
|
|
160
|
+
minDate: Date | null
|
|
161
|
+
onCellClick: (date: Date) => void
|
|
162
|
+
onCellKeyDown: (event: KeyboardEvent<HTMLDivElement>, date: Date) => void
|
|
163
|
+
onCellMouseEnter: (date: Date) => void
|
|
164
|
+
onCellMouseLeave: () => void
|
|
165
|
+
onMonthClick: (month: number, view: string) => void
|
|
166
|
+
onYearClick: (date: Date, view: string) => void
|
|
167
|
+
selectEndDate: boolean | undefined
|
|
168
|
+
startDate: Date | null
|
|
169
|
+
view: string
|
|
170
|
+
weekdayFormat: number | 'long' | 'narrow' | 'short' | ((date: Date) => string | number)
|
|
171
|
+
}) => {
|
|
172
|
+
const {
|
|
173
|
+
addMonths,
|
|
174
|
+
calendarDate,
|
|
175
|
+
dayFormat,
|
|
176
|
+
disabledDates,
|
|
177
|
+
endDate,
|
|
178
|
+
firstDayOfWeek,
|
|
179
|
+
hoverDate,
|
|
180
|
+
locale,
|
|
181
|
+
maxDate,
|
|
182
|
+
minDate,
|
|
183
|
+
onCellClick,
|
|
184
|
+
onCellKeyDown,
|
|
185
|
+
onCellMouseEnter,
|
|
186
|
+
onCellMouseLeave,
|
|
187
|
+
onMonthClick,
|
|
188
|
+
onYearClick,
|
|
189
|
+
selectEndDate,
|
|
190
|
+
startDate,
|
|
191
|
+
view,
|
|
192
|
+
weekdayFormat,
|
|
193
|
+
} = props
|
|
194
|
+
const [date, setDate] = useState<Date>(calendarDate)
|
|
195
|
+
const [listOfMonths, setListOfMonths] = useState<string[][]>([])
|
|
196
|
+
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
if (addMonths !== 0) {
|
|
199
|
+
setDate(new Date(calendarDate.getFullYear(), calendarDate.getMonth() + addMonths, 1))
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
setDate(calendarDate)
|
|
204
|
+
}, [calendarDate])
|
|
205
|
+
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
setListOfMonths(createGroupsInArray(getMonthsNames(locale), 4))
|
|
208
|
+
}, [])
|
|
209
|
+
|
|
210
|
+
const monthDetails = getMonthDetails(date.getFullYear(), date.getMonth(), firstDayOfWeek)
|
|
211
|
+
const listOfYears = createGroupsInArray(getYears(date.getFullYear()), 4)
|
|
212
|
+
const weekDays = monthDetails[0]
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<table>
|
|
216
|
+
{view === 'days' && (
|
|
217
|
+
<thead>
|
|
218
|
+
<tr>
|
|
219
|
+
{weekDays.map(({ date }: { date: Date }, idx: number) => (
|
|
220
|
+
<th key={idx} className="calendar-cell">
|
|
221
|
+
<div className="calendar-header-cell-inner">
|
|
222
|
+
{typeof weekdayFormat === 'function'
|
|
223
|
+
? weekdayFormat(date)
|
|
224
|
+
: typeof weekdayFormat === 'string'
|
|
225
|
+
? date.toLocaleDateString(locale, { weekday: weekdayFormat })
|
|
226
|
+
: date.toLocaleDateString(locale, { weekday: 'long' }).slice(0, weekdayFormat)}
|
|
227
|
+
</div>
|
|
228
|
+
</th>
|
|
229
|
+
))}
|
|
230
|
+
</tr>
|
|
231
|
+
</thead>
|
|
232
|
+
)}
|
|
233
|
+
<tbody>
|
|
234
|
+
{view === 'days' &&
|
|
235
|
+
monthDetails.map((week, index) => {
|
|
236
|
+
return (
|
|
237
|
+
<tr key={index}>
|
|
238
|
+
{week.map(({ date, month }: { date: Date; month: string }, idx: number) => (
|
|
239
|
+
<td
|
|
240
|
+
className={classNames('calendar-cell', {
|
|
241
|
+
today: month === 'current' && isToday(date),
|
|
242
|
+
disabled: isDateDisabled(date, minDate, maxDate, disabledDates),
|
|
243
|
+
[month]: true,
|
|
244
|
+
last: isLastDayOfMonth(date),
|
|
245
|
+
'range-hover':
|
|
246
|
+
month === 'current' &&
|
|
247
|
+
(hoverDate && selectEndDate
|
|
248
|
+
? isDateInRange(date, startDate, hoverDate)
|
|
249
|
+
: isDateInRange(date, hoverDate, endDate)),
|
|
250
|
+
range: month === 'current' && isDateInRange(date, startDate, endDate),
|
|
251
|
+
selected: isDateSelected(date, startDate, endDate),
|
|
252
|
+
start: isStartDate(date, startDate, endDate),
|
|
253
|
+
end: isEndDate(date, startDate, endDate),
|
|
254
|
+
})}
|
|
255
|
+
key={idx}
|
|
256
|
+
tabIndex={0}
|
|
257
|
+
title={date.toLocaleDateString(locale)}
|
|
258
|
+
{...(month === 'current' && {
|
|
259
|
+
onBlur: () => onCellMouseLeave(),
|
|
260
|
+
onClick: () => onCellClick(date),
|
|
261
|
+
onFocus: () => onCellMouseEnter(date),
|
|
262
|
+
onKeyDown: (event) => onCellKeyDown(event, date),
|
|
263
|
+
onMouseEnter: () => onCellMouseEnter(date),
|
|
264
|
+
onMouseLeave: () => onCellMouseLeave(),
|
|
265
|
+
})}
|
|
266
|
+
{...(month !== 'current' && {
|
|
267
|
+
onMouseEnter: () => onCellMouseLeave(),
|
|
268
|
+
})}
|
|
269
|
+
>
|
|
270
|
+
<div className="calendar-cell-inner">
|
|
271
|
+
{typeof dayFormat === 'function'
|
|
272
|
+
? dayFormat(date)
|
|
273
|
+
: date.toLocaleDateString(locale, { day: dayFormat })}
|
|
274
|
+
</div>
|
|
275
|
+
</td>
|
|
276
|
+
))}
|
|
277
|
+
</tr>
|
|
278
|
+
)
|
|
279
|
+
})}
|
|
280
|
+
{view === 'months' &&
|
|
281
|
+
listOfMonths.map((row, index) => {
|
|
282
|
+
return (
|
|
283
|
+
<tr key={index}>
|
|
284
|
+
{row.map((month, idx) => {
|
|
285
|
+
return (
|
|
286
|
+
<td
|
|
287
|
+
key={idx}
|
|
288
|
+
className="calendar-cell month"
|
|
289
|
+
onClick={() => onMonthClick(index * 3 + idx - addMonths, 'days')}
|
|
290
|
+
>
|
|
291
|
+
<div className="calendar-cell-inner">{month}</div>
|
|
292
|
+
</td>
|
|
293
|
+
)
|
|
294
|
+
})}
|
|
295
|
+
</tr>
|
|
296
|
+
)
|
|
297
|
+
})}
|
|
298
|
+
{view === 'years' &&
|
|
299
|
+
listOfYears.map((row, index) => {
|
|
300
|
+
return (
|
|
301
|
+
<tr key={index}>
|
|
302
|
+
{row.map((year, idx) => {
|
|
303
|
+
return (
|
|
304
|
+
<td
|
|
305
|
+
key={idx}
|
|
306
|
+
className="calendar-cell year"
|
|
307
|
+
onClick={() =>
|
|
308
|
+
onYearClick(
|
|
309
|
+
new Date(year, date.getMonth() - addMonths, date.getDate()),
|
|
310
|
+
'months',
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
>
|
|
314
|
+
<div className="calendar-cell-inner">
|
|
315
|
+
{new Date(year, 0, 1).toLocaleDateString(locale, { year: 'numeric' })}
|
|
316
|
+
</div>
|
|
317
|
+
</td>
|
|
318
|
+
)
|
|
319
|
+
})}
|
|
320
|
+
</tr>
|
|
321
|
+
)
|
|
322
|
+
})}
|
|
323
|
+
</tbody>
|
|
324
|
+
</table>
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const Navigation = (props: {
|
|
329
|
+
addMonths: number
|
|
330
|
+
calendarDate: Date
|
|
331
|
+
locale: string
|
|
332
|
+
navigation: boolean
|
|
333
|
+
navNextDoubleIcon: ReactNode
|
|
334
|
+
navNextIcon: ReactNode
|
|
335
|
+
navPrevDoubleIcon: ReactNode
|
|
336
|
+
navPrevIcon: ReactNode
|
|
337
|
+
navYearFirst: boolean | undefined
|
|
338
|
+
onMonthClick: () => void
|
|
339
|
+
onNavigationClick: (direction: string, double?: boolean) => void
|
|
340
|
+
onYearClick: () => void
|
|
341
|
+
view: string
|
|
342
|
+
}) => {
|
|
343
|
+
const {
|
|
344
|
+
addMonths,
|
|
345
|
+
calendarDate,
|
|
346
|
+
locale,
|
|
347
|
+
navigation,
|
|
348
|
+
navNextDoubleIcon,
|
|
349
|
+
navNextIcon,
|
|
350
|
+
navPrevDoubleIcon,
|
|
351
|
+
navPrevIcon,
|
|
352
|
+
navYearFirst,
|
|
353
|
+
onMonthClick,
|
|
354
|
+
onNavigationClick,
|
|
355
|
+
onYearClick,
|
|
356
|
+
view,
|
|
357
|
+
} = props
|
|
358
|
+
|
|
359
|
+
const [date, setDate] = useState<Date | null>()
|
|
360
|
+
useEffect(() => {
|
|
361
|
+
if (addMonths !== 0) {
|
|
362
|
+
setDate(new Date(calendarDate.getFullYear(), calendarDate.getMonth() + addMonths, 1))
|
|
363
|
+
return
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
setDate(calendarDate)
|
|
367
|
+
}, [calendarDate])
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<div className="calendar-nav">
|
|
371
|
+
{navigation && (
|
|
372
|
+
<div className="calendar-nav-prev">
|
|
373
|
+
<CButton color="transparent" size="sm" onClick={() => onNavigationClick('prev', true)}>
|
|
374
|
+
{navPrevDoubleIcon ? (
|
|
375
|
+
navPrevDoubleIcon
|
|
376
|
+
) : (
|
|
377
|
+
<span className="calendar-nav-icon calendar-nav-icon-double-prev" />
|
|
378
|
+
)}
|
|
379
|
+
</CButton>
|
|
380
|
+
{view === 'days' && (
|
|
381
|
+
<CButton color="transparent" size="sm" onClick={() => onNavigationClick('prev')}>
|
|
382
|
+
{navPrevIcon ? (
|
|
383
|
+
navPrevIcon
|
|
384
|
+
) : (
|
|
385
|
+
<span className="calendar-nav-icon calendar-nav-icon-prev" />
|
|
386
|
+
)}
|
|
387
|
+
</CButton>
|
|
388
|
+
)}
|
|
389
|
+
</div>
|
|
390
|
+
)}
|
|
391
|
+
<div
|
|
392
|
+
className="calendar-nav-date"
|
|
393
|
+
{...(navYearFirst && { style: { display: 'flex', justifyContent: 'center' } })}
|
|
394
|
+
>
|
|
395
|
+
{view === 'days' && (
|
|
396
|
+
<CButton color="transparent" size="sm" onClick={() => navigation && onMonthClick()}>
|
|
397
|
+
{date && date.toLocaleDateString(locale, { month: 'long' })}
|
|
398
|
+
</CButton>
|
|
399
|
+
)}
|
|
400
|
+
<CButton
|
|
401
|
+
color="transparent"
|
|
402
|
+
size="sm"
|
|
403
|
+
onClick={() => navigation && onYearClick()}
|
|
404
|
+
{...(navYearFirst && { style: { order: '-1' } })}
|
|
405
|
+
>
|
|
406
|
+
{date && date.toLocaleDateString(locale, { year: 'numeric' })}
|
|
407
|
+
</CButton>
|
|
408
|
+
</div>
|
|
409
|
+
{navigation && (
|
|
410
|
+
<div className="calendar-nav-next">
|
|
411
|
+
{view === 'days' && (
|
|
412
|
+
<CButton color="transparent" size="sm" onClick={() => onNavigationClick('next')}>
|
|
413
|
+
{navNextIcon ? (
|
|
414
|
+
navNextIcon
|
|
415
|
+
) : (
|
|
416
|
+
<span className="calendar-nav-icon calendar-nav-icon-next" />
|
|
417
|
+
)}
|
|
418
|
+
</CButton>
|
|
419
|
+
)}
|
|
420
|
+
<CButton color="transparent" size="sm" onClick={() => onNavigationClick('next', true)}>
|
|
421
|
+
{navNextDoubleIcon ? (
|
|
422
|
+
navNextDoubleIcon
|
|
423
|
+
) : (
|
|
424
|
+
<span className="calendar-nav-icon calendar-nav-icon-double-next" />
|
|
425
|
+
)}
|
|
426
|
+
</CButton>
|
|
427
|
+
</div>
|
|
428
|
+
)}
|
|
429
|
+
</div>
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
|
|
149
433
|
export const CCalendar = forwardRef<HTMLDivElement, CCalendarProps>(
|
|
150
434
|
(
|
|
151
435
|
{
|
|
152
|
-
|
|
436
|
+
startDate,
|
|
437
|
+
endDate,
|
|
438
|
+
calendarDate = startDate || endDate || null,
|
|
153
439
|
calendars = 1,
|
|
154
440
|
className,
|
|
155
441
|
dayFormat = 'numeric',
|
|
156
442
|
disabledDates,
|
|
157
|
-
endDate,
|
|
158
443
|
firstDayOfWeek = 1,
|
|
159
444
|
locale = 'default',
|
|
160
445
|
maxDate,
|
|
@@ -167,7 +452,6 @@ export const CCalendar = forwardRef<HTMLDivElement, CCalendarProps>(
|
|
|
167
452
|
navYearFirst,
|
|
168
453
|
range,
|
|
169
454
|
selectEndDate,
|
|
170
|
-
startDate,
|
|
171
455
|
weekdayFormat = 2,
|
|
172
456
|
onCalendarCellHover,
|
|
173
457
|
onCalendarDateChange,
|
|
@@ -179,13 +463,17 @@ export const CCalendar = forwardRef<HTMLDivElement, CCalendarProps>(
|
|
|
179
463
|
ref,
|
|
180
464
|
) => {
|
|
181
465
|
const isInitialMount = useRef(true)
|
|
182
|
-
const [_calendarDate, setCalendarDate] = useState<Date>(
|
|
183
|
-
|
|
184
|
-
)
|
|
466
|
+
const [_calendarDate, setCalendarDate] = useState<Date | null>(null)
|
|
467
|
+
|
|
185
468
|
useEffect(() => {
|
|
469
|
+
if (calendarDate === null) {
|
|
470
|
+
setCalendarDate(new Date())
|
|
471
|
+
return
|
|
472
|
+
}
|
|
473
|
+
|
|
186
474
|
if (calendarDate) {
|
|
187
|
-
const
|
|
188
|
-
!isSameDateAs(_calendarDate,
|
|
475
|
+
const date = new Date(calendarDate)
|
|
476
|
+
!isSameDateAs(_calendarDate, date) && setCalendarDate(date)
|
|
189
477
|
}
|
|
190
478
|
}, [calendarDate])
|
|
191
479
|
|
|
@@ -247,6 +535,10 @@ export const CCalendar = forwardRef<HTMLDivElement, CCalendarProps>(
|
|
|
247
535
|
}, [])
|
|
248
536
|
|
|
249
537
|
const setCalendarPage = (years: number, months = 0, setMonth?: number) => {
|
|
538
|
+
if (_calendarDate === null) {
|
|
539
|
+
return
|
|
540
|
+
}
|
|
541
|
+
|
|
250
542
|
const year = _calendarDate.getFullYear()
|
|
251
543
|
const month = _calendarDate.getMonth()
|
|
252
544
|
const d = new Date(year, month, 1)
|
|
@@ -356,237 +648,56 @@ export const CCalendar = forwardRef<HTMLDivElement, CCalendarProps>(
|
|
|
356
648
|
}
|
|
357
649
|
}
|
|
358
650
|
|
|
359
|
-
const Calendar = (props: { addMonths: number }) => {
|
|
360
|
-
const { addMonths } = props
|
|
361
|
-
let date = _calendarDate
|
|
362
|
-
|
|
363
|
-
if (addMonths !== 0) {
|
|
364
|
-
date = new Date(_calendarDate.getFullYear(), _calendarDate.getMonth() + addMonths, 1)
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const monthDetails = getMonthDetails(date.getFullYear(), date.getMonth(), firstDayOfWeek)
|
|
368
|
-
const listOfMonths = createGroupsInArray(getMonthsNames(locale), 4)
|
|
369
|
-
const listOfYears = createGroupsInArray(getYears(date.getFullYear()), 4)
|
|
370
|
-
const weekDays = monthDetails[0]
|
|
371
|
-
return (
|
|
372
|
-
<table>
|
|
373
|
-
{view === 'days' && (
|
|
374
|
-
<thead>
|
|
375
|
-
<tr>
|
|
376
|
-
{weekDays.map(({ date }: { date: Date }, idx: number) => (
|
|
377
|
-
<th key={idx} className="calendar-cell">
|
|
378
|
-
<div className="calendar-header-cell-inner">
|
|
379
|
-
{typeof weekdayFormat === 'function'
|
|
380
|
-
? weekdayFormat(date)
|
|
381
|
-
: typeof weekdayFormat === 'string'
|
|
382
|
-
? date.toLocaleDateString(locale, { weekday: weekdayFormat })
|
|
383
|
-
: date
|
|
384
|
-
.toLocaleDateString(locale, { weekday: 'long' })
|
|
385
|
-
.slice(0, weekdayFormat)}
|
|
386
|
-
</div>
|
|
387
|
-
</th>
|
|
388
|
-
))}
|
|
389
|
-
</tr>
|
|
390
|
-
</thead>
|
|
391
|
-
)}
|
|
392
|
-
<tbody>
|
|
393
|
-
{view === 'days' &&
|
|
394
|
-
monthDetails.map((week, index) => {
|
|
395
|
-
return (
|
|
396
|
-
<tr key={index}>
|
|
397
|
-
{week.map(({ date, month }: { date: Date; month: string }, idx: number) => (
|
|
398
|
-
<td
|
|
399
|
-
className={classNames('calendar-cell', {
|
|
400
|
-
today: month === 'current' && isToday(date),
|
|
401
|
-
disabled: isDateDisabled(date, _minDate, _maxDate, disabledDates),
|
|
402
|
-
[month]: true,
|
|
403
|
-
last: isLastDayOfMonth(date),
|
|
404
|
-
'range-hover':
|
|
405
|
-
month === 'current' &&
|
|
406
|
-
(_hoverDate && _selectEndDate
|
|
407
|
-
? isDateInRange(date, _startDate, _hoverDate)
|
|
408
|
-
: isDateInRange(date, _hoverDate, _endDate)),
|
|
409
|
-
range: month === 'current' && isDateInRange(date, _startDate, _endDate),
|
|
410
|
-
selected: isDateSelected(date, _startDate, _endDate),
|
|
411
|
-
start: isStartDate(date, _startDate, _endDate),
|
|
412
|
-
end: isEndDate(date, _startDate, _endDate),
|
|
413
|
-
})}
|
|
414
|
-
key={idx}
|
|
415
|
-
tabIndex={0}
|
|
416
|
-
title={date.toLocaleDateString(locale)}
|
|
417
|
-
{...(month === 'current' && {
|
|
418
|
-
onBlur: () => handleCellMouseLeave(),
|
|
419
|
-
onClick: () => handleCellOnClick(date),
|
|
420
|
-
onFocus: () => handleCellMouseEnter(date),
|
|
421
|
-
onKeyDown: (event) => handleCellKeyDown(event, date),
|
|
422
|
-
onMouseEnter: () => handleCellMouseEnter(date),
|
|
423
|
-
onMouseLeave: () => handleCellMouseLeave(),
|
|
424
|
-
})}
|
|
425
|
-
{...(month !== 'current' && {
|
|
426
|
-
onMouseEnter: () => handleCellMouseLeave(),
|
|
427
|
-
})}
|
|
428
|
-
>
|
|
429
|
-
<div className="calendar-cell-inner">
|
|
430
|
-
{typeof dayFormat === 'function'
|
|
431
|
-
? dayFormat(date)
|
|
432
|
-
: date.toLocaleDateString(locale, { day: dayFormat })}
|
|
433
|
-
</div>
|
|
434
|
-
</td>
|
|
435
|
-
))}
|
|
436
|
-
</tr>
|
|
437
|
-
)
|
|
438
|
-
})}
|
|
439
|
-
{view === 'months' &&
|
|
440
|
-
listOfMonths.map((row, index) => {
|
|
441
|
-
return (
|
|
442
|
-
<tr key={index}>
|
|
443
|
-
{row.map((month, idx) => {
|
|
444
|
-
return (
|
|
445
|
-
<td
|
|
446
|
-
key={idx}
|
|
447
|
-
className="calendar-cell month"
|
|
448
|
-
onClick={() => {
|
|
449
|
-
setCalendarPage(0, 0, index * 3 + idx - addMonths)
|
|
450
|
-
setView('days')
|
|
451
|
-
}}
|
|
452
|
-
>
|
|
453
|
-
<div className="calendar-cell-inner">{month}</div>
|
|
454
|
-
</td>
|
|
455
|
-
)
|
|
456
|
-
})}
|
|
457
|
-
</tr>
|
|
458
|
-
)
|
|
459
|
-
})}
|
|
460
|
-
{view === 'years' &&
|
|
461
|
-
listOfYears.map((row, index) => {
|
|
462
|
-
return (
|
|
463
|
-
<tr key={index}>
|
|
464
|
-
{row.map((year, idx) => {
|
|
465
|
-
return (
|
|
466
|
-
<td
|
|
467
|
-
key={idx}
|
|
468
|
-
className="calendar-cell year"
|
|
469
|
-
onClick={() => {
|
|
470
|
-
setCalendarDate(
|
|
471
|
-
new Date(year, date.getMonth() - addMonths, date.getDate()),
|
|
472
|
-
)
|
|
473
|
-
setView('months')
|
|
474
|
-
}}
|
|
475
|
-
>
|
|
476
|
-
<div className="calendar-cell-inner">
|
|
477
|
-
{new Date(year, 0, 1).toLocaleDateString(locale, { year: 'numeric' })}
|
|
478
|
-
</div>
|
|
479
|
-
</td>
|
|
480
|
-
)
|
|
481
|
-
})}
|
|
482
|
-
</tr>
|
|
483
|
-
)
|
|
484
|
-
})}
|
|
485
|
-
</tbody>
|
|
486
|
-
</table>
|
|
487
|
-
)
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
const Navigation = (props: { addMonths: number }) => {
|
|
491
|
-
const { addMonths } = props
|
|
492
|
-
let date = _calendarDate
|
|
493
|
-
|
|
494
|
-
if (addMonths !== 0) {
|
|
495
|
-
date = new Date(_calendarDate.getFullYear(), _calendarDate.getMonth() + addMonths, 1)
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return (
|
|
499
|
-
<div className="calendar-nav">
|
|
500
|
-
{navigation && (
|
|
501
|
-
<div className="calendar-nav-prev">
|
|
502
|
-
<CButton
|
|
503
|
-
color="transparent"
|
|
504
|
-
size="sm"
|
|
505
|
-
onClick={() => handleNavigationOnClick('prev', true)}
|
|
506
|
-
>
|
|
507
|
-
{navPrevDoubleIcon ? (
|
|
508
|
-
navPrevDoubleIcon
|
|
509
|
-
) : (
|
|
510
|
-
<span className="calendar-nav-icon calendar-nav-icon-double-prev" />
|
|
511
|
-
)}
|
|
512
|
-
</CButton>
|
|
513
|
-
{view === 'days' && (
|
|
514
|
-
<CButton
|
|
515
|
-
color="transparent"
|
|
516
|
-
size="sm"
|
|
517
|
-
onClick={() => handleNavigationOnClick('prev')}
|
|
518
|
-
>
|
|
519
|
-
{navPrevIcon ? (
|
|
520
|
-
navPrevIcon
|
|
521
|
-
) : (
|
|
522
|
-
<span className="calendar-nav-icon calendar-nav-icon-prev" />
|
|
523
|
-
)}
|
|
524
|
-
</CButton>
|
|
525
|
-
)}
|
|
526
|
-
</div>
|
|
527
|
-
)}
|
|
528
|
-
<div
|
|
529
|
-
className="calendar-nav-date"
|
|
530
|
-
{...(navYearFirst && { style: { display: 'flex', justifyContent: 'center' } })}
|
|
531
|
-
>
|
|
532
|
-
{view === 'days' && (
|
|
533
|
-
<CButton
|
|
534
|
-
color="transparent"
|
|
535
|
-
size="sm"
|
|
536
|
-
onClick={() => navigation && setView('months')}
|
|
537
|
-
>
|
|
538
|
-
{date.toLocaleDateString(locale, { month: 'long' })}
|
|
539
|
-
</CButton>
|
|
540
|
-
)}
|
|
541
|
-
<CButton
|
|
542
|
-
color="transparent"
|
|
543
|
-
size="sm"
|
|
544
|
-
onClick={() => navigation && setView('years')}
|
|
545
|
-
{...(navYearFirst && { style: { order: '-1' } })}
|
|
546
|
-
>
|
|
547
|
-
{date.toLocaleDateString(locale, { year: 'numeric' })}
|
|
548
|
-
</CButton>
|
|
549
|
-
</div>
|
|
550
|
-
{navigation && (
|
|
551
|
-
<div className="calendar-nav-next">
|
|
552
|
-
{view === 'days' && (
|
|
553
|
-
<CButton
|
|
554
|
-
color="transparent"
|
|
555
|
-
size="sm"
|
|
556
|
-
onClick={() => handleNavigationOnClick('next')}
|
|
557
|
-
>
|
|
558
|
-
{navNextIcon ? (
|
|
559
|
-
navNextIcon
|
|
560
|
-
) : (
|
|
561
|
-
<span className="calendar-nav-icon calendar-nav-icon-next" />
|
|
562
|
-
)}
|
|
563
|
-
</CButton>
|
|
564
|
-
)}
|
|
565
|
-
<CButton
|
|
566
|
-
color="transparent"
|
|
567
|
-
size="sm"
|
|
568
|
-
onClick={() => handleNavigationOnClick('next', true)}
|
|
569
|
-
>
|
|
570
|
-
{navNextDoubleIcon ? (
|
|
571
|
-
navNextDoubleIcon
|
|
572
|
-
) : (
|
|
573
|
-
<span className="calendar-nav-icon calendar-nav-icon-double-next" />
|
|
574
|
-
)}
|
|
575
|
-
</CButton>
|
|
576
|
-
</div>
|
|
577
|
-
)}
|
|
578
|
-
</div>
|
|
579
|
-
)
|
|
580
|
-
}
|
|
581
|
-
|
|
582
651
|
return (
|
|
583
652
|
<div className={classNames('calendars', className)}>
|
|
584
|
-
{
|
|
585
|
-
|
|
586
|
-
{
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
653
|
+
{_calendarDate &&
|
|
654
|
+
Array.from({ length: calendars }, (_, index) => (
|
|
655
|
+
<div className={classNames('calendar', view)} key={index} ref={ref}>
|
|
656
|
+
<Navigation
|
|
657
|
+
addMonths={index}
|
|
658
|
+
calendarDate={_calendarDate}
|
|
659
|
+
locale={locale}
|
|
660
|
+
navigation={navigation}
|
|
661
|
+
navNextDoubleIcon={navNextDoubleIcon}
|
|
662
|
+
navNextIcon={navNextIcon}
|
|
663
|
+
navPrevDoubleIcon={navPrevDoubleIcon}
|
|
664
|
+
navPrevIcon={navPrevIcon}
|
|
665
|
+
navYearFirst={navYearFirst}
|
|
666
|
+
onMonthClick={() => setView('months')}
|
|
667
|
+
onNavigationClick={handleNavigationOnClick}
|
|
668
|
+
onYearClick={() => setView('years')}
|
|
669
|
+
view={view}
|
|
670
|
+
/>
|
|
671
|
+
<Calendar
|
|
672
|
+
addMonths={index}
|
|
673
|
+
calendarDate={_calendarDate}
|
|
674
|
+
dayFormat={dayFormat}
|
|
675
|
+
disabledDates={disabledDates}
|
|
676
|
+
endDate={_endDate}
|
|
677
|
+
firstDayOfWeek={firstDayOfWeek}
|
|
678
|
+
hoverDate={_hoverDate}
|
|
679
|
+
locale={locale}
|
|
680
|
+
maxDate={_maxDate}
|
|
681
|
+
minDate={_minDate}
|
|
682
|
+
onCellClick={handleCellOnClick}
|
|
683
|
+
onCellKeyDown={handleCellKeyDown}
|
|
684
|
+
onCellMouseEnter={handleCellMouseEnter}
|
|
685
|
+
onCellMouseLeave={handleCellMouseLeave}
|
|
686
|
+
onMonthClick={(month, view) => {
|
|
687
|
+
setCalendarPage(0, 0, month)
|
|
688
|
+
setView(view)
|
|
689
|
+
}}
|
|
690
|
+
onYearClick={(date, view) => {
|
|
691
|
+
setCalendarDate(date)
|
|
692
|
+
setView(view)
|
|
693
|
+
}}
|
|
694
|
+
selectEndDate={_selectEndDate}
|
|
695
|
+
startDate={_startDate}
|
|
696
|
+
view={view}
|
|
697
|
+
weekdayFormat={weekdayFormat}
|
|
698
|
+
/>
|
|
699
|
+
</div>
|
|
700
|
+
))}
|
|
590
701
|
</div>
|
|
591
702
|
)
|
|
592
703
|
},
|