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:icon): add provideNzIcon and provideNzIconPatch API #8650

Merged
merged 5 commits into from
Jul 25, 2024

Conversation

Laffery
Copy link
Collaborator

@Laffery Laffery commented Jul 25, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Application (the showcase website) / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Developer can use provideNzIcon API in root and provideNzIconPatch in lazy-loading module or standalone component to provide icons now.
Of course the former NzIconModule.forRoot and NzIconModule.forChild API are still supported but not recommended in standalone mode any more.

[USAGE]

import { provideNzIcon } from 'ng-zorro-antd/icon';

export const appConfig = {
  providers: [provideNzIcon(icons)]
}
import { NzIconModule, provideNzIconPatch } from 'ng-zorro-antd/icon';

// in xxx.component.ts
@Component({
  standalone: true,
  imports: [NzIconModule],
  providers: [provideNzIconPatch([QuestionOutline])]
})
class ChildComponent {}

// or in xxx.routes.ts
const routes: Routes = [{
  path: '',
  providers: [provideNzIconPatch([QuestionOutline])],
}]

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@Laffery Laffery requested a review from wzhudev as a code owner July 25, 2024 02:29
@Laffery Laffery added this to the v18.1 milestone Jul 25, 2024
Copy link

zorro-bot bot commented Jul 25, 2024

This preview will be available after the AzureCI is passed.

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.52%. Comparing base (bef12e6) to head (67c19f2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8650      +/-   ##
==========================================
- Coverage   91.52%   91.52%   -0.01%     
==========================================
  Files         535      536       +1     
  Lines       18441    18445       +4     
  Branches     2907     2907              
==========================================
+ Hits        16879    16882       +3     
- Misses       1242     1243       +1     
  Partials      320      320              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 17 to 38
export const provideNzIcon = (icons: IconDefinition[]): EnvironmentProviders => {
return makeEnvironmentProviders([
{
provide: NZ_ICONS,
useValue: icons
}
]);
};

/**
* Provide icon definitions for NzIcon in feature module or standalone component
* @param icons Icon definitions
*/
export const provideNzIconPatch = (icons: IconDefinition[]): Provider[] => {
return [
NzIconPatchService,
{
provide: NZ_ICONS_PATCH,
useValue: icons
}
];
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

NzIconModule 应该可以直接复用这两个函数:

export class NzIconModule {
  static forRoot(icons: IconDefinition[]): ModuleWithProviders<NzIconModule> {
    return {
      ngModule: NzIconModule,
      providers: [
        provideNzIcon(icons)
      ]
    };
  }

  static forChild(icons: IconDefinition[]): ModuleWithProviders<NzIconModule> {
    return {
      ngModule: NzIconModule,
      providers: [
        provideNzIconPatch(icons)
      ]
    };
  }
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

在之前的 ng g 原理图中,我们还手动定义了一个 provideNzIcons 函数,此时我们需要将它替换为当前的实现。

QQ_1721875061104

Copy link
Collaborator

@HyperLife1119 HyperLife1119 Jul 25, 2024

Choose a reason for hiding this comment

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

NIT: 这两个函数的命名需要考虑改为复数形式吗?WDYT?

provideNzIcons / provideNzIconsPatch

Copy link
Collaborator Author

@Laffery Laffery Jul 25, 2024

Choose a reason for hiding this comment

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

在之前的 ng g 原理图中,我们还手动定义了一个 provideNzIcons 函数,此时我们需要将它替换为当前的实现。

赞同,我稍后会更新下 schematics。还有上次提到的 doc 里的 app.config.ts

命名我们 follow 之前定义的 provideNzIcons 吧,复数语义上也更合理

@Laffery Laffery requested a review from hsuanxyz as a code owner July 25, 2024 04:05
Copy link
Collaborator

@HyperLife1119 HyperLife1119 left a comment

Choose a reason for hiding this comment

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

LGTM

@HyperLife1119 HyperLife1119 merged commit b22672d into NG-ZORRO:master Jul 25, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants