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

Use inline SVG instead of Material-Icons font for wl-expander #73

Open
brettwillis opened this issue Jun 13, 2019 · 2 comments
Open

Use inline SVG instead of Material-Icons font for wl-expander #73

brettwillis opened this issue Jun 13, 2019 · 2 comments

Comments

@brettwillis
Copy link

Consider this scenario:

  • I use my own set of inline SVG for icons so I can share and bundle them within my app
  • I use your wl-expander

Now I need to load the entire Material Icons font just for the glyph on the wl-expander. I also have issues around the Material Icons font being a render-blocking resource for the page (reported by Lighthouse), and I also have to deal with Flash-of-un-styled-text, etc in slow network conditions.

If you use inline SVG, now the icon is bundled with the source, and I don't need to worry about loading the font, or any of the accompanying issues.

For example:

html`<svg width="24" height="24" viewBox="0 0 24 24"><path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"/><path d="M0 0h24v24H0z" fill="none"/></svg>`

Instead of:

<!-- Required only for the wl-icon in the wl-expansion -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

And (in expansion.ts):

import "../icon";
...
html`<wl-icon id="icon">${this.icon}</wl-icon>`

I guess the down-side is that there may be increased file size for projects that do use wl-icon and the Material Icons font.

Perhaps you would export a set of SVG icons that are used within Weightless so that they can also be shared/bundled in the parent project.

Thoughts? Is this good or have I got the wrong idea here?

@Lattyware
Copy link

Lattyware commented Jun 14, 2019

By far the best option as I see it is to make all icons in other components slots - it gives way more flexibility to anyone using the components. Given how many different options there are for icons, trying to find a solution that fits everyone without just delegating seems like a fool's errand. Defaults are another thing, of course - filling the slot with wl-icon seems like a sensible default. Given that, it seems like a good solution in general.

Of note is that the select component uses inline SVG as you describe (but, by contrast, has no option to customise it at all).

@brettwillis
Copy link
Author

Ok, that sounds reasonable.

So then the action required here is to move the <wl-icon> into the default/fallback content of the indicator slot.

Current code is:

<div id="indicator">
  <slot name="indicator"></slot>
  ${this.icon != null ? html`<wl-icon id="icon">${this.icon}</wl-icon>` : nothing}
</div>

Meaning that there is no way to override the <wl-icon>.

Is it also reasonable to omit import "../icon"; (to reduce code size if using a different approach) and leave it up to the parent project to import it... seeing as we have to manually import the font anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants