From ff030fff586473e8a148be4eb6c4f335e71c4fc7 Mon Sep 17 00:00:00 2001 From: Wendell Date: Mon, 25 Feb 2019 10:14:37 +0800 Subject: [PATCH] feat(module:popconfirm): support custom icon (#2964) * feat(module:popconfirm): support custom icon close #2196 * fix(module:cascader): add missed TemplateRef * fix: fix tsconfig * docs: fix cascader doc type --- components/cascader/doc/index.en-US.md | 2 +- components/cascader/doc/index.zh-CN.md | 2 +- components/cascader/nz-cascader.component.ts | 2 +- components/popconfirm/demo/custom-icon.md | 14 ++++++ components/popconfirm/demo/custom-icon.ts | 14 ++++++ components/popconfirm/doc/index.en-US.md | 11 +++-- components/popconfirm/doc/index.zh-CN.md | 1 + .../popconfirm/nz-popconfirm.component.html | 4 +- .../popconfirm/nz-popconfirm.component.ts | 12 ++++- .../popconfirm/nz-popconfirm.directive.ts | 6 ++- components/popconfirm/nz-popconfirm.module.ts | 10 +++- components/popconfirm/nz-popconfirm.spec.ts | 47 ++++++++++++++++--- 12 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 components/popconfirm/demo/custom-icon.md create mode 100644 components/popconfirm/demo/custom-icon.ts diff --git a/components/cascader/doc/index.en-US.md b/components/cascader/doc/index.en-US.md index ed749eceaf3..6381cf57a04 100755 --- a/components/cascader/doc/index.en-US.md +++ b/components/cascader/doc/index.en-US.md @@ -32,7 +32,7 @@ Cascade selection box. | `[nzExpandTrigger]` | expand current item when click or hover, one of 'click' 'hover' | `'click'|'hover'` | `'click'` | | `[nzMenuClassName]` | additional className of popup overlay | `string` | - | | `[nzMenuStyle]` | additional css style of popup overlay | `object` | - | -| `[nzNotFoundContent]` | Specify content to show when no result matches. | `string` | - | +| `[nzNotFoundContent]` | Specify content to show when no result matches. | `string|TemplateRef` | - | | `[nzLabelProperty]` | the label property name of options | `string` | `'label'` | | `[nzLabelRender]` | render template of displaying selected options | `TemplateRef` | - | | `[nzLoadData]` | To load option lazily. If setting `ngModel` with an array value and `nzOptions` is not setting, lazy load will be call immediately | `(option: any, index?: index) => PromiseLike` | - | diff --git a/components/cascader/doc/index.zh-CN.md b/components/cascader/doc/index.zh-CN.md index 6791c25ab7e..0ad7b836624 100755 --- a/components/cascader/doc/index.zh-CN.md +++ b/components/cascader/doc/index.zh-CN.md @@ -33,7 +33,7 @@ subtitle: 级联选择 | `[nzExpandTrigger]` | 次级菜单的展开方式,可选 'click' 和 'hover' | `'click'|'hover'` | `'click'` | | `[nzMenuClassName]` | 自定义浮层类名 | `string` | - | | `[nzMenuStyle]` | 自定义浮层样式 | `object` | - | -| `[nzNotFoundContent]` | 当下拉列表为空时显示的内容 | `string` | - | +| `[nzNotFoundContent]` | 当下拉列表为空时显示的内容 | `string|TemplateRef` | - | | `[nzLabelProperty]` | 选项的显示值的属性名 | `string` | `'label'` | | `[nzLabelRender]` | 选择后展示的渲染模板 | `TemplateRef` | - | | `[nzLoadData]` | 用于动态加载选项。如果提供了`ngModel`初始值,且未提供`nzOptions`值,则会立即触发动态加载。 | `(option: any, index?: index) => PromiseLike` | - | diff --git a/components/cascader/nz-cascader.component.ts b/components/cascader/nz-cascader.component.ts index d76d29e69f2..6d5342dab4b 100644 --- a/components/cascader/nz-cascader.component.ts +++ b/components/cascader/nz-cascader.component.ts @@ -85,7 +85,7 @@ export class NzCascaderComponent implements OnDestroy, ControlValueAccessor { @Input() nzValueProperty = 'value'; @Input() nzLabelRender: TemplateRef; @Input() nzLabelProperty = 'label'; - @Input() nzNotFoundContent: string; + @Input() nzNotFoundContent: string | TemplateRef; @Input() nzSize: NzCascaderSize = 'default'; @Input() nzShowSearch: boolean | NzShowSearchOptions; @Input() nzPlaceHolder = 'Please select'; diff --git a/components/popconfirm/demo/custom-icon.md b/components/popconfirm/demo/custom-icon.md new file mode 100644 index 00000000000..4705de58d99 --- /dev/null +++ b/components/popconfirm/demo/custom-icon.md @@ -0,0 +1,14 @@ +--- +order: 4 +title: + zh-CN: 自定义 icon 图标 + en-US: Customize icon +--- + +## zh-CN + +使用 `nzIcon` 自定义提示图标。 + +## en-US + +Set `nzIcon` to customize the icon. diff --git a/components/popconfirm/demo/custom-icon.ts b/components/popconfirm/demo/custom-icon.ts new file mode 100644 index 00000000000..9afc37d4486 --- /dev/null +++ b/components/popconfirm/demo/custom-icon.ts @@ -0,0 +1,14 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'nz-demo-popconfirm-custom-icon', + template: ` + Delete + + + + ` +}) + +export class NzDemoPopconfirmCustomIconComponent { +} diff --git a/components/popconfirm/doc/index.en-US.md b/components/popconfirm/doc/index.en-US.md index 18e762a2e58..9c0f447c8db 100644 --- a/components/popconfirm/doc/index.en-US.md +++ b/components/popconfirm/doc/index.en-US.md @@ -18,13 +18,14 @@ The difference with the `confirm` modal dialog is that it's more lightweight tha | Param | Description | Type | Default value | | ----- | ----------- | ---- | ------------- | -| `[nzCancelText]` | text of the Cancel button | `string` | `'Cancel'` | -| `[nzOkText]` | text of the Confirm button | `string` | `'Confirm'` | +| `[nzCancelText]` | Text of the Cancel button | `string` | `'Cancel'` | +| `[nzOkText]` | Text of the Confirm button | `string` | `'Confirm'` | | `[nzOkType]` | Button `type` of the Confirm button | `'primary'|'ghost'|'dashed'|'danger'|'default'` | `'primary'` | -| `[nzTitle]` | title of the confirmation box | `string|TemplateRef` | - | +| `[nzTitle]` | Title of the confirmation box | `string|TemplateRef` | - | | `[nzCondition]` | Whether to directly emit `onConfirm` without showing Popconfirm | `boolean` | `false` | -| `(nzOnCancel)` | callback of cancel | `EventEmitter` | - | -| `(nzOnConfirm)` | callback of confirmation | `EventEmitter` | - | +| `[nzIcon]` | Customize icon of confirmation | `string|TemplateRef` | - | +| `(nzOnCancel)` | Callback of cancel | `EventEmitter` | - | +| `(nzOnConfirm)` | Callback of confirmation | `EventEmitter` | - | Consult [Tooltip's documentation](/components/tooltip/en#api) to find more APIs. diff --git a/components/popconfirm/doc/index.zh-CN.md b/components/popconfirm/doc/index.zh-CN.md index 5b042dc1d82..1ce6679854d 100644 --- a/components/popconfirm/doc/index.zh-CN.md +++ b/components/popconfirm/doc/index.zh-CN.md @@ -24,6 +24,7 @@ title: Popconfirm | `[nzOkType]` | 确认按钮类型 | `'primary'|'ghost'|'dashed'|'danger'|'default'` | `'primary'` | | `[nzTitle]` | 确认框的描述 | `string|TemplateRef` | - | | `[nzCondition]` | 是否直接触发 `nzOnConfirm` 而不弹出框 | `boolean` | `false` | +| `[nzIcon]` | 自定义弹出框的 icon | `string|TemplateRef` | - | | `(nzOnCancel)` | 点击取消的回调 | `EventEmitter` | - | | `(nzOnConfirm)` | 点击确认的回调 | `EventEmitter` | - | diff --git a/components/popconfirm/nz-popconfirm.component.html b/components/popconfirm/nz-popconfirm.component.html index c02bd63efce..6de3a0474f4 100644 --- a/components/popconfirm/nz-popconfirm.component.html +++ b/components/popconfirm/nz-popconfirm.component.html @@ -22,7 +22,9 @@
- + + +
{{ nzTitle }}
diff --git a/components/popconfirm/nz-popconfirm.component.ts b/components/popconfirm/nz-popconfirm.component.ts index f046a36e4f8..0ffd44d0391 100644 --- a/components/popconfirm/nz-popconfirm.component.ts +++ b/components/popconfirm/nz-popconfirm.component.ts @@ -1,4 +1,13 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core'; +import { + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + EventEmitter, + Input, + Output, + TemplateRef, + ViewEncapsulation +} from '@angular/core'; import { zoomBigMotion } from '../core/animation/zoom'; import { InputBoolean } from '../core/util/convert'; import { NzToolTipComponent } from '../tooltip/nz-tooltip.component'; @@ -25,6 +34,7 @@ export class NzPopconfirmComponent extends NzToolTipComponent { @Input() nzOkType: string = 'primary'; @Input() nzCancelText: string; @Input() @InputBoolean() nzCondition = false; + @Input() nzIcon: string | TemplateRef; @Output() readonly nzOnCancel: EventEmitter = new EventEmitter(); @Output() readonly nzOnConfirm: EventEmitter = new EventEmitter(); diff --git a/components/popconfirm/nz-popconfirm.directive.ts b/components/popconfirm/nz-popconfirm.directive.ts index 7dccc4bdcf4..a443ca79a80 100644 --- a/components/popconfirm/nz-popconfirm.directive.ts +++ b/components/popconfirm/nz-popconfirm.directive.ts @@ -8,7 +8,7 @@ import { OnInit, Optional, Output, - Renderer2, + Renderer2, TemplateRef, ViewContainerRef } from '@angular/core'; @@ -40,12 +40,14 @@ export class NzPopconfirmDirective extends NzTooltipDirective implements OnInit 'nzOkText', 'nzOkType', 'nzCancelText', - 'nzCondition' + 'nzCondition', + 'nzIcon' ]; @Input() nzOkText: string; @Input() nzOkType: string; @Input() nzCancelText: string; + @Input() nzIcon: string | TemplateRef; @Input() @InputBoolean() nzCondition: boolean; @Output() readonly nzOnCancel = new EventEmitter(); @Output() readonly nzOnConfirm = new EventEmitter(); diff --git a/components/popconfirm/nz-popconfirm.module.ts b/components/popconfirm/nz-popconfirm.module.ts index 7fae3df1514..68df27f28c5 100644 --- a/components/popconfirm/nz-popconfirm.module.ts +++ b/components/popconfirm/nz-popconfirm.module.ts @@ -14,7 +14,15 @@ import { NzPopconfirmDirective } from './nz-popconfirm.directive'; @NgModule({ declarations : [ NzPopconfirmComponent, NzPopconfirmDirective ], exports : [ NzPopconfirmComponent, NzPopconfirmDirective ], - imports : [ CommonModule, NzButtonModule, OverlayModule, NzI18nModule, NzIconModule, NzAddOnModule, NzOverlayModule ], + imports : [ + CommonModule, + NzButtonModule, + OverlayModule, + NzI18nModule, + NzIconModule, + NzAddOnModule, + NzOverlayModule + ], entryComponents: [ NzPopconfirmComponent ] }) diff --git a/components/popconfirm/nz-popconfirm.spec.ts b/components/popconfirm/nz-popconfirm.spec.ts index 1d13d742b63..c7bdd44e834 100644 --- a/components/popconfirm/nz-popconfirm.spec.ts +++ b/components/popconfirm/nz-popconfirm.spec.ts @@ -245,18 +245,50 @@ describe('NzPopconfirm', () => { const triggerElement = component.inBtnGroup.nativeElement; expect(triggerElement.nextSibling.tagName).toBe('BUTTON'); })); + it('should support custom icon', fakeAsync(() => { + component.icon = 'question-circle'; + const triggerElement = component.iconTemplate.nativeElement; + dispatchMouseEvent(triggerElement, 'click'); + fixture.detectChanges(); + tick(500); + fixture.detectChanges(); + expect(overlayContainerElement.querySelector('.anticon-exclamation-circle')).toBeFalsy(); + expect(overlayContainerElement.querySelector('.anticon-question-circle')).toBeTruthy(); + })); }); }); @Component({ selector: 'nz-popconfirm-test-new', template: ` - Delete - Delete + + Delete + + + Delete + + + Delete + title-template
- +
` @@ -265,17 +297,19 @@ export class NzpopconfirmTestNewComponent { confirm = jasmine.createSpy('confirm'); cancel = jasmine.createSpy('cancel'); condition = false; + icon: string = undefined; @ViewChild('stringTemplate') stringTemplate: ElementRef; @ViewChild('templateTemplate') templateTemplate: ElementRef; @ViewChild('inBtnGroup') inBtnGroup: ElementRef; - + @ViewChild('iconTemplate') iconTemplate: ElementRef; } @Component({ selector: 'nz-popconfirm-test-wrapper', template: ` - Show + Show + @@ -291,7 +325,8 @@ export class NzpopconfirmTestNewComponent { Show - + Show `