Skip to content

Commit

Permalink
feat(accordion): add config file for accordion component
Browse files Browse the repository at this point in the history
* feat(karma config for saucelabs testing)

* revert changes

* feat(accordion): add config file for accordion component
  • Loading branch information
musienkoyuriy authored and valorkin committed Dec 14, 2016
1 parent d8870d6 commit 0838055
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/accordion/accordion.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, HostBinding, Input } from '@angular/core';
import { AccordionPanelComponent } from './accordion-group.component';
import { AccordionConfig } from './accordion.config';

@Component({
selector: 'accordion',
Expand All @@ -15,6 +16,10 @@ export class AccordionComponent {

protected groups:AccordionPanelComponent[] = [];

public constructor(config: AccordionConfig) {
Object.assign(this, config);
}

public closeOtherPanels(openGroup:AccordionPanelComponent):void {
if (!this.closeOthers) {
return;
Expand Down
6 changes: 6 additions & 0 deletions src/accordion/accordion.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Injectable } from '@angular/core';

Injectable();
export class AccordionConfig {
public closeOthers: Boolean = false;
}
3 changes: 2 additions & 1 deletion src/accordion/accordion.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { NgModule, ModuleWithProviders } from '@angular/core';
import { CollapseModule } from '../collapse/collapse.module';
import { AccordionPanelComponent } from './accordion-group.component';
import { AccordionComponent } from './accordion.component';
import { AccordionConfig } from './accordion.config';

@NgModule({
imports: [CommonModule, CollapseModule],
declarations: [AccordionComponent, AccordionPanelComponent],
exports: [AccordionComponent, AccordionPanelComponent]
})
export class AccordionModule {
public static forRoot(): ModuleWithProviders {return {ngModule: AccordionModule, providers: []};}
public static forRoot(): ModuleWithProviders {return {ngModule: AccordionModule, providers: [AccordionConfig]};}
}
1 change: 1 addition & 0 deletions src/accordion/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { AccordionPanelComponent } from './accordion-group.component';
export { AccordionComponent } from './accordion.component';
export { AccordionModule } from './accordion.module';
export { AccordionConfig } from './accordion.config';
7 changes: 6 additions & 1 deletion src/spec/accordion.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AccordionModule } from '../accordion/accordion.module';
import { AccordionConfig } from '../accordion/accordion.config';

const html = `
<accordion [closeOthers]="oneAtATime">
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('Component: Accordion', () => {
let element:any;

beforeEach(() => {
TestBed.configureTestingModule({declarations: [TestAccordionComponent], imports: [AccordionModule]});
TestBed.configureTestingModule({declarations: [TestAccordionComponent], imports: [AccordionModule.forRoot()]});
TestBed.overrideComponent(TestAccordionComponent, {set: {template: html}});
fixture = TestBed.createComponent(TestAccordionComponent);
context = fixture.componentInstance;
Expand Down Expand Up @@ -150,4 +151,8 @@ class TestAccordionComponent {
{isOpen: false, isDisabled: false},
{isOpen: false, isDisabled: false}
];

public constructor(config: AccordionConfig) {
Object.assign(this, config);
}
}

0 comments on commit 0838055

Please sign in to comment.