@@ -12,45 +12,38 @@ import {
1212import { BehaviorSubject } from "rxjs" ;
1313import { css } from "emotion" ;
1414import { CssUtils } from "../utils" ;
15- import { responsiveSizes } from "./../variables" ;
16- import {
17- coerceBooleanProperty ,
18- coerceNumberProperty ,
19- } from "@angular/cdk/coercion" ;
20- import { SidenavService } from "./services/sidenav.service" ;
2115import { BackgroundProviderService } from "../background-provider/service/background-provider.service" ;
2216
17+ type Space =
18+ | "xxsmall"
19+ | "xsmall"
20+ | "small"
21+ | "medium"
22+ | "large"
23+ | "xlarge"
24+ | "xxlarge" ;
25+
26+ type Padding = {
27+ top ?: Space ;
28+ bottom ?: Space ;
29+ left ?: Space ;
30+ right ?: Space ;
31+ } ;
2332@Component ( {
2433 selector : "dxc-sidenav" ,
2534 templateUrl : "./dxc-sidenav.component.html" ,
26- styleUrls : [ "./dxc-sidenav.component.scss" ] ,
27- providers : [ CssUtils , SidenavService , BackgroundProviderService ] ,
35+ providers : [ CssUtils , BackgroundProviderService ] ,
2836} )
2937export class DxcSidenavComponent implements OnInit {
3038 @HostBinding ( "class" ) sidenavStyles ;
31- @Input ( ) mode : string = "push" ;
32- @Input ( ) padding : any ;
33- @Input ( )
34- get displayArrow ( ) : boolean {
35- return this . _displayArrow ;
36- }
37- set displayArrow ( value : boolean ) {
38- this . _displayArrow = coerceBooleanProperty ( value ) ;
39- }
40- _displayArrow = true ;
41- @Input ( )
42- get tabIndexValue ( ) : number {
43- return this . _tabIndexValue ;
44- }
45- set tabIndexValue ( value : number ) {
46- this . _tabIndexValue = coerceNumberProperty ( value ) ;
47- }
48- private _tabIndexValue ;
39+
40+ /**
41+ * Size of the padding to be applied to the custom area ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
42+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different padding sizes.
43+ */
44+ @Input ( ) padding : Space | Padding ;
4945
5046 firstClick : boolean = false ; //remove animation on first load
51- innerWidth ;
52- isResponsive = true ;
53- isShown : boolean ;
5447
5548 currentBackgroundColor : string ;
5649
@@ -62,41 +55,15 @@ export class DxcSidenavComponent implements OnInit {
6255 @ViewChild ( "sidenavContainer" , { static : false } ) sidenav : ElementRef ;
6356 sidenavArrow : any ;
6457
65- constructor ( private utils : CssUtils , private service : SidenavService ) { }
66-
67- @HostListener ( "window:resize" , [ "$event" ] )
68- onResize ( event ) {
69- this . updateCss ( ) ;
70- }
58+ constructor ( private utils : CssUtils ) { }
7159
7260 ngOnInit ( ) {
73- this . updateState ( ) ;
7461 this . sidenavStyles = `${ this . getDynamicStyle ( {
7562 ...this . defaultInputs . getValue ( ) ,
76- mode : this . mode ,
77- innerWidth : this . innerWidth ,
78- isResponsive : this . isResponsive ,
79- isShown : this . isShown ,
8063 } ) } `;
8164 }
8265
83- public arrowClicked ( ) {
84- this . isShown = ! this . isShown ;
85- this . firstClick = true ;
86- console . log ( this . isShown ) ;
87- this . updateCss ( ) ;
88- }
89-
90- public arrowKey ( $event ) {
91- if ( $event . keyCode && $event . keyCode === 32 ) {
92- $event . preventDefault ( ) ;
93- this . isShown = ! this . isShown ;
94- this . updateCss ( ) ;
95- }
96- }
97-
9866 public ngOnChanges ( changes : SimpleChanges ) : void {
99- this . service . setTabIndexValue ( this . tabIndexValue ) ;
10067 this . currentBackgroundColor = this . utils . readProperty (
10168 "--sidenav-backgroundColor"
10269 ) ;
@@ -105,41 +72,6 @@ export class DxcSidenavComponent implements OnInit {
10572 return result ;
10673 } , { } ) ;
10774 this . defaultInputs . next ( { ...this . defaultInputs . getValue ( ) , ...inputs } ) ;
108- if ( this . sidenav ) {
109- this . updateCss ( ) ;
110- }
111- }
112-
113- updateState ( ) {
114- this . innerWidth = window . innerWidth ;
115- if ( this . innerWidth <= responsiveSizes . tablet ) {
116- this . isResponsive = true ;
117- if ( ! this . displayArrow ) {
118- this . displayArrow = true ;
119- }
120- } else {
121- this . isResponsive = false ;
122- if ( ! this . displayArrow && ! this . isShown ) {
123- this . isShown = true ;
124- }
125- }
126- this . isShown =
127- this . isShown !== undefined
128- ? this . isShown
129- : this . innerWidth <= responsiveSizes . tablet
130- ? false
131- : true ;
132- }
133-
134- updateCss ( ) {
135- this . updateState ( ) ;
136- this . sidenavStyles = `${ this . getDynamicStyle ( {
137- ...this . defaultInputs . getValue ( ) ,
138- mode : this . mode ,
139- innerWidth : this . innerWidth ,
140- isResponsive : this . isResponsive ,
141- isShown : this . isShown ,
142- } ) } `;
14375 }
14476
14577 getDynamicStyle ( inputs ) {
0 commit comments