Skip to content

Commit 959bd4a

Browse files
tibing-old-emailnnixaa
authored andcommitted
refactor(theme): remove user context menu (#231)
BREAKING CHANGES: NbUserComponent no longer has context menu. We've completely moved context menu in the separate component. So, to migrate from the previous version you have to remove user menu items ``` <nb-user [menu]="items"></nb-user> ``` and use NbContextMenuDirective: ``` <nb-user [nbContextMenu]="items"></nb-user> ```
1 parent c044e5d commit 959bd4a

File tree

8 files changed

+63
-533
lines changed

8 files changed

+63
-533
lines changed

docs/output.json

Lines changed: 54 additions & 319 deletions
Large diffs are not rendered by default.

src/app/user-test/user-test.component.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone
1919
template: `
2020
<nb-layout id="layout-fluid">
2121
<nb-layout-header fixed>
22-
<nb-user showInitials size="medium" name="Dmitry Nehaychik" title="Worker"
23-
[menu]="contextMenu" (menuClick)="onMenuItemClick($event)"></nb-user>
22+
<nb-user showInitials size="medium" name="Dmitry Nehaychik" title="Worker"></nb-user>
2423
</nb-layout-header>
2524
2625
@@ -44,21 +43,17 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone
4443
<nb-user inverse onlyPicture size="medium" name="Dmitry Nehaychik" title="Worker"></nb-user>
4544
</div>
4645
<div class="test-row">
47-
<nb-user inverse size="medium" name="Dmitry Nehaychik" title="Worker"
48-
[menu]="contextMenu" (menuClick)="onMenuItemClick($event)"></nb-user>
46+
<nb-user inverse size="medium" name="Dmitry Nehaychik" title="Worker"></nb-user>
4947
</div>
5048
<div class="test-row">
51-
<nb-user inverse onlyPicture size="medium" name="Dmitry Nehaychik" title="Worker"
52-
[menu]="contextMenu" (menuClick)="onMenuItemClick($event)"></nb-user>
49+
<nb-user inverse onlyPicture size="medium" name="Dmitry Nehaychik" title="Worker"></nb-user>
5350
</div>
5451
<div class="test-row">
5552
<nb-user inverse size="large" picture="http://lorempixel.com/400/200/animals/"
56-
name="Dmitry Nehaychik" title="Worker"
57-
[menu]="contextMenu" (menuClick)="onMenuItemClick($event)"></nb-user>
53+
name="Dmitry Nehaychik" title="Worker"></nb-user>
5854
</div>
5955
<div class="test-row">
60-
<nb-user inverse showInitials size="medium" name="Dmitry Nehaychik" title="Worker"
61-
[menu]="contextMenu" (menuClick)="onMenuItemClick($event)"></nb-user>
56+
<nb-user inverse showInitials size="medium" name="Dmitry Nehaychik" title="Worker"></nb-user>
6257
</div>
6358
6459
<div class="test-row">
@@ -101,8 +96,6 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone
10196
picture="http://lorempixel.com/400/200/animals/"
10297
name="Dmitry Nehaychik"
10398
title="Worker"
104-
[menu]="contextMenu"
105-
(menuClick)="onMenuItemClick($event)"
10699
badgeText="29"
107100
[badgeStatus]="badge.STATUS_DANGER"
108101
[badgePosition]="badge.TOP_LEFT">
@@ -119,14 +112,4 @@ import { NbBadgeComponent } from 'framework/theme/components/badge/badge.compone
119112
export class NbUserTestComponent {
120113

121114
badge = NbBadgeComponent;
122-
123-
contextMenu = [
124-
{ title: 'Profile', link: 'some/link', icon: 'nb-person' },
125-
{ title: 'Billing', target: '_blank', url: 'http://akveo.com' },
126-
{ title: 'Exit', key: 'exit' },
127-
];
128-
129-
onMenuItemClick(event) {
130-
console.info(event);
131-
}
132115
}

src/framework/theme/components/user/_user.component.theme.scss

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,5 @@
6060
width: nb-theme(user-size-xlarge);
6161
}
6262
}
63-
64-
.user-context-menu {
65-
border: 2px solid nb-theme(user-menu-border);
66-
background: nb-theme(user-menu-bg);
67-
68-
ul > li > a {
69-
color: nb-theme(user-menu-fg);
70-
71-
@include hover-focus-active {
72-
color: nb-theme(user-menu-active-fg);
73-
background: nb-theme(user-menu-active-bg);
74-
text-decoration: none;
75-
}
76-
}
77-
78-
ul > li.arrow {
79-
border-bottom: 11px solid nb-theme(user-menu-border) !important;
80-
81-
&::after {
82-
border-bottom: 11px solid nb-theme(user-menu-bg) !important;
83-
}
84-
}
85-
}
8663
}
8764
}
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="user-container" (click)="toggleMenu()" [ngClass]="{'with-menu' : hasMenu()}">
1+
<div class="user-container">
22
<div *ngIf="imageBackgroundStyle" class="user-picture image" [style.background-image]="imageBackgroundStyle">
33
<nb-badge *ngIf="badgeText" [text]="badgeText" [status]="badgeStatus" [position]="badgePosition"></nb-badge>
44
</div>
@@ -13,26 +13,4 @@
1313
<div *ngIf="showNameValue && name" class="user-name">{{ name }}</div>
1414
<div *ngIf="showTitleValue && title" class="user-title">{{ title }}</div>
1515
</div>
16-
17-
<div *ngIf="hasMenu()"
18-
[ngStyle]="{display: isMenuShown ? 'block' : 'none'}" class="user-context-menu">
19-
<ul>
20-
<li class="arrow"></li>
21-
<li *ngFor="let item of menu" [class.with-icon]="item.icon">
22-
<a *ngIf="item.link && !item.url" [routerLink]="item.link" [attr.target]="item.target">
23-
<span *ngIf="item.icon" class="item-icon {{ item.icon }}"></span>
24-
{{ item.title }}
25-
</a>
26-
<a *ngIf="item.url && !item.link" [attr.href]="item.url" [attr.target]="item.target">
27-
<span *ngIf="item.icon" class="item-icon {{ item.icon }}"></span>
28-
{{ item.title }}
29-
</a>
30-
<a *ngIf="!item.link && !item.url" href="#" [attr.target]="item.target"
31-
(click)="itemClick($event, item)">
32-
<span *ngIf="item.icon" class="item-icon {{ item.icon }}"></span>
33-
{{ item.title }}
34-
</a>
35-
</li>
36-
</ul>
37-
</div>
3816
</div>

src/framework/theme/components/user/user.component.scss

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*/
66

7-
@import '../../styles/core/mixins';
8-
97
:host {
108
display: flex;
119
}
@@ -14,10 +12,6 @@
1412
position: relative;
1513
display: flex;
1614
align-items: center;
17-
18-
&.with-menu {
19-
cursor: pointer;
20-
}
2115
}
2216

2317
.user-picture {
@@ -44,59 +38,3 @@
4438
.info-container {
4539
margin-left: 0.5rem;
4640
}
47-
48-
.user-context-menu {
49-
@include center-horizontal-absolute();
50-
51-
z-index: 1000;
52-
top: calc(100% + 10px);
53-
background-clip: padding-box;
54-
border-radius: 5px;
55-
font-size: 0.875rem;
56-
line-height: 1.5rem;
57-
58-
ul {
59-
margin: 0;
60-
padding: 0.5rem 0;
61-
list-style: none;
62-
63-
li {
64-
display: block;
65-
white-space: nowrap;
66-
> a {
67-
padding: 0.375rem 3rem;
68-
display: flex;
69-
}
70-
71-
&.with-icon > a {
72-
padding-left: 1rem;
73-
74-
.item-icon {
75-
font-size: 1.5rem;
76-
padding-right: 0.5rem;
77-
}
78-
}
79-
80-
&.arrow {
81-
@include center-horizontal-absolute();
82-
83-
top: -22px;
84-
width: 0;
85-
height: 0;
86-
border: 11px solid transparent;
87-
88-
&::after {
89-
position: absolute;
90-
content: ' ';
91-
width: 0;
92-
height: 0;
93-
top: -9px;
94-
left: 0;
95-
margin-left: -12px;
96-
display: block;
97-
border: 12px solid transparent;
98-
}
99-
}
100-
}
101-
}
102-
}

src/framework/theme/components/user/user.component.ts

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,14 @@
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*/
66

7-
import { Component, Input, HostBinding, Output, EventEmitter, HostListener, ElementRef } from '@angular/core';
7+
import { Component, Input, HostBinding } from '@angular/core';
88
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
99
import { convertToBoolProperty } from '../helpers';
1010

11-
/**
12-
* Action dropdown menu
13-
*/
14-
export class NbUserMenuItem {
15-
/**
16-
* Menu title
17-
* @type string
18-
*/
19-
title: string;
20-
/**
21-
* Menu link for [routerLink] directive
22-
* @type string
23-
*/
24-
link?: string;
25-
/**
26-
* URL for absolute urls, used directly in href
27-
* @type string
28-
*/
29-
url?: string;
30-
/**
31-
* Link target (_blank, _self, etc)
32-
* @type string
33-
*/
34-
target?: string;
35-
/**
36-
* Icon class
37-
* @type string
38-
*/
39-
icon?: string;
40-
}
41-
4211
/**
4312
* Represents a component showing a user avatar (picture) with a user name on the right.
4413
*
45-
* Can be used as a user profile link or can bring a user context menu.
14+
* Can be used as a user profile link.
4615
*
4716
* @styles
4817
*
@@ -56,11 +25,6 @@ export class NbUserMenuItem {
5625
* user-size-medium:
5726
* user-size-large:
5827
* user-size-xlarge:
59-
* user-menu-fg:
60-
* user-menu-bg:
61-
* user-menu-active-fg:
62-
* user-menu-active-bg:
63-
* user-menu-border:
6428
*/
6529
@Component({
6630
selector: 'nb-user',
@@ -133,12 +97,6 @@ export class NbUserComponent {
13397
*/
13498
@Input() color: string;
13599

136-
/**
137-
* List of menu items for a user context menu (shown when clicked)
138-
* @type NbUserMenuItem[]
139-
*/
140-
@Input() menu: NbUserMenuItem[] = [];
141-
142100
/**
143101
* Size of the component, small|medium|large
144102
* @type string
@@ -214,40 +172,13 @@ export class NbUserComponent {
214172
*/
215173
@Input() badgePosition: string;
216174

217-
/**
218-
* Outputs when a context menu item is clicked
219-
* @type EventEmitter<NbUserMenuItem>
220-
*/
221-
@Output() menuClick = new EventEmitter<NbUserMenuItem>();
222-
223175
imageBackgroundStyle: SafeStyle;
224176
showNameValue: boolean = true;
225177
showTitleValue: boolean = true;
226178
showInitialsValue: boolean = true;
227179
isMenuShown: boolean = false;
228180

229-
constructor(
230-
private el: ElementRef,
231-
private domSanitizer: DomSanitizer) { }
232-
233-
itemClick(event: any, item: NbUserMenuItem): boolean {
234-
this.menuClick.emit(item);
235-
return false;
236-
}
237-
238-
/**
239-
* Toggles a context menu
240-
*/
241-
toggleMenu() {
242-
this.isMenuShown = !this.isMenuShown;
243-
}
244-
245-
@HostListener('document:click', ['$event'])
246-
hideMenu(event: any) {
247-
if (!this.el.nativeElement.contains(event.target)) {
248-
this.isMenuShown = false;
249-
}
250-
}
181+
constructor(private domSanitizer: DomSanitizer) { }
251182

252183
getInitials(): string {
253184
if (this.name) {
@@ -258,9 +189,4 @@ export class NbUserComponent {
258189

259190
return '';
260191
}
261-
262-
hasMenu(): boolean {
263-
return this.menu && this.menu.length > 0;
264-
}
265-
266192
}

src/framework/theme/styles/themes/_cosmic.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ $theme: (
6161
user-fg: color-bg,
6262
user-bg: color-fg,
6363
user-fg-highlight: color-fg-highlight,
64-
user-menu-active-bg: color-primary,
65-
user-menu-border: color-primary,
6664

6765
popover-border: color-primary,
6866
popover-shadow: shadow,

src/framework/theme/styles/themes/_default.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ $theme: (
226226
user-size-medium: 2.5rem,
227227
user-size-large: 3.25rem,
228228
user-size-xlarge: 4rem,
229-
user-menu-fg: color-fg-heading,
230-
user-menu-bg: color-bg,
231-
user-menu-active-fg: #ffffff,
232-
user-menu-active-bg: color-success,
233-
user-menu-border: color-success,
234229

235230
popover-fg: color-fg-heading,
236231
popover-bg: color-bg,

0 commit comments

Comments
 (0)