Giter VIP home page Giter VIP logo

vue-sample-svg-icons's Introduction

Sample SVG Icon usage for Vue.js

A demo to show how I prefer to set up an SVG icon system in Vue.js. You can see a demo live here. You don't have to do it this way, it's an opinionated example. More details for why it's set up in this manner in the Vue Cookbook.

Documentation site

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

For a detailed explanation on how things work, check out the guide and docs for vue-loader.

vue-sample-svg-icons's People

Contributors

dependabot[bot] avatar sdras avatar tessasac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-sample-svg-icons's Issues

Setup for external icon library?

Thanks for this great example! 😃 One downside of this approach is that it forces us to split the svg and its paths. When working with a design system or external SVG library, all icons would probably be provided as plain .svg files.

Is there a way to easily generate all the path icon components from a set of .svg files?

icon system for icons with different viewports

I am trying implement this but I will have icons of different heights and widths coming from the design team. I am thinking the icon components could wrap themselves in the IconBase component and send a specific viewport to it. An icon component template would look like this:

<IconBase view-port="0 0 12 7" :width="width" :height="height"> <IconTrash/> </IconBase>

So I think I will need a more basic base icon that can take in props and put this together. I had been passing the viewport in to the IconBase but that should really be stored in each icon. I this making sense?

请问针对渐变的Svg应该如何处理

`<svg xmlns="http://www.w3.org/2000/svg"
:width="width"
:height="height"
:viewBox="viewBox"
:aria-labelledby="iconName"
role="presentation"

<title
    :id="iconName"
    lang="en"
>{{ iconName }} icon</title>
<defs>
    <linearGradient x1="100%" y1="81.5315548%" x2="0%" y2="18.4684452%" id="linearGradient-1">
        <stop stop-color="#35B8FF" offset="0%"></stop>
        <stop stop-color="#007EFE" offset="100%"></stop>
    </linearGradient>
</defs>
<g :fill="iconColor">
    <slot />
</g>

`

如上所示,defs如何放在子组件里

Vue warning

so I got this warning:
"IconWrite" was accessed during render but is not defined on instance.

and I don't know why?

Using the icon name for id/aria-labelledby has a high risk for duplicate ids

Hi, and sorry for the lengthy bug. :P

The id/aria-labelledby pattern used for the icon components can be useful for VoiceOver support (other screen readers should manage to read the <title> without it), but it’s a difficult technique because it requires unique ids and there’s a risk of duplicate ids in the document. So using the icon name only is a bit risky.

  1. If this name is generic, e.g. menu, it may already be used in the page, and adding an element with this id before the “real” target using that id may break existing functionality (e.g. <a href="#menu">Skip to navigation</a> might point to an icon and not to the menu somewhere else in the page, <label for="user">User name</label> may point to an icon and not the relevant input, etc.).

  2. If an icon is used several times (e.g. in a loop), the document will have duplicate ids and it’s unclear if aria-labelledby will work correctly in this case.

It might be safer to generate a unique id, for instance:

// only once at instantiation, not sure if that should be a computed property in Vue
const id = 'icon-' + iconName + '-' + Math.floor(Math.random() * 1000000) // e.g. "icon-arrow-764820"

Do you think this could be included in your examples in some way?

On a related topic, in my experience using a technical name (e.g. an icon id derived from a file name) is not satisfying alternative text: the icon name may be different from the meaning we’re trying to convey, and when we start localizing the site it’s even more unhelpful (e.g. a Spanish speaker would be lost with a button whose label is "looking-glass icon").

I’ve used two different solutions in the past:

  1. Pass a different prop/parameter explicitly for the alt text (a prop named alt could make sense). Then in the icon component or template I only output the <title id="…">…</title> and aria-labelledby attribute if alt text is provided.
  2. Or avoid alt text on <svg> icons altogether, and:
    • for "icon + visible label" patterns, do nothing;
    • for icon-only buttons and links, use <a aria-label="…">…</a> and <button aria-label="…">…</button>, which has less flaky support in screen readers.

Because of the technical difficulty and footgun of duplicate ids I tend to go with the second solution, but both are okay.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.