Skip to content

Commit c43ffda

Browse files
committed
refactor(collapse): use @input() transform
1 parent b08aa14 commit c43ffda

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

projects/coreui-angular/src/lib/collapse/collapse.directive.ts

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
AfterViewInit,
3+
booleanAttribute,
34
Directive,
45
DoCheck,
56
ElementRef,
@@ -14,8 +15,6 @@ import {
1415
} from '@angular/core';
1516
import { AnimationBuilder, AnimationPlayer, useAnimation } from '@angular/animations';
1617

17-
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
18-
1918
import {
2019
collapseAnimation,
2120
collapseHorizontalAnimation,
@@ -32,65 +31,40 @@ import {
3231
})
3332
export class CollapseDirective implements OnChanges, OnDestroy, DoCheck, AfterViewInit {
3433

35-
static ngAcceptInputType_horizontal: BooleanInput;
36-
static ngAcceptInputType_navbar: BooleanInput;
37-
static ngAcceptInputType_visible: BooleanInput;
38-
3934
/**
4035
* @ignore
4136
*/
42-
@Input()
43-
set animate(value: boolean) {
44-
this._animate = value;
45-
}
46-
47-
get animate(): boolean {
48-
return this._animate;
49-
}
50-
51-
private _animate = true;
37+
@Input({ transform: booleanAttribute }) animate: boolean = true;
5238

5339
/**
5440
* Set horizontal collapsing to transition the width instead of height.
41+
* @type boolean
42+
* @default false
5543
*/
56-
@Input()
57-
set horizontal(value: boolean) {
58-
this._horizontal = coerceBooleanProperty(value);
59-
}
60-
61-
get horizontal(): boolean {
62-
return this._horizontal;
63-
}
64-
65-
private _horizontal: boolean = false;
44+
@Input({ transform: booleanAttribute }) horizontal: boolean = false;
6645

6746
/**
6847
* Toggle the visibility of collapsible element.
48+
* @type boolean
49+
* @default false
6950
*/
70-
@Input()
51+
@Input({ transform: booleanAttribute })
7152
set visible(value) {
72-
this._visible = coerceBooleanProperty(value);
53+
this._visible = value;
7354
}
7455

7556
get visible(): boolean {
7657
return this._visible;
7758
}
7859

79-
private _visible = false;
60+
private _visible: boolean = false;
8061

8162
/**
8263
* Add `navbar` prop for grouping and hiding navbar contents by a parent breakpoint.
64+
* @type boolean
65+
* @default false
8366
*/
84-
@Input()
85-
set navbar(value: boolean) {
86-
this._navbar = coerceBooleanProperty(value);
87-
};
88-
89-
get navbar() {
90-
return this._navbar;
91-
}
92-
93-
private _navbar = false;
67+
@Input({ transform: booleanAttribute }) navbar: boolean = false;
9468

9569
/**
9670
* @ignore

0 commit comments

Comments
 (0)