-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(context-menu): add context menu component
- Loading branch information
1 parent
959bd4a
commit 13799a5
Showing
19 changed files
with
387 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { browser, by, element } from 'protractor'; | ||
|
||
const withContextMenu = by.css('nb-card:nth-child(1) nb-user:nth-child(1)'); | ||
const popover = by.css('nb-layout > nb-popover'); | ||
|
||
describe('nb-context-menu', () => { | ||
|
||
beforeEach((done) => { | ||
browser.get('#/context-menu').then(done); | ||
}); | ||
|
||
it('have to be opened by click', () => { | ||
element(withContextMenu).click(); | ||
const containerContent = element(popover).element(by.css('nb-menu > ul')); | ||
expect(containerContent.isPresent()).toBeTruthy(); | ||
}); | ||
|
||
it('should have two menu items', () => { | ||
element(withContextMenu).click(); | ||
const menuItems = element(popover).all(by.css('nb-menu > ul > li')); | ||
|
||
expect(menuItems.count()).toEqual(2); | ||
}); | ||
|
||
it('have to open user page after click on first item', () => { | ||
element(withContextMenu).click(); | ||
const menuItems = element(popover).all(by.css('nb-menu > ul > li')); | ||
menuItems.get(0).click(); | ||
|
||
expect(browser.getCurrentUrl().then(it => it.split('#/')[1])).toEqual('user'); | ||
}); | ||
|
||
it('have to open popover page after click on second item', () => { | ||
element(withContextMenu).click(); | ||
const menuItems = element(popover).all(by.css('nb-menu > ul > li')); | ||
menuItems.get(1).click(); | ||
|
||
expect(browser.getCurrentUrl().then(it => it.split('#/')[1])).toEqual('popover'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'nb-context-menu-test', | ||
template: ` | ||
<nb-layout> | ||
<nb-layout-column> | ||
<nb-card> | ||
<nb-card-header>Context Menu</nb-card-header> | ||
<nb-card-body> | ||
<nb-user name="Nikita Poltoratsky" title="full-stack developer" [nbContextMenu]="items"> | ||
</nb-user> | ||
</nb-card-body> | ||
</nb-card> | ||
<nb-card> | ||
<nb-card-header>Context Menu</nb-card-header> | ||
<nb-card-body> | ||
<nb-user name="Nikita Poltoratsky" title="full-stack developer" [nbContextMenu]="itemsWithIcons"> | ||
</nb-user> | ||
</nb-card-body> | ||
</nb-card> | ||
</nb-layout-column> | ||
</nb-layout> | ||
`, | ||
}) | ||
export class NbContextMenuTestComponent { | ||
|
||
items = [ | ||
{ title: 'Profile', link: '/user' }, | ||
{ title: 'Logout', link: '/popover' }, | ||
]; | ||
|
||
itemsWithIcons = [ | ||
{ title: 'Profile', link: '/user', icon: 'nb-compose' }, | ||
{ title: 'Logout', link: '/popover', icon: 'nb-gear' }, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/framework/theme/components/context-menu/_context-menu.component.theme.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@import '../../styles/core/mixins'; | ||
|
||
@mixin nb-context-menu-theme() { | ||
nb-menu.context-menu .menu-items .menu-item a { | ||
color: nb-theme(context-menu-fg); | ||
font-weight: nb-theme(font-weight-normal); | ||
|
||
.menu-icon { | ||
color: nb-theme(context-menu-fg); | ||
} | ||
|
||
@include hover-focus-active { | ||
color: nb-theme(context-menu-active-fg); | ||
background: nb-theme(context-menu-active-bg); | ||
font-weight: nb-theme(font-weight-normal); | ||
|
||
.menu-icon { | ||
color: nb-theme(context-menu-active-fg); | ||
} | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/framework/theme/components/context-menu/context-menu.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
:host /deep/ nb-menu { | ||
display: inline; | ||
font-size: 0.875rem; | ||
line-height: 1.5rem; | ||
|
||
ul.menu-items { | ||
margin: 0; | ||
padding: 0.5rem 0; | ||
|
||
.menu-item { | ||
border: none; | ||
white-space: nowrap; | ||
|
||
&:first-child { | ||
border: none; | ||
} | ||
|
||
a { | ||
cursor: pointer; | ||
border-radius: 0; | ||
padding: 0; | ||
|
||
.menu-icon { | ||
font-size: 1.5rem; | ||
width: auto; | ||
} | ||
|
||
.menu-title { | ||
padding: 0.375rem 3rem; | ||
} | ||
|
||
.menu-icon ~ .menu-title { | ||
padding-left: 0; | ||
} | ||
|
||
.menu-icon:first-child { | ||
padding-left: 1rem; | ||
} | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/framework/theme/components/context-menu/context-menu.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { Component, Input } from '@angular/core'; | ||
import { NbMenuItem } from '../../'; | ||
|
||
/** | ||
* Context menu component used as content within NbContextMenuDirective. | ||
* | ||
* @styles | ||
* | ||
* context-menu-fg | ||
* context-menu-active-fg | ||
* context-menu-active-bg | ||
* */ | ||
@Component({ | ||
selector: 'nb-context-menu', | ||
styleUrls: ['./context-menu.component.scss'], | ||
template: '<nb-menu class="context-menu" [items]="items"></nb-menu>', | ||
}) | ||
export class NbContextMenuComponent { | ||
|
||
@Input() | ||
items: NbMenuItem[] = []; | ||
} |
Oops, something went wrong.