@@ -39,10 +39,11 @@ import type {
3939  formatWeekday  as  defaultFormatWeekday , 
4040  formatYear  as  defaultFormatYear , 
4141}  from  './shared/dateFormatter.js' ; 
42+ import  WeekView  from  './WeekView.js' ; 
4243
4344const  baseClassName  =  'react-calendar' ; 
44- const  allViews  =  [ 'century' ,  'decade' ,  'year' ,  'month' ]  as  const ; 
45- const  allValueTypes  =  [ 'decade' ,  'year' ,  'month' ,  'day' ]  as  const ; 
45+ const  allViews  =  [ 'century' ,  'decade' ,  'year' ,  'month' ,   'week' ]  as  const ; 
46+ const  allValueTypes  =  [ 'decade' ,  'year' ,  'month' ,  'day' ,   'day' ]  as  const ; 
4647
4748const  defaultMinDate  =  new  Date ( ) ; 
4849defaultMinDate . setFullYear ( 1 ,  0 ,  1 ) ; 
@@ -487,13 +488,14 @@ function getValue(value: LooseValue | undefined, index: 0 | 1): Date | null {
487488} 
488489
489490type  DetailArgs  =  { 
491+   calendarType ?: CalendarType ; 
490492  value ?: LooseValue ; 
491493  minDate ?: Date ; 
492494  maxDate ?: Date ; 
493495  maxDetail : Detail ; 
494496} ; 
495497
496- function  getDetailValue ( {  value,  minDate,  maxDate,  maxDetail } : DetailArgs ,  index : 0  |  1 )  { 
498+ function  getDetailValue ( {  calendarType ,   value,  minDate,  maxDate,  maxDetail } : DetailArgs ,  index : 0  |  1 )  { 
497499  const  valuePiece  =  getValue ( value ,  index ) ; 
498500
499501  if  ( ! valuePiece )  { 
@@ -505,9 +507,9 @@ function getDetailValue({ value, minDate, maxDate, maxDetail }: DetailArgs, inde
505507  const  detailValueFrom  =  ( ( )  =>  { 
506508    switch  ( index )  { 
507509      case  0 :
508-         return  getBegin ( valueType ,  valuePiece ) ; 
510+         return  getBegin ( valueType ,  valuePiece ,   calendarType ) ; 
509511      case  1 :
510-         return  getEnd ( valueType ,  valuePiece ) ; 
512+         return  getEnd ( valueType ,  valuePiece ,   calendarType ) ; 
511513      default :
512514        throw  new  Error ( `Invalid index value: ${ index }  ) ; 
513515    } 
@@ -527,6 +529,7 @@ const getDetailValueArray = (args: DetailArgs) =>
527529  ] ; 
528530
529531function  getActiveStartDate ( { 
532+   calendarType, 
530533  maxDate, 
531534  maxDetail, 
532535  minDate, 
@@ -540,17 +543,19 @@ function getActiveStartDate({
540543  const  rangeType  =  getView ( view ,  minDetail ,  maxDetail ) ; 
541544  const  valueFrom  = 
542545    getDetailValueFrom ( { 
546+       calendarType, 
543547      value, 
544548      minDate, 
545549      maxDate, 
546550      maxDetail, 
547551    } )  ||  new  Date ( ) ; 
548552
549-   return  getBegin ( rangeType ,  valueFrom ) ; 
553+   return  getBegin ( rangeType ,  valueFrom ,   calendarType ) ; 
550554} 
551555
552556function  getInitialActiveStartDate ( { 
553557  activeStartDate, 
558+   calendarType, 
554559  defaultActiveStartDate, 
555560  defaultValue, 
556561  defaultView, 
@@ -562,6 +567,7 @@ function getInitialActiveStartDate({
562567  view, 
563568} : { 
564569  activeStartDate ?: Date ; 
570+   calendarType ?: CalendarType ; 
565571  defaultActiveStartDate ?: Date ; 
566572  defaultValue ?: LooseValue ; 
567573  defaultView ?: View ; 
@@ -576,10 +582,11 @@ function getInitialActiveStartDate({
576582  const  valueFrom  =  activeStartDate  ||  defaultActiveStartDate ; 
577583
578584  if  ( valueFrom )  { 
579-     return  getBegin ( rangeType ,  valueFrom ) ; 
585+     return  getBegin ( rangeType ,  valueFrom ,   calendarType ) ; 
580586  } 
581587
582588  return  getActiveStartDate ( { 
589+     calendarType, 
583590    maxDate, 
584591    maxDetail, 
585592    minDate, 
@@ -675,6 +682,7 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
675682      activeStartDateProps  || 
676683      activeStartDateState  || 
677684      getInitialActiveStartDate ( { 
685+         calendarType, 
678686        activeStartDate : activeStartDateProps , 
679687        defaultActiveStartDate, 
680688        defaultValue, 
@@ -736,13 +744,14 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
736744        } ) ( ) ; 
737745
738746        return  processFunction ( { 
747+           calendarType, 
739748          maxDate, 
740749          maxDetail, 
741750          minDate, 
742751          value, 
743752        } ) ; 
744753      } , 
745-       [ maxDate ,  maxDetail ,  minDate ,  returnValue ] , 
754+       [ calendarType ,   maxDate ,  maxDetail ,  minDate ,  returnValue ] , 
746755    ) ; 
747756
748757    const  setActiveStartDate  =  useCallback ( 
@@ -773,6 +782,8 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
773782              return  onClickYear ; 
774783            case  'year' :
775784              return  onClickMonth ; 
785+             case  'week' :
786+               return  onClickDay ; 
776787            case  'month' :
777788              return  onClickDay ; 
778789            default :
@@ -845,7 +856,7 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
845856        throw  new  Error ( 'Attempted to drill up from the highest view.' ) ; 
846857      } 
847858
848-       const  nextActiveStartDate  =  getBegin ( nextView ,  activeStartDate ) ; 
859+       const  nextActiveStartDate  =  getBegin ( nextView ,  activeStartDate ,   calendarType ) ; 
849860
850861      setActiveStartDateState ( nextActiveStartDate ) ; 
851862      setViewState ( nextView ) ; 
@@ -870,6 +881,7 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
870881      } 
871882    } ,  [ 
872883      activeStartDate , 
884+       calendarType , 
873885      drillUpAvailable , 
874886      onActiveStartDateChange , 
875887      onDrillUp , 
@@ -894,7 +906,7 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
894906          if  ( isFirstValueInRange )  { 
895907            // Value has 0 or 2 elements - either way we're starting a new array 
896908            // First value 
897-             nextValue  =  getBegin ( valueType ,  rawNextValue ) ; 
909+             nextValue  =  getBegin ( valueType ,  rawNextValue ,   calendarType ) ; 
898910          }  else  { 
899911            if  ( ! previousValue )  { 
900912              throw  new  Error ( 'previousValue is required' ) ; 
@@ -920,6 +932,7 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
920932          // Range selection turned on, second value, goToRangeStartOnSelect toggled on 
921933          goToRangeStartOnSelect 
922934            ? getActiveStartDate ( { 
935+                 calendarType, 
923936                maxDate, 
924937                maxDetail, 
925938                minDate, 
@@ -966,6 +979,7 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
966979      [ 
967980        activeStartDate , 
968981        allowPartialRange , 
982+         calendarType , 
969983        getProcessedValue , 
970984        goToRangeStartOnSelect , 
971985        maxDate , 
@@ -1006,8 +1020,8 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
10061020
10071021    function  renderContent ( next ?: boolean )  { 
10081022      const  currentActiveStartDate  =  next 
1009-         ? getBeginNext ( view ,  activeStartDate ) 
1010-         : getBegin ( view ,  activeStartDate ) ; 
1023+         ? getBeginNext ( view ,  activeStartDate ,   calendarType ) 
1024+         : getBegin ( view ,  activeStartDate ,   calendarType ) ; 
10111025
10121026      const  onClick  =  drillDownAvailable  ? drillDown  : onChange ; 
10131027
@@ -1075,6 +1089,26 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
10751089            /> 
10761090          ) ; 
10771091        } 
1092+         case  'week' : { 
1093+           return  ( 
1094+             < WeekView 
1095+               calendarType = { calendarType } 
1096+               formatDay = { formatDay } 
1097+               formatLongDate = { formatLongDate } 
1098+               formatShortWeekday = { formatShortWeekday } 
1099+               formatWeekday = { formatWeekday } 
1100+               onClickWeekNumber = { onClickWeekNumber } 
1101+               onMouseLeave = { selectRange  ? onMouseLeave  : undefined } 
1102+               showFixedNumberOfWeeks = { 
1103+                 typeof  showFixedNumberOfWeeks  !==  'undefined' 
1104+                   ? showFixedNumberOfWeeks 
1105+                   : showDoubleView 
1106+               } 
1107+               showWeekNumbers = { showWeekNumbers } 
1108+               { ...commonProps } 
1109+             /> 
1110+           ) ; 
1111+         } 
10781112        default :
10791113          throw  new  Error ( `Invalid view: ${ view }  ) ; 
10801114      } 
@@ -1088,6 +1122,7 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
10881122      return  ( 
10891123        < Navigation 
10901124          activeStartDate = { activeStartDate } 
1125+           calendarType = { calendarType } 
10911126          drillUp = { drillUp } 
10921127          formatMonthYear = { formatMonthYear } 
10931128          formatYear = { formatYear } 
0 commit comments