1
1
import {
2
+ booleanAttribute ,
2
3
Component ,
3
4
EventEmitter ,
4
5
HostBinding ,
@@ -12,7 +13,6 @@ import {
12
13
SimpleChanges
13
14
} from '@angular/core' ;
14
15
import { DOCUMENT } from '@angular/common' ;
15
- import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
16
16
import { BreakpointObserver , BreakpointState } from '@angular/cdk/layout' ;
17
17
import { Subscription } from 'rxjs' ;
18
18
@@ -22,18 +22,11 @@ import { SidebarBackdropService } from '../sidebar-backdrop/sidebar-backdrop.ser
22
22
@Component ( {
23
23
selector : 'c-sidebar' ,
24
24
exportAs : 'cSidebar' ,
25
- template : '<ng-content></ng-content >' ,
25
+ template : '<ng-content / >' ,
26
26
standalone : true
27
27
} )
28
28
export class SidebarComponent implements OnChanges , OnDestroy , OnInit {
29
- static ngAcceptInputType_narrow : BooleanInput ;
30
- static ngAcceptInputType_overlaid : BooleanInput ;
31
- static ngAcceptInputType_unfoldable : BooleanInput ;
32
- static ngAcceptInputType_visible : BooleanInput ;
33
-
34
- #narrow = false ;
35
- #overlaid = false ;
36
- #unfoldable = false ;
29
+
37
30
#visible = false ;
38
31
#onMobile = false ;
39
32
#layoutChangeSubscription! : Subscription ;
@@ -66,28 +59,16 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
66
59
/**
67
60
* Make sidebar narrow. [docs]
68
61
* @type boolean
62
+ * @default false
69
63
*/
70
- @Input ( )
71
- set narrow ( value : boolean ) {
72
- this . #narrow = coerceBooleanProperty ( value ) ;
73
- }
74
-
75
- get narrow ( ) {
76
- return this . #narrow;
77
- }
64
+ @Input ( { transform : booleanAttribute } ) narrow : boolean = false ;
78
65
79
66
/**
80
67
* Set sidebar to overlaid variant.
81
68
* @type boolean
69
+ * @default false
82
70
*/
83
- @Input ( )
84
- set overlaid ( value : boolean ) {
85
- this . #overlaid = coerceBooleanProperty ( value ) ;
86
- }
87
-
88
- get overlaid ( ) {
89
- return this . #overlaid;
90
- }
71
+ @Input ( { transform : booleanAttribute } ) overlaid : boolean = false ;
91
72
92
73
/**
93
74
* Components placement, there’s no default placement. [docs]
@@ -108,22 +89,19 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
108
89
109
90
/**
110
91
* Expand narrowed sidebar on hover. [docs]
92
+ * @type boolean
93
+ * @default false
111
94
*/
112
- @Input ( )
113
- set unfoldable ( value : boolean ) {
114
- this . #unfoldable = coerceBooleanProperty ( value ) ;
115
- }
116
-
117
- get unfoldable ( ) {
118
- return this . #unfoldable;
119
- }
95
+ @Input ( { transform : booleanAttribute } ) unfoldable : boolean = false ;
120
96
121
97
/**
122
98
* Toggle the visibility of sidebar component. [docs]
99
+ * @type boolean
100
+ * @default false
123
101
*/
124
- @Input ( )
102
+ @Input ( { transform : booleanAttribute } )
125
103
set visible ( value : boolean ) {
126
- const visible = coerceBooleanProperty ( value ) ;
104
+ const visible = value ;
127
105
if ( this . #visible !== visible ) {
128
106
this . #visible = visible ;
129
107
this . visibleChange . emit ( this . #visible) ;
@@ -192,8 +170,11 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
192
170
'sidebar-narrow' : this . narrow && ! this . unfoldable ,
193
171
'sidebar-narrow-unfoldable' : this . unfoldable ,
194
172
'sidebar-overlaid' : this . overlaid ,
173
+ [ `sidebar-${ this . placement } ` ] : ! ! this . placement ,
174
+ [ `sidebar-${ this . colorScheme } ` ] : ! ! this . colorScheme ,
195
175
[ `sidebar-${ this . size } ` ] : ! ! this . size ,
196
- show : visible && this . #onMobile,
176
+ show : visible ,
177
+ // show: visible && this.#onMobile, //todo: check
197
178
hide : ! visible
198
179
} ;
199
180
}
@@ -219,7 +200,7 @@ export class SidebarComponent implements OnChanges, OnDestroy, OnInit {
219
200
for ( const propName in changes ) {
220
201
if ( propList . includes ( propName ) ) {
221
202
if ( changes [ propName ] && ! changes [ propName ] . firstChange ) {
222
- const value = coerceBooleanProperty ( changes [ propName ] . currentValue ) ;
203
+ const value = booleanAttribute ( changes [ propName ] . currentValue ) ;
223
204
if ( oldStateMap . get ( propName ) !== value ) {
224
205
newStateMap . set ( propName , value ) ;
225
206
}
0 commit comments