@coreui/react-pro 4.8.0-alpha.3 → 4.9.0-next.0
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/calendar/index.d.ts +2 -0
- package/dist/components/calendar/utils.d.ts +23 -0
- package/dist/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +2 -2
- package/dist/components/element-cover/CElementCover.d.ts +3 -7
- package/dist/components/element-cover/index.d.ts +2 -0
- package/dist/components/form/CFormInput.d.ts +1 -1
- package/dist/components/form/CFormSwitch.d.ts +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/nav/CNavGroup.d.ts +4 -4
- package/dist/components/offcanvas/COffcanvas.d.ts +8 -2
- package/dist/components/sidebar/CSidebar.d.ts +4 -4
- 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 +46 -109
- package/dist/components/smart-table/types.d.ts +53 -0
- package/dist/components/smart-table/utils.d.ts +16 -0
- package/dist/components/table/CTable.d.ts +5 -5
- package/dist/components/time-picker/types.d.ts +15 -0
- package/dist/components/time-picker/utils.d.ts +23 -0
- 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 +1246 -1865
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1246 -1863
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/isInViewport.d.ts +2 -0
- package/dist/utils/isObjectInArray.d.ts +2 -0
- package/package.json +14 -14
- package/src/components/accordion/CAccordionBody.tsx +1 -1
- package/src/components/alert/CAlert.tsx +1 -1
- package/src/components/backdrop/CBackdrop.tsx +1 -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 -1
- package/src/components/carousel/CCarousel.tsx +4 -4
- 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 +3 -3
- package/src/components/dropdown/CDropdown.tsx +1 -1
- package/src/components/dropdown/CDropdownToggle.tsx +1 -1
- package/src/components/element-cover/CElementCover.tsx +19 -25
- package/src/components/element-cover/index.ts +3 -0
- package/src/components/form/CFormCheck.tsx +1 -1
- package/src/components/form/CFormControlWrapper.tsx +14 -20
- package/src/components/form/CFormInput.tsx +1 -1
- package/src/components/form/CFormSwitch.tsx +1 -1
- package/src/components/grid/CCol.tsx +4 -0
- package/src/components/index.ts +2 -0
- package/src/components/modal/CModal.tsx +1 -1
- package/src/components/nav/CNavGroup.tsx +4 -4
- package/src/components/nav/CNavLink.tsx +2 -1
- package/src/components/offcanvas/COffcanvas.tsx +36 -18
- package/src/components/sidebar/CSidebar.tsx +10 -10
- package/src/components/smart-table/CSmartTable.tsx +279 -259
- package/src/components/smart-table/CSmartTableBody.tsx +31 -41
- 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 +53 -103
- package/src/components/smart-table/CSmartTableInterface.tsx +57 -120
- package/src/components/smart-table/CSmartTableItemsPerPageSelector.tsx +1 -2
- package/src/components/smart-table/types.tsx +65 -0
- package/src/components/smart-table/utils.tsx +199 -0
- package/src/components/table/CTable.tsx +12 -9
- package/src/components/tabs/CTabPane.tsx +1 -1
- package/src/components/time-picker/CTimePicker.tsx +50 -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 +1 -1
- package/src/components/virtual-scroller/CVirtualScroller.tsx +1 -1
- 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
- package/src/utils/index.ts +3 -2
- package/src/utils/isInViewport.ts +11 -0
- package/src/utils/isObjectInArray.ts +14 -0
- package/src/utils/isVisible.ts +0 -11
|
@@ -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
|
},
|
|
@@ -4,7 +4,7 @@ export const convertToLocalDate = (d: Date, locale: string, options = {}) =>
|
|
|
4
4
|
export const convertToLocalTime = (d: Date, locale: string, options = {}) =>
|
|
5
5
|
d.toLocaleTimeString(locale, options)
|
|
6
6
|
|
|
7
|
-
export const createGroupsInArray = (arr:
|
|
7
|
+
export const createGroupsInArray = <T>(arr: T[], numberOfGroups: number): T[][] => {
|
|
8
8
|
const perGroup = Math.ceil(arr.length / numberOfGroups)
|
|
9
9
|
return new Array(numberOfGroups)
|
|
10
10
|
.fill('')
|
|
@@ -11,8 +11,8 @@ import React, {
|
|
|
11
11
|
import PropTypes from 'prop-types'
|
|
12
12
|
import classNames from 'classnames'
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
import { useForkedRef } from '../../
|
|
14
|
+
import { isInViewport } from '../../utils'
|
|
15
|
+
import { useForkedRef } from '../../hooks'
|
|
16
16
|
|
|
17
17
|
export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
|
|
18
18
|
/**
|
|
@@ -157,7 +157,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
|
|
|
157
157
|
const nextItemWhenVisible = () => {
|
|
158
158
|
// Don't call next when the page isn't visible
|
|
159
159
|
// or the carousel or its parent isn't visible
|
|
160
|
-
if (!document.hidden && carouselRef.current &&
|
|
160
|
+
if (!document.hidden && carouselRef.current && isInViewport(carouselRef.current)) {
|
|
161
161
|
if (animating) {
|
|
162
162
|
return
|
|
163
163
|
}
|
|
@@ -195,7 +195,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
const handleScroll = () => {
|
|
198
|
-
if (!document.hidden && carouselRef.current &&
|
|
198
|
+
if (!document.hidden && carouselRef.current && isInViewport(carouselRef.current)) {
|
|
199
199
|
setVisible(true)
|
|
200
200
|
} else {
|
|
201
201
|
setVisible(false)
|
|
@@ -2,7 +2,7 @@ import React, { forwardRef, HTMLAttributes, useContext, useEffect, useState, use
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
|
-
import { useForkedRef } from '../../
|
|
5
|
+
import { useForkedRef } from '../../hooks'
|
|
6
6
|
import { CCarouselContext } from './CCarousel'
|
|
7
7
|
export interface CCarouselItemProps extends HTMLAttributes<HTMLDivElement> {
|
|
8
8
|
/**
|