Skip to content

Commit

Permalink
feat(module:breadcrumb): support indenpendent separator (#4713)
Browse files Browse the repository at this point in the history
* chore(module:breadcrumb): refactor breadcrumb

* feat(module:breadcrumb): add independent separator component

* fix: fix new component not exported
  • Loading branch information
Wendell committed Feb 28, 2020
1 parent 09bf8f4 commit 1f490e9
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 42 deletions.
23 changes: 21 additions & 2 deletions ...readcrumb/nz-breadcrumb-item.component.ts → ...s/breadcrumb/breadcrumb-item.component.ts 100755 → 100644
Expand Up @@ -10,15 +10,34 @@ import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@a

import { NzDropdownMenuComponent } from 'ng-zorro-antd/dropdown';

import { NzBreadCrumbComponent } from './nz-breadcrumb.component';
import { NzBreadCrumbComponent } from './breadcrumb.component';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-breadcrumb-item',
exportAs: 'nzBreadcrumbItem',
preserveWhitespaces: false,
templateUrl: './nz-breadcrumb-item.component.html',
template: `
<ng-container *ngIf="!!nzOverlay; else noMenuTpl">
<span class="ant-breadcrumb-overlay-link" nz-dropdown [nzDropdownMenu]="nzOverlay">
<ng-template [ngTemplateOutlet]="noMenuTpl"></ng-template>
<i *ngIf="!!nzOverlay" nz-icon nzType="down"></i>
</span>
</ng-container>
<ng-template #noMenuTpl>
<span class="ant-breadcrumb-link">
<ng-content></ng-content>
</span>
</ng-template>
<span class="ant-breadcrumb-separator" *ngIf="nzBreadCrumbComponent.nzSeparator">
<ng-container *nzStringTemplateOutlet="nzBreadCrumbComponent.nzSeparator">
{{ nzBreadCrumbComponent.nzSeparator }}
</ng-container>
</span>
`,
styles: [
`
nz-breadcrumb-item:last-child {
Expand Down
20 changes: 20 additions & 0 deletions components/breadcrumb/breadcrumb-separator.component.ts
@@ -0,0 +1,20 @@
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { Component } from '@angular/core';

@Component({
selector: 'nz-breadcrumb-separator',
exportAs: 'nzBreadcrumbSeparator',
template: `
<span class="ant-breadcrumb-separator">
<ng-content></ng-content>
</span>
`
})
export class NzBreadCrumbSeparatorComponent {}
Expand Up @@ -38,7 +38,14 @@ export interface BreadcrumbOption {
selector: 'nz-breadcrumb',
exportAs: 'nzBreadcrumb',
preserveWhitespaces: false,
templateUrl: './nz-breadcrumb.component.html',
template: `
<ng-content></ng-content>
<ng-container *ngIf="nzAutoGenerate">
<nz-breadcrumb-item *ngFor="let breadcrumb of breadcrumbs">
<a [attr.href]="breadcrumb.url" (click)="navigate(breadcrumb.url, $event)">{{ breadcrumb.label }}</a>
</nz-breadcrumb-item>
</ng-container>
`,
styles: [
`
nz-breadcrumb {
Expand All @@ -49,7 +56,7 @@ export interface BreadcrumbOption {
})
export class NzBreadCrumbComponent implements OnInit, OnDestroy {
@Input() @InputBoolean() nzAutoGenerate = false;
@Input() nzSeparator: string | TemplateRef<void> = '/';
@Input() nzSeparator: string | TemplateRef<void> | null = '/';
@Input() nzRouteLabel: string = 'breadcrumb';

breadcrumbs: BreadcrumbOption[] | undefined = [];
Expand Down
Expand Up @@ -14,12 +14,13 @@ import { NzOutletModule, NzOverlayModule } from 'ng-zorro-antd/core';
import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
import { NzIconModule } from 'ng-zorro-antd/icon';

import { NzBreadCrumbItemComponent } from './nz-breadcrumb-item.component';
import { NzBreadCrumbComponent } from './nz-breadcrumb.component';
import { NzBreadCrumbItemComponent } from './breadcrumb-item.component';
import { NzBreadCrumbSeparatorComponent } from './breadcrumb-separator.component';
import { NzBreadCrumbComponent } from './breadcrumb.component';

@NgModule({
imports: [CommonModule, NzOutletModule, OverlayModule, NzOverlayModule, NzDropDownModule, NzIconModule],
declarations: [NzBreadCrumbComponent, NzBreadCrumbItemComponent],
exports: [NzBreadCrumbComponent, NzBreadCrumbItemComponent]
declarations: [NzBreadCrumbComponent, NzBreadCrumbItemComponent, NzBreadCrumbSeparatorComponent],
exports: [NzBreadCrumbComponent, NzBreadCrumbItemComponent, NzBreadCrumbSeparatorComponent]
})
export class NzBreadCrumbModule {}
Expand Up @@ -9,11 +9,11 @@ import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
import { NzIconTestModule } from 'ng-zorro-antd/icon/testing';
import { NzDemoBreadcrumbDropdownComponent } from './demo/dropdown';

import { NzBreadCrumbItemComponent } from './breadcrumb-item.component';
import { NzBreadCrumbComponent } from './breadcrumb.component';
import { NzBreadCrumbModule } from './breadcrumb.module';
import { NzDemoBreadcrumbBasicComponent } from './demo/basic';
import { NzDemoBreadcrumbSeparatorComponent } from './demo/separator';
import { NzBreadCrumbItemComponent } from './nz-breadcrumb-item.component';
import { NzBreadCrumbComponent } from './nz-breadcrumb.component';
import { NzBreadCrumbModule } from './nz-breadcrumb.module';

describe('breadcrumb', () => {
describe('basic', () => {
Expand Down
15 changes: 15 additions & 0 deletions components/breadcrumb/demo/separator-independent.md
@@ -0,0 +1,15 @@
---
order: 6
title:
zh-CN: 独立的分隔符
en-US: Configuring the Separator Independently
---

## zh-CN

使用 `nz-breadcrumb-separator` 可以自定义分隔符。

## en-US

The separator can be customized by using the component `nz-breadcrumb-separator`.

31 changes: 31 additions & 0 deletions components/breadcrumb/demo/separator-independent.ts
@@ -0,0 +1,31 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-breadcrumb-separator-independent',
template: `
<nz-breadcrumb [nzSeparator]="null">
<nz-breadcrumb-item>
Location
</nz-breadcrumb-item>
<nz-breadcrumb-separator>
:
</nz-breadcrumb-separator>
<nz-breadcrumb-item>
<a>Application Center</a>
</nz-breadcrumb-item>
<nz-breadcrumb-separator>
/
</nz-breadcrumb-separator>
<nz-breadcrumb-item>
Application List
</nz-breadcrumb-item>
<nz-breadcrumb-separator>
/
</nz-breadcrumb-separator>
<nz-breadcrumb-item>
An Application
</nz-breadcrumb-item>
</nz-breadcrumb>
`
})
export class NzDemoBreadcrumbSeparatorIndependentComponent {}
2 changes: 1 addition & 1 deletion components/breadcrumb/doc/index.en-US.md
Expand Up @@ -23,7 +23,7 @@ import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| `[nzSeparator]` | Custom separator | `string \| TemplateRef<void>` | `'/'` |
| `[nzSeparator]` | Custom separator | `string \| TemplateRef<void> \| null` | `'/'` |
| `[nzAutoGenerate]` | Auto generate breadcrumb | `boolean` | `false` |
| `[nzRouteLabel]` | Name of property that determines displayed text in routing config. It should be used when `nzAutoGenerate` is `true` | `string` | `'breadcrumb'` |

Expand Down
2 changes: 1 addition & 1 deletion components/breadcrumb/doc/index.zh-CN.md
Expand Up @@ -23,7 +23,7 @@ import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| `[nzSeparator]` | 分隔符自定义 | `string \| TemplateRef<void>` | `'/'` |
| `[nzSeparator]` | 分隔符自定义 | `string \| TemplateRef<void> \| null` | `'/'` |
| `[nzAutoGenerate]` | 自动生成 Breadcrumb | `boolean` | `false` |
| `[nzRouteLabel]` | 自定义 route data 属性名称, `nzAutoGenerate``true` 时才生效 | `string` | `'breadcrumb'` |

Expand Down
18 changes: 0 additions & 18 deletions components/breadcrumb/nz-breadcrumb-item.component.html

This file was deleted.

8 changes: 0 additions & 8 deletions components/breadcrumb/nz-breadcrumb.component.html

This file was deleted.

7 changes: 4 additions & 3 deletions components/breadcrumb/public-api.ts
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

export * from './nz-breadcrumb-item.component';
export * from './nz-breadcrumb.component';
export * from './nz-breadcrumb.module';
export * from './breadcrumb-item.component';
export * from './breadcrumb.component';
export * from './breadcrumb.module';
export * from './breadcrumb-separator.component';

0 comments on commit 1f490e9

Please sign in to comment.