-
Notifications
You must be signed in to change notification settings - Fork 93
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(NgxSvgSprite): add a directive for rendering symbols of svg sprites #219
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d97625f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ⌛ The following targets are in progress
✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
@nartc Hello again, could you please review this feature and share your thoughts on the API 😄 |
@RobbyRabbitman A general question: This doesn't need to be specific to fonticons/fontAwesome. Do you think we can make this configurable to accept any SVG file? We could also refactor to load the SVG file lazily on first use. Thoughts? |
@ajitzero The configuration accepts any url. That means any svg can be used. The example shows fontawesome. I think the js fetch is already lazy, I should add test to verify that. The directive adds an use element, I don't know if the use element has a lazy loading feature like the img element. I will research that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contributions. Couple of nits and suggestions.
Thank you for the review and your suggestions, I will refactor the code 😄 |
xhr has the feature to parse documents from URL-based resources. We dont have to parse manually.
@ajitzero I think possible solutions for lazy loading are Intersection Observers: You can even use Angulars new deferrable views to skip setting up the observers by yourself. Maybe like so: @defer (on viewport) {
<svg faBrand="github"></svg>
} @placeholder {
<span>Some skeletton</span>
} |
A directive for rendering symbols of svg sprites. It is done with the
use
element.Import
Usage
In this example the symbol
github
of the fontawesome svg spritefa-brands
is rendered. A symbol is identified by afragment
. Learn more about URLs.Without
NgxSvgSpriteFragment
:With Directive Composition Api
In your project you can utilize the Directive Composition Api to create specific svg sprites.
In this example a fontawesome brands svg sprite is created.
Configuration
In order to render a symbol, sprites have to be provided.
The
name
property can reference any arbitrary value, but should be unique, since you can register multiple different svg sprites.The
sprite
input of theNgxSvgSpriteFragment
should reference thename
property of a provided sprite.Auto View Box
When a symbol of an svg sprite is rendered the
viewBox
attribute orheight
andwidth
should be set. Thesvg
element does not copy/use theviewBox
attribute of the symbol in the svg sprite, therefore the svg will have default dimensions of 300x150 px, which is probably not preferred.Per default when an svg sprite is registered, the svg sprite is fetched with js in addition.
NgxSvgSpriteFragment
will copy theviewBox
attribute of the symbol to its host.This behavior can be disabled.
Disable via DI
Auto View Box is disabled for the svg sprite.
Disable via
autoViewBoxDisabled
InputAuto View Box is disabled for a
svg
element, when theautoViewBoxDisabled
input is set tofalse
.Disable via
viewBox
AttributeAuto View Box is disabled for a
svg
element, when theviewBox
attribute already is defined.Classes
When the
classes
function is set, a list of classes will be added by theNgxSvgSpriteFragment
to its host.Url
Per default when using the
createSvgSprite
function, theurl
will return'${baseUrl}#${fragment}'
. This can be overwritten: