Skip to content

Commit cb7efc0

Browse files
authored
Merge pull request #16 from edcarroll/develop
v0.4.0 into master
2 parents 9395051 + 6df6507 commit cb7efc0

Some content is hidden

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

56 files changed

+1221
-474
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Now you're good to go!
4444

4545
## Dependencies
4646

47-
* [Angular 2](https://angular.io) (2.0.0-rc.5 **or higher**)
47+
* [Angular 2](https://angular.io) (2.0.0-rc.7)
4848
* [Semantic UI CSS](http://semantic-ui.com/) (jQuery is **not** required)
4949

5050
## Components
@@ -62,6 +62,7 @@ The current list of available components with links to their docs is below:
6262
* [Search](http://edcarroll.github.io/ng2-semantic-ui/#/components/search)
6363
* [Select](http://edcarroll.github.io/ng2-semantic-ui/#/components/select)
6464
* [Tabs](http://edcarroll.github.io/ng2-semantic-ui/#/components/tabs)
65+
* [Transition](http://edcarroll.github.io/ng2-semantic-ui/#/components/transition)
6566

6667
## Development
6768

components/accordion/accordion.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {NgModule} from '@angular/core';
22
import {SUI_ACCORDION_DIRECTIVES, SUI_ACCORDION_PROVIDERS} from "./accordion";
33
import {SuiCollapseModule} from "../collapse/collapse.module";
4+
import {CommonModule} from "@angular/common";
45

56
@NgModule({
6-
imports: [SuiCollapseModule],
7+
imports: [CommonModule, SuiCollapseModule],
78
declarations: SUI_ACCORDION_DIRECTIVES,
89
exports: SUI_ACCORDION_DIRECTIVES,
910
providers: SUI_ACCORDION_PROVIDERS

components/checkbox/checkbox.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import {NgModule} from '@angular/core';
22
import {FormsModule} from "@angular/forms";
33
import {SUI_CHECKBOX_DIRECTIVES} from "./checkbox";
44
import {SUI_RADIOBUTTON_DIRECTIVES} from "./radiobutton";
5+
import {CommonModule} from "@angular/common";
56

67
@NgModule({
7-
imports: [FormsModule],
8+
imports: [CommonModule, FormsModule],
89
declarations: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES],
910
exports: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES]
1011
})

components/collapse/collapse.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {NgModule} from '@angular/core';
22
import {SUI_COLLAPSE_DIRECTIVES} from './collapse';
3+
import {CommonModule} from "@angular/common";
34

45
@NgModule({
6+
imports: [CommonModule],
57
declarations: SUI_COLLAPSE_DIRECTIVES,
68
exports: SUI_COLLAPSE_DIRECTIVES
79
})

components/dimmer/dimmer.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {NgModule} from '@angular/core';
22
import {SUI_DIMMER_DIRECTIVES} from "./dimmer";
3+
import {CommonModule} from "@angular/common";
34

45
@NgModule({
6+
imports: [CommonModule],
57
declarations: SUI_DIMMER_DIRECTIVES,
68
exports: SUI_DIMMER_DIRECTIVES
79
})
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import {Directive, ElementRef, HostBinding} from '@angular/core';
1+
import {Directive, ElementRef, HostBinding, Renderer} from '@angular/core';
22
import {SuiDropdownService} from './dropdown.service';
3+
import {SuiTransition} from "../transition/transition";
34

45
@Directive({
56
selector: '[suiDropdownMenu]'
67
})
78
export class SuiDropdownMenu {
89
private _service:SuiDropdownService;
10+
private _transition:SuiTransition;
11+
912
public set service(service:SuiDropdownService) {
1013
this._service = service;
1114
this._service.menuElement = this.el;
15+
this._service.transition = this._transition;
16+
if (service.isOpen) {
17+
this._transition.isVisible = true;
18+
}
1219
}
1320

14-
public el:ElementRef;
15-
public constructor(el:ElementRef) {
16-
this.el = el;
17-
}
18-
19-
@HostBinding('class.visible')
20-
@HostBinding('class.transition')
21-
public get isOpen():boolean {
22-
if (this._service) {
23-
return this._service.isOpen;
24-
}
25-
return;
21+
public constructor(public el:ElementRef, public renderer:Renderer) {
22+
this._transition = new SuiTransition(el, renderer);
23+
this._transition.isVisible = false;
2624
}
2725
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {NgModule} from '@angular/core';
2-
import {SUI_DROPDOWN_DIRECTIVES, SUI_DROPDOWN_PROVIDERS} from "./dropdown";
2+
import {SUI_DROPDOWN_DIRECTIVES} from "./dropdown";
3+
import {CommonModule} from "@angular/common";
4+
import {SuiTransitionModule} from "../transition/transition.module";
35

46
@NgModule({
7+
imports: [CommonModule, SuiTransitionModule],
58
declarations: SUI_DROPDOWN_DIRECTIVES,
6-
exports: SUI_DROPDOWN_DIRECTIVES,
7-
providers: SUI_DROPDOWN_PROVIDERS
9+
exports: SUI_DROPDOWN_DIRECTIVES
810
})
911
export class SuiDropdownModule {}

components/dropdown/dropdown.service.ts

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import {EventEmitter, ElementRef} from '@angular/core';
2+
import {SuiTransition} from "../transition/transition";
23

3-
const DISABLED = 'disabled';
4-
const OUTSIDECLICK = 'outsideClick';
4+
const Disabled = 'disabled';
5+
const OutsideClick = 'outsideClick';
56

6-
export const KEYCODE = {
7-
LEFT: 37,
8-
UP: 38,
9-
RIGHT: 39,
10-
DOWN: 40,
7+
export const KeyCode = {
8+
Left: 37,
9+
Up: 38,
10+
Right: 39,
11+
Down: 40,
1112

12-
ESCAPE: 27,
13-
ENTER: 13,
13+
Escape: 27,
14+
Enter: 13,
1415

15-
BACKSPACE: 8
16+
Space: 32,
17+
Backspace: 8
1618
};
1719

1820
export class SuiDropdownService {
@@ -41,14 +43,28 @@ export class SuiDropdownService {
4143
public itemSelectedClass = "selected";
4244
public itemDisabledClass = "disabled";
4345

46+
// Transitions
47+
public transition:SuiTransition;
48+
public isVisible:boolean;
49+
4450
public get isOpen():boolean {
4551
return this._isOpen;
4652
}
4753

4854
public set isOpen(value:boolean) {
55+
if (value == this._isOpen) { return; }
4956
if (this.isDisabled) { value = false; }
5057

5158
this._isOpen = value;
59+
if (this.transition) {
60+
this.isVisible = true;
61+
this.transition.stopAll();
62+
this.transition.animate({
63+
name: "slide down",
64+
duration: 200,
65+
callback: () => this.isVisible = this.isOpen
66+
});
67+
}
5268

5369
if (this.isOpen) {
5470
this.bindDocumentEvents();
@@ -84,7 +100,7 @@ export class SuiDropdownService {
84100

85101
private closeDropdown(event:MouseEvent):void {
86102
//Never close the dropdown if autoClose is disabled
87-
if (event && this.autoClose === DISABLED) {
103+
if (event && this.autoClose === Disabled) {
88104
return;
89105
}
90106

@@ -108,7 +124,7 @@ export class SuiDropdownService {
108124
}
109125

110126
//Don't close the dropdown when clicking inside if autoClose is outsideClick
111-
if (event && this.autoClose === OUTSIDECLICK &&
127+
if (event && this.autoClose === OutsideClick &&
112128
this.menuElement &&
113129
this.menuElement.nativeElement.contains(event.target)) {
114130
return;
@@ -119,14 +135,14 @@ export class SuiDropdownService {
119135
}
120136

121137
private keybindFilter(event:KeyboardEvent):void {
122-
if (event.which === KEYCODE.ESCAPE) {
138+
if (event.which === KeyCode.Escape) {
123139
this.isOpen = false;
124140
return;
125141
}
126142

127143
//noinspection TypeScriptUnresolvedFunction
128144
if (this.isOpen &&
129-
([KEYCODE.ENTER, KEYCODE.UP, KEYCODE.RIGHT, KEYCODE.DOWN, KEYCODE.LEFT]
145+
([KeyCode.Enter, KeyCode.Up, KeyCode.Right, KeyCode.Down, KeyCode.Left]
130146
.find(keyCode => event.which == keyCode))) {
131147
event.preventDefault();
132148
event.stopPropagation();
@@ -150,26 +166,26 @@ export class SuiDropdownService {
150166
public keyPress(keyCode:number):void {
151167
//noinspection FallThroughInSwitchStatementJS
152168
switch (keyCode) {
153-
case KEYCODE.DOWN:
169+
case KeyCode.Down:
154170
this.selectNextItem();
155171
break;
156-
case KEYCODE.UP:
172+
case KeyCode.Up:
157173
this.selectPreviousItem();
158174
break;
159-
case KEYCODE.ENTER:
175+
case KeyCode.Enter:
160176
if (this.selectedItem && !this.selectedItem.hasAttribute("suiDropdown")) {
161177
(<HTMLElement> this.selectedItem).click();
162178
this.selectedItem = null;
163179
break;
164180
}
165181
//Fall through on purpose! (So enter on a nested dropdown acts as right arrow)
166-
case KEYCODE.RIGHT:
182+
case KeyCode.Right:
167183
if (this.selectedItem && this.selectedItem.hasAttribute("suiDropdown")) {
168184
(<HTMLElement> this.selectedItem).click();
169185
this.selectedItem = this.selectedItem.querySelector(`.${this.itemClass}:not(.${this.itemDisabledClass})`);
170186
}
171187
break;
172-
case KEYCODE.LEFT:
188+
case KeyCode.Left:
173189
if (this.selectedItem.parentElement != this.menuElement.nativeElement) {
174190
(<HTMLElement> this.selectedItem.parentElement.parentElement).click();
175191
this.selectedItem = this.selectedItem.parentElement.parentElement;
@@ -193,12 +209,16 @@ export class SuiDropdownService {
193209
}
194210

195211
public selectPreviousItem():void {
196-
var previousItem = this.selectedItem.previousElementSibling;
197-
if (previousItem) {
198-
this.selectedItem = previousItem;
199-
if (this.selectedItem.classList.contains(this.itemDisabledClass)) {
200-
this.selectPreviousItem();
212+
if (this.selectedItem) {
213+
var previousItem = this.selectedItem.previousElementSibling;
214+
if (previousItem) {
215+
this.selectedItem = previousItem;
216+
if (this.selectedItem.classList.contains(this.itemDisabledClass)) {
217+
this.selectPreviousItem();
218+
}
201219
}
220+
return;
202221
}
222+
this.selectNextItem();
203223
}
204224
}

components/dropdown/dropdown.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class SuiDropdown implements AfterContentInit {
99
protected _service:SuiDropdownService;
1010
@ContentChild(SuiDropdownMenu) protected _menu:SuiDropdownMenu;
1111

12-
@HostBinding('class.visible')
12+
@HostBinding('class.active')
1313
@Input()
1414
public get isOpen():boolean {
1515
return this._service.isOpen;
@@ -38,6 +38,11 @@ export class SuiDropdown implements AfterContentInit {
3838
return this._service.isOpenChange;
3939
}
4040

41+
@HostBinding('class.visible')
42+
public get isVisible() {
43+
return this._service.isVisible;
44+
}
45+
4146
@HostBinding('class.disabled')
4247
@Input()
4348
public get isDisabled():boolean {
@@ -69,4 +74,3 @@ export class SuiDropdown implements AfterContentInit {
6974
}
7075

7176
export const SUI_DROPDOWN_DIRECTIVES = [SuiDropdown, SuiDropdownMenu];
72-
export const SUI_DROPDOWN_PROVIDERS = [SuiDropdownService];

components/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {SuiRatingModule} from "./rating/rating.module";
1111
import {SuiSearchModule} from "./search/search.module";
1212
import {SuiTabsModule} from "./tabs/tab.module";
1313
import {SuiSelectModule} from "./select/select.module";
14+
import {SuiTransitionModule} from "./transition/transition.module";
1415

1516
@NgModule({
1617
exports: [
@@ -24,7 +25,8 @@ import {SuiSelectModule} from "./select/select.module";
2425
SuiRatingModule,
2526
SuiSearchModule,
2627
SuiSelectModule,
27-
SuiTabsModule
28+
SuiTabsModule,
29+
SuiTransitionModule
2830
]
2931
})
3032
export class SuiModule {}
@@ -38,5 +40,7 @@ export {SuiMessageModule};
3840
export {SuiProgressModule};
3941
export {SuiRatingModule};
4042
export {SuiSearchModule};
41-
export {SuiTabsModule};
4243
export {SuiSelectModule};
44+
export {SuiTabsModule};
45+
export {SuiTransitionModule};
46+

0 commit comments

Comments
 (0)