1
- /* eslint-disable multiline-ternary */
2
- /* eslint-disable no-mixed-operators */
3
- /* eslint-disable indent */
1
+ /* eslint-disable indent, multiline-ternary */
4
2
/**
5
3
* --------------------------------------------------------------------------
6
- * CoreUI (v4.1.0 ): calendar.js
7
- * Licensed under MIT (https://coreui.io/license)
4
+ * CoreUI PRO (v4.2.0-beta.2 ): calendar.js
5
+ * License (https://coreui.io/pro/ license-new/ )
8
6
* --------------------------------------------------------------------------
9
7
*/
10
8
@@ -16,7 +14,7 @@ import {
16
14
getMonthDetails ,
17
15
getMonthsNames ,
18
16
getYears ,
19
- isDisabled ,
17
+ isDateDisabled ,
20
18
isDateInRange ,
21
19
isDateSelected ,
22
20
isLastDayOfMonth ,
@@ -54,13 +52,13 @@ const Default = {
54
52
disabledDates : null ,
55
53
endDate : null ,
56
54
firstDayOfWeek : 1 ,
57
- locale : navigator . language ,
55
+ locale : 'default' ,
58
56
maxDate : null ,
59
57
minDate : null ,
60
58
range : true ,
61
59
startDate : null ,
62
60
selectEndDate : false ,
63
- weekdayLength : 2
61
+ weekdayFormat : 2
64
62
}
65
63
66
64
const DefaultType = {
@@ -74,7 +72,7 @@ const DefaultType = {
74
72
range : 'boolean' ,
75
73
startDate : '(date|string|null)' ,
76
74
selectEndDate : 'boolean' ,
77
- weekdayLength : 'number'
75
+ weekdayFormat : '( number|string) '
78
76
}
79
77
80
78
/**
@@ -158,7 +156,7 @@ class Calendar extends BaseComponent {
158
156
159
157
EventHandler . on ( this . _element , 'click' , '.btn-double-prev' , event => {
160
158
event . preventDefault ( )
161
- this . _modifyCalendarDate ( - 1 )
159
+ this . _modifyCalendarDate ( this . _view === 'years' ? - 10 : - 1 )
162
160
} )
163
161
164
162
EventHandler . on ( this . _element , 'click' , '.btn-next' , event => {
@@ -168,7 +166,7 @@ class Calendar extends BaseComponent {
168
166
169
167
EventHandler . on ( this . _element , 'click' , '.btn-double-next' , event => {
170
168
event . preventDefault ( )
171
- this . _modifyCalendarDate ( 1 )
169
+ this . _modifyCalendarDate ( this . _view === 'years' ? 10 : 1 )
172
170
} )
173
171
174
172
EventHandler . on ( this . _element , 'click' , '.btn-month' , event => {
@@ -209,9 +207,11 @@ class Calendar extends BaseComponent {
209
207
210
208
this . _calendarDate = d
211
209
212
- EventHandler . trigger ( this . _element , EVENT_CALENDAR_DATE_CHANGE , {
213
- date : d
214
- } )
210
+ if ( this . _view === 'days' ) {
211
+ EventHandler . trigger ( this . _element , EVENT_CALENDAR_DATE_CHANGE , {
212
+ date : d
213
+ } )
214
+ }
215
215
216
216
this . _updateCalendar ( )
217
217
}
@@ -233,7 +233,7 @@ class Calendar extends BaseComponent {
233
233
}
234
234
235
235
_selectDate ( date ) {
236
- if ( isDisabled ( date , this . _config . minDate , this . _config . maxDate , this . _config . disabledDates ) ) {
236
+ if ( isDateDisabled ( date , this . _config . minDate , this . _config . maxDate , this . _config . disabledDates ) ) {
237
237
return
238
238
}
239
239
@@ -254,7 +254,7 @@ class Calendar extends BaseComponent {
254
254
}
255
255
256
256
_createCalendar ( ) {
257
- const { firstDayOfWeek, locale, weekdayLength } = this . _config
257
+ const { firstDayOfWeek, locale, weekdayFormat } = this . _config
258
258
const year = this . _calendarDate . getFullYear ( )
259
259
const month = this . _calendarDate . getMonth ( )
260
260
@@ -266,9 +266,9 @@ class Calendar extends BaseComponent {
266
266
<button class="btn btn-transparent btn-sm btn-double-prev">
267
267
<span class="calendar-nav-icon calendar-nav-icon-double-prev"></span>
268
268
</button>
269
- <button class="btn btn-transparent btn-sm btn-prev">
269
+ ${ this . _view === 'days' ? ` <button class="btn btn-transparent btn-sm btn-prev">
270
270
<span class="calendar-nav-icon calendar-nav-icon-prev"></span>
271
- </button>
271
+ </button>` : '' }
272
272
</div>
273
273
<div class="calendar-nav-date">
274
274
<button class="btn btn-transparent btn-sm btn-month">
@@ -279,9 +279,9 @@ class Calendar extends BaseComponent {
279
279
</button>
280
280
</div>
281
281
<div class="calendar-nav-next">
282
- <button class="btn btn-transparent btn-sm btn-next">
282
+ ${ this . _view === 'days' ? ` <button class="btn btn-transparent btn-sm btn-next">
283
283
<span class="calendar-nav-icon calendar-nav-icon-next"></span>
284
- </button>
284
+ </button>` : '' }
285
285
<button class="btn btn-transparent btn-sm btn-double-next">
286
286
<span class="calendar-nav-icon calendar-nav-icon-double-next"></span>
287
287
</button>
@@ -301,7 +301,11 @@ class Calendar extends BaseComponent {
301
301
${ weekDays . map ( ( { date } ) => (
302
302
`<th class="calendar-cell">
303
303
<div class="calendar-header-cell-inner">
304
- ${ date . toLocaleDateString ( locale , { weekday : 'long' } ) . slice ( 0 , weekdayLength ) }
304
+ ${ typeof weekdayFormat === 'string' ?
305
+ date . toLocaleDateString ( locale , { weekday : weekdayFormat } ) :
306
+ date
307
+ . toLocaleDateString ( locale , { weekday : 'long' } )
308
+ . slice ( 0 , weekdayFormat ) }
305
309
</div>
306
310
</th>`
307
311
) ) . join ( '' ) }
@@ -311,17 +315,16 @@ class Calendar extends BaseComponent {
311
315
${ this . _view === 'days' ? monthDetails . map ( week => (
312
316
`<tr>${ week . map ( ( { date, month } ) => (
313
317
`<td class="calendar-cell ${ this . _dayClassNames ( date , month ) } ">
314
- <div
315
- class="calendar-cell-inner day"
316
- data-coreui-date="${ date } "
317
- >${ date . toLocaleDateString ( locale , { day : 'numeric' } ) } </div>
318
+ <div class="calendar-cell-inner day" data-coreui-date="${ date } ">
319
+ ${ date . toLocaleDateString ( locale , { day : 'numeric' } ) }
320
+ </div>
318
321
</td>`
319
322
) ) . join ( '' ) } </tr>`
320
323
) ) . join ( '' ) : '' }
321
324
${ this . _view === 'months' ? listOfMonths . map ( ( row , index ) => (
322
325
`<tr>${ row . map ( ( month , idx ) => (
323
326
`<td class="calendar-cell">
324
- <div class="calendar-cell-inner month" data-coreui-month="${ index * 3 + idx } ">
327
+ <div class="calendar-cell-inner month" data-coreui-month="${ ( index * 3 ) + idx } ">
325
328
${ month }
326
329
</div>
327
330
</td>`
@@ -351,7 +354,7 @@ class Calendar extends BaseComponent {
351
354
_dayClassNames ( date , month ) {
352
355
const classNames = [
353
356
isToday ( date ) && 'today' ,
354
- isDisabled ( date , this . _config . minDate , this . _config . maxDate , this . _config . disabledDates ) && 'disabled' ,
357
+ isDateDisabled ( date , this . _config . minDate , this . _config . maxDate , this . _config . disabledDates ) && 'disabled' ,
355
358
`${ month } ` ,
356
359
isLastDayOfMonth ( date ) && 'last' ,
357
360
month === 'current' && isDateInRange ( date , this . _startDate , this . _endDate ) && 'range' ,
0 commit comments