11import registerComponent from '@js/core/component_registrator' ;
22import devices from '@js/core/devices' ;
3+ import type { dxElementWrapper } from '@js/core/renderer' ;
34import $ from '@js/core/renderer' ;
4- import Calendar from '@js/ui/calendar' ;
55import Popover from '@js/ui/popover/ui.popover' ;
66import Popup from '@js/ui/popup/ui.popup' ;
7- import type { dxSchedulerOptions } from '@js/ui/scheduler' ;
8- import Scrollable from '@js/ui/scroll_view/ui.scrollable' ;
9- import Widget from '@js/ui/widget/ui.widget' ;
7+ import type { OptionChanged } from '@ts/core/widget/types' ;
8+ import Widget from '@ts/core/widget/widget' ;
9+ import type { KeyboardKeyDownEvent } from '@ts/events/core/m_keyboard_processor' ;
10+ import type { CalendarProperties } from '@ts/ui/calendar/calendar' ;
11+ import Calendar from '@ts/ui/calendar/calendar' ;
12+ import Scrollable from '@ts/ui/scroll_view/scrollable' ;
13+
14+ import type { HeaderCalendarOptions } from './types' ;
1015
1116const CALENDAR_CLASS = 'dx-scheduler-navigator-calendar' ;
1217const CALENDAR_POPOVER_CLASS = 'dx-scheduler-navigator-calendar-popover' ;
1318
14- export default class SchedulerCalendar extends Widget < dxSchedulerOptions > {
15- _overlay : any ;
19+ export default class SchedulerCalendar extends Widget < HeaderCalendarOptions > {
20+ _overlay ?: Popup | Popover ;
1621
17- _calendar : any ;
22+ _calendar ?: Calendar ;
1823
19- show ( target ) {
20- if ( ! this . _isMobileLayout ( ) ) {
21- this . _overlay . option ( 'target' , target ) ;
24+ public async show ( target : HTMLElement ) : Promise < void > {
25+ if ( ! SchedulerCalendar . _isMobileLayout ( ) ) {
26+ this . _overlay ? .option ( 'target' , target ) ;
2227 }
23- this . _overlay . show ( ) ;
28+
29+ await this . _overlay ?. show ( ) ;
2430 }
2531
26- hide ( ) {
27- this . _overlay . hide ( ) ;
32+ public async hide ( ) : Promise < void > {
33+ await this . _overlay ? .hide ( ) ;
2834 }
2935
30- _keyboardHandler ( opts ) : void {
31- this . _calendar ?. _keyboardHandler ( opts ) ;
36+ public _keyboardHandler ( opts : KeyboardKeyDownEvent ) : boolean {
37+ return this . _calendar ?. _keyboardHandler ( opts ) ?? false ;
3238 }
3339
34- _init ( ) : void {
35- // @ts -expect-error
40+ public _init ( ) : void {
3641 super . _init ( ) ;
3742 this . $element ( ) ;
3843 }
3944
40- _render ( ) : void {
41- // @ts -expect-error
45+ public _render ( ) : void {
4246 super . _render ( ) ;
4347 this . _renderOverlay ( ) ;
4448 }
4549
46- _renderOverlay ( ) : void {
50+ private _renderOverlay ( ) : void {
4751 this . $element ( ) . addClass ( CALENDAR_POPOVER_CLASS ) ;
4852
49- const isMobileLayout = this . _isMobileLayout ( ) ;
53+ const isMobileLayout = SchedulerCalendar . _isMobileLayout ( ) ;
5054
51- const overlayType = isMobileLayout ? Popup : Popover ;
52-
53- // @ts -expect-error
54- this . _overlay = this . _createComponent ( this . $element ( ) , overlayType , {
55- contentTemplate : ( ) => this . _createOverlayContent ( ) ,
56- onShown : ( ) => this . _calendar . focus ( ) ,
55+ const overlayConfig = {
56+ contentTemplate : ( ) : dxElementWrapper => this . _createOverlayContent ( ) ,
57+ onShown : ( ) : void => {
58+ this . _calendar ?. focus ( ) ;
59+ } ,
5760 defaultOptionsRules : [
5861 {
59- device : ( ) => isMobileLayout ,
62+ device : ( ) : boolean => isMobileLayout ,
6063 options : {
6164 fullScreen : true ,
6265 showCloseButton : false ,
@@ -67,24 +70,28 @@ export default class SchedulerCalendar extends Widget<dxSchedulerOptions> {
6770 } ,
6871 } ,
6972 ] ,
70- } ) ;
73+ } ;
74+
75+ if ( isMobileLayout ) {
76+ this . _overlay = this . _createComponent ( this . $element ( ) , Popup , overlayConfig ) ;
77+ } else {
78+ this . _overlay = this . _createComponent ( this . $element ( ) , Popover , overlayConfig ) ;
79+ }
7180 }
7281
73- _createOverlayContent ( ) {
82+ private _createOverlayContent ( ) : dxElementWrapper {
7483 const result = $ ( '<div>' ) . addClass ( CALENDAR_CLASS ) ;
75- // @ts -expect-error
7684 this . _calendar = this . _createComponent ( result , Calendar , this . _getCalendarOptions ( ) ) ;
7785
78- if ( this . _isMobileLayout ( ) ) {
86+ if ( SchedulerCalendar . _isMobileLayout ( ) ) {
7987 const scrollable = this . _createScrollable ( result ) ;
8088 return scrollable . $element ( ) ;
8189 }
8290
8391 return result ;
8492 }
8593
86- _createScrollable ( content ) {
87- // @ts -expect-error
94+ private _createScrollable ( content : dxElementWrapper ) : Scrollable {
8895 const result = this . _createComponent ( '<div>' , Scrollable , {
8996 height : 'auto' ,
9097 direction : 'both' ,
@@ -94,7 +101,11 @@ export default class SchedulerCalendar extends Widget<dxSchedulerOptions> {
94101 return result ;
95102 }
96103
97- _optionChanged ( { name, value } ) {
104+ public _optionChanged (
105+ args : OptionChanged < HeaderCalendarOptions > ,
106+ ) : void {
107+ const { name, value } = args ;
108+
98109 switch ( name ) {
99110 case 'value' :
100111 this . _calendar ?. option ( 'value' , value ) ;
@@ -104,23 +115,26 @@ export default class SchedulerCalendar extends Widget<dxSchedulerOptions> {
104115 }
105116 }
106117
107- _getCalendarOptions ( ) {
118+ private _getCalendarOptions ( ) : CalendarProperties {
119+ const {
120+ value, min, max, firstDayOfWeek, focusStateEnabled, tabIndex, onValueChanged,
121+ } = this . option ( ) ;
108122 return {
109- value : this . option ( 'value' ) ,
110- min : this . option ( 'min' ) ,
111- max : this . option ( 'max' ) ,
112- firstDayOfWeek : this . option ( 'firstDayOfWeek' ) ,
113- focusStateEnabled : this . option ( 'focusStateEnabled' ) ,
114- onValueChanged : this . option ( 'onValueChanged' ) ,
123+ value,
124+ min,
125+ max,
126+ firstDayOfWeek,
127+ focusStateEnabled,
128+ tabIndex,
129+ onValueChanged,
130+ // @ts -expect-error skipFocusCheck is an internal Calendar property
115131 skipFocusCheck : true ,
116- tabIndex : this . option ( 'tabIndex' ) ,
117132 } ;
118133 }
119134
120- _isMobileLayout ( ) {
135+ private static _isMobileLayout ( ) : boolean {
121136 return ! devices . current ( ) . generic ;
122137 }
123138}
124139
125- // @ts -expect-error
126140registerComponent ( 'dxSchedulerCalendarPopup' , SchedulerCalendar ) ;
0 commit comments