diff --git a/components/spin/demo/fullscreen.md b/components/spin/demo/fullscreen.md new file mode 100644 index 00000000000..12bbb8bfdff --- /dev/null +++ b/components/spin/demo/fullscreen.md @@ -0,0 +1,14 @@ +--- +order: 7 +title: + zh-CN: 全屏 + en-US: Fullscreen +--- + +## zh-CN + +`fullscreen` 属性非常适合创建流畅的页面加载器。它添加了半透明覆盖层,并在其中心放置了一个旋转加载符号。 + +## en-US + +The `fullscreen` mode is perfect for creating page loaders. It adds a dimmed overlay with a centered spinner. diff --git a/components/spin/demo/fullscreen.ts b/components/spin/demo/fullscreen.ts new file mode 100644 index 00000000000..2a696b01383 --- /dev/null +++ b/components/spin/demo/fullscreen.ts @@ -0,0 +1,20 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'nz-demo-spin-fullscreen', + template: ` + + + ` +}) +export class NzDemoSpinFullscreenComponent { + public isSpinning = false; + + public showSpinner(): void { + this.isSpinning = true; + + setTimeout(() => { + this.isSpinning = false; + }, 3000); + } +} diff --git a/components/spin/demo/module b/components/spin/demo/module index b523000e2e5..202a15852d8 100644 --- a/components/spin/demo/module +++ b/components/spin/demo/module @@ -2,5 +2,6 @@ import { NzSpinModule } from 'ng-zorro-antd/spin'; import { NzAlertModule } from 'ng-zorro-antd/alert'; import { NzIconModule } from 'ng-zorro-antd/icon'; import { NzSwitchModule } from 'ng-zorro-antd/switch'; +import { NzButtonModule } from 'ng-zorro-antd/button'; -export const moduleList = [ NzSpinModule, NzAlertModule, NzIconModule, NzSwitchModule ]; +export const moduleList = [ NzSpinModule, NzAlertModule, NzIconModule, NzSwitchModule, NzButtonModule ]; diff --git a/components/spin/doc/index.en-US.md b/components/spin/doc/index.en-US.md index 5cd3b443673..1ec1e20653f 100644 --- a/components/spin/doc/index.en-US.md +++ b/components/spin/doc/index.en-US.md @@ -19,11 +19,12 @@ import { NzSpinModule } from 'ng-zorro-antd/spin'; ### nz-spin -| Property | Description | Type | Default Value | Global Config | -| -------- | ----------- | ---- | ------------- | ------------- | -| `[nzDelay]` | specifies a delay in milliseconds for loading state (prevent flush), unit: milliseconds | `number` | - | -| `[nzIndicator]` | the spinning indicator | `TemplateRef` | - | ✅ | -| `[nzSize]` | size of Spin | `'large' \| 'small' \| 'default'` | `'default'` | -| `[nzSpinning]` | whether Spin is spinning | `boolean` | `true` | -| `[nzSimple]` | whether Spin has no children | `boolean` | `false` | -| `[nzTip]` | customize description content when Spin has children | `string` | - | +| Property | Description | Type | Default Value | Global Config | +| ---------------- | --------------------------------------------------------------------------------------- | --------------------------------- | ------------- | ------------- | +| `[nzDelay]` | specifies a delay in milliseconds for loading state (prevent flush), unit: milliseconds | `number` | - | +| `[nzIndicator]` | the spinning indicator | `TemplateRef` | - | ✅ | +| `[nzSize]` | size of Spin | `'large' \| 'small' \| 'default'` | `'default'` | +| `[nzSpinning]` | whether Spin is spinning | `boolean` | `true` | +| `[nzSimple]` | whether Spin has no children | `boolean` | `false` | +| `[nzTip]` | customize description content when Spin has children | `string` | - | +| `[nzFullscreen]` | display a backdrop with the `Spin` component | `boolean` | `false` | diff --git a/components/spin/doc/index.zh-CN.md b/components/spin/doc/index.zh-CN.md index 6282836d102..6a92748dcc1 100644 --- a/components/spin/doc/index.zh-CN.md +++ b/components/spin/doc/index.zh-CN.md @@ -20,11 +20,12 @@ import { NzSpinModule } from 'ng-zorro-antd/spin'; ### nz-spin -| 参数 | 说明 | 类型 | 默认值 | 全局配置 | -| --- | --- | --- | --- | --- | -| `[nzDelay]` | 延迟显示加载效果的时间(防止闪烁),单位:毫秒 | `number` | - | -| `[nzIndicator]` | 加载指示符 | `TemplateRef` | - | ✅ | -| `[nzSize]` | 组件大小 | `'large' \| 'small' \| 'default'` | `'default'` | -| `[nzSpinning]` | 是否旋转 | `boolean` | `true` | -| `[nzSimple]` | 是否包裹元素 | `boolean` | `false` | -| `[nzTip]` | 当作为包裹元素时,可以自定义描述文案 | `string` | - | +| 参数 | 说明 | 类型 | 默认值 | 全局配置 | +| ---------------- | ---------------------------------------------- | --------------------------------- | ----------- | -------- | +| `[nzDelay]` | 延迟显示加载效果的时间(防止闪烁),单位:毫秒 | `number` | - | +| `[nzIndicator]` | 加载指示符 | `TemplateRef` | - | ✅ | +| `[nzSize]` | 组件大小 | `'large' \| 'small' \| 'default'` | `'default'` | +| `[nzSpinning]` | 是否旋转 | `boolean` | `true` | +| `[nzSimple]` | 是否包裹元素 | `boolean` | `false` | +| `[nzTip]` | 当作为包裹元素时,可以自定义描述文案 | `string` | - | +| `[nzFullscreen]` | 显示带有 `Spin` 组件的背景 | `boolean` | `false` | diff --git a/components/spin/spin.component.ts b/components/spin/spin.component.ts index 59a2b4ab862..49277b2203a 100644 --- a/components/spin/spin.component.ts +++ b/components/spin/spin.component.ts @@ -47,6 +47,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'spin'; [class.ant-spin-lg]="nzSize === 'large'" [class.ant-spin-sm]="nzSize === 'small'" [class.ant-spin-show-text]="nzTip" + [class.ant-spin-fullscreen]="nzFullscreen" >
{{ nzTip }}
@@ -57,7 +58,8 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'spin'; `, host: { - '[class.ant-spin-nested-loading]': '!nzSimple' + '[class.ant-spin-nested-loading]': '!nzSimple', + '[class.ant-spin-nested-loading-fullscreen]': '!nzSimple && nzFullscreen' } }) export class NzSpinComponent implements OnChanges, OnDestroy, OnInit { @@ -73,6 +75,7 @@ export class NzSpinComponent implements OnChanges, OnDestroy, OnInit { @Input() @InputNumber() nzDelay = 0; @Input() @InputBoolean() nzSimple = false; @Input() @InputBoolean() nzSpinning = true; + @Input() @InputBoolean() nzFullscreen = false; private destroy$ = new Subject(); private spinning$ = new BehaviorSubject(this.nzSpinning); private delay$ = new ReplaySubject(1); diff --git a/components/spin/spin.spec.ts b/components/spin/spin.spec.ts index ce3a45fba2f..ef0f36e9216 100644 --- a/components/spin/spin.spec.ts +++ b/components/spin/spin.spec.ts @@ -149,6 +149,31 @@ describe('spin', () => { expect(spin.nativeElement.querySelector('.ant-spin').classList).not.toContain('ant-spin-rtl'); }); }); + + describe('spin fullscreen', () => { + it('should div with classname ant-spin also have the correct class name', () => { + const fixture = TestBed.createComponent(NzTestSpinBasicComponent); + const spin = fixture.debugElement.query(By.directive(NzSpinComponent)); + fixture.detectChanges(); + expect(spin.nativeElement.querySelector('.ant-spin').classList).not.toContain('ant-spin-fullscreen'); + fixture.componentInstance.isFullscreen = true; + fixture.detectChanges(); + expect(spin.nativeElement.querySelector('.ant-spin').classList).toContain('ant-spin-fullscreen'); + }); + + it('should spin component have the correct classname when nested and fullscreen is active', () => { + const fixture = TestBed.createComponent(NzTestSpinBasicComponent); + const spin = fixture.debugElement.query(By.directive(NzSpinComponent)); + fixture.componentInstance.isFullscreen = false; + fixture.componentInstance.simple = true; + fixture.detectChanges(); + expect(spin.nativeElement.classList).not.toContain('ant-spin-nested-loading-fullscreen'); + fixture.componentInstance.isFullscreen = true; + fixture.componentInstance.simple = false; + fixture.detectChanges(); + expect(spin.nativeElement.classList).toContain('ant-spin-nested-loading-fullscreen'); + }); + }); }); @Component({ @@ -163,6 +188,7 @@ describe('spin', () => { [nzSpinning]="spinning" [nzSimple]="simple" [nzIndicator]="indicator" + [nzFullscreen]="isFullscreen" >
test
@@ -177,6 +203,7 @@ export class NzTestSpinBasicComponent { indicator?: TemplateRef; tip?: string; simple = false; + isFullscreen = false; constructor(public nzConfigService: NzConfigService) {} } diff --git a/components/spin/style/index.less b/components/spin/style/index.less index 2dee02e28ef..f33e8829a55 100644 --- a/components/spin/style/index.less +++ b/components/spin/style/index.less @@ -73,6 +73,34 @@ margin-top: -(@spin-dot-size-lg / 2) - 10px; } } + + &-fullscreen { + > div > .@{spin-prefix-cls} { + max-height: unset; + + .@{spin-prefix-cls}-text { + color: @white; + text-shadow: unset; + } + } + } + } + + &-fullscreen, + &-nested-loading-fullscreen > div > .@{spin-prefix-cls} { + position: fixed; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + pointer-events: none; + background-color: rgba(0, 0, 0, 0.45); + z-index: 1000; + max-height: unset; + + .@{spin-prefix-cls}-dot-item { + background-color: @white; + } } &-container {