Skip to content

Commit f60cb3a

Browse files
committed
fix #5
1 parent c555e19 commit f60cb3a

File tree

11 files changed

+166
-91
lines changed

11 files changed

+166
-91
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ demo/app/*.js
33
components/*.js
44
components/*/*.js
55
angular2-semantic-ui.js
6+
index.js
67
.vscode/
78
typings/

Diff for: .npmignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.vscode/
22
node_modules/
33
typings/
4-
components/**/**.js
5-
angular2-semantic-ui.js
6-
index.js
74
tsconfig.json
8-
typings.json
5+
typings.json
6+
systemjs.config.js

Diff for: README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ Angular2 Components for <a href="http://semantic-ui.com/">Semantic UI</a>
1212
```
1313
npm install angular2-semantic-ui --save
1414
15-
import { SEMANTIC_UI_COMPONENTS } from 'angular2-semantic-ui';
15+
import { L_SEMANTIC_UI_MODULE } from 'angular2-semantic-ui';
1616
```
1717

18-
#Demo
19-
<a href="https://lon-yang.github.io/angular2-semantic-ui-demo">Online Demo</a>&nbsp;&nbsp;&nbsp;&nbsp;
18+
# Demo
19+
<a href="https://lon-yang.github.io/angular2-semantic-ui-demo">Online Demo</a>
2020
<a href="https://github.com/lon-yang/angular2-semantic-ui-demo">Demo Code</a>
2121
```cmd
2222
git clone https://github.com/lon-yang/angular2-semantic-ui-demo.git
23-
2423
cd angular2-semantic-ui-demo
25-
2624
npm install
27-
2825
npm start
2926
```
3027

@@ -42,7 +39,10 @@ npm start
4239
- <a href="https://github.com/lon-yang/angular2-semantic-ui/tree/master/components/pagination">Pagination</a>
4340
- <a href="https://github.com/lon-yang/angular2-semantic-ui/tree/master/components/tags-input">Tags-Input</a>
4441

45-
#Change Log
42+
# Using with Systemjs
43+
Please see [systemjs.config.js](https://github.com/lon-yang/angular2-semantic-ui/blob/master/systemjs.config.js)
44+
45+
# Change Log
4646

4747
- 2016-06-02 Add Pagination Component
4848
- 2016-06-03 Fix bug
@@ -53,3 +53,4 @@ npm start
5353
- 2016-08-30 Add component of `lsu-tagsInput`
5454
- 2016-09-18 Upgrade angular2 to `final`, Optimization code
5555
- 2016-10-19 Upgrade angular2 to `2.1.0`, Optimization code and add animation
56+
- 2016-11-13 Support NgModule, fix #5

Diff for: angular2-semantic-ui.ts

-40
This file was deleted.

Diff for: components/dimmer/dimmer.ts

+27-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component, Input, ElementRef } from '@angular/core'
1+
import { Component, Input, ElementRef, ViewChild } from '@angular/core'
22

33
@Component({
44
selector: 'lsu-dimmer',
55
template: `
6-
<div class="ui dimmer" [ngClass]="dimmerCls">
6+
<div #dimmerDiv class="ui dimmer" [ngClass]="{'active': active}">
77
<div class="content">
88
<div class="center">
99
<ng-content></ng-content>
@@ -14,27 +14,38 @@ import { Component, Input, ElementRef } from '@angular/core'
1414
})
1515

1616
export class DimmerComponent {
17-
private dimmerCls: any
17+
@ViewChild("dimmerDiv") dimmerDiv: ElementRef;
18+
1819
private parentEle: any
20+
private _active: boolean;
1921

2022
@Input()
2123
public set active(val: boolean) {
22-
if (this.parentEle) {
23-
if (val) {
24-
this.parentEle.classList.add("dimmable");
25-
this.parentEle.classList.add("dimmed");
26-
} else {
27-
this.parentEle.classList.remove("dimmable");
28-
this.parentEle.classList.remove("dimmed");
29-
}
30-
this.dimmerCls.active = val;
24+
this._active = val;
25+
this.toggleDimmer()
26+
}
27+
public get active(): boolean {
28+
return this._active;
29+
}
30+
31+
constructor() {
32+
}
33+
34+
ngAfterViewInit() {
35+
if (!this.parentEle) {
36+
this.parentEle = this.dimmerDiv.nativeElement.parentElement.parentElement;
3137
}
38+
this.toggleDimmer();
3239
}
3340

34-
constructor(el: ElementRef) {
35-
this.parentEle = el.nativeElement.parentElement;
36-
this.dimmerCls = {
37-
active: this.active
41+
toggleDimmer() {
42+
if (!this.parentEle) return;
43+
if (this.active) {
44+
this.parentEle.classList.add("dimmable");
45+
this.parentEle.classList.add("dimmed");
46+
} else {
47+
this.parentEle.classList.remove("dimmable");
48+
this.parentEle.classList.remove("dimmed");
3849
}
3950
}
4051
}

Diff for: components/loader/loader.ts

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import { Component, Input, ElementRef } from '@angular/core'
1+
import { Component, Input, ElementRef, ViewChild } from '@angular/core'
22

33
@Component({
44
selector: "lsu-loader",
55
template: `
6-
<div class="ui dimmer" [ngClass]="{'active': isActive}">
6+
<div #loaderDiv class="ui dimmer" [ngClass]="{'active': active}">
77
<div class="ui {{loaderSize}} text loader">{{ loaderText }}</div>
88
</div>
99
`
1010
})
1111

1212
export class LoaderComponent {
13+
@ViewChild("loaderDiv") loaderDiv: ElementRef;
14+
15+
private _active: boolean;
1316
@Input()
1417
public set active(val: boolean) {
15-
this.isActive = val;
16-
if (this.parentEle) {
17-
if (val) {
18-
this.parentEle.classList.add("ui");
19-
this.parentEle.classList.add("segment");
20-
} else {
21-
this.parentEle.classList.remove("ui");
22-
this.parentEle.classList.remove("segment");
23-
}
24-
}
18+
this._active = val;
19+
this.toggleLoader();
20+
}
21+
public get active(): boolean {
22+
return this._active;
2523
}
2624

2725
@Input()
@@ -31,9 +29,24 @@ export class LoaderComponent {
3129
public loaderSize: string
3230

3331
private parentEle: any
34-
private isActive: boolean
3532

36-
constructor(el: ElementRef) {
37-
this.parentEle = el.nativeElement.parentElement;
33+
constructor() {
34+
}
35+
36+
ngAfterViewInit() {
37+
if (!this.parentEle) {
38+
this.parentEle = this.loaderDiv.nativeElement.parentElement.parentElement;
39+
}
40+
}
41+
42+
toggleLoader() {
43+
if (!this.parentEle) return;
44+
if (this.active) {
45+
this.parentEle.classList.add("ui");
46+
this.parentEle.classList.add("segment");
47+
} else {
48+
this.parentEle.classList.remove("ui");
49+
this.parentEle.classList.remove("segment");
50+
}
3851
}
3952
}

Diff for: components/tags-input/tags-input.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, ElementRef, forwardRef } from '@angular/core';
1+
import { Component, Input, ElementRef, forwardRef, ViewChild } from '@angular/core';
22
import { ControlValueAccessor, NgModel, NG_VALUE_ACCESSOR, Validators, ValidatorFn, FormControl } from '@angular/forms';
33

44
@Component({
@@ -38,7 +38,7 @@ import { ControlValueAccessor, NgModel, NG_VALUE_ACCESSOR, Validators, Validator
3838
`
3939
],
4040
template: `
41-
<div class="ui fluid dropdown selection multiple tags-input" [class.invalid]="tagInputCtrl.invalid && submitted" tabindex="-1" (click)="tagsInput.focus()" (keyup)="topKeyup($event)">
41+
<div #rootEleRef class="ui fluid dropdown selection multiple tags-input" [class.invalid]="tagInputCtrl.invalid && submitted" tabindex="-1" (click)="tagsInput.focus()" (keyup)="topKeyup($event)">
4242
<a class="ui label transition visible" [class.deleteTarget]="delTarget == tag" *ngFor="let tag of tags; let i = index; let last = last;"
4343
(click)="setDeltarget(tag, $event)">
4444
{{ tag }}
@@ -59,6 +59,8 @@ import { ControlValueAccessor, NgModel, NG_VALUE_ACCESSOR, Validators, Validator
5959
})
6060
export class TagsInputComponent implements ControlValueAccessor {
6161

62+
@ViewChild('rootEleRef') rootEleRef: ElementRef;
63+
6264
@Input()
6365
placeholder: string = 'Add Tag';
6466

@@ -79,7 +81,7 @@ export class TagsInputComponent implements ControlValueAccessor {
7981
private _onChange = (_: any) => { };
8082
private _onTouched = () => { };
8183

82-
constructor(private element: ElementRef) {
84+
constructor() {
8385

8486
}
8587

@@ -88,7 +90,9 @@ export class TagsInputComponent implements ControlValueAccessor {
8890
}
8991

9092
ngAfterViewInit() {
91-
this.rootEle = this.element.nativeElement.children[0];
93+
if (!this.rootEle) {
94+
this.rootEle = this.rootEleRef.nativeElement;
95+
}
9296
}
9397

9498
writeValue(value: any): void {

Diff for: index.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { NgModule } from '@angular/core';
2+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
3+
import { CommonModule } from '@angular/common';
4+
15
import { CHECKBOX_DIRECTIVES } from './components/checkbox';
26
import { DIMMER_DIRECTIVES } from './components/dimmer';
37
import { DROPDOWN_DIRECTIVES } from './components/dropdown';
@@ -25,7 +29,7 @@ export * from './components/pagination';
2529
export * from './components/tags-input';
2630

2731
export const SEMANTIC_UI_COMPONENTS: Array<any> = [
28-
...ACCORDION_DIRECTIVES,
32+
...ACCORDION_DIRECTIVES,
2933
...CHECKBOX_DIRECTIVES,
3034
...DIMMER_DIRECTIVES,
3135
...DROPDOWN_DIRECTIVES,
@@ -37,4 +41,19 @@ export const SEMANTIC_UI_COMPONENTS: Array<any> = [
3741
...POPUP_DIRECTIVES,
3842
...PAGINATION_DIRECTIVES,
3943
...TAGS_INPUT_DIRECTIVES
40-
]
44+
]
45+
46+
@NgModule({
47+
imports: [
48+
FormsModule,
49+
ReactiveFormsModule,
50+
CommonModule
51+
],
52+
declarations: [
53+
...SEMANTIC_UI_COMPONENTS
54+
],
55+
exports: [
56+
...SEMANTIC_UI_COMPONENTS
57+
]
58+
})
59+
export class L_SEMANTIC_UI_MODULE { }

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-semantic-ui",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Angular2 Directives for Semantic UI",
55
"main": "index.js",
66
"scripts": {
@@ -24,11 +24,14 @@
2424
},
2525
"homepage": "https://github.com/lon-yang/angular2-semantic-ui#readme",
2626
"peerDependencies": {
27+
"@angular/common": "^2.1.0",
2728
"@angular/core": "^2.1.0",
2829
"@angular/forms": "^2.1.0"
2930
},
3031
"devDependencies": {
32+
"@angular/common": "^2.1.0",
3133
"@angular/core": "^2.1.0",
32-
"@angular/forms": "^2.1.0"
34+
"@angular/forms": "^2.1.0",
35+
"rxjs": "^5.0.0-rc.2"
3336
}
3437
}

0 commit comments

Comments
 (0)