Skip to content

Commit

Permalink
feat(module:menu): support auto active menu-item via routerLink
Browse files Browse the repository at this point in the history
  • Loading branch information
vthinkxie authored and vthinkxie committed Jun 21, 2019
1 parent 0cde4d7 commit c9e84c7
Show file tree
Hide file tree
Showing 17 changed files with 418 additions and 44 deletions.
191 changes: 191 additions & 0 deletions components/badge/style/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
@import '../../style/themes/index';
@import '../../style/mixins/index';

@badge-prefix-cls: ~'@{ant-prefix}-badge';
@number-prefix-cls: ~'@{ant-prefix}-scroll-number';

.@{badge-prefix-cls} {
.reset-component;

position: relative;
display: inline-block;
color: unset;
line-height: 1;

&-count {
z-index: @zindex-badge;
min-width: @badge-height;
height: @badge-height;
padding: 0 6px;
color: @badge-text-color;
font-weight: @badge-font-weight;
font-size: @badge-font-size;
line-height: @badge-height;
white-space: nowrap;
text-align: center;
background: @highlight-color;
border-radius: @badge-height / 2;
box-shadow: 0 0 0 1px @shadow-color-inverse;
a,
a:hover {
color: @badge-text-color;
}
}

&-multiple-words {
padding: 0 8px;
}

&-dot {
z-index: @zindex-badge;
width: @badge-dot-size;
height: @badge-dot-size;
background: @highlight-color;
border-radius: 100%;
box-shadow: 0 0 0 1px @shadow-color-inverse;
}

&-count,
&-dot,
.@{number-prefix-cls}-custom-component {
position: absolute;
top: 0;
right: 0;
transform: translate(50%, -50%);
transform-origin: 100% 0%;
}

&-status {
line-height: inherit;
vertical-align: baseline;

&-dot {
position: relative;
top: -1px;
display: inline-block;
width: @badge-status-size;
height: @badge-status-size;
vertical-align: middle;
border-radius: 50%;
}
&-success {
background-color: @success-color;
}
&-processing {
position: relative;
background-color: @processing-color;
&::after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 1px solid @processing-color;
border-radius: 50%;
animation: antStatusProcessing 1.2s infinite ease-in-out;
content: '';
}
}
&-default {
background-color: @normal-color;
}
&-error {
background-color: @error-color;
}
&-warning {
background-color: @warning-color;
}

// mixin to iterate over colors and create CSS class for each one
.make-color-classes(@i: length(@preset-colors)) when (@i > 0) {
.make-color-classes(@i - 1);
@color: extract(@preset-colors, @i);
@darkColor: '@{color}-6';
&-@{color} {
background: @@darkColor;
}
}
.make-color-classes();

&-text {
margin-left: 8px;
color: @text-color;
font-size: @font-size-base;
}
}

&-zoom-appear,
&-zoom-enter {
animation: antZoomBadgeIn 0.3s @ease-out-back;
animation-fill-mode: both;
}

&-zoom-leave {
animation: antZoomBadgeOut 0.3s @ease-in-back;
animation-fill-mode: both;
}

&-not-a-wrapper {
&:not(.@{badge-prefix-cls}-status) {
vertical-align: middle;
}

.@{ant-prefix}-scroll-number {
position: relative;
top: auto;
display: block;
}

.@{badge-prefix-cls}-count {
transform: none;
}
}
}

@keyframes antStatusProcessing {
0% {
transform: scale(0.8);
opacity: 0.5;
}
100% {
transform: scale(2.4);
opacity: 0;
}
}

.@{number-prefix-cls} {
overflow: hidden;
&-only {
display: inline-block;
height: @badge-height;
transition: all 0.3s @ease-in-out;
> p {
height: @badge-height;
margin: 0;
}
}

&-symbol {
vertical-align: top;
}
}

@keyframes antZoomBadgeIn {
0% {
transform: scale(0) translate(50%, -50%);
opacity: 0;
}
100% {
transform: scale(1) translate(50%, -50%);
}
}

@keyframes antZoomBadgeOut {
0% {
transform: scale(1) translate(50%, -50%);
}
100% {
transform: scale(0) translate(50%, -50%);
opacity: 0;
}
}
2 changes: 1 addition & 1 deletion components/layout/demo/side.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Component } from '@angular/core';
</li>
<li nz-menu-item>
<i nz-icon nzType="file"></i>
File
<span>File</span>
</li>
</ul>
</nz-sider>
Expand Down
2 changes: 1 addition & 1 deletion components/menu/demo/horizontal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Component } from '@angular/core';
selector: 'nz-demo-menu-horizontal',
template: `
<ul nz-menu nzMode="horizontal">
<li nz-menu-item>
<li nz-menu-item nzSelected>
<i nz-icon nzType="mail"></i>
Navigation One
</li>
Expand Down
6 changes: 3 additions & 3 deletions components/menu/demo/inline-collapsed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Component } from '@angular/core';
selector: 'nz-demo-menu-inline-collapsed',
template: `
<div class="wrapper">
<button nz-button [nzType]="'primary'" (click)="toggleCollapsed()">
<button nz-button nzType="primary" (click)="toggleCollapsed()">
<i nz-icon [nzType]="isCollapsed ? 'menu-unfold' : 'menu-fold'"></i>
</button>
<ul nz-menu [nzMode]="'inline'" nzTheme="dark" [nzInlineCollapsed]="isCollapsed">
<li nz-menu-item nz-tooltip nzPlacement="right" [nzTitle]="isCollapsed ? 'Navigation One' : ''">
<ul nz-menu nzMode="inline" nzTheme="dark" [nzInlineCollapsed]="isCollapsed">
<li nz-menu-item nz-tooltip nzPlacement="right" [nzTitle]="isCollapsed ? 'Navigation One' : ''" nzSelected>
<i nz-icon nzType="mail"></i>
<span>Navigation One</span>
</li>
Expand Down
4 changes: 2 additions & 2 deletions components/menu/demo/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Component } from '@angular/core';
selector: 'nz-demo-menu-inline',
template: `
<ul nz-menu nzMode="inline">
<li nz-submenu nzTitle="Navigation One" nzIcon="mail">
<li nz-submenu nzTitle="Navigation One" nzIcon="mail" nzOpen>
<ul>
<li nz-menu-group nzTitle="Item 1">
<ul>
<li nz-menu-item>Option 1</li>
<li nz-menu-item nzSelected>Option 1</li>
<li nz-menu-item>Option 2</li>
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion components/menu/demo/recursive.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
order: 6
order: 7
title:
zh-CN: 递归生成菜单
en-US: Recursive
Expand Down
4 changes: 2 additions & 2 deletions components/menu/demo/recursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-menu-recursive',
template: `
<ul nz-menu [nzMode]="'inline'" style="width: 240px;">
<ul nz-menu nzMode="inline" style="width: 240px;">
<ng-container *ngTemplateOutlet="menuTpl; context: { $implicit: menus }"></ng-container>
<ng-template #menuTpl let-menus>
<ng-container *ngFor="let menu of menus">
Expand All @@ -14,7 +14,7 @@ import { Component } from '@angular/core';
[nzDisabled]="menu.disabled"
[nzSelected]="menu.selected"
>
<i nz-icon [type]="menu.icon" *ngIf="menu.icon"></i>
<i nz-icon [nzType]="menu.icon" *ngIf="menu.icon"></i>
<span>{{ menu.title }}</span>
</li>
<li
Expand Down
14 changes: 14 additions & 0 deletions components/menu/demo/router.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 6
title:
zh-CN: 配合路由使用
en-US: Router
---

## zh-CN

自动根据路由激活菜单项,需要结合 [routerLink](https://www.angular.cn/api/router/RouterLink) 一起使用。

## en-US

Automatically activate menu items based on routing, should work with [routerLink](https://angular.io/api/router/RouterLink).
16 changes: 16 additions & 0 deletions components/menu/demo/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-menu-router',
template: `
<ul nz-menu nzMode="horizontal">
<li nz-menu-item nzMatchRouter>
<a [routerLink]="['/', 'components', 'menu', 'en']">English Menu Document</a>
</li>
<li nz-menu-item nzMatchRouter>
<a [routerLink]="['/', 'components', 'menu', 'zh']">Chinese Menu Document</a>
</li>
</ul>
`
})
export class NzDemoMenuRouterComponent {}
2 changes: 1 addition & 1 deletion components/menu/demo/sider-current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-menu-sider-current',
template: `
<ul nz-menu [nzMode]="'inline'" style="width: 240px;">
<ul nz-menu nzMode="inline" style="width: 240px;">
<li
nz-submenu
[(nzOpen)]="openMap.sub1"
Expand Down
4 changes: 2 additions & 2 deletions components/menu/demo/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { Component } from '@angular/core';
</nz-switch>
<br />
<br />
<ul nz-menu [nzMode]="'inline'" style="width: 240px;" [nzTheme]="theme ? 'dark' : 'light'">
<ul nz-menu nzMode="inline" style="width: 240px;" [nzTheme]="theme ? 'dark' : 'light'">
<li nz-submenu nzOpen nzTitle="Navigation One" nzIcon="mail">
<ul>
<li nz-menu-group nzTitle="Item 1">
<ul>
<li nz-menu-item>Option 1</li>
<li nz-menu-item nzSelected>Option 1</li>
<li nz-menu-item>Option 2</li>
</ul>
</li>
Expand Down
10 changes: 6 additions & 4 deletions components/menu/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import { NzMenuModule } from 'ng-zorro-antd';
| ----- | ----------- | ---- | ------------- |
| `[nzDisabled]` | whether menu item is disabled or not | `boolean` | `false` |
| `[nzSelected]` | whether menu item is selected or not | `boolean` | `false` |
| `[nzMatchRouter]` | whether auto set `nzSelected` according to [routerLink](https://www.angular.cn/api/router/RouterLink) | `boolean` | `false` |
| `[nzMatchRouterExact]` | only match when the url matches the link exactly, same as [routerLinkActiveOptions](https://angular.io/api/router/RouterLinkActive#routerLinkActiveOptions) | `boolean` | `false` |

### [nz-submenu]

Expand All @@ -62,10 +64,10 @@ You can set the title of `[nz-submenu]` in the following ways.
```html
<li nz-submenu nzTitle="SubTitle" nzIcon="appstore"></li>

<li nz-submenu><span title><i nz-icon nzType="appstore"></i>SubTitle</span></li>
<li nz-submenu><span title><i nz-icon nzType="appstore"></i><span>SubTitle</span></span></li>

<li nz-submenu [nzTitle]="titleTpl"></li>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i>SubTitle</ng-template>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i><span>SubTitle</span></ng-template>
```

| Param | Description | Type | Default value |
Expand All @@ -84,10 +86,10 @@ You can set the title of `[nz-menu-group]` in the following ways.
```html
<li nz-menu-group nzTitle="SubTitle" nzIcon="appstore"></li>

<li nz-menu-group><span title><i nz-icon nzType="appstore"></i>SubTitle</span></li>
<li nz-menu-group><span title><i nz-icon nzType="appstore"></i><span>SubTitle</span></span></li>

<li nz-menu-group [nzTitle]="titleTpl"></li>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i>SubTitle</ng-template>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i><span>SubTitle</span></ng-template>
```

| Param | Description | Type | Default value |
Expand Down
10 changes: 6 additions & 4 deletions components/menu/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import { NzMenuModule } from 'ng-zorro-antd';
| --- | --- | --- | --- |
| `[nzDisabled]` | 是否禁用 | `boolean` | `false` |
| `[nzSelected]` | 是否被选中 | `boolean` | `false` |
| `[nzMatchRouter]` | 是否根据 [routerLink](https://www.angular.cn/api/router/RouterLink) 自动设定 `nzSelected` | `boolean` | `false` |
| `[nzMatchRouterExact]` | 是否路由完整精确匹配, 详见 [routerLinkActiveOptions](https://angular.io/api/router/RouterLinkActive#routerLinkActiveOptions) | `boolean` | `false` |

### [nz-submenu]

Expand All @@ -63,10 +65,10 @@ import { NzMenuModule } from 'ng-zorro-antd';
```html
<li nz-submenu nzTitle="SubTitle" nzIcon="appstore"></li>

<li nz-submenu><span title><i nz-icon nzType="appstore"></i>SubTitle</span></li>
<li nz-submenu><span title><i nz-icon nzType="appstore"></i><span>SubTitle</span></span></li>

<li nz-submenu [nzTitle]="titleTpl"></li>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i>SubTitle</ng-template>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i><span>SubTitle</span></ng-template>
```

| 参数 | 说明 | 类型 | 默认值 |
Expand All @@ -86,10 +88,10 @@ import { NzMenuModule } from 'ng-zorro-antd';
```html
<li nz-menu-group nzTitle="SubTitle" nzIcon="appstore"></li>

<li nz-menu-group><span title><i nz-icon nzType="appstore"></i>SubTitle</span></li>
<li nz-menu-group><span title><i nz-icon nzType="appstore"></i><span>SubTitle</span></span></li>

<li nz-menu-group [nzTitle]="titleTpl"></li>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i>SubTitle</ng-template>
<ng-template #titleTpl><i nz-icon nzType="appstore"></i><span>SubTitle</span></ng-template>
```
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
Expand Down
Loading

0 comments on commit c9e84c7

Please sign in to comment.