UNPKG

3.99 kBJavaScriptView Raw
1import { Directive, ElementRef, EventEmitter, HostBinding, Input, Output, Renderer } from '@angular/core';
2export var CollapseDirective = (function () {
3 function CollapseDirective(_el, _renderer) {
4 /** This event fires as soon as content collapses */
5 this.collapsed = new EventEmitter();
6 /** This event fires as soon as content becomes visible */
7 this.expanded = new EventEmitter();
8 // shown
9 this.isExpanded = true;
10 // hidden
11 this.isCollapsed = false;
12 // stale state
13 this.isCollapse = true;
14 // animation state
15 this.isCollapsing = false;
16 this._el = _el;
17 this._renderer = _renderer;
18 }
19 Object.defineProperty(CollapseDirective.prototype, "collapse", {
20 get: function () {
21 return this.isExpanded;
22 },
23 /** A flag indicating visibility of content (shown or hidden) */
24 set: function (value) {
25 this.isExpanded = value;
26 this.toggle();
27 },
28 enumerable: true,
29 configurable: true
30 });
31 /** allows to manually toggle content visibility */
32 CollapseDirective.prototype.toggle = function () {
33 if (this.isExpanded) {
34 this.hide();
35 }
36 else {
37 this.show();
38 }
39 };
40 /** allows to manually hide content */
41 CollapseDirective.prototype.hide = function () {
42 this.isCollapse = false;
43 this.isCollapsing = true;
44 this.isExpanded = false;
45 this.isCollapsed = true;
46 this.isCollapse = true;
47 this.isCollapsing = false;
48 this.display = 'none';
49 this.collapsed.emit(this);
50 };
51 /** allows to manually show collapsed content */
52 CollapseDirective.prototype.show = function () {
53 this.isCollapse = false;
54 this.isCollapsing = true;
55 this.isExpanded = true;
56 this.isCollapsed = false;
57 this.display = 'block';
58 // this.height = 'auto';
59 this.isCollapse = true;
60 this.isCollapsing = false;
61 this._renderer.setElementStyle(this._el.nativeElement, 'overflow', 'visible');
62 this._renderer.setElementStyle(this._el.nativeElement, 'height', 'auto');
63 this.expanded.emit(this);
64 };
65 CollapseDirective.decorators = [
66 { type: Directive, args: [{
67 selector: '[collapse]',
68 exportAs: 'bs-collapse',
69 /* tslint:disable-next-line */
70 host: { '[class.collapse]': 'true' } /*,
71 animations: [
72 trigger('active', [
73 state('void', style({height: 0})),
74 state('closed', style({height: 0})),
75 state('open', style({height: '*'})),
76 transition('void => closed', [animate(0)]),
77 transition('closed => open', [animate('350ms ease-out')]),
78 transition('open => closed', [animate('350ms ease-out')])
79 ])
80 ]*/
81 },] },
82 ];
83 /** @nocollapse */
84 CollapseDirective.ctorParameters = function () { return [
85 { type: ElementRef, },
86 { type: Renderer, },
87 ]; };
88 CollapseDirective.propDecorators = {
89 'collapsed': [{ type: Output },],
90 'expanded': [{ type: Output },],
91 'display': [{ type: HostBinding, args: ['style.display',] },],
92 'isExpanded': [{ type: HostBinding, args: ['class.in',] }, { type: HostBinding, args: ['class.show',] }, { type: HostBinding, args: ['attr.aria-expanded',] },],
93 'isCollapsed': [{ type: HostBinding, args: ['attr.aria-hidden',] },],
94 'isCollapse': [{ type: HostBinding, args: ['class.collapse',] },],
95 'isCollapsing': [{ type: HostBinding, args: ['class.collapsing',] },],
96 'collapse': [{ type: Input },],
97 };
98 return CollapseDirective;
99}());
100//# sourceMappingURL=collapse.directive.js.map
\No newline at end of file