UNPKG

9.2 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('@angular/common'), require('ngx-bootstrap/collapse')) :
3 typeof define === 'function' && define.amd ? define('ngx-bootstrap/accordion', ['exports', '@angular/core', 'ngx-bootstrap/utils', '@angular/common', 'ngx-bootstrap/collapse'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].accordion = {}), global.ng.core, global.utils, global.ng.common, global.collapse));
5}(this, (function (exports, i0, utils, common, collapse) { 'use strict';
6
7 /**
8 * Configuration service, provides default values for the AccordionComponent.
9 */
10 var AccordionConfig = /** @class */ (function () {
11 function AccordionConfig() {
12 /** Whether the other panels should be closed when a panel is opened */
13 this.closeOthers = false;
14 /** turn on/off animation */
15 this.isAnimated = false;
16 }
17 return AccordionConfig;
18 }());
19 AccordionConfig.ɵprov = i0.ɵɵdefineInjectable({ factory: function AccordionConfig_Factory() { return new AccordionConfig(); }, token: AccordionConfig, providedIn: "root" });
20 AccordionConfig.decorators = [
21 { type: i0.Injectable, args: [{
22 providedIn: 'root'
23 },] }
24 ];
25
26 /** Displays collapsible content panels for presenting information in a limited amount of space. */
27 var AccordionComponent = /** @class */ (function () {
28 function AccordionComponent(config) {
29 /** turn on/off animation */
30 this.isAnimated = false;
31 /** if `true` expanding one item will close all others */
32 this.closeOthers = false;
33 this.groups = [];
34 Object.assign(this, config);
35 }
36 AccordionComponent.prototype.closeOtherPanels = function (openGroup) {
37 if (!this.closeOthers) {
38 return;
39 }
40 this.groups.forEach(function (group) {
41 if (group !== openGroup) {
42 group.isOpen = false;
43 }
44 });
45 };
46 AccordionComponent.prototype.addGroup = function (group) {
47 group.isAnimated = this.isAnimated;
48 this.groups.push(group);
49 };
50 AccordionComponent.prototype.removeGroup = function (group) {
51 var index = this.groups.indexOf(group);
52 if (index !== -1) {
53 this.groups.splice(index, 1);
54 }
55 };
56 return AccordionComponent;
57 }());
58 AccordionComponent.decorators = [
59 { type: i0.Component, args: [{
60 selector: 'accordion',
61 template: "<ng-content></ng-content>",
62 // eslint-disable-next-line @angular-eslint/no-host-metadata-property
63 host: {
64 '[attr.aria-multiselectable]': 'closeOthers',
65 role: 'tablist',
66 class: 'panel-group',
67 style: 'display: block'
68 }
69 },] }
70 ];
71 AccordionComponent.ctorParameters = function () { return [
72 { type: AccordionConfig }
73 ]; };
74 AccordionComponent.propDecorators = {
75 isAnimated: [{ type: i0.Input }],
76 closeOthers: [{ type: i0.Input }]
77 };
78
79 /**
80 * ### Accordion heading
81 * Instead of using `heading` attribute on the `accordion-group`, you can use
82 * an `accordion-heading` attribute on `any` element inside of a group that
83 * will be used as group's header template.
84 */
85 var AccordionPanelComponent = /** @class */ (function () {
86 function AccordionPanelComponent(accordion) {
87 /** turn on/off animation */
88 this.isAnimated = false;
89 /** Provides an ability to use Bootstrap's contextual panel classes
90 * (`panel-primary`, `panel-success`, `panel-info`, etc...).
91 * List of all available classes [available here]
92 * (https://getbootstrap.com/docs/3.3/components/#panels-alternatives)
93 */
94 this.panelClass = 'panel-default';
95 /** if <code>true</code> — disables accordion group */
96 this.isDisabled = false;
97 /** Emits when the opened state changes */
98 this.isOpenChange = new i0.EventEmitter();
99 this._isOpen = false;
100 this.accordion = accordion;
101 }
102 Object.defineProperty(AccordionPanelComponent.prototype, "isOpen", {
103 // Questionable, maybe .panel-open should be on child div.panel element?
104 /** Is accordion group open or closed. This property supports two-way binding */
105 get: function () {
106 return this._isOpen;
107 },
108 set: function (value) {
109 var _this = this;
110 if (value !== this.isOpen) {
111 if (value) {
112 this.accordion.closeOtherPanels(this);
113 }
114 this._isOpen = value;
115 Promise.resolve(null)
116 .then(function () {
117 _this.isOpenChange.emit(value);
118 });
119 }
120 },
121 enumerable: false,
122 configurable: true
123 });
124 Object.defineProperty(AccordionPanelComponent.prototype, "isBs3", {
125 get: function () {
126 return utils.isBs3();
127 },
128 enumerable: false,
129 configurable: true
130 });
131 AccordionPanelComponent.prototype.ngOnInit = function () {
132 this.accordion.addGroup(this);
133 };
134 AccordionPanelComponent.prototype.ngOnDestroy = function () {
135 this.accordion.removeGroup(this);
136 };
137 AccordionPanelComponent.prototype.toggleOpen = function () {
138 if (!this.isDisabled) {
139 this.isOpen = !this.isOpen;
140 }
141 };
142 return AccordionPanelComponent;
143 }());
144 AccordionPanelComponent.decorators = [
145 { type: i0.Component, args: [{
146 selector: 'accordion-group, accordion-panel',
147 template: "<div class=\"panel card\" [ngClass]=\"panelClass\">\n <div\n class=\"panel-heading card-header\"\n role=\"tab\"\n (click)=\"toggleOpen()\"\n [ngClass]=\"isDisabled ? 'panel-disabled' : 'panel-enabled'\"\n >\n <div class=\"panel-title\">\n <div role=\"button\" class=\"accordion-toggle\" [attr.aria-expanded]=\"isOpen\">\n <button class=\"btn btn-link\" *ngIf=\"heading\" [ngClass]=\"{ 'text-muted': isDisabled }\" type=\"button\">\n {{ heading }}\n </button>\n <ng-content select=\"[accordion-heading]\"></ng-content>\n </div>\n </div>\n </div>\n <div class=\"panel-collapse collapse\" role=\"tabpanel\" [collapse]=\"!isOpen\" [isAnimated]=\"isAnimated\">\n <div class=\"panel-body card-block card-body\">\n <ng-content></ng-content>\n </div>\n </div>\n</div>\n",
148 // eslint-disable-next-line @angular-eslint/no-host-metadata-property
149 host: {
150 class: 'panel',
151 style: 'display: block'
152 },
153 styles: [":host .card-header.panel-enabled{cursor:pointer}:host .card-header.panel-disabled .btn.btn-link{cursor:default;text-decoration:none}"]
154 },] }
155 ];
156 AccordionPanelComponent.ctorParameters = function () { return [
157 { type: AccordionComponent, decorators: [{ type: i0.Inject, args: [AccordionComponent,] }] }
158 ]; };
159 AccordionPanelComponent.propDecorators = {
160 heading: [{ type: i0.Input }],
161 panelClass: [{ type: i0.Input }],
162 isDisabled: [{ type: i0.Input }],
163 isOpenChange: [{ type: i0.Output }],
164 isOpen: [{ type: i0.HostBinding, args: ['class.panel-open',] }, { type: i0.Input }]
165 };
166
167 var AccordionModule = /** @class */ (function () {
168 function AccordionModule() {
169 }
170 AccordionModule.forRoot = function () {
171 return { ngModule: AccordionModule, providers: [] };
172 };
173 return AccordionModule;
174 }());
175 AccordionModule.decorators = [
176 { type: i0.NgModule, args: [{
177 imports: [common.CommonModule, collapse.CollapseModule],
178 declarations: [AccordionComponent, AccordionPanelComponent],
179 exports: [AccordionComponent, AccordionPanelComponent]
180 },] }
181 ];
182
183 /**
184 * Generated bundle index. Do not edit.
185 */
186
187 exports.AccordionComponent = AccordionComponent;
188 exports.AccordionConfig = AccordionConfig;
189 exports.AccordionModule = AccordionModule;
190 exports.AccordionPanelComponent = AccordionPanelComponent;
191
192 Object.defineProperty(exports, '__esModule', { value: true });
193
194})));
195//# sourceMappingURL=ngx-bootstrap-accordion.umd.js.map