Skip to content

Commit

Permalink
feat(collapse): add 'NgbCollapseConfig' (#3736)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxokorokov committed May 18, 2020
1 parent 0416a6a commit 8d5417a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/collapse/collapse-config.spec.ts
@@ -0,0 +1,11 @@
import {NgbConfig} from '../ngb-config';
import {NgbCollapseConfig} from './collapse-config';

describe('ngb-collapse-config', () => {
it('should have sensible default values', () => {
const config = new NgbConfig();
const collapseConfig = new NgbCollapseConfig(config);

expect(collapseConfig.animation).toBe(config.animation);
});
});
15 changes: 15 additions & 0 deletions src/collapse/collapse-config.ts
@@ -0,0 +1,15 @@
import {Injectable} from '@angular/core';
import {NgbConfig} from '../ngb-config';

/**
* A configuration service for the [NgbCollapse](#/components/collapse/api#NgbCollapse) component.
*
* You can inject this service, typically in your root component, and customize its properties
* to provide default values for all collapses used in the application.
*/
@Injectable({providedIn: 'root'})
export class NgbCollapseConfig {
animation: boolean;

constructor(ngbConfig: NgbConfig) { this.animation = ngbConfig.animation; }
}
1 change: 1 addition & 0 deletions src/collapse/collapse.module.ts
Expand Up @@ -2,6 +2,7 @@ import {NgModule} from '@angular/core';
import {NgbCollapse} from './collapse';

export {NgbCollapse} from './collapse';
export {NgbCollapseConfig} from './collapse-config';

@NgModule({declarations: [NgbCollapse], exports: [NgbCollapse]})
export class NgbCollapseModule {
Expand Down
4 changes: 2 additions & 2 deletions src/collapse/collapse.ts
@@ -1,7 +1,7 @@
import {Directive, Input, ElementRef, Output, EventEmitter} from '@angular/core';
import {ngbRunTransition} from '../util/transition/ngbTransition';
import {ngbCollapsingTransition} from '../util/transition/ngbCollapseTransition';
import {NgbConfig} from '../ngb-config';
import {NgbCollapseConfig} from './collapse-config';

/**
* A directive to provide a simple way of hiding and showing elements on the page.
Expand All @@ -27,7 +27,7 @@ export class NgbCollapse {

@Output() ngbCollapseChange = new EventEmitter<boolean>();

constructor(private _element: ElementRef, ngbConfig: NgbConfig) { this.animation = ngbConfig.animation; }
constructor(private _element: ElementRef, config: NgbCollapseConfig) { this.animation = config.animation; }

/**
* Triggers collapsing programmatically.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -44,7 +44,7 @@ export {
NgbSlideEventDirection,
NgbSlideEventSource
} from './carousel/carousel.module';
export {NgbCollapse, NgbCollapseModule} from './collapse/collapse.module';
export {NgbCollapse, NgbCollapseConfig, NgbCollapseModule} from './collapse/collapse.module';
export {
NgbCalendar,
NgbCalendarGregorian,
Expand Down

0 comments on commit 8d5417a

Please sign in to comment.