-
Notifications
You must be signed in to change notification settings - Fork 167
🛠️ A New Era for Angular Font Awesome: Directive-First Icon Rendering Refactor #483
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
base: main
Are you sure you want to change the base?
🛠️ A New Era for Angular Font Awesome: Directive-First Icon Rendering Refactor #483
Conversation
…host directives
…ent to use host directives
… use host directives
…kDirective in FontAwesomeModule
|
@devoto13 Thanks again for merging my previous PR today! 🙌 |
|
Thanks for the PR @medbenmakhlouf! I was thinking about adding directives for a while, but I haven't ever found any strong use cases for this. Do you have some good practical examples of when such directive is better choice than the component? My thinking was mostly around building a directive to put specifically on the |
|
@devoto13 Thanks for the thoughtful feedback! You’re right that there isn’t a strong must-have use case that absolutely requires directives — but in practice I’ve found the directive approach feels more flexible and “closer to the template,” especially in places where adding a dedicated component can feel a bit heavy. For example, when working with tables, lists, or other structured markup, it’s convenient to place an icon directly on elements like " My goal isn’t to replace the existing component API but to offer an additional, lightweight option. The current usage remains fully supported; the directive-based API simply gives developers another tool when they prefer more control over their HTML structure. Also, looking at Angular’s current direction, they recently introduced the new @angular/aria package, which is built entirely around directives rather than components. It still provides high-level functionality, but leaves full structural control to the developer. Your idea of attaching a directive directly to the In any case, please feel free to accept or reject the PR based on what fits the library’s long-term vision. My goal is simply to offer more flexibility and match patterns that Angular developers are increasingly using. |
|
Thanks for sharing additional details! I may be a bit out of touch as for what is happening in Angular ecosystem this days as I'm not using Angular daily, it's interesting to hear about the move towards the directives. I'm still leaning towards the idea that the added benefit of this particular solution does cover the cost of the expanded API surface, but let's leave this PR open for a while and see if maybe some other users can provide additional feedback. I'm somewhat more open towards having |
This pull request refactors the Font Awesome Angular integration to use directives as the primary mechanism for icon rendering, replacing the previous component-only approach. By shifting rendering logic into directives, icons can now be applied to any element—not just dedicated or components—resulting in a more flexible and extensible API. The update also adds new directives for duotone styling and advanced icon features, and updates documentation and tests accordingly.
Core Refactor: Directive-Based Icon Rendering
New icon rendering directives
Introduces
FaIconDirectivewhich encapsulate all icon rendering behavior previously held inFaIconComponentFaDuotoneIconDirectivewhich encapsulate all icon rendering behavior previously held inFaDuotoneIconComponentFaLayersDirectivewhich encapsulate all icon rendering behavior previously held inFaLayersComponentFaLayersCounterDirectivewhich encapsulate all icon rendering behavior previously held inFaLayersCounterComponentFaLayersTextDirectivewhich encapsulate all icon rendering behavior previously held inFaLayersTextComponentFaStackDirectivewhich encapsulate all icon rendering behavior previously held inFaStackComponentThese directives now own all inputs, outputs, change detection, and DOM updates.
(See:
src/lib/icon/icon.directive.ts,src/lib/icon/duotone-icon.directive.ts)Example usage:
Lightweight components using hostDirectives
FaIconComponentandFaDuotoneIconComponentare now thin wrappers that attach the new directives via hostDirectives. This preserves backwards compatibility while moving all logic to the directive layer.(See: src/lib/icon/icon.component.ts, src/lib/icon/duotone-icon.component.ts)
Module & Public API Adjustments
All new directives are declared and exported through FontAwesomeModule, making them available for both standalone and module-based Angular setups.
(src/lib/fontawesome.module.ts)