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:spin): now supports fullscreen #8183

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions components/spin/demo/fullscreen.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions components/spin/demo/fullscreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-spin-fullscreen',
template: `
<button nz-button nzType="default" (click)="showSpinner()">Show fullscreen for 3s</button>
<nz-spin nzSimple [nzSpinning]="isSpinning" [nzFullscreen]="true"></nz-spin>
`
})
export class NzDemoSpinFullscreenComponent {
public isSpinning = false;

public showSpinner(): void {
this.isSpinning = true;

setTimeout(() => {
this.isSpinning = false;
}, 3000);
}
}
3 changes: 2 additions & 1 deletion components/spin/demo/module
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
17 changes: 9 additions & 8 deletions components/spin/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>` | - | ✅ |
| `[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<void>` | - | ✅ |
| `[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` |
17 changes: 9 additions & 8 deletions components/spin/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import { NzSpinModule } from 'ng-zorro-antd/spin';

### nz-spin

| 参数 | 说明 | 类型 | 默认值 | 全局配置 |
| --- | --- | --- | --- | --- |
| `[nzDelay]` | 延迟显示加载效果的时间(防止闪烁),单位:毫秒 | `number` | - |
| `[nzIndicator]` | 加载指示符 | `TemplateRef<void>` | - | ✅ |
| `[nzSize]` | 组件大小 | `'large' \| 'small' \| 'default'` | `'default'` |
| `[nzSpinning]` | 是否旋转 | `boolean` | `true` |
| `[nzSimple]` | 是否包裹元素 | `boolean` | `false` |
| `[nzTip]` | 当作为包裹元素时,可以自定义描述文案 | `string` | - |
| 参数 | 说明 | 类型 | 默认值 | 全局配置 |
| ---------------- | ---------------------------------------------- | --------------------------------- | ----------- | -------- |
| `[nzDelay]` | 延迟显示加载效果的时间(防止闪烁),单位:毫秒 | `number` | - |
| `[nzIndicator]` | 加载指示符 | `TemplateRef<void>` | - | ✅ |
| `[nzSize]` | 组件大小 | `'large' \| 'small' \| 'default'` | `'default'` |
| `[nzSpinning]` | 是否旋转 | `boolean` | `true` |
| `[nzSimple]` | 是否包裹元素 | `boolean` | `false` |
| `[nzTip]` | 当作为包裹元素时,可以自定义描述文案 | `string` | - |
| `[nzFullscreen]` | 显示带有 `Spin` 组件的背景 | `boolean` | `false` |
5 changes: 4 additions & 1 deletion components/spin/spin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<ng-template [ngTemplateOutlet]="nzIndicator || defaultTemplate"></ng-template>
<div class="ant-spin-text" *ngIf="nzTip">{{ nzTip }}</div>
Expand All @@ -57,7 +58,8 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'spin';
</div>
`,
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 {
Expand All @@ -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<void>();
private spinning$ = new BehaviorSubject(this.nzSpinning);
private delay$ = new ReplaySubject<number>(1);
Expand Down
27 changes: 27 additions & 0 deletions components/spin/spin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -163,6 +188,7 @@ describe('spin', () => {
[nzSpinning]="spinning"
[nzSimple]="simple"
[nzIndicator]="indicator"
[nzFullscreen]="isFullscreen"
>
<div>test</div>
</nz-spin>
Expand All @@ -177,6 +203,7 @@ export class NzTestSpinBasicComponent {
indicator?: TemplateRef<void>;
tip?: string;
simple = false;
isFullscreen = false;

constructor(public nzConfigService: NzConfigService) {}
}
Expand Down
28 changes: 28 additions & 0 deletions components/spin/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;

.ant-spin-dot-item {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.@{spin-prefix-cls}-item

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to .@{spin-prefix-cls}-dot-item

background-color: @white;
}
}

&-container {
Expand Down