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

Commit e5082dc

Browse files
author
Michael Oberwasserlechner
committed
feat(style): Added new item styles for individual styling of each part of a specific menu item. #19
1 parent 79120a2 commit e5082dc

File tree

5 files changed

+60
-45
lines changed

5 files changed

+60
-45
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class MenuPage {
187187
};
188188

189189
// add a parent menu item with a special style and expand it per default
190-
this.menuConfig.add({title: "menu.personal.section", style: "top-section", expanded: true});
190+
this.menuConfig.add({title: "menu.personal.section", styleLine: "top-section", expanded: true});
191191
// Add simple menu item with a reference to the parent. Because we said that items are delivered as flat list.
192192
// The component will create the hierarchical structure by itself
193193
this.menuConfig.add({title: "menu.personal.home", parentRef: "menu.personal.section", page: HomePage});
@@ -196,7 +196,7 @@ export class MenuPage {
196196
// Another menu item with a index because its a tabbed page
197197
this.menuConfig.add({title: "menu.personal.events", parentRef: "menu.personal.section", page: TabsPage, pageOptions: {tabIndex: 0}});
198198
// A parent menu item
199-
this.menuConfig.add({title: "menu.settings.section", style: "top-section", expanded: true});
199+
this.menuConfig.add({title: "menu.settings.section", styleLine: "top-section", expanded: true});
200200

201201
this.menuConfig.add({title: "menu.settings.language", parentRef: "menu.settings.section"});
202202
for (let lang of ["de","en"]) {
@@ -219,7 +219,7 @@ It's also possible to load menu items after first init, e.g. from a backend serv
219219
//
220220
loadMenuItems() {
221221
const ITEM_ID = "menu.chosen_club.section";
222-
this.menuConfig.addBefore("menu.settings.section", { id: ITEM_ID, title: "Special section", expanded: true, style: "special-section"});
222+
this.menuConfig.addBefore("menu.settings.section", { id: ITEM_ID, title: "Special section", expanded: true, styleLine: "special-section"});
223223

224224
// this is a
225225
this.backendService.getMenuItems().subscribe(

src/hierarchical-menu-item.component.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,28 @@ import {HierarchicalMenuItem, IconMode, HierarchicalMenuConfig} from "./hierarch
44
@Component({
55
selector: "hierarchical-menu-item",
66
template: `
7-
<ul class="hm-level">
8-
<li *ngFor="let item of items">
9-
<div [ngClass]="buildStyles(item)">
10-
<div class="hm-link">
11-
<button (click)="onClickLink(item)">
12-
<ion-icon *ngIf="useIconsByIonic(item)" [name]="item.icon"></ion-icon>
13-
<i *ngIf="useIconsByFontAwesome(item)" class="fa {{ item.icon }}" aria-hidden="true"></i>
14-
{{ translateIt(item) }}
15-
</button>
16-
</div>
17-
<div class="hm-expander">
18-
<button *ngIf="hasChildren(item)" (click)="onClickExpander(item)">
19-
<ion-icon [name]="getExpanderIcon(item)"></ion-icon>
20-
</button>
21-
</div>
22-
</div>
23-
<hierarchical-menu-item *ngIf="item.expanded && hasChildren(item)" [items]="item.children" [config]="config"></hierarchical-menu-item>
24-
</li>
25-
</ul>
7+
<ul class="hm-level">
8+
<li *ngFor="let item of items" [ngClass]="buildStyles('hm-item', item.styleItem)">
9+
<div [ngClass]="buildStyles('hm-line', item.styleLine)">
10+
<div [ngClass]="buildStyles('hm-link', item.styleLink)">
11+
<button (click)="onClickLink(item)" icon-left>
12+
<ion-icon [ngClass]="buildStyles('hm-icon', item.styleIcon)" *ngIf="useIconsByIonic(item)" [name]="item.icon"></ion-icon>
13+
<i *ngIf="useIconsByFontAwesome(item)" [ngClass]="buildStyles('hm-icon', item.styleIcon, 'fa', item.icon)" aria-hidden="true"></i>
14+
<span [ngClass]="buildStyles('hm-text', item.styleText)">
15+
{{ translateIt(item) }}
16+
</span>
17+
</button>
18+
</div>
19+
<div [ngClass]="buildStyles('hm-expander', item.styleExpander)">
20+
<button *ngIf="hasChildren(item)" (click)="onClickExpander(item)">
21+
<ion-icon [name]="getExpanderIcon(item)"></ion-icon>
22+
</button>
23+
</div>
24+
</div>
25+
<hierarchical-menu-item *ngIf="item.expanded && hasChildren(item)" [items]="item.children"
26+
[config]="config"></hierarchical-menu-item>
27+
</li>
28+
</ul>
2629
`
2730
})
2831
export class HierarchicalMenuItemComponent implements OnInit {
@@ -79,8 +82,11 @@ export class HierarchicalMenuItemComponent implements OnInit {
7982
return menuItem.icon != null && (menuItem.iconMode === IconMode.IONIC || menuItem.iconMode == null);
8083
}
8184

82-
buildStyles(menuItem: HierarchicalMenuItem) {
83-
return "hm-item-line " + (menuItem.style || "");
85+
buildStyles(...styles: string[]) {
86+
if (styles) {
87+
return styles.join(" ").trim();
88+
}
89+
return "";
8490
}
8591

8692
translateIt(menuItem: HierarchicalMenuItem):string {

src/hierarchical-menu.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Injectable} from "@angular/core";
2+
import {deprecate} from "util";
23

34

45
/**
@@ -226,7 +227,13 @@ export class HierarchicalMenuItem {
226227

227228
icon?: string | null;
228229
iconMode?: IconMode = IconMode.IONIC;
229-
style?: string | null;
230+
231+
styleItem?: string; // ul > li
232+
styleLine?: string; // ul > li > div
233+
styleLink?: string; // ul > li > div > div
234+
styleIcon?: string; // ul > li > div > div > button > ion-icon | i
235+
styleText?: string; // ul > li > div > div > button > span
236+
styleExpander?: string; //
230237

231238
page?: any;
232239
pageOptions?: any = {};

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ describe("HierarchicalMenuItemComponent", () => {
3232
it('should be a custom item line style set', () => {
3333
// componentFixture.componentInstance.menuItems = menuItems;
3434
// componentFixture.detectChanges();
35-
let styles = componentFixture.componentInstance.buildStyles({ title: "styleTest", style: "test-style"});
36-
expect(styles).toBe("hm-item-line test-style");
35+
let styles = componentFixture.componentInstance.buildStyles();
36+
expect(styles).toBe("");
37+
38+
styles = componentFixture.componentInstance.buildStyles("hm-link", null);
39+
expect(styles).toBe("hm-link");
40+
41+
styles = componentFixture.componentInstance.buildStyles("hm-link", "fa", "icon");
42+
expect(styles).toBe("hm-link fa icon");
3743
});
3844

3945

themes/scss/hierarchical-menu.themes.default.scss

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22

33
.hierarchical-menu {
44
width: 100%;
5-
//height: 100%; /* Full height */
6-
//position: fixed; /* Make it stick, even on scroll */
7-
//overflow: auto; /* Enable scrolling if the sidenav has too much content */
85

96
// ul
107
.hm-level {
118
list-style-type: none;
129
margin: 0;
1310
padding: 0;
14-
li {
15-
text-align: left !important;
16-
}
1711
}
1812

19-
// class on the div in li
20-
.hm-item-line {
13+
// ul > li
14+
.hm-item {
15+
text-align: left !important;
16+
}
17+
// ul > li > div
18+
.hm-line {
19+
2120
display: flex;
2221
align-items: center;
2322
justify-content: space-between;
24-
//overflow: hidden#;
2523

2624
margin: 0;
2725
padding: 0;
@@ -43,6 +41,10 @@
4341
button {
4442
color: $hierarchical-menu-text-color;
4543
padding: 8px 10px;
44+
45+
.hm-icon {
46+
47+
}
4648
}
4749
}
4850

@@ -73,16 +75,10 @@
7375
text-decoration: none;
7476
width: 100%;
7577
}
76-
7778
}
78-
.hm-item-line:hover {
79+
80+
.hm-line:hover {
7981
color: $hierarchical-menu-hover-text-color;
8082
background-color: $hierarchical-menu-hover-bg-color;
8183
}
82-
83-
// ul li
84-
.hm-item {
85-
86-
87-
}
88-
}
84+
}

0 commit comments

Comments
 (0)