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

feat(module:*): support global config #3613

Merged
merged 9 commits into from
Sep 9, 2019
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
8 changes: 4 additions & 4 deletions components/affix/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { NzAffixModule } from 'ng-zorro-antd/affix';

### nz-affix

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| `[nzOffsetBottom]` | Pixels to offset from bottom when calculating position of scroll | `number` | - |
| `[nzOffsetTop]` | Pixels to offset from top when calculating position of scroll | `number` | `0` |
| Property | Description | Type | Default | Global Config |
| -------- | ----------- | ---- | ------- | ------------- |
| `[nzOffsetBottom]` | Pixels to offset from bottom when calculating position of scroll | `number` | - | ✅ |
| `[nzOffsetTop]` | Pixels to offset from top when calculating position of scroll | `number` | `0` | ✅ |
| `[nzTarget]` | specifies the scrollable area dom node | `string \| HTMLElement` | `window` |
| `(nzChange)` | Callback for when affix state is changed | `EventEmitter<boolean>` | - |

Expand Down
8 changes: 4 additions & 4 deletions components/affix/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import { NzAffixModule } from 'ng-zorro-antd/affix';

### nz-affix

| 成员 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| `[nzOffsetBottom]` | 距离窗口底部达到指定偏移量后触发 | `number` | - |
| `[nzOffsetTop]` | 距离窗口顶部达到指定偏移量后触发 | `number` | `0` |
| 成员 | 说明 | 类型 | 默认值 | 全局配置 |
| --- | --- | --- | --- | --- |
| `[nzOffsetBottom]` | 距离窗口底部达到指定偏移量后触发 | `number` | - | ✅ |
| `[nzOffsetTop]` | 距离窗口顶部达到指定偏移量后触发 | `number` | `0` | ✅ |
| `[nzTarget]` | 设置 `nz-affix` 需要监听其滚动事件的元素,值为一个返回对应 DOM 元素的函数 | `string \| HTMLElement` | `window` |
| `(nzChange)` | 固定状态改变时触发的回调函数 | `EventEmitter<boolean>` | - |

Expand Down
44 changes: 39 additions & 5 deletions components/affix/nz-affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ import {
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { shallowEqual, toNumber, NgStyleInterface, NzScrollService } from 'ng-zorro-antd/core';
import { fromEvent, merge, Subscription } from 'rxjs';
import { auditTime } from 'rxjs/operators';

import {
shallowEqual,
toNumber,
NgStyleInterface,
NzConfigService,
NzScrollService,
WithConfig
} from 'ng-zorro-antd/core';

export const NZ_AFFIX_DEFAULT_SCROLL_TIME = 20;

@Component({
Expand All @@ -46,8 +54,35 @@ export const NZ_AFFIX_DEFAULT_SCROLL_TIME = 20;
})
export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
@Input() nzTarget: string | Element | Window;
@Input() nzOffsetTop: number | null;
@Input() nzOffsetBottom: number | null;

@Input()
@WithConfig<number | null>()
set nzOffsetTop(value: number | null) {
if (value === undefined || value === null) {
return;
}
this._offsetTop = toNumber(value, null);
this.updatePosition({} as Event);
}

get nzOffsetTop(): number | null {
return this._offsetTop;
}

private _offsetTop: number | null;

@Input()
@WithConfig<number>()
set nzOffsetBottom(value: number) {
if (typeof value === 'undefined') {
return;
}
this._offsetBottom = toNumber(value, null);
this.updatePosition({} as Event);
}

private _offsetBottom: number | null;

@Output() readonly nzChange = new EventEmitter<boolean>();
@ViewChild('fixedEl', { static: true }) private fixedEl: ElementRef<HTMLDivElement>;

Expand All @@ -57,8 +92,6 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
private readonly placeholderNode: HTMLElement;
private affixStyle: NgStyleInterface | undefined;
private placeholderStyle: NgStyleInterface | undefined;
private _offsetTop: number | null;
private _offsetBottom: number | null;

private get target(): Element | Window {
const el = this.nzTarget;
Expand All @@ -67,6 +100,7 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {

constructor(
_el: ElementRef,
public nzConfigService: NzConfigService,
private scrollSrv: NzScrollService,
// tslint:disable-next-line:no-any
@Inject(DOCUMENT) private doc: any,
Expand Down
8 changes: 4 additions & 4 deletions components/alert/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import { NzAlertModule } from 'ng-zorro-antd/alert';

### nz-alert

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| Property | Description | Type | Default | Global Config |
| -------- | ----------- | ---- | ------- | ------------- |
| `[nzBanner]` | Whether to show as banner | `boolean` | `false` |
| `[nzCloseable]` | Whether Alert can be closed | `boolean` | - |
| `[nzCloseable]` | Whether Alert can be closed | `boolean` | - | ✅ |
| `[nzCloseText]` | Close text to show | `string \| TemplateRef<void>` | - |
| `[nzDescription]` | Additional content of Alert | `string \| TemplateRef<void>` | - |
| `[nzMessage]` | Content of Alert | `string \| TemplateRef<void>` | - |
| `[nzShowIcon]` | Whether to show icon, in `nzBanner` mode default is `true` | `boolean` | `false` |
| `[nzShowIcon]` | Whether to show icon, in `nzBanner` mode default is `true` | `boolean` | `false` | ✅ |
| `[nzIconType]` | Icon type, effective when `nzShowIcon` is `true` | `string \| string[] \| Set<string> \| { [klass: string]: any; }` | - |
| `[nzType]` | Type of Alert styles, in `nzBanner` mode default is `'warning'` | `'success' \| 'info' \| 'warning' \| 'error'` | `'info'` |
| `(nzOnClose)` | Callback when Alert is closed | `EventEmitter<void>` | - |
8 changes: 4 additions & 4 deletions components/alert/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import { NzAlertModule } from 'ng-zorro-antd/alert';

### nz-alert

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| 参数 | 说明 | 类型 | 默认值 | 全局配置 |
| --- | --- | --- | --- | --- |
| `[nzBanner]` | 是否用作顶部公告 | `boolean` | `false` |
| `[nzCloseable]` | 默认不显示关闭按钮 | `boolean` | - |
| `[nzCloseable]` | 默认不显示关闭按钮 | `boolean` | - | ✅ |
| `[nzCloseText]` | 自定义关闭按钮 | `string \| TemplateRef<void>` | - |
| `[nzDescription]` | 警告提示的辅助性文字介绍 | `string \| TemplateRef<void>` | - |
| `[nzMessage]` | 警告提示内容 | `string \| TemplateRef<void>` | - |
| `[nzShowIcon]` | 是否显示辅助图标,`nzBanner` 模式下默认值为 `true` | `boolean` | `false` |
| `[nzShowIcon]` | 是否显示辅助图标,`nzBanner` 模式下默认值为 `true` | `boolean` | `false` | ✅ |
| `[nzIconType]` | 自定义图标类型,`nzShowIcon` 为 `true` 时有效 | `string \| string[] \| Set<string> \| { [klass: string]: any; }` | - |
| `[nzType]` | 指定警告提示的样式,`nzBanner` 模式下默认值为 `'warning'` | `'success' \| 'info' \| 'warning' \| 'error'` | `'info'` |
| `(nzOnClose)` | 关闭时触发的回调函数 | `EventEmitter<void>` | - |
8 changes: 5 additions & 3 deletions components/alert/nz-alert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { slideAlertMotion, InputBoolean, NgClassType } from 'ng-zorro-antd/core';
import { slideAlertMotion, InputBoolean, NgClassType, NzConfigService, WithConfig } from 'ng-zorro-antd/core';

@Component({
selector: 'nz-alert',
Expand All @@ -41,8 +41,8 @@ export class NzAlertComponent implements OnChanges {
@Input() nzMessage: string | TemplateRef<void>;
@Input() nzDescription: string | TemplateRef<void>;
@Input() nzType: 'success' | 'info' | 'warning' | 'error' = 'info';
@Input() @InputBoolean() nzCloseable = false;
@Input() @InputBoolean() nzShowIcon = false;
@Input() @WithConfig(false) @InputBoolean() nzCloseable: boolean;
@Input() @WithConfig(false) @InputBoolean() nzShowIcon: boolean;
@Input() @InputBoolean() nzBanner = false;
@Output() readonly nzOnClose = new EventEmitter<boolean>();

Expand All @@ -58,6 +58,8 @@ export class NzAlertComponent implements OnChanges {
private isShowIconSet = false;
private inferredIconType: string = 'info-circle';

constructor(public nzConfigService: NzConfigService) {}

closeAlert(): void {
this.destroy = true;
}
Expand Down
10 changes: 5 additions & 5 deletions components/anchor/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { NzAnchorModule } from 'ng-zorro-antd/anchor';

### nz-anchor

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| Property | Description | Type | Default | Global Config |
| -------- | ----------- | ---- | ------- | ------------- |
| `[nzAffix]` | Fixed mode of Anchor | `boolean` | `true` |
| `[nzBounds]` | Bounding distance of anchor area, unit: px | `number` | `5` |
| `[nzOffsetTop]` | Pixels to offset from top when calculating position of scroll | `number` | `0` |
| `[nzShowInkInFixed]` | Whether show ink-balls in Fixed mode | `boolean` | `false` |
| `[nzBounds]` | Bounding distance of anchor area, unit: px | `number` | `5` | ✅ |
| `[nzOffsetTop]` | Pixels to offset from top when calculating position of scroll | `number` | `0` | ✅ |
| `[nzShowInkInFixed]` | Whether show ink-balls in Fixed mode | `boolean` | `false` | ✅ |
| `[nzTarget]` | Scrolling container | `string \| HTMLElement` | `window` |
| `(nzClick)` | Click of Anchor item | `EventEmitter<string>` | - |
| `(nzScroll)` | The scroll function that is triggered when scrolling to an anchor. | `EventEmitter<NzAnchorLinkComponent>` | - |
Expand Down
10 changes: 5 additions & 5 deletions components/anchor/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import { NzAnchorModule } from 'ng-zorro-antd/anchor';

### nz-anchor

| 成员 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| 成员 | 说明 | 类型 | 默认值 | 全局配置 |
| --- | --- | --- | --- | --- |
| `[nzAffix]` | 固定模式 | `boolean` | `true` |
| `[nzBounds]` | 锚点区域边界,单位:px | `number` | `5` |
| `[nzOffsetTop]` | 距离窗口顶部达到指定偏移量后触发 | `number` | - |
| `[nzShowInkInFixed]` | 固定模式是否显示小圆点 | `boolean` | `false` |
| `[nzBounds]` | 锚点区域边界,单位:px | `number` | `5` | ✅ |
| `[nzOffsetTop]` | 距离窗口顶部达到指定偏移量后触发 | `number` | - | ✅ |
| `[nzShowInkInFixed]` | 固定模式是否显示小圆点 | `boolean` | `false` | ✅ |
| `[nzTarget]` | 指定滚动的容器 | `string \| HTMLElement` | `window` |
| `(nzClick)` | 点击项触发 | `EventEmitter<string>` | - |
| `(nzScroll)` | 滚动至某锚点时触发 | `EventEmitter<NzAnchorLinkComponent>` | - |
Expand Down
16 changes: 13 additions & 3 deletions components/anchor/nz-anchor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ import {
import { fromEvent, Subscription } from 'rxjs';
import { distinctUntilChanged, throttleTime } from 'rxjs/operators';

import { toNumber, InputBoolean, InputNumber, NgStyleInterface, NzScrollService } from 'ng-zorro-antd/core';
import {
toNumber,
InputBoolean,
InputNumber,
NgStyleInterface,
NzConfigService,
NzScrollService,
WithConfig
} from 'ng-zorro-antd/core';

import { NzAnchorLinkComponent } from './nz-anchor-link.component';

Expand All @@ -48,10 +56,11 @@ export class NzAnchorComponent implements OnDestroy, AfterViewInit {
@ViewChild('ink', { static: false }) private ink: ElementRef;

@Input() @InputBoolean() nzAffix = true;
@Input() @InputBoolean() nzShowInkInFixed = false;
@Input() @InputNumber() nzBounds: number = 5;
@Input() @WithConfig(false) @InputBoolean() nzShowInkInFixed: boolean;
@Input() @WithConfig(5) @InputNumber() nzBounds: number;

@Input()
@WithConfig<number>()
set nzOffsetTop(value: number) {
this._offsetTop = toNumber(value, 0);
this.wrapperStyle = {
Expand Down Expand Up @@ -84,6 +93,7 @@ export class NzAnchorComponent implements OnDestroy, AfterViewInit {
private destroyed = false;

constructor(
public nzConfigService: NzConfigService,
private scrollSrv: NzScrollService,
/* tslint:disable-next-line:no-any */
@Inject(DOCUMENT) private doc: any,
Expand Down
8 changes: 4 additions & 4 deletions components/avatar/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { NzAvatarModule } from 'ng-zorro-antd/avatar';

### nz-avatar

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| Property | Description | Type | Default | Global Config |
| -------- | ----------- | ---- | ------- | ------------- |
| `[nzIcon]` | the `Icon` type for an icon avatar, see `Icon` | `string` | - |
| `[nzShape]` | the shape of avatar | `'circle' \| 'square'` | `'circle'` |
| `[nzSize]` | the size of the avatar | `'large' \| 'small' \| 'default' \| number` | `'default'` |
| `[nzShape]` | the shape of avatar | `'circle' \| 'square'` | `'circle'` | ✅ |
| `[nzSize]` | the size of the avatar | `'large' \| 'small' \| 'default' \| number` | `'default'` | ✅ |
| `[nzSrc]` | the address of the image for an image avatar | `string` | - |
| `[nzSrcSet]` | a list of sources to use for different screen resolutions | string | - |
| `[nzAlt]` | This attribute defines the alternative text describing the image | string | - |
Expand Down
8 changes: 4 additions & 4 deletions components/avatar/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { NzAvatarModule } from 'ng-zorro-antd/avatar';

### nz-avatar

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| 参数 | 说明 | 类型 | 默认值 | 全局配置 |
| --- | --- | --- | --- | --- |
| `[nzIcon]` | 设置头像的图标类型,参考 `Icon` | `string` | - |
| `[nzShape]` | 指定头像的形状 | `'circle' \| 'square'` | `'circle'` |
| `[nzSize]` | 设置头像的大小 | `'large' \| 'small' \| 'default' \| number` | `'default'` |
| `[nzShape]` | 指定头像的形状 | `'circle' \| 'square'` | `'circle'` | ✅ |
| `[nzSize]` | 设置头像的大小 | `'large' \| 'small' \| 'default' \| number` | `'default'` | ✅ |
| `[nzSrc]` | 图片类头像的资源地址 | `string` | - |
| `[nzSrcSet]` | 设置图片类头像响应式资源地址 | string | - |
| `[nzAlt]` | 图像无法显示时的替代文本 | string | - |
Expand Down
21 changes: 11 additions & 10 deletions components/avatar/nz-avatar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {
ViewEncapsulation
} from '@angular/core';

import { NzSizeLDSType, NzSizeMap, NzUpdateHostClassService } from 'ng-zorro-antd/core';

export type NzAvatarShape = 'square' | 'circle';
export type NzAvatarSize = NzSizeLDSType | number;

export interface NzAvatarSizeMap {
[size: string]: string;
}
import {
NzConfigService,
NzShapeSCType,
NzSizeLDSType,
NzSizeMap,
NzUpdateHostClassService,
WithConfig
} from 'ng-zorro-antd/core';

@Component({
selector: 'nz-avatar',
Expand All @@ -41,8 +41,8 @@ export interface NzAvatarSizeMap {
encapsulation: ViewEncapsulation.None
})
export class NzAvatarComponent implements OnChanges {
@Input() nzShape: NzAvatarShape = 'circle';
@Input() nzSize: NzAvatarSize = 'default';
@Input() @WithConfig('circle') nzShape: NzShapeSCType;
@Input() @WithConfig('default') nzSize: NzSizeLDSType | number;
@Input() nzText: string;
@Input() nzSrc: string;
@Input() nzSrcSet: string;
Expand All @@ -63,6 +63,7 @@ export class NzAvatarComponent implements OnChanges {
private sizeMap: NzSizeMap = { large: 'lg', small: 'sm' };

constructor(
public nzConfigService: NzConfigService,
private elementRef: ElementRef,
private cd: ChangeDetectorRef,
private updateHostClassService: NzUpdateHostClassService,
Expand Down
6 changes: 3 additions & 3 deletions components/back-top/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import { NzBackTopModule } from 'ng-zorro-antd/back-top';
> The distance to the bottom is set to `50px` by default, which is overridable.
> If you decide to use custom styles, please note the size limit: no more than `40px * 40px`.

| Property | Description | Type | Default |
| --- | --- | --- | --- |
| Property | Description | Type | Default | Global Config |
| --- | --- | --- | --- | --- |
| `[nzTemplate]` | custom content | `TemplateRef<void>` | - |
| `[nzVisibilityHeight]` | the `nz-back-top` button will not show until the scroll height reaches this value | `number` | `400` |
| `[nzVisibilityHeight]` | the `nz-back-top` button will not show until the scroll height reaches this value | `number` | `400` | ✅ |
| `[nzTarget]` | specifies the scrollable area dom node | `string \| Element` | `window` |
| `(nzClick)` | a callback function, which can be executed when you click the button | `EventEmitter<boolean>` | - |

6 changes: 3 additions & 3 deletions components/back-top/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { NzBackTopModule } from 'ng-zorro-antd/back-top';
> 有默认样式,距离底部 `50px`,可覆盖。
> 自定义样式宽高不大于 `40px * 40px`。

| 成员 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| 成员 | 说明 | 类型 | 默认值 | 全局配置 |
| --- | --- | --- | --- | --- |
| `[nzTemplate]` | 自定义内容,见示例 | `TemplateRef<void>` | - |
| `[nzVisibilityHeight]` | 滚动高度达到此参数值才出现 `nz-back-top` | `number` | `400` |
| `[nzVisibilityHeight]` | 滚动高度达到此参数值才出现 `nz-back-top` | `number` | `400` | ✅ |
| `[nzTarget]` | 设置需要监听其滚动事件的元素,值为一个返回对应 DOM 元素的函数 | `string \| Element` | `window` |
| `(nzClick)` | 点击按钮的回调函数 | `EventEmitter<boolean>` | - |
15 changes: 3 additions & 12 deletions components/back-top/nz-back-top.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
ViewEncapsulation
} from '@angular/core';

import { fadeMotion, toNumber, NzScrollService } from 'ng-zorro-antd/core';
import { fadeMotion, InputNumber, NzConfigService, NzScrollService, WithConfig } from 'ng-zorro-antd/core';
import { fromEvent, Subscription } from 'rxjs';
import { distinctUntilChanged, throttleTime } from 'rxjs/operators';

Expand All @@ -42,17 +42,7 @@ export class NzBackTopComponent implements OnInit, OnDestroy {
visible: boolean = false;

@Input() nzTemplate: TemplateRef<void>;

private _visibilityHeight: number = 400;

@Input()
set nzVisibilityHeight(value: number) {
this._visibilityHeight = toNumber(value, 400);
}

get nzVisibilityHeight(): number {
return this._visibilityHeight;
}
@Input() @WithConfig(400) @InputNumber() nzVisibilityHeight: number;

@Input()
set nzTarget(el: string | HTMLElement) {
Expand All @@ -63,6 +53,7 @@ export class NzBackTopComponent implements OnInit, OnDestroy {
@Output() readonly nzClick: EventEmitter<boolean> = new EventEmitter();

constructor(
public nzConfigService: NzConfigService,
private scrollSrv: NzScrollService,
// tslint:disable-next-line:no-any
@Inject(DOCUMENT) private doc: any,
Expand Down
Loading