Skip to content
This repository was archived by the owner on Nov 2, 2018. It is now read-only.

Commit 08b9854

Browse files
author
Michael Oberwasserlechner
committed
fix(): Replace enums with types for usage in systemjs setups #21
1 parent e5082dc commit 08b9854

File tree

6 files changed

+34
-29
lines changed

6 files changed

+34
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you use SystemJS to load your files, you might have to update your config:
1717
```js
1818
System.config({
1919
map: {
20-
'@byteowls/ionic-hierarchical-menu': 'node_modules/@byteowls/ionic-hierarchical-menu/bundles/index.umd.js'
20+
'@byteowls/ionic-hierarchical-menu': 'npm:@byteowls/ionic-hierarchical-menu/bundles/index.umd.js'
2121
}
2222
});
2323
```
@@ -48,7 +48,7 @@ For that can use the `config` section in our `packages.json`
4848
"@angular/platform-browser-dynamic": "2.4.8",
4949
"@angular/platform-server": "2.4.8",
5050
"@ionic/storage": "2.0.1",
51-
"@byteowls/ionic-hierarchical-menu": "~1.0.0-beta1",
51+
"@byteowls/ionic-hierarchical-menu": "~1.0.0-beta2",
5252
"angular2-jwt": "0.1.28",
5353
"ionic-angular": "2.3.0",
5454
"ionic-native": "2.8.1",
@@ -163,7 +163,7 @@ export class MenuPage {
163163
// create the config object
164164
this.menuConfig = new HierarchicalMenuConfig();
165165
// the menu items are structured a flat list
166-
this.menuConfig.menuItemStructure = MenuItemStructure.FLAT;
166+
this.menuConfig.menuItemStructure = "F";
167167
// translate menu item titles using this callback
168168
this.menuConfig.onTranslate = (code: string) => {
169169
return this.i18n.instant(code);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@byteowls/ionic-hierarchical-menu",
33
"description": "Hierarchical menu is a hierarchical / multi-level menu component for Ionic 2+",
4-
"version": "1.0.0-beta1",
4+
"version": "1.0.0-beta2",
55
"scripts": {
66
"ngc": "ngc",
77
"webpack": "webpack",

src/hierarchical-menu-item.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ export class HierarchicalMenuItemComponent implements OnInit {
7575
}
7676

7777
useIconsByFontAwesome(menuItem: HierarchicalMenuItem): boolean {
78-
return menuItem.icon != null && menuItem.iconMode === IconMode.FONTAWESOME;
78+
return menuItem.icon != null && menuItem.iconMode === "FA";
7979
}
8080

8181
useIconsByIonic(menuItem: HierarchicalMenuItem) {
82-
return menuItem.icon != null && (menuItem.iconMode === IconMode.IONIC || menuItem.iconMode == null);
82+
return menuItem.icon != null && (menuItem.iconMode === "ION" || menuItem.iconMode == null);
8383
}
8484

8585
buildStyles(...styles: string[]) {

src/hierarchical-menu.service.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ import {deprecate} from "util";
55
/**
66
* Menu item mode describes the form of incoming menu items. Are the already hierarchical or add only referencing their parents.
77
*/
8-
export enum MenuItemStructure {
9-
FLAT, HIERARCHICAL
10-
}
8+
export type MenuItemStructure = (
9+
"F" // Flat
10+
|
11+
"H" // Hierarchical
12+
|
13+
null // defaults to hierarchical
14+
);
15+
16+
17+
export type IconMode = (
18+
"ION" | "FA" | null
19+
);
1120

1221
@Injectable()
1322
export class HierarchicalMenuConfig {
@@ -17,7 +26,7 @@ export class HierarchicalMenuConfig {
1726
private _menuItems: HierarchicalMenuItem[] = [];
1827
private rebuildRequired: boolean = false;
1928

20-
menuItemStructure: MenuItemStructure = MenuItemStructure.HIERARCHICAL;
29+
menuItemStructure: MenuItemStructure = "H";
2130
useTitleAsId: boolean = true;
2231
onClickLink: Function;
2332
onClickExpander: Function;
@@ -149,7 +158,7 @@ export class HierarchicalMenuConfig {
149158
*/
150159
rebuild(force:boolean = false) {
151160
if (this.rebuildRequired || force) {
152-
if (this.menuItemStructure === MenuItemStructure.FLAT) {
161+
if (this.menuItemStructure === "F") {
153162
this._menuItems = this.treeify(this._menuItems);
154163
}
155164
if (this.expandedIds && this.expandedIds.length > 0) {
@@ -226,7 +235,7 @@ export class HierarchicalMenuItem {
226235
order?: number = 0;
227236

228237
icon?: string | null;
229-
iconMode?: IconMode = IconMode.IONIC;
238+
iconMode?: IconMode = "ION";
230239

231240
styleItem?: string; // ul > li
232241
styleLine?: string; // ul > li > div
@@ -260,7 +269,3 @@ export class HierarchicalMenuItem {
260269
}
261270
}
262271
}
263-
264-
export enum IconMode {
265-
FONTAWESOME, IONIC
266-
}

tests/hierarchical-menu-item.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("HierarchicalMenuItemComponent", () => {
9393

9494
it("should use fontawesome icons", () => {
9595
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
96-
config.add({title: "a", icon: "alarm", iconMode: IconMode.FONTAWESOME});
96+
config.add({title: "a", icon: "alarm", iconMode: "FA"});
9797

9898
componentFixture.componentInstance.config = config;
9999
componentFixture.componentInstance.items = config.menuItems;

tests/hierarchical-menu.component.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ describe("HierarchicalMenuComponent", () => {
3232

3333
it("should be flat mode ", () => {
3434
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
35-
config.menuItemStructure = MenuItemStructure.FLAT;
36-
expect(config.menuItemStructure).toBe(MenuItemStructure.FLAT);
35+
config.menuItemStructure = "F";
36+
expect(config.menuItemStructure).toBe("F");
3737
});
3838

3939
it("should build a hierarchy from a simple flat list", () => {
4040
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
41-
config.menuItemStructure = MenuItemStructure.FLAT;
41+
config.menuItemStructure = "F";
4242
config.add({ id: "b", title: "item b ref a", parentRef: "a" });
4343
config.add({ id: "a", title: "item a", parentRef: "" });
4444
config.add({ id: "c", title: "item c ref b", parentRef: "b" });
4545

4646
componentFixture.componentInstance.config = config;
47-
expect(config.menuItemStructure).toBe(MenuItemStructure.FLAT);
47+
expect(config.menuItemStructure).toBe("F");
4848

4949
let menuItems: HierarchicalMenuItem[] = componentFixture.componentInstance.config.menuItems;
5050
// only one item or top level item respectively
@@ -57,7 +57,7 @@ describe("HierarchicalMenuComponent", () => {
5757
it("should build a little more complex hierarchy from a flat list", () => {
5858

5959
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
60-
config.menuItemStructure = MenuItemStructure.FLAT;
60+
config.menuItemStructure = "F";
6161
config.add({title: "menu.personal.section"});
6262
config.add({title: "menu.personal.home", parentRef: "menu.personal.section"});
6363
config.add({title: "menu.personal.profile", parentRef: "menu.personal.section"});
@@ -140,7 +140,7 @@ describe("HierarchicalMenuComponent", () => {
140140

141141
it("should have no expanded items", () => {
142142
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
143-
config.menuItemStructure = MenuItemStructure.FLAT;
143+
config.menuItemStructure = "F";
144144
config.add({title: "a"});
145145
config.add({title: "b"});
146146
config.add({title: "c"});
@@ -155,7 +155,7 @@ describe("HierarchicalMenuComponent", () => {
155155

156156
it("should have expanded items", () => {
157157
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
158-
config.menuItemStructure = MenuItemStructure.FLAT;
158+
config.menuItemStructure = "F";
159159
config.add({title: "a", expanded: true});
160160
config.add({title: "aa", parentRef: "a"});
161161

@@ -176,7 +176,7 @@ describe("HierarchicalMenuComponent", () => {
176176

177177
it("should have all parent items expanded", () => {
178178
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
179-
config.menuItemStructure = MenuItemStructure.FLAT;
179+
config.menuItemStructure = "F";
180180
config.add({title: "a"});
181181
config.add({title: "aa", parentRef: "a"});
182182
config.add({title: "aaa", parentRef: "aa"});
@@ -203,7 +203,7 @@ describe("HierarchicalMenuComponent", () => {
203203

204204
it("should have all parent items collapsed", () => {
205205
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
206-
config.menuItemStructure = MenuItemStructure.FLAT;
206+
config.menuItemStructure = "F";
207207
config.add({title: "a", expanded: true});
208208
config.add({title: "aa", parentRef: "a"});
209209

@@ -225,7 +225,7 @@ describe("HierarchicalMenuComponent", () => {
225225

226226
it("should expand defined items and close others", () => {
227227
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
228-
config.menuItemStructure = MenuItemStructure.FLAT;
228+
config.menuItemStructure = "F";
229229
config.add({title: "a", expanded: true});
230230
config.add({title: "aa", parentRef: "a"});
231231

@@ -250,7 +250,7 @@ describe("HierarchicalMenuComponent", () => {
250250

251251
it("should expand defined items instantly and dont touch existing others", () => {
252252
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
253-
config.menuItemStructure = MenuItemStructure.FLAT;
253+
config.menuItemStructure = "F";
254254
config.add({title: "a", expanded: true});
255255
config.add({title: "aa", parentRef: "a"});
256256

@@ -279,7 +279,7 @@ describe("HierarchicalMenuComponent", () => {
279279

280280
it("should expand defined items on rebuild", () => {
281281
let config: HierarchicalMenuConfig = new HierarchicalMenuConfig();
282-
config.menuItemStructure = MenuItemStructure.FLAT;
282+
config.menuItemStructure = "F";
283283
config.add({title: "a", expanded: true});
284284
config.add({title: "aa", parentRef: "a"});
285285

0 commit comments

Comments
 (0)