Skip to content

Commit 280919b

Browse files
authored
refactor: angular 10 (#165)
1 parent 3ebaf18 commit 280919b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+704
-619
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# [10.0.0-rc.1](https://github.com/cipchk/ngx-weui/compare/9.0.0...10.0.0-rc.1) (2020-07-08)
2+
3+
4+
### Features
5+
6+
* **module:picker:** add `className` property of options ([#164](https://github.com/cipchk/ngx-weui/issues/164)) ([e4e6f0e](https://github.com/cipchk/ngx-weui/commit/e4e6f0e5490944b3a22d6fe8db6019ba22b74e0b))
7+
* angular 10 ([4655b41](https://github.com/cipchk/ngx-weui/commit/4655b4177dc7634fe8cf89e1f1254bef47ff8469))
8+
9+
10+
111
# [9.1.0](https://github.com/cipchk/ngx-weui/compare/9.0.0...9.1.0) (2020-07-08)
212

313

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ NGX-WEUI
2222

2323
- WeUI `1.x` using `7.0.x`
2424
- WeUI `<= 2.2` using `8.x` & Angular 8
25-
- WeUI `>= 2.3` using `9.x` & Angular 9, Support dark & light theme
25+
- WeUI `>= 2.3` using `9.x` & Angular 9, 10, Support dark & light theme
2626

2727
## Table of Contents
2828

@@ -36,9 +36,9 @@ NGX-WEUI
3636

3737
## Usage & Demo
3838

39-
- [Documentation](https://cipchk.github.io/ngx-weui/) [国内镜像](https://cipchk.gitee.io/ngx-weui/)
40-
- [Live Demo](https://cipchk.github.io/ngx-weui/) [国内镜像](https://cipchk.gitee.io/ngx-weui/)
41-
- [Stackblitz](https://stackblitz.com/edit/ngx-weui)
39+
- [Documentation](https://cipchk.github.io/ngx-weui/) - [国内镜像](https://cipchk.gitee.io/ngx-weui/)
40+
- [Live Demo](https://cipchk.github.io/ngx-weui/) - [国内镜像](https://cipchk.gitee.io/ngx-weui/)
41+
- [Stackblitz](https://stackblitz.com/edit/ngx-weui), [Codesandbox](https://codesandbox.io/s/ngx-weui-wki41?file=/src/app/app.component.ts)
4242

4343
## Create project
4444

angular.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"outputPath": "dist",
1515
"index": "src/index.html",
1616
"main": "src/main.ts",
17-
"tsConfig": "src/tsconfig.json",
17+
"tsConfig": "src/tsconfig.app.json",
1818
"polyfills": "src/polyfills.ts",
1919
"aot": false,
2020
"assets": [
@@ -72,13 +72,6 @@
7272
"browserTarget": "ngx-weui-doc:build:production"
7373
}
7474
}
75-
},
76-
"lint": {
77-
"builder": "@angular-devkit/build-angular:tslint",
78-
"options": {
79-
"tsConfig": ["src/tsconfig.json"],
80-
"exclude": ["**/node_modules/**"]
81-
}
8275
}
8376
}
8477
},

components/accordion/accordion-panel.component.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

components/accordion/accordion.component.ts

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, EventEmitter, Host, Input, OnDestroy, OnInit, Output, ViewEncapsulation } from '@angular/core';
22
import { AnimateType, InputBoolean } from 'ngx-weui/core';
3-
import { AccordionPanelComponent } from './accordion-panel.component';
43
import { AccordionConfig } from './accordion.config';
54

65
@Component({
@@ -66,3 +65,60 @@ export class AccordionComponent {
6665
});
6766
}
6867
}
68+
69+
@Component({
70+
selector: 'weui-accordion-panel',
71+
exportAs: 'weuiAccordionPanel',
72+
template: `
73+
<div role="tab" (click)="_toggle()"><ng-content select="[heading]"></ng-content></div>
74+
<div role="tabpanel" class="weui-accordion-content"><ng-content></ng-content></div>
75+
`,
76+
host: {
77+
'[class.weui-accordion-panel-disabled]': 'disabled',
78+
'[class.weui-accordion-active]': 'active',
79+
},
80+
preserveWhitespaces: false,
81+
changeDetection: ChangeDetectionStrategy.OnPush,
82+
encapsulation: ViewEncapsulation.None,
83+
})
84+
export class AccordionPanelComponent implements OnInit, OnDestroy {
85+
/**
86+
* 是否禁止
87+
*/
88+
@Input() @InputBoolean() disabled: boolean = false;
89+
90+
private _active: boolean = false;
91+
92+
/**
93+
* 是否展开
94+
*/
95+
@Input()
96+
@InputBoolean()
97+
get active(): boolean {
98+
return this._active;
99+
}
100+
101+
set active(value: boolean) {
102+
this._active = value;
103+
if (value) {
104+
this.accordion._closeOthers(this);
105+
}
106+
}
107+
108+
constructor(@Host() protected accordion: AccordionComponent) {}
109+
110+
ngOnInit(): void {
111+
this.accordion._add(this);
112+
}
113+
114+
ngOnDestroy(): void {
115+
this.accordion._remove(this);
116+
}
117+
118+
_toggle(): void {
119+
if (!this.disabled) {
120+
this.active = !this.active;
121+
this.accordion.select.emit(this.accordion._index(this));
122+
}
123+
}
124+
}

components/accordion/accordion.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
3-
import { AccordionPanelComponent } from './accordion-panel.component';
4-
import { AccordionComponent } from './accordion.component';
3+
4+
import { AccordionComponent, AccordionPanelComponent } from './accordion.component';
55

66
@NgModule({
77
imports: [CommonModule],

components/accordion/accordion.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function expectOpenPanels(nativeEl: HTMLElement, openPanelsDef: boolean[]): void
4848
describe('Component: Accordion', () => {
4949
let fixture: ComponentFixture<TestAccordionComponent>;
5050
let context: TestAccordionComponent;
51-
let element: any;
51+
let element: HTMLElement;
5252

5353
beforeEach(() => {
5454
TestBed.configureTestingModule({
@@ -101,7 +101,7 @@ describe('Component: Accordion', () => {
101101

102102
describe('Component: Accordion: Auto', () => {
103103
let fixture: ComponentFixture<TestAccordionComponent>;
104-
let element: any;
104+
let element: HTMLElement;
105105

106106
beforeEach(() => {
107107
TestBed.configureTestingModule({
@@ -124,7 +124,7 @@ describe('Component: Accordion: Auto', () => {
124124
@Component({ template: '' })
125125
class TestAccordionComponent {
126126
collapsible: boolean = true;
127-
panels: any[] = [
127+
panels = [
128128
{ title: 'title1', content: 'content1', active: false, disabled: false },
129129
{ title: 'title2', content: 'content2', active: false, disabled: false },
130130
{ title: 'title3', content: 'content3', active: false, disabled: false },

components/accordion/public-api.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export { AccordionPanelComponent } from './accordion-panel.component';
2-
export { AccordionComponent } from './accordion.component';
3-
export { AccordionConfig } from './accordion.config';
4-
export { AccordionModule } from './accordion.module';
1+
export * from './accordion.component';
2+
export * from './accordion.config';
3+
export * from './accordion.module';

components/actionsheet/actionsheet.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { ActionSheetMenuItem } from './actionsheet.types';
3434
encapsulation: ViewEncapsulation.None,
3535
})
3636
export class ActionSheetComponent implements OnDestroy {
37-
private observer: Observer<any>;
37+
private observer: Observer<ActionSheetMenuItem>;
3838
private destroied = false;
3939
_shown = false;
4040
/**
@@ -116,7 +116,7 @@ export class ActionSheetComponent implements OnDestroy {
116116
/**
117117
* 选择动作
118118
*/
119-
_onSelect(menu: { text?: string; [key: string]: any }): void {
119+
_onSelect(menu: ActionSheetMenuItem): void {
120120
this.observer.next(menu);
121121
this.observer.complete();
122122
this.hide();

components/actionsheet/actionsheet.service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { DOCUMENT } from '@angular/common';
2-
import { ApplicationRef, ComponentFactoryResolver, Inject, Injectable, Injector } from '@angular/core';
1+
import { Injectable } from '@angular/core';
32
import { BaseService } from 'ngx-weui/core';
43
import { Observable } from 'rxjs';
54
import { ActionSheetComponent } from './actionsheet.component';
@@ -8,10 +7,6 @@ import { ActionSheetMenuItem } from './actionsheet.types';
87

98
@Injectable({ providedIn: 'root' })
109
export class ActionSheetService extends BaseService {
11-
constructor(resolver: ComponentFactoryResolver, applicationRef: ApplicationRef, injector: Injector, @Inject(DOCUMENT) doc: any) {
12-
super(resolver, applicationRef, injector, doc);
13-
}
14-
1510
/**
1611
* 创建一个弹出式菜单并显示
1712
*

components/actionsheet/actionsheet.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Component: ActionSheet', () => {
3232
describe('[default]', () => {
3333
let fixture: ComponentFixture<TestActionSheetComponent>;
3434
let context: TestActionSheetComponent;
35-
let el: any;
35+
let el: HTMLDivElement;
3636

3737
const html = `
3838
<weui-actionsheet
@@ -76,7 +76,7 @@ describe('Component: ActionSheet', () => {
7676
}
7777
done();
7878
});
79-
(getItems(el)[0] as any).click();
79+
(getItems(el)[0] as HTMLElement).click();
8080
});
8181

8282
it('should be android when set auto and isAndroid is true', done => {
@@ -89,7 +89,7 @@ describe('Component: ActionSheet', () => {
8989
document.querySelector('body')?.removeAttribute('data-platform');
9090
done();
9191
});
92-
(getItems(el)[0] as any).click();
92+
(getItems(el)[0] as HTMLElement).click();
9393
});
9494

9595
it('should be opened set actionsheet title', done => {
@@ -99,7 +99,7 @@ describe('Component: ActionSheet', () => {
9999
expect(getTitle(el).textContent).toBe(str);
100100
done();
101101
});
102-
(getItems(el)[0] as any).click();
102+
(getItems(el)[0] as HTMLElement).click();
103103
});
104104

105105
it('should be opened set actionsheet items', done => {
@@ -111,7 +111,7 @@ describe('Component: ActionSheet', () => {
111111
expect(items[1].textContent?.trim()).toBe('menu2');
112112
done();
113113
});
114-
(getItems(el)[0] as any).click();
114+
(getItems(el)[0] as HTMLElement).click();
115115
});
116116

117117
it('should be opened set actionsheet action', done => {
@@ -121,7 +121,7 @@ describe('Component: ActionSheet', () => {
121121
expect(getAction(el).textContent).toBe(str);
122122
done();
123123
});
124-
(getItems(el)[0] as any).click();
124+
(getItems(el)[0] as HTMLElement).click();
125125
});
126126

127127
it('should be opened if android not title & action', done => {
@@ -134,7 +134,7 @@ describe('Component: ActionSheet', () => {
134134
expect(getAction(el)).toBeNull();
135135
done();
136136
});
137-
(getItems(el)[0] as any).click();
137+
(getItems(el)[0] as HTMLElement).click();
138138
});
139139

140140
it('should choose item and get back a result', done => {
@@ -147,7 +147,7 @@ describe('Component: ActionSheet', () => {
147147
expect(res.other).toBe(1);
148148
done();
149149
});
150-
(getItems(el)[0] as any).click();
150+
(getItems(el)[0] as HTMLElement).click();
151151
});
152152

153153
it('should click backdrop has closed', done => {
@@ -157,22 +157,22 @@ describe('Component: ActionSheet', () => {
157157
expect(true).toBeTruthy();
158158
done();
159159
});
160-
el.querySelector('.weui-mask').click();
160+
(el.querySelector('.weui-mask') as HTMLElement).click();
161161
});
162162

163163
it('should click backdrop not-allow closing', () => {
164164
context.config = { ...context.config, backdrop: false };
165165
context.actioinSheet.show();
166166
fixture.detectChanges();
167-
el.querySelector('.weui-mask').click();
167+
(el.querySelector('.weui-mask') as HTMLElement).click();
168168
expect(context.actioinSheet._shown).toBe(true);
169169
});
170170
});
171171

172172
describe('[service]', () => {
173173
let service: ActionSheetService;
174-
let fixture: any;
175-
let el: any;
174+
let fixture: ComponentFixture<TestActionSheetServiceComponent>;
175+
let el: HTMLDivElement;
176176

177177
beforeEach(fakeAsync(() => {
178178
TestBed.configureTestingModule({
@@ -202,13 +202,13 @@ describe('Component: ActionSheet', () => {
202202
});
203203

204204
fixture.detectChanges();
205-
(getItems(el.nextSibling)[0] as any).click();
205+
(getItems(el.nextSibling as HTMLElement)[0] as HTMLElement).click();
206206
});
207207

208208
it('should be show if specify [config] param', () => {
209209
service.show([...MENUS], { ...CONFIG });
210210
fixture.detectChanges();
211-
expect(el.nextSibling.nodeName).toBe('WEUI-ACTIONSHEET');
211+
expect((el.nextSibling as HTMLElement).nodeName).toBe('WEUI-ACTIONSHEET');
212212
});
213213
});
214214
});
@@ -225,7 +225,7 @@ class TestActionSheetServiceComponent {}
225225
class TestActionSheetComponent {
226226
@ViewChild(ActionSheetComponent, { static: true }) actioinSheet: ActionSheetComponent;
227227

228-
menus: any[] = [...MENUS];
228+
menus = [...MENUS];
229229

230230
config: ActionSheetConfig = { ...CONFIG };
231231

0 commit comments

Comments
 (0)