Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:modal): add nzOkDanger to avoid old button style #6157

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions components/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ import {
ViewEncapsulation
} from '@angular/core';
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
import { warnDeprecation } from 'ng-zorro-antd/core/logger';
import { BooleanInput } from 'ng-zorro-antd/core/types';
import { InputBoolean } from 'ng-zorro-antd/core/util';

import { NzIconDirective } from 'ng-zorro-antd/icon';
import { Subject } from 'rxjs';
import { filter, startWith, takeUntil } from 'rxjs/operators';

export type NzButtonType = 'primary' | 'default' | 'dashed' | 'danger' | 'link' | 'text' | null;
/**
* @deprecated `danger` not supported, use `nzDanger` instead
* @breaking-change 12.0.0
*/
type NzLegacyButtonType = 'primary' | 'default' | 'dashed' | 'danger' | 'link' | 'text' | null;

export type NzButtonType = NzLegacyButtonType;
export type NzButtonShape = 'circle' | 'round' | null;
export type NzButtonSize = 'large' | 'default' | 'small';

Expand Down Expand Up @@ -123,10 +130,14 @@ export class NzButtonComponent implements OnDestroy, OnChanges, AfterViewInit, A
}

ngOnChanges(changes: SimpleChanges): void {
const { nzLoading } = changes;
const { nzLoading, nzType } = changes;
if (nzLoading) {
this.loading$.next(this.nzLoading);
}

if (nzType) {
warnDeprecation(`'danger' value of 'nzType' in Button is going to be removed in 12.0.0. Please use 'nzDanger' instead.`);
}
}

ngAfterViewInit(): void {
Expand Down
4 changes: 3 additions & 1 deletion components/modal/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ The dialog is currently divided into 2 modes, `normal mode` and `confirm box mod
| nzCloseOnNavigation | Whether to close the modal when the navigation history changes | `boolean` | `true` | ✅ |
| nzMaskStyle | Style for modal's mask element. | `object` | - |
| nzOkText | Text of the OK button. <i>Set to null to show no ok button (this value is invalid if the nzFooter parameter is used in normal mode)</i> | `string` | OK |
| nzOkType | Button type of the OK button. <i>Consistent with the type of the `nz-button`.</i> | `string` | primary |
| nzOkType | Button type of the OK button. <i>Consistent with the `nzType` of the `nz-button`.</i> | `string` | `primary` |
| nzOkDanger | Danger status of the OK button. <i>Consistent with the `nzDanger` of the `nz-button`.</i> | `boolean` | `false` |
| nzStyle | Style of floating layer, typically used at least for adjusting the position. | `object` | - |
| nzCloseIcon | Custom close icon | `string\|TemplateRef<void>` | - |
| nzTitle | The modal dialog's title. <i>Leave blank to show no title. The usage of TemplateRef can refer to the case</i> | string / TemplateRef | - |
Expand Down Expand Up @@ -136,6 +137,7 @@ The button configuration items are as follows (along with the button component):
nzFooter: [{
label: string; // Button text
type?: string; // Types
danger?: boolean; // Whether danger
shape?: string; // Shape
ghost?: boolean; // Whether ghost
size?: string; // Size
Expand Down
4 changes: 3 additions & 1 deletion components/modal/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import { NzModalModule } from 'ng-zorro-antd/modal';
| nzCloseOnNavigation | 导航历史变化时是否关闭模态框 | `boolean` | `true` | ✅ |
| nzMaskStyle | 遮罩样式 | `object` | - |
| nzOkText | 确认按钮文字。<i>设为 null 表示不显示确认按钮(若在普通模式下使用了 nzFooter 参数,则该值无效)</i> | `string` | 确定 |
| nzOkType | 确认按钮类型。<i>与button的type类型值一致</i> | `string` | primary |
| nzOkType | 确认按钮类型。<i>与 `nz-button` 的 `nzType` 类型值一致</i> | `string` | `primary` |
| nzOkDanger | 确认按钮是否为危险按钮。<i>与 `nz-button` 的 `nzDanger` 值保持一致</i> | `boolean` | `false` |
| nzStyle | 可用于设置浮层的样式,调整浮层位置等 | `object` | - |
| nzTitle | 标题。<i>留空表示不展示标题。TemplateRef的使用方法可参考案例</i> | string<br>TemplateRef | - |
| nzCloseIcon | 自定义关闭图标 | `string\|TemplateRef<void>` | - |
Expand Down Expand Up @@ -136,6 +137,7 @@ constructor(modal: NzModalService) {
nzFooter: [{
label: string; // 按钮文本
type?: string; // 类型
danger?: boolean; // 是否danger
shape?: string; // 形状
ghost?: boolean; // 是否ghost
size?: string; // 大小
Expand Down
2 changes: 2 additions & 0 deletions components/modal/modal-footer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ModalButtonOptions, ModalOptions } from './modal-types';
[nzLoading]="getButtonCallableProp(button, 'loading')"
[disabled]="getButtonCallableProp(button, 'disabled')"
[nzType]="button.type!"
[nzDanger]="button.danger"
[nzShape]="button.shape!"
[nzSize]="button.size!"
[nzGhost]="button.ghost!"
Expand All @@ -54,6 +55,7 @@ import { ModalButtonOptions, ModalOptions } from './modal-types';
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
[nzDanger]="config.nzOkDanger"
(click)="onOk()"
[nzLoading]="!!config.nzOkLoading"
[disabled]="config.nzOkDisabled"
Expand Down
2 changes: 2 additions & 0 deletions components/modal/modal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class ModalOptions<T = NzSafeAny, R = NzSafeAny> {
nzWidth?: number | string = 520;
nzCloseIcon?: string | TemplateRef<void> = 'close';
nzOkType?: NzButtonType = 'primary';
nzOkDanger?: boolean = false;
nzModalType?: ModalTypes = 'default';
nzOnCancel?: EventEmitter<T> | OnClickCallback<T> = noopFun;
nzOnOk?: EventEmitter<T> | OnClickCallback<T> = noopFun;
Expand Down Expand Up @@ -70,6 +71,7 @@ export class ModalOptions<T = NzSafeAny, R = NzSafeAny> {
export interface ModalButtonOptions<T = NzSafeAny> {
label: string;
type?: NzButtonType;
danger?: boolean;
shape?: NzButtonShape;
ghost?: boolean;
size?: NzButtonSize;
Expand Down
2 changes: 2 additions & 0 deletions components/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class NzModalComponent<T = NzSafeAny, R = NzSafeAny> implements OnChanges
static ngAcceptInputType_nzCancelLoading: BooleanInput;
static ngAcceptInputType_nzKeyboard: BooleanInput;
static ngAcceptInputType_nzNoAnimation: BooleanInput;
static ngAcceptInputType_nzOkDanger: BooleanInput;

@Input() @InputBoolean() nzMask?: boolean;
@Input() @InputBoolean() nzMaskClosable?: boolean;
Expand Down Expand Up @@ -87,6 +88,7 @@ export class NzModalComponent<T = NzSafeAny, R = NzSafeAny> implements OnChanges
@Input() nzOkText?: string | null;
@Input() nzCancelText?: string | null;
@Input() nzOkType: NzButtonType = 'primary';
@Input() @InputBoolean() nzOkDanger: boolean = false;
@Input() nzIconType: string = 'question-circle'; // Confirm Modal ONLY
@Input() nzModalType: ModalTypes = 'default';
@Input() nzAutofocus: 'ok' | 'cancel' | 'auto' | null = 'auto';
Expand Down
2 changes: 2 additions & 0 deletions components/modal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function getConfigFromComponent(component: NzModalComponent): ModalOption
nzOkText,
nzCancelText,
nzOkType,
nzOkDanger,
nzIconType,
nzModalType,
nzOnOk,
Expand Down Expand Up @@ -85,6 +86,7 @@ export function getConfigFromComponent(component: NzModalComponent): ModalOption
nzOkText,
nzCancelText,
nzOkType,
nzOkDanger,
nzIconType,
nzModalType,
nzOnOk,
Expand Down