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

RFC: Feather SVG Icon System #101

Closed
colebemis opened this issue Jun 8, 2017 · 8 comments
Closed

RFC: Feather SVG Icon System #101

colebemis opened this issue Jun 8, 2017 · 8 comments

Comments

@colebemis
Copy link
Member

colebemis commented Jun 8, 2017

This is a place to discuss how to best implement an SVG Icon System for Feather. This is a continuation of the discussions in #47 and #41. The goal of this thread is to define a usage spec for Feather.

Here's the consensus so far:

  • The icons directory should remain the single source of truth.
  • An SVG sprite sheet should be generated from the icons directory.
  • Feather should expose an icons object to make the NPM package more useful.
  • Feather should provide a way to inject SVGs into the DOM with JavaScript. This would allow for the use of a CDN making it easier to prototype with Feather icons.
  • Feather should provide integration with popular JS frameworks like React and Vue through separate packages (react-feather, vue-feather, etc.).

Related reading:

Other SVG icon systems:

@Swizz
Copy link

Swizz commented Jun 8, 2017

Evil-icons looks very close to that you have in mind ; but the renderIcons function needs to be called each time the dom change, this is pretty messy against how easy the using of a font icon is.

Like you said, the SVG Symbol Sprite need to be the single source of truth, according to this, the CDN loader need to encore the use of <use> by doing only the in dom injection.

So, I discourage the use of class or data-icon.

@colebemis
Copy link
Member Author

I was actually thinking that the individual SVGs in the icons directory should be the single source of truth. Everything else can be generated from that directory. That way all we have to do to add an icon is put an SVG into the icons directory and everything else updates.

In terms of DOM injection, I'm doing some research on that right now. I'll post a write-up of my findings soon.

@colebemis
Copy link
Member Author

Here are my ideas on ways Feather could be used:

Option 1: Copy & Paste

If you only need one or two icons, copying and pasting the SVG code directly into your markup might be the best solution. This is by far the simplest way to use Feather.

Option 2: Node

For more advanced use cases, Feather could expose an icons object, making icon information easily accessible. Additionally, Feather could provide a toSVG method that accepts an icon name and an options object and returns a string of the <svg> tag.

Example:

const feather = require('feather-icons');

feather.icons.mail

/* {
    name: 'mail',
    contents: '<path d="..."/><polyline points="..."/>',
    options: {
        class: 'feather feather-mail',
        width: 24,
        height: 24,   
        viewBox: '0 0 24 24',
        fill: 'none',
        stroke: 'currentColor',
        'stroke-width': 2,
        'stroke-linecap': 'round',
        'stroke-linejoin': 'round',
    },
} */


feather.toSVG('mail', {})

// '<svg ...><path d="..."/><polyline points="..."/></svg>'

This option would make Feather easier to use with front-end frameworks like React and Vue and would aid in the creation of packages like 'react-feather', 'vue-feather', etc.

I imagine that this feather object would be the core of the Feather icon library. All other usage implementations could reference this object for icon information.

Option 3: JavaScript Injection

The feather object could have an inject method that accepts a DOM NodeList and replaces those elements with the SVG icon that corresponds to the element's data-icon attribute.

Example:

<script src="/path/to/feather.min.js"></script>

<span class="feather" data-icon="mail"></span>

<script>
    const icons = document.querySelectorAll('feather');
    feather.inject(icons);
</script>

This option would be good for prototyping in the browser because it could utilize a CDN.

Option 4: Spritesheet

Feather could generate an SVG sprite by looping over every key in feather.icons object. To use the sprite, you could either paste the contents of feather.svg immediately below the opening body tag and use it like this:

<svg><use xlink:href="#mail"/></svg>

or just reference feather.svg like this:

<svg><use xlink:href="/path/to/feather.svg#mail"></svg>

I know IE has some problems referencing external SVGs in this way so we would probably have to provide a polyfill of some kind.

Final Thoughts

I'd like to keep the main feather repo as barebones as possible and keep it platform agnostic. We can create helper repos like react-feather for platform specific use cases.

I'd love to get feedback on these ideas. Let me know if you have any ideas about how to best deliver Feather. I want to design the best possible experience for Feather users before getting in the weeds with implementation details.

@tthallos
Copy link
Contributor

@carmelopullara
Copy link
Member

Just published react-feather.

@colebemis
Copy link
Member Author

@mage3k @carmelopullara I just merged a pull request adding a Related Projects to the README. I'd love for you guys to add your projects to the list. Just submit a pull request 👍

@carmelopullara
Copy link
Member

@colebemis just submitted. Thanks!

@tnguyen14
Copy link

With this issue closed, is there one tracking the progress of SVG sprite?

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

5 participants