-
Notifications
You must be signed in to change notification settings - Fork 12
feat: six-icon now supports custom svgs #445
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?
Conversation
|
|
||
| /** | ||
| * @since 1.0 | ||
| * @since 5.2 |
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.
THe since indicates since when the component has been available. Pleas revert
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.
Please check
| * | ||
| * Icon library for this instance. Overrides the global default. | ||
| * - "material-icons" β Material Icons | ||
| * - "material-icons" β Material Icons |
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.
Remove space
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.
Please check
| }) | ||
| export class SixIcon { | ||
| /** Name of the icon, path to SVG file or a data image */ | ||
| @Prop() src?: string; |
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.
As I already mentioned in #425 (comment)
Using src as the prop name for the input, in case when we are passing an icon name, makes no sense to me. I would separate the different types, meaning
src: SVG File or Data URLname: Name of the icon => you can introduce this already, but keep the slot
If I put myself in the user's shoes, I find this to be a lot easier to understand.
You can then define a hierarchy, like src > name > slot
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.
Well, i think it makes more sense than having prop name and prop src... how the users know which one takes priority? ... Just makes things more complicated than they should be. I will change it anyway.
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.
Please check
| * - <svg><use/></svg> is better for styling (e.g. fill: red), but slower at rendering. | ||
| * - <img> is better for HTTP caching, but you cannot style the internal SVG elements. | ||
| */ | ||
| @Prop({ reflect: true }) inlineSvg: boolean = false; |
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.
Is this really needed? What performance hit are talking about?
I would simply default to the <svg><use/></svg> since, as you mention, its better for styling
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.
As you can see there img is good for HTTP caching... you can in some instances visually see the difference rendering/loading the icons...
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.
There is however a caveat which you have to put id="img" inside your svg for it to work and properties inside svg have precedence i.e. if you have fill in some vector you cannot override it from outside.
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.
I am not sure if there is a more elegant way to approach this... this is what i have at the moment.
| if (this.src !== undefined) { | ||
| if (isSvg) { | ||
| if (this.inlineSvg) { | ||
| return ( | ||
| <svg part="svg"> | ||
| <use href={`${this.src}#img`} /> | ||
| </svg> | ||
| ); | ||
| } | ||
| return <img src={this.src} />; | ||
| } | ||
| return this.src; | ||
| } | ||
| return <slot />; |
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.
if (this.src === undefined) {
return <slot />;
}
if (!isSvg) {
return this.src;
}
if (!this.inlineSvg) {
return <img src={this.src} />;
}
return (
<svg part="svg">
<use href={`${this.src}#img`} />
</svg>
);
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.
Your solution does not work if you want to have name prop... i will adjust it..
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.
Please check
| }; | ||
|
|
||
| private renderContent(isSvg: boolean) { | ||
| if (this.src !== undefined) { |
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.
So the svg here has precedence over the slot?
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.
Why not? When you explitly place a path to a SVG you are showing a more clear intention to use svg over anything else.
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.
Please check
| <six-icon>sick</six-icon> | ||
| <six-icon>fort</six-icon> | ||
| <six-icon>castle</six-icon> | ||
| <six-icon src="fort"></six-icon> |
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.
I would add a comment explaining the two possible ways to do this => slot and prop
| } | ||
|
|
||
| /* ========================================================================== | ||
| Size helpers (unchanged API, a bit more explicit) |
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.
Remove the content inside the brackets
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.
Please check
π Linked issue
β Type of change
π Description
#425
π Checklist
mainbranchfix #xxx[,#xxx], where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information: