From 252e21be46346de66fc24e80befcaf925eb341e5 Mon Sep 17 00:00:00 2001
From: Laffery <49607541+Laffery@users.noreply.github.com>
Date: Wed, 20 Nov 2024 17:48:44 +0800
Subject: [PATCH] chore: bump icons-angular to v19 (#677)
* chore: bump icons-angular to v19
* chore: update example site
* chore: bump cross-env to v7
---
...terceptor.module.ts => app-interceptor.ts} | 0
.../examples/app/app.component.html | 8 +-
.../examples/app/app.component.ts | 19 +--
.../icons-angular/examples/app/app.config.ts | 17 +++
.../icons-angular/examples/app/app.module.ts | 25 ----
packages/icons-angular/examples/main.ts | 8 +-
packages/icons-angular/package.json | 47 ++++----
packages/icons-angular/src/README.md | 43 ++++---
.../src/component/icon.directive.ts | 6 +-
.../src/component/icon.module.ts | 12 +-
.../src/component/icon.provider.ts | 17 +++
.../src/component/icon.service.ts | 4 +-
.../icons-angular/src/component/icon.spec.ts | 29 ++---
packages/icons-angular/src/package.json | 13 +-
packages/icons-angular/src/public_api.ts | 1 +
.../icons-angular/src/tests/index.spec.ts | 111 ++++--------------
16 files changed, 153 insertions(+), 207 deletions(-)
rename packages/icons-angular/examples/app/{app-interceptor.module.ts => app-interceptor.ts} (100%)
create mode 100644 packages/icons-angular/examples/app/app.config.ts
delete mode 100644 packages/icons-angular/examples/app/app.module.ts
create mode 100644 packages/icons-angular/src/component/icon.provider.ts
diff --git a/packages/icons-angular/examples/app/app-interceptor.module.ts b/packages/icons-angular/examples/app/app-interceptor.ts
similarity index 100%
rename from packages/icons-angular/examples/app/app-interceptor.module.ts
rename to packages/icons-angular/examples/app/app-interceptor.ts
diff --git a/packages/icons-angular/examples/app/app.component.html b/packages/icons-angular/examples/app/app.component.html
index 2456f36a3..8e46fa450 100644
--- a/packages/icons-angular/examples/app/app.component.html
+++ b/packages/icons-angular/examples/app/app.component.html
@@ -11,14 +11,14 @@
Ant Design Icons
-
+@for (name of icons; track name) {
-
+}
-
+@if (currentTheme === 'fill') {
With Namespace
-
+}
diff --git a/packages/icons-angular/examples/app/app.component.ts b/packages/icons-angular/examples/app/app.component.ts
index 7183375d0..bc985e146 100644
--- a/packages/icons-angular/examples/app/app.component.ts
+++ b/packages/icons-angular/examples/app/app.component.ts
@@ -1,21 +1,12 @@
+import { FormsModule } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
-import { manifest, IconService, Manifest, ThemeType } from '@ant-design/icons-angular';
-
-// const pandaLiteral = ``;
+import { manifest, IconService, Manifest, ThemeType, IconDirective } from '@ant-design/icons-angular';
@Component({
- selector : 'app-root',
+ selector: 'app-root',
+ imports: [FormsModule, IconDirective],
templateUrl: './app.component.html',
- styleUrls : [ './app.component.css' ]
+ styleUrl: './app.component.css'
})
export class AppComponent implements OnInit {
currentTheme: ThemeType = 'fill';
diff --git a/packages/icons-angular/examples/app/app.config.ts b/packages/icons-angular/examples/app/app.config.ts
new file mode 100644
index 000000000..9e9a2158f
--- /dev/null
+++ b/packages/icons-angular/examples/app/app.config.ts
@@ -0,0 +1,17 @@
+import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
+import { ApplicationConfig } from '@angular/core';
+
+import { AppInterceptor } from './app-interceptor';
+import { provideAntIcons } from '@ant-design/icons-angular';
+
+export const appConfig: ApplicationConfig = {
+ providers: [
+ {
+ provide: HTTP_INTERCEPTORS,
+ useClass: AppInterceptor,
+ multi: true
+ },
+ provideAntIcons([]),
+ provideHttpClient(withInterceptorsFromDi())
+ ]
+};
diff --git a/packages/icons-angular/examples/app/app.module.ts b/packages/icons-angular/examples/app/app.module.ts
deleted file mode 100644
index 485d70f7a..000000000
--- a/packages/icons-angular/examples/app/app.module.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { BrowserModule } from '@angular/platform-browser';
-import { CommonModule } from '@angular/common';
-import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
-import { NgModule } from '@angular/core';
-import { FormsModule } from '@angular/forms';
-
-import { AppInterceptor } from './app-interceptor.module';
-import { IconModule } from '@ant-design/icons-angular';
-import { AppComponent } from './app.component';
-
-@NgModule({ declarations: [
- AppComponent
- ],
- bootstrap: [AppComponent], imports: [CommonModule,
- FormsModule,
- BrowserModule,
- IconModule], providers: [
- {
- provide: HTTP_INTERCEPTORS,
- useClass: AppInterceptor,
- multi: true
- },
- provideHttpClient(withInterceptorsFromDi()),
- ] })
-export class AppModule { }
diff --git a/packages/icons-angular/examples/main.ts b/packages/icons-angular/examples/main.ts
index 91ec6da5f..cb790b31c 100644
--- a/packages/icons-angular/examples/main.ts
+++ b/packages/icons-angular/examples/main.ts
@@ -1,12 +1,12 @@
import { enableProdMode } from '@angular/core';
-import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
+import { bootstrapApplication } from '@angular/platform-browser';
-import { AppModule } from './app/app.module';
+import { AppComponent } from './app/app.component';
+import { appConfig } from './app/app.config';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
-platformBrowserDynamic().bootstrapModule(AppModule)
- .catch(err => console.log(err));
+bootstrapApplication(AppComponent, appConfig).catch(err => console.log(err));
diff --git a/packages/icons-angular/package.json b/packages/icons-angular/package.json
index 2c3aea259..6a8a46e70 100644
--- a/packages/icons-angular/package.json
+++ b/packages/icons-angular/package.json
@@ -2,7 +2,6 @@
"name": "@ant-design/icons-angular-workspace",
"version": "0.0.0-NOT-VALID",
"scripts": {
- "ng": "ng",
"start": "ng serve",
"lint": "ng lint",
"test": "ng test --no-watch --no-progress --browsers=ChromeHeadlessCI --code-coverage",
@@ -16,35 +15,35 @@
"license": "MIT",
"private": true,
"dependencies": {
- "@angular/common": "^18.0.0",
- "@angular/core": "^18.0.0",
+ "@angular/common": "^19.0.0",
+ "@angular/core": "^19.0.0",
"@ant-design/colors": "^7.0.0"
},
"devDependencies": {
- "@angular-devkit/build-angular": "^18.0.1",
- "@angular-eslint/builder": "^18.0.0-alpha.5",
- "@angular-eslint/eslint-plugin": "^18.0.0-alpha.5",
- "@angular-eslint/eslint-plugin-template": "^18.0.0-alpha.5",
- "@angular-eslint/schematics": "^18.0.0-alpha.5",
- "@angular-eslint/template-parser": "^18.0.0-alpha.5",
- "@angular/animations": "^18.0.0",
- "@angular/cli": "^18.0.1",
- "@angular/compiler": "^18.0.0",
- "@angular/compiler-cli": "^18.0.0",
- "@angular/forms": "^18.0.0",
- "@angular/language-service": "^18.0.0",
- "@angular/platform-browser": "^18.0.0",
- "@angular/platform-browser-dynamic": "^18.0.0",
- "@angular/router": "^18.0.0",
+ "@angular-devkit/build-angular": "^19.0.0",
+ "@angular-eslint/builder": "^19.0.0-alpha.0",
+ "@angular-eslint/eslint-plugin": "^19.0.0-alpha.0",
+ "@angular-eslint/eslint-plugin-template": "^19.0.0-alpha.0",
+ "@angular-eslint/schematics": "^19.0.0-alpha.0",
+ "@angular-eslint/template-parser": "^19.0.0-alpha.0",
+ "@angular/animations": "^19.0.0",
+ "@angular/cli": "^19.0.0",
+ "@angular/compiler": "^19.0.0",
+ "@angular/compiler-cli": "^19.0.0",
+ "@angular/forms": "^19.0.0",
+ "@angular/language-service": "^19.0.0",
+ "@angular/platform-browser": "^19.0.0",
+ "@angular/platform-browser-dynamic": "^19.0.0",
+ "@angular/router": "^19.0.0",
"@ant-design/icons-svg": "^4.0.0",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/lodash": "^4.14.136",
- "@types/node": "^13.9.3",
+ "@types/node": "^20.11.1",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"classlist": "^2.0.0",
- "cross-env": "^5.2.0",
+ "cross-env": "^7.0.3",
"eslint": "^8.53.0",
"fs-extra": "^7.0.0",
"globby": "^8.0.1",
@@ -57,11 +56,11 @@
"karma-jasmine-html-reporter": "^2.0.0",
"karma-spec-reporter": "^0.0.36",
"lodash": "^4.17.11",
- "ng-packagr": "^18.0.0",
+ "ng-packagr": "^19.0.0",
"prettier": "^2.8.8",
"rxjs": "^7.8.0",
"ts-node": "~10.9.0",
- "typescript": "~5.4.5",
- "zone.js": "~0.14.2"
+ "typescript": "~5.6.3",
+ "zone.js": "~0.15.0"
}
-}
\ No newline at end of file
+}
diff --git a/packages/icons-angular/src/README.md b/packages/icons-angular/src/README.md
index 11bdd02b7..bc226ed3e 100644
--- a/packages/icons-angular/src/README.md
+++ b/packages/icons-angular/src/README.md
@@ -21,17 +21,15 @@ ng add @ant-design/icons-angular
## Usage
-You should import `IconModule` in your application's root module.
+You should import `IconDirective` in your component.
```ts
-import { IconModule } from '@ant-design/icons-angular';
+import { IconDirective } from '@ant-design/icons-angular';
-@NgModule({
- imports: [
- IconModule
- ]
+@Component({
+ imports: [ IconDirective ]
})
-export class AppModule { }
+export class AppComponent {}
```
And register the icons that you need to `IconService` (all or explicitly, we call it **static loading**):
@@ -39,23 +37,22 @@ And register the icons that you need to `IconService` (all or explicitly, we cal
> ATTENTION! We strongly suggest you not to register all icons. That would increase your bundle's size dramatically.
```ts
-import { Component, OnInit } from '@angular/core';
-import { IconDefinition, IconService } from '@ant-design/icons-angular';
+import { Component } from '@angular/core';
+import { IconService } from '@ant-design/icons-angular';
import { AccountBookFill } from '@ant-design/icons-angular/icons'
// import * as AllIcons from 'ant-icons-angular/icons';
@Component({
- selector : 'app-root',
- templateUrl: './app.component.html',
- styleUrls : ['./app.component.css']
+ // ...
})
-export class AppComponent implements OnInit {
+export class AppComponent {
constructor(private _iconService: IconService) {
// Import all. NOT RECOMMENDED. ❌
// const antDesignIcons = AllIcons as {
// [key: string]: IconDefinition;
// };
// this._iconService.addIcon(...Object.keys(antDesignIcons).map(key => antDesignIcons[key]));
+
// Import what you need! ✔️
this._iconService.addIcon(...[ AccountBookFill ]);
this._iconService.twoToneColor = { primaryColor: '#1890ff' };
@@ -63,6 +60,20 @@ export class AppComponent implements OnInit {
}
```
+You can also provide icons you need in the `app.config.ts`:
+
+```ts
+import { ApplicationConfig } from '@angular/core';
+import { provideAntIcons } from '@ant-design/icons-angular';
+import { AccountBookFill } from '@ant-design/icons-angular/icons';
+
+export const appConfig: ApplicationConfig = {
+ providers: [
+ provideAntIcons([ AccountBookFill ])
+ ]
+};
+```
+
When you want to render an icon:
```html
@@ -75,7 +86,7 @@ For icons provided by Ant Design, we provide **dynamic loading** strategy to red
### Namespace
-Namespace is a new feature first introduced in `2.0.0-beta.2`. It allows users to register their own icons with simple API, support both dynamic loading and static loading.
+Namespace is first introduced in `2.0.0-beta.2`. It allows users to register their own icons with simple API, support both dynamic loading and static loading.
Say you want to add a `panda` icon in `animal` namespace. For static loading, you should call `addIconLiteral('animal:panda', '')`. For dynamic loading, just put `panda.svg` under `assets/animal`. And render a panda like: ``.
@@ -99,4 +110,6 @@ Run `npm run build:lib`.
### Extension
-You can simply extend this package by creating directives or services that extends `IconDirective` and `IconService`. And it is worth mentioning that `_changeIcon` method returns a `Promise