@@ -60,8 +60,10 @@ const Default = {
6060 selectAdjacementDays : false ,
6161 selectEndDate : false ,
6262 showAdjacementDays : true ,
63+ showWeekNumber : false ,
6364 startDate : null ,
64- weekdayFormat : 2
65+ weekdayFormat : 2 ,
66+ weekNumbersLabel : null
6567}
6668
6769const DefaultType = {
@@ -77,8 +79,10 @@ const DefaultType = {
7779 selectAdjacementDays : 'boolean' ,
7880 selectEndDate : 'boolean' ,
7981 showAdjacementDays : 'boolean' ,
82+ showWeekNumber : 'boolean' ,
8083 startDate : '(date|string|null)' ,
81- weekdayFormat : '(number|string)'
84+ weekdayFormat : '(number|string)' ,
85+ weekNumbersLabel : '(string|null)'
8286}
8387
8488/**
@@ -333,19 +337,26 @@ class Calendar extends BaseComponent {
333337 const monthDetails = getMonthDetails ( year , month , this . _config . firstDayOfWeek )
334338 const listOfMonths = createGroupsInArray ( getMonthsNames ( this . _config . locale ) , 4 )
335339 const listOfYears = createGroupsInArray ( getYears ( date . getFullYear ( ) ) , 4 )
336- const weekDays = monthDetails [ 0 ]
340+ const weekDays = monthDetails [ 0 ] . days
337341
338342 const calendarTable = document . createElement ( 'table' )
339343 calendarTable . innerHTML = `
340344 ${ this . _view === 'days' ? `
341345 <thead>
342346 <tr>
347+ ${ this . _config . showWeekNumber ?
348+ `<th class="calendar-cell">
349+ <div class="calendar-header-cell-inner">
350+ ${ this . _config . weekNumbersLabel ?? '' }
351+ </div>
352+ </th>` : ''
353+ }
343354 ${ weekDays . map ( ( { date } ) => (
344355 `<th class="calendar-cell">
345356 <div class="calendar-header-cell-inner">
346357 ${ typeof this . _config . weekdayFormat === 'string' ?
347- date . toLocaleDateString ( this . _config . locale , { weekday : this . _config . weekdayFormat } ) :
348- date
358+ date . toLocaleDateString ( this . _config . locale , { weekday : this . _config . weekdayFormat } ) :
359+ date
349360 . toLocaleDateString ( this . _config . locale , { weekday : 'long' } )
350361 . slice ( 0 , this . _config . weekdayFormat ) }
351362 </div>
@@ -355,7 +366,13 @@ class Calendar extends BaseComponent {
355366 </thead>` : '' }
356367 <tbody>
357368 ${ this . _view === 'days' ? monthDetails . map ( week => (
358- `<tr>${ week . map ( ( { date, month } ) => (
369+ `<tr class="calendar-row">
370+ ${ this . _config . showWeekNumber ?
371+ `<td class="calendar-cell week-number">
372+ <div class="calendar-cell-inner">${ week . weekNumber } </div>
373+ </td>` : ''
374+ }
375+ ${ week . days . map ( ( { date, month } ) => (
359376 month === 'current' || this . _config . showAdjacementDays ?
360377 `<td class="calendar-cell ${ this . _dayClassNames ( date , month ) } ">
361378 <div class="calendar-cell-inner day" data-coreui-date="${ date } ">
0 commit comments