import { Story, Meta, html } from '@open-wc/demoing-storybook'; import * as bugs from './icons/bugs-collection.js'; import arrowLeftSvg from './icons/arrowLeft.svg.js'; import '../lion-icon.js'; # Icon A web component for displaying icons. {html` `} ```html ``` ## How to use ### Installation ```sh npm i --save @lion/icon ``` ```js import '@lion/icon/lion-icon.js'; ``` ## Icon format Icon file is an ES module with an extension `.svg.js` which exports a function like this: ```js // bug.svg.js export default tag => tag` ... `; ``` Make sure you have `focusable="false"` in the icon file to prevent bugs in IE/Edge when the icon appears in tab-order. ### Accessibility It is recommended to add an `aria-label` to provide information to visually impaired users: A `lion-icon` without an `aria-label` attribute will be automatically be given an `aria-hidden` attribute. {html` `} ```html ``` ### Styling By default, a `lion-icon` will be `1em` × `1em` (the current line-height). `lion-icon` uses SVGs and may be styled with CSS, including using CSS properties such as `fill` and `stroke`: {html` `} ```html ``` See SVG and CSS on MDN web docs for more information. ### Collections Due to the `.svg.js` format using ES Modules, it is very easy to compose and load your own icon collections. You can bundle them like this: ```js import bug01 from './bugs/bug01.svg.js'; import bug02 from './bugs/bug02.svg.js'; import bug05 from './bugs/bug05.svg.js'; import bug06 from './bugs/bug06.svg.js'; import bug08 from './bugs/bug08.svg.js'; import bug12 from './bugs/bug12.svg.js'; import bug19 from './bugs/bug19.svg.js'; import bug23 from './bugs/bug23.svg.js'; import bug24 from './bugs/bug24.svg.js'; export { bug01, bug02, bug05, bug06, bug08, bug12, bug19, bug23, bug24 }; ``` {html`
`}
And then use them by either importing them all: ```js import * as bugs from './icons/bugs-collection.js'; ``` Or one by one: ```js import { bug01, bug02, bug05, bug06, bug08, bug12, bug19, bug23, bug24, } from './icons/bugs-collection.js'; ``` ### Dynamic import It is also possible to dynamically import the `.svg.js` file. This will load the icon asynchronously. ```js ``` The demo is currently disabled for this feature due to an issue with Storybook.