Skip to content

Commit

Permalink
chore: adopt prettier code formatter (NG-ZORRO#3129)
Browse files Browse the repository at this point in the history
* chore: adopt prettier code formatter

* chore: add less as ignored

* fix: fix tsconfig

* fix: unmerged file

* fix: lint

* fix: lint
  • Loading branch information
Wendell authored and Ricbet committed Apr 9, 2020
1 parent 42386aa commit e25c6ba
Show file tree
Hide file tree
Showing 746 changed files with 14,088 additions and 11,814 deletions.
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/*.md
**/*.svg
**/*.html
**/test.ts
**/*.less
coverage/
publish/
site/
package.json
**/template/*
14 changes: 14 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
]
}
45 changes: 18 additions & 27 deletions components/affix/affix.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Component, DebugElement, ViewChild } from '@angular/core';
import {
discardPeriodicTasks,
fakeAsync,
tick,
ComponentFixture,
TestBed
} from '@angular/core/testing';
import { discardPeriodicTasks, fakeAsync, tick, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { NzScrollService } from '../core/scroll/nz-scroll.service';
Expand Down Expand Up @@ -373,8 +367,8 @@ describe('affix', () => {
constructor() {
spyOn(component, 'getOffset').and.callFake(this.getOffset.bind(this));
spyOn(scrollService, 'getScroll').and.callFake(this.getScroll.bind(this));
this.offsets = { 'undefined': { top: 10, left: 0, height: 0, width: 0 } };
this.scrolls = { 'undefined': { top: 10, left: 0 } };
this.offsets = { undefined: { top: 10, left: 0, height: 0, width: 0 } };
this.scrolls = { undefined: { top: 10, left: 0 } };
}

getScroll(el?: Element | Window, top: boolean = true): number {
Expand All @@ -392,7 +386,7 @@ describe('affix', () => {

emitScroll(el: Element | Window, top: number, left: number = 0): void {
this.scrolls[this.getKey(el)] = { top, left };
this.emitEvent((el || window), scrollEvent);
this.emitEvent(el || window, scrollEvent);
}

offsetTo(el: Element, offset: Offset): void {
Expand All @@ -405,15 +399,12 @@ describe('affix', () => {
}

offsetYTo(el: Element, offsetTop: number): void {
this.offsetTo(
el,
{
top: offsetTop,
left: 0,
height,
width
}
);
this.offsetTo(el, {
top: offsetTop,
left: 0,
height,
width
});
}

content(): HTMLElement {
Expand Down Expand Up @@ -476,7 +467,10 @@ describe('affix-extra', () => {
dl = fixture.debugElement;
});
it('#getOffset', () => {
const ret = fixture.componentInstance.nzAffixComponent.getOffset(fixture.debugElement.query(By.css('#affix')).nativeElement, window);
const ret = fixture.componentInstance.nzAffixComponent.getOffset(
fixture.debugElement.query(By.css('#affix')).nativeElement,
window
);
expect(ret).not.toBeUndefined();
});
it('with window when scrolled below the bottom offset', fakeAsync(() => {
Expand Down Expand Up @@ -504,13 +498,10 @@ describe('affix-extra', () => {

@Component({
template: `
<nz-affix id="affix"
[nzTarget]="fakeTarget"
[nzOffsetTop]="newOffset"
[nzOffsetBottom]="newOffsetBottom">
<button id="content">Affix Button</button>
</nz-affix>
<div id="target"></div>
<nz-affix id="affix" [nzTarget]="fakeTarget" [nzOffsetTop]="newOffset" [nzOffsetBottom]="newOffsetBottom">
<button id="content">Affix Button</button>
</nz-affix>
<div id="target"></div>
`
})
class TestAffixComponent {
Expand Down
29 changes: 14 additions & 15 deletions components/affix/demo/basic.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Component } from '@angular/core';

@Component({
selector : 'nz-demo-affix-basic',
template : `
<nz-affix>
<button nz-button [nzType]="'primary'">
<span>Affix top</span>
</button>
</nz-affix>
<br>
<nz-affix nzOffsetBottom="0">
<button nz-button [nzType]="'primary'">
<span>Affix bottom</span>
</button>
</nz-affix>
selector: 'nz-demo-affix-basic',
template: `
<nz-affix>
<button nz-button [nzType]="'primary'">
<span>Affix top</span>
</button>
</nz-affix>
<br />
<nz-affix nzOffsetBottom="0">
<button nz-button [nzType]="'primary'">
<span>Affix bottom</span>
</button>
</nz-affix>
`
})
export class NzDemoAffixBasicComponent {
}
export class NzDemoAffixBasicComponent {}
8 changes: 4 additions & 4 deletions components/affix/demo/on-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-affix-on-change',
template: `
<nz-affix [nzOffsetTop]="120" (nzChange)="onChange($event)">
<button nz-button>
<nz-affix [nzOffsetTop]="120" (nzChange)="onChange($event)">
<button nz-button>
<span>120px to affix top</span>
</button>
</nz-affix>
</button>
</nz-affix>
`
})
export class NzDemoAffixOnChangeComponent {
Expand Down
40 changes: 21 additions & 19 deletions components/affix/demo/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ import { Component } from '@angular/core';
@Component({
selector: 'nz-demo-affix-target',
template: `
<div class="scrollable-container" #target>
<div class="background">
<nz-affix [nzTarget]="target" id="affix-container-target">
<button nz-button [nzType]="'primary'">
<div class="scrollable-container" #target>
<div class="background">
<nz-affix [nzTarget]="target" id="affix-container-target">
<button nz-button [nzType]="'primary'">
<span>Fixed at the top of container</span>
</button>
</nz-affix>
</button>
</nz-affix>
</div>
</div>
</div>
`,
styles: [`
.scrollable-container {
height: 100px;
overflow-y: scroll;
}
styles: [
`
.scrollable-container {
height: 100px;
overflow-y: scroll;
}
.background {
padding-top: 60px;
height: 300px;
background-image: url(//zos.alipayobjects.com/rmsportal/RmjwQiJorKyobvI.jpg);
}
`]
.background {
padding-top: 60px;
height: 300px;
background-image: url(//zos.alipayobjects.com/rmsportal/RmjwQiJorKyobvI.jpg);
}
`
]
})
export class NzDemoAffixTargetComponent { }
export class NzDemoAffixTargetComponent {}
80 changes: 41 additions & 39 deletions components/affix/nz-affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ import { toNumber } from '../core/util/convert';
import { throttleByAnimationFrameDecorator } from '../core/util/throttleByAnimationFrame';

@Component({
selector : 'nz-affix',
templateUrl : './nz-affix.component.html',
selector: 'nz-affix',
templateUrl: './nz-affix.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
styles : [ `
nz-affix {
display: block;
}
` ],
encapsulation : ViewEncapsulation.None
styles: [
`
nz-affix {
display: block;
}
`
],
encapsulation: ViewEncapsulation.None
})
export class NzAffixComponent implements OnInit, OnDestroy {

@Input()
set nzTarget(value: string | Element | Window) {
this.clearEventListeners();
Expand Down Expand Up @@ -65,15 +66,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {
@Output() readonly nzChange = new EventEmitter<boolean>();

private timeout: number;
private readonly events = [
'resize',
'scroll',
'touchstart',
'touchmove',
'touchend',
'pageshow',
'load'
];
private readonly events = ['resize', 'scroll', 'touchstart', 'touchmove', 'touchend', 'pageshow', 'load'];
@ViewChild('fixedEl') private fixedEl: ElementRef;

private readonly placeholderNode: HTMLElement;
Expand Down Expand Up @@ -103,7 +96,10 @@ export class NzAffixComponent implements OnInit, OnDestroy {
(this.updatePosition as any).cancel();
}

getOffset(element: Element, target: Element | Window | undefined): {
getOffset(
element: Element,
target: Element | Window | undefined
): {
top: number;
left: number;
width: number;
Expand All @@ -120,9 +116,9 @@ export class NzAffixComponent implements OnInit, OnDestroy {
const clientLeft = docElem.clientLeft || 0;

return {
top : elemRect.top - targetRect.top + scrollTop - clientTop,
left : elemRect.left - targetRect.left + scrollLeft - clientLeft,
width : elemRect.width,
top: elemRect.top - targetRect.top + scrollTop - clientTop,
left: elemRect.left - targetRect.left + scrollLeft - clientLeft,
width: elemRect.width,
height: elemRect.height
};
}
Expand All @@ -141,19 +137,21 @@ export class NzAffixComponent implements OnInit, OnDestroy {
}

private getTargetRect(target: Element | Window | undefined): ClientRect {
return target !== window ?
(target as HTMLElement).getBoundingClientRect() :
{ top: 0, left: 0, bottom: 0 } as ClientRect;
return target !== window
? (target as HTMLElement).getBoundingClientRect()
: ({ top: 0, left: 0, bottom: 0 } as ClientRect);
}

private genStyle(affixStyle?: NGStyleInterface): string {
if (!affixStyle) {
return '';
}
return Object.keys(affixStyle).map(key => {
const val = affixStyle[ key ];
return `${key}:${typeof val === 'string' ? val : val + 'px'}`;
}).join(';');
return Object.keys(affixStyle)
.map(key => {
const val = affixStyle[key];
return `${key}:${typeof val === 'string' ? val : val + 'px'}`;
})
.join(';');
}

private setAffixStyle(e: Event, affixStyle?: NGStyleInterface): void {
Expand Down Expand Up @@ -213,11 +211,11 @@ export class NzAffixComponent implements OnInit, OnDestroy {
const elemOffset = this.getOffset(this.placeholderNode, targetNode);
const fixedNode = this.fixedEl.nativeElement as HTMLElement;
const elemSize = {
width : fixedNode.offsetWidth,
width: fixedNode.offsetWidth,
height: fixedNode.offsetHeight
};
const offsetMode = {
top : false,
top: false,
bottom: false
};
// Default to `offsetTop=0`.
Expand All @@ -229,15 +227,14 @@ export class NzAffixComponent implements OnInit, OnDestroy {
offsetMode.bottom = typeof this._offsetBottom === 'number';
}
const targetRect = this.getTargetRect(targetNode);
const targetInnerHeight =
(targetNode as Window).innerHeight || (targetNode as HTMLElement).clientHeight;
const targetInnerHeight = (targetNode as Window).innerHeight || (targetNode as HTMLElement).clientHeight;
if (scrollTop >= elemOffset.top - (offsetTop as number) && offsetMode.top) {
const width = elemOffset.width;
const top = targetRect.top + (offsetTop as number);
this.setAffixStyle(e, {
position : 'fixed',
position: 'fixed',
top,
left : targetRect.left + elemOffset.left,
left: targetRect.left + elemOffset.left,
maxHeight: `calc(100vh - ${top}px)`,
width
});
Expand All @@ -249,20 +246,25 @@ export class NzAffixComponent implements OnInit, OnDestroy {
scrollTop <= elemOffset.top + elemSize.height + (this._offsetBottom as number) - targetInnerHeight &&
offsetMode.bottom
) {
const targetBottomOffet = targetNode === window ? 0 : (window.innerHeight - targetRect.bottom);
const targetBottomOffet = targetNode === window ? 0 : window.innerHeight - targetRect.bottom;
const width = elemOffset.width;
this.setAffixStyle(e, {
position: 'fixed',
bottom : targetBottomOffet + (this._offsetBottom as number),
left : targetRect.left + elemOffset.left,
bottom: targetBottomOffet + (this._offsetBottom as number),
left: targetRect.left + elemOffset.left,
width
});
this.setPlaceholderStyle({
width,
height: elemOffset.height
});
} else {
if (e.type === 'resize' && this.affixStyle && this.affixStyle.position === 'fixed' && this.placeholderNode.offsetWidth) {
if (
e.type === 'resize' &&
this.affixStyle &&
this.affixStyle.position === 'fixed' &&
this.placeholderNode.offsetWidth
) {
this.setAffixStyle(e, { ...this.affixStyle, width: this.placeholderNode.offsetWidth });
} else {
this.setAffixStyle(e);
Expand Down
11 changes: 5 additions & 6 deletions components/affix/nz-affix.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { SCROLL_SERVICE_PROVIDER } from '../core/scroll/nz-scroll.service';
import { NzAffixComponent } from './nz-affix.component';

@NgModule({
declarations: [ NzAffixComponent ],
exports : [ NzAffixComponent ],
imports : [ CommonModule ],
providers : [ SCROLL_SERVICE_PROVIDER ]
declarations: [NzAffixComponent],
exports: [NzAffixComponent],
imports: [CommonModule],
providers: [SCROLL_SERVICE_PROVIDER]
})
export class NzAffixModule {
}
export class NzAffixModule {}
Loading

0 comments on commit e25c6ba

Please sign in to comment.