Skip to content

Commit 82e540e

Browse files
committed
Upgraded Accordion, Checkbox, Collapse
1 parent 53ad505 commit 82e540e

File tree

111 files changed

+1196
-789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1196
-789
lines changed

angular-cli.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
{
2-
"project": {
3-
"version": "1.0.0-beta.11-webpack.2",
4-
"name": "ng2-semantic-ui"
5-
},
6-
"apps": [
7-
{
8-
"main": "demo/main.ts",
9-
"tsconfig": "demo/tsconfig.json",
10-
"mobile": false
2+
"project": {
3+
"version": "1.0.0-beta.11-webpack.2",
4+
"name": "ng2-semantic-ui"
5+
},
6+
"apps": [
7+
{
8+
"main": "demo/main.ts",
9+
"tsconfig": "demo/tsconfig.json",
10+
"mobile": false
11+
}
12+
],
13+
"addons": [],
14+
"packages": [],
15+
"e2e": {
16+
"protractor": {
17+
"config": "demo/config/protractor.conf.js"
18+
}
19+
},
20+
"test": {
21+
"karma": {
22+
"config": "demo/config/karma.conf.js"
23+
}
24+
},
25+
"defaults": {
26+
"prefix": "demo",
27+
"sourceDir": "demo",
28+
"styleExt": "css",
29+
"prefixInterfaces": false,
30+
"lazyRoutePrefix": "+"
1131
}
12-
],
13-
"addons": [],
14-
"packages": [],
15-
"e2e": {
16-
"protractor": {
17-
"config": "demo/config/protractor.conf.js"
18-
}
19-
},
20-
"test": {
21-
"karma": {
22-
"config": "demo/config/karma.conf.js"
23-
}
24-
},
25-
"defaults": {
26-
"prefix": "app",
27-
"sourceDir": "demo",
28-
"styleExt": "css",
29-
"prefixInterfaces": false,
30-
"lazyRoutePrefix": "+"
31-
}
3232
}

components/accordion/accordion-panel.component.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {Component, Input, Output, EventEmitter} from '@angular/core';
2+
import {SuiAccordionService} from "./accordion.service";
3+
4+
@Component({
5+
selector: 'sui-accordion-panel',
6+
exportAs: 'suiAccordionPanel',
7+
template: `
8+
<div class="title" [class.active]="isOpen" (click)="toggleOpen($event)">
9+
<ng-content select="[title]"></ng-content>
10+
</div>
11+
<div [suiCollapse]="!isOpen">
12+
<div class="content" [class.active]="isOpen">
13+
<ng-content select="[content]"></ng-content>
14+
</div>
15+
</div>
16+
`,
17+
styles: [`
18+
.content {
19+
padding: .5em 0 1em
20+
}
21+
22+
:host:last-child .content {
23+
padding-bottom: 0
24+
}
25+
`]
26+
})
27+
export class SuiAccordionPanel {
28+
private _service:SuiAccordionService;
29+
public set service(service:SuiAccordionService) {
30+
this._service = service;
31+
}
32+
33+
@Input() public isDisabled:boolean;
34+
35+
@Input()
36+
public get isOpen():boolean {
37+
return this._isOpen;
38+
}
39+
@Output() public isOpenChange:EventEmitter<boolean> = new EventEmitter<boolean>(false);
40+
41+
public set isOpen(value:boolean) {
42+
this._isOpen = value;
43+
if (value && this._service) {
44+
this._service.closeOtherPanels(this);
45+
}
46+
this.isOpenChange.emit(this._isOpen);
47+
}
48+
49+
private _isOpen:boolean = false;
50+
51+
public toggleOpen(event:MouseEvent):any {
52+
event.preventDefault();
53+
if (!this.isDisabled) {
54+
this.isOpen = !this.isOpen;
55+
}
56+
}
57+
}

components/accordion/accordion.component.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {NgModule} from '@angular/core';
2+
import {SUI_ACCORDION_DIRECTIVES, SUI_ACCORDION_PROVIDERS} from "./accordion";
3+
import {SuiCollapseModule} from "../collapse/collapse.module";
4+
5+
@NgModule({
6+
imports: [SuiCollapseModule],
7+
declarations: SUI_ACCORDION_DIRECTIVES,
8+
exports: SUI_ACCORDION_DIRECTIVES,
9+
providers: SUI_ACCORDION_PROVIDERS
10+
})
11+
export class SuiAccordionModule {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {SuiAccordionPanel} from "./accordion-panel";
2+
3+
export class SuiAccordionService {
4+
// State
5+
public closeOthers:boolean = true;
6+
7+
public panels:SuiAccordionPanel[] = [];
8+
9+
public addPanel(panel:SuiAccordionPanel) {
10+
panel.service = this;
11+
this.panels.push(panel);
12+
}
13+
14+
public closeOtherPanels(panel:SuiAccordionPanel) {
15+
if (!this.closeOthers) {
16+
return;
17+
}
18+
19+
this.panels.forEach((p:SuiAccordionPanel) => {
20+
if (p !== panel) {
21+
p.isOpen = false;
22+
}
23+
});
24+
}
25+
}

components/accordion/accordion.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {
2+
Component, Input, HostBinding, ContentChildren, QueryList,
3+
AfterContentInit
4+
} from "@angular/core";
5+
import {SuiAccordionPanel} from "./accordion-panel";
6+
import {SuiAccordionService} from "./accordion.service";
7+
8+
@Component({
9+
selector: 'sui-accordion',
10+
exportAs: 'suiAccordion',
11+
template: `
12+
<ng-content></ng-content>
13+
`,
14+
styles: [`
15+
/* Fix for general styling issues */
16+
:host {
17+
display: block;
18+
}
19+
/* Fix for styled border issue */
20+
:host.styled sui-accordion-panel:first-child .title {
21+
border-top: none
22+
}
23+
24+
`]
25+
})
26+
export class SuiAccordion implements AfterContentInit {
27+
@Input()
28+
public get closeOthers():boolean {
29+
return this._service.closeOthers;
30+
}
31+
32+
public set closeOthers(value:boolean) {
33+
this._service.closeOthers = value;
34+
}
35+
36+
@HostBinding('class.ui')
37+
@HostBinding('class.accordion') classes = true;
38+
39+
protected _service:SuiAccordionService;
40+
@ContentChildren(SuiAccordionPanel)
41+
protected panels:QueryList<SuiAccordionPanel>;
42+
43+
constructor() {
44+
this._service = new SuiAccordionService();
45+
}
46+
47+
ngAfterContentInit() {
48+
this.panels.forEach(p => this._service.addPanel(p));
49+
}
50+
}
51+
52+
export const SUI_ACCORDION_DIRECTIVES = [SuiAccordion, SuiAccordionPanel];
53+
export const SUI_ACCORDION_PROVIDERS = [SuiAccordionService];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {NgModule} from '@angular/core';
2+
import {FormsModule} from "@angular/forms";
3+
import {SUI_CHECKBOX_DIRECTIVES} from "./checkbox";
4+
import {SUI_RADIOBUTTON_DIRECTIVES} from "./radiobutton";
5+
6+
@NgModule({
7+
imports: [FormsModule],
8+
declarations: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES],
9+
exports: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES]
10+
})
11+
export class SuiCheckboxModule {}

0 commit comments

Comments
 (0)