UNPKG

9.01 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/animations'), require('@angular/core')) :
3 typeof define === 'function' && define.amd ? define('ngx-bootstrap/collapse', ['exports', '@angular/animations', '@angular/core'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].collapse = {}), global.ng.animations, global.ng.core));
5}(this, (function (exports, animations, core) { 'use strict';
6
7 var COLLAPSE_ANIMATION_TIMING = '400ms cubic-bezier(0.4,0.0,0.2,1)';
8 var expandAnimation = [
9 animations.style({ height: 0, visibility: 'hidden' }),
10 animations.animate(COLLAPSE_ANIMATION_TIMING, animations.style({ height: '*', visibility: 'visible' }))
11 ];
12 var collapseAnimation = [
13 animations.style({ height: '*', visibility: 'visible' }),
14 animations.animate(COLLAPSE_ANIMATION_TIMING, animations.style({ height: 0, visibility: 'hidden' }))
15 ];
16
17 var CollapseDirective = /** @class */ (function () {
18 function CollapseDirective(_el, _renderer, _builder) {
19 this._el = _el;
20 this._renderer = _renderer;
21 /** This event fires as soon as content collapses */
22 this.collapsed = new core.EventEmitter();
23 /** This event fires when collapsing is started */
24 this.collapses = new core.EventEmitter();
25 /** This event fires as soon as content becomes visible */
26 this.expanded = new core.EventEmitter();
27 /** This event fires when expansion is started */
28 this.expands = new core.EventEmitter();
29 // shown
30 this.isExpanded = true;
31 this.collapseNewValue = true;
32 // hidden
33 this.isCollapsed = false;
34 // stale state
35 this.isCollapse = true;
36 // animation state
37 this.isCollapsing = false;
38 /** turn on/off animation */
39 this.isAnimated = false;
40 this._display = 'block';
41 this._stylesLoaded = false;
42 this._COLLAPSE_ACTION_NAME = 'collapse';
43 this._EXPAND_ACTION_NAME = 'expand';
44 this._factoryCollapseAnimation = _builder.build(collapseAnimation);
45 this._factoryExpandAnimation = _builder.build(expandAnimation);
46 }
47 Object.defineProperty(CollapseDirective.prototype, "display", {
48 set: function (value) {
49 if (!this.isAnimated) {
50 this._renderer.setStyle(this._el.nativeElement, 'display', value);
51 return;
52 }
53 this._display = value;
54 if (value === 'none') {
55 this.hide();
56 return;
57 }
58 this.show();
59 },
60 enumerable: false,
61 configurable: true
62 });
63 Object.defineProperty(CollapseDirective.prototype, "collapse", {
64 get: function () {
65 return this.isExpanded;
66 },
67 /** A flag indicating visibility of content (shown or hidden) */
68 set: function (value) {
69 this.collapseNewValue = value;
70 if (!this._player || this._isAnimationDone) {
71 this.isExpanded = value;
72 this.toggle();
73 }
74 },
75 enumerable: false,
76 configurable: true
77 });
78 CollapseDirective.prototype.ngAfterViewChecked = function () {
79 this._stylesLoaded = true;
80 if (!this._player || !this._isAnimationDone) {
81 return;
82 }
83 this._player.reset();
84 this._renderer.setStyle(this._el.nativeElement, 'height', '*');
85 };
86 /** allows to manually toggle content visibility */
87 CollapseDirective.prototype.toggle = function () {
88 if (this.isExpanded) {
89 this.hide();
90 }
91 else {
92 this.show();
93 }
94 };
95 /** allows to manually hide content */
96 CollapseDirective.prototype.hide = function () {
97 var _this = this;
98 this.isCollapsing = true;
99 this.isExpanded = false;
100 this.isCollapsed = true;
101 this.isCollapsing = false;
102 this.collapses.emit(this);
103 this._isAnimationDone = false;
104 this.animationRun(this.isAnimated, this._COLLAPSE_ACTION_NAME)(function () {
105 _this._isAnimationDone = true;
106 if (_this.collapseNewValue !== _this.isCollapsed && _this.isAnimated) {
107 _this.show();
108 return;
109 }
110 _this.collapsed.emit(_this);
111 _this._renderer.setStyle(_this._el.nativeElement, 'display', 'none');
112 });
113 };
114 /** allows to manually show collapsed content */
115 CollapseDirective.prototype.show = function () {
116 var _this = this;
117 this._renderer.setStyle(this._el.nativeElement, 'display', this._display);
118 this.isCollapsing = true;
119 this.isExpanded = true;
120 this.isCollapsed = false;
121 this.isCollapsing = false;
122 this.expands.emit(this);
123 this._isAnimationDone = false;
124 this.animationRun(this.isAnimated, this._EXPAND_ACTION_NAME)(function () {
125 _this._isAnimationDone = true;
126 if (_this.collapseNewValue !== _this.isCollapsed && _this.isAnimated) {
127 _this.hide();
128 return;
129 }
130 _this.expanded.emit(_this);
131 _this._renderer.removeStyle(_this._el.nativeElement, 'overflow');
132 });
133 };
134 CollapseDirective.prototype.animationRun = function (isAnimated, action) {
135 var _this = this;
136 if (!isAnimated || !this._stylesLoaded) {
137 return function (callback) { return callback(); };
138 }
139 this._renderer.setStyle(this._el.nativeElement, 'overflow', 'hidden');
140 this._renderer.addClass(this._el.nativeElement, 'collapse');
141 var factoryAnimation = (action === this._EXPAND_ACTION_NAME)
142 ? this._factoryExpandAnimation
143 : this._factoryCollapseAnimation;
144 if (this._player) {
145 this._player.destroy();
146 }
147 this._player = factoryAnimation.create(this._el.nativeElement);
148 this._player.play();
149 return function (callback) { var _a; return (_a = _this._player) === null || _a === void 0 ? void 0 : _a.onDone(callback); };
150 };
151 return CollapseDirective;
152 }());
153 CollapseDirective.decorators = [
154 { type: core.Directive, args: [{
155 selector: '[collapse]',
156 exportAs: 'bs-collapse',
157 // eslint-disable-next-line @angular-eslint/no-host-metadata-property
158 host: {
159 '[class.collapse]': 'true'
160 }
161 },] }
162 ];
163 CollapseDirective.ctorParameters = function () { return [
164 { type: core.ElementRef },
165 { type: core.Renderer2 },
166 { type: animations.AnimationBuilder }
167 ]; };
168 CollapseDirective.propDecorators = {
169 collapsed: [{ type: core.Output }],
170 collapses: [{ type: core.Output }],
171 expanded: [{ type: core.Output }],
172 expands: [{ type: core.Output }],
173 isExpanded: [{ type: core.HostBinding, args: ['class.in',] }, { type: core.HostBinding, args: ['class.show',] }, { type: core.HostBinding, args: ['attr.aria-expanded',] }],
174 isCollapsed: [{ type: core.HostBinding, args: ['attr.aria-hidden',] }],
175 isCollapse: [{ type: core.HostBinding, args: ['class.collapse',] }],
176 isCollapsing: [{ type: core.HostBinding, args: ['class.collapsing',] }],
177 display: [{ type: core.Input }],
178 isAnimated: [{ type: core.Input }],
179 collapse: [{ type: core.Input }]
180 };
181
182 var CollapseModule = /** @class */ (function () {
183 function CollapseModule() {
184 }
185 CollapseModule.forRoot = function () {
186 return { ngModule: CollapseModule, providers: [] };
187 };
188 return CollapseModule;
189 }());
190 CollapseModule.decorators = [
191 { type: core.NgModule, args: [{
192 declarations: [CollapseDirective],
193 exports: [CollapseDirective]
194 },] }
195 ];
196
197 /**
198 * Generated bundle index. Do not edit.
199 */
200
201 exports.CollapseDirective = CollapseDirective;
202 exports.CollapseModule = CollapseModule;
203
204 Object.defineProperty(exports, '__esModule', { value: true });
205
206})));
207//# sourceMappingURL=ngx-bootstrap-collapse.umd.js.map