2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-14 00:34:04 +00:00
iconify/iconify-icon/icon/README.md

324 lines
13 KiB
Markdown
Raw Normal View History

2022-04-29 20:19:22 +00:00
# What is Iconify?
There are many excellent icon sets available. Each icon set has its own custom syntax, some are available only as fonts. Unfortunately, almost all of them load an entire set, even if you are displaying just a few icons. This makes it hard to use different icon sets.
Iconify tries to unify all icon sets. You can use the same code no matter what icon set you choose. You can mix icons from multiple icon sets on the same page.
2022-04-29 20:19:22 +00:00
Iconify is the most versatile icon framework.
- Unified icon framework that can be used with any icon library.
- Out of the box includes 100+ icon sets with more than 100,000 icons.
- Embed icons in HTML with Iconify icon web component and components for various front-end frameworks.
2022-04-29 20:19:22 +00:00
- Embed icons in designs with plug-ins for Figma, Sketch and Adobe XD.
- Add icon search to your applications with Iconify Icon Finder.
For more information visit [https://iconify.design/](https://iconify.design/).
# IconifyIcon web component
2022-04-29 20:19:22 +00:00
Iconify Icon web component renders icons.
2022-04-29 20:19:22 +00:00
Add this line to your page to load IconifyIcon (you can add it to `<head>` section of the page or before `</body>`):
2022-04-29 20:19:22 +00:00
```html
2022-05-02 06:40:11 +00:00
<script src="https://code.iconify.design/iconify-icon/0.0.4/iconify-icon.min.js"></script>
2022-04-29 20:19:22 +00:00
```
or
```html
2022-05-02 06:40:11 +00:00
<script src="https://cdn.jsdelivr.net/npm/iconify-icon@0.0.4/dist/iconify-icon.min.js"></script>
2022-04-29 20:19:22 +00:00
```
or, if you are building a project with something like WebPack or Rollup, you can include the script by installing `iconify-icon` as a dependency and importing it in your project:
2022-04-29 20:19:22 +00:00
```js
2022-05-02 06:40:11 +00:00
import 'iconify-icon';
2022-04-29 20:19:22 +00:00
```
To add any icon, write something like this:
```html
<iconify-icon icon="eva:people-outline"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
&nbsp;&nbsp;&nbsp; ![Sample](https://iconify.design/assets/images/eva-people-outline.svg)
That is it. Change `icon` attribute to the name of the icon you want to use. There are over 100,000 premade icons to choose from, including Material Symbols, Photphor, Remix Icons, Carbon, Unicons, Bootstrap Icons and even several emoji sets.
2022-04-29 20:19:22 +00:00
Do you want to make your own icon sets? Everything you need is [available on GitHub](https://github.com/iconify): tools for creating custom icon sets, Iconify API application and documentation to help you.
## Advantages
What are advantages of using IconifyIcon web component?
Advantages of using Iconify components:
- No need to pre-bundle icons. Pass icon name as parameter, component will load data for icon from public API and render it.
- Huge choice of icons, no icon fonts!
- Easy to style. All monotone icons use font color for color (`currentColor`) and font size for size (height is set to `1em`), making it easy to change color and size.
Main advantage of web component over other implementations is shadow DOM. Using shadow DOM instead of inlining SVG has the following advantages:
- Document's styles do not affect content of shadow DOM, so there are no conflicting styles.
- HTML served from server does not contain long code for icons. It only contains `<iconify-icon />` tags, which reduces document size. Frameworks that use SSR and hydration, using web component for icons means same HTML code generated on server and rendered in client, preventing potential hydration errors. Actual icon code is hidden in shadow DOM.
2022-04-29 20:19:22 +00:00
## Full documentation
This package is in development, documentation for it is not ready yet.
2022-04-29 20:19:22 +00:00
Until it is ready, you can look at SVG framework documentation instead:
2022-04-29 20:19:22 +00:00
- [SVG framework documentation](https://docs.iconify.design/icon-components/svg-framework/).
- [React component documentation](https://docs.iconify.design/icon-components/react/).
- [Iconify API documentation](https://docs.iconify.design/api/).
- [Creating icon bundles](https://docs.iconify.design/icon-components/bundles/).
- [Iconify Tools documentation](https://docs.iconify.design/tools/tools2/).
2022-04-29 20:19:22 +00:00
## How does it work?
Iconify icon script registers a web component `iconify-icon`.
2022-04-29 20:19:22 +00:00
Web component uses the following logic to render icon:
2022-04-29 20:19:22 +00:00
1. Retrieves icon name from `icon` attribute.
2022-04-29 20:19:22 +00:00
2. Checks if icon exists. If not, it sends a request to Iconify API to retrieve icon data.
3. Renders icon in shadow DOM in web component.
2022-04-29 20:19:22 +00:00
### Inline mode
Usually, icon fonts do not render like normal images, they render like text. Text is aligned slightly below the baseline.
Visual example to show the difference between inline and block modes:
&nbsp;&nbsp;&nbsp; ![Inline icon](https://iconify.design/assets/images/inline.png)
To help developers, Iconify Icon has inline mode.
2022-04-29 20:19:22 +00:00
Why is the inline mode needed?
- To easily align icons within the text, such as emojis.
- To make the transition from outdated icon fonts to SVG easier.
You can toggle inline mode by adding `inline` attribute:
2022-04-29 20:19:22 +00:00
```html
<iconify-icon inline icon="material-symbols:account-circle"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
You can also do that by applying style:
2022-04-29 20:19:22 +00:00
```html
<iconify-icon
icon="material-symbols:account-circle"
2022-04-29 20:19:22 +00:00
style="vertical-align: -0.125em"
></iconify-icon>
2022-04-29 20:19:22 +00:00
```
## Render modes
Web component has several render modes, which can be changed by passing `mode` property:
- `svg`: renders icon as `<svg>`.
- `bg`: renders icon as `<span>` with background set to SVG.
- `mask`: same as `bg`, but uses masks instead, combined with `background-color: currentColor`, which results in icon rendered as background that uses text color.
- `style`: `bg` or `mask`, depending on icon content.
Why are these modes needed?
It solves issues with SVG 2 animations. Usually, when SVG contains animations, animations do not start until DOM is ready. This can be affected by small things like ad code failing to load, preventing animations from working and causing frustration to developers. However, this is not an issue if SVG is rendered as background - animations are ran instantly. Also performance of SVG 2 animations is much better when used as background or mask. Background is used when icon does not contain `currentColor`, so all colors are displayed properly. Mask is used when icon contains `currentColor`, so icon is used as mask for background that uses `currentColor`, so icon correctly follows `currentColor`.
If background and masks are so good, why SVG mode is available? First issue is color: if icon has mix of `currentColor` and palette (please do not design icons like that, it is bad practice!), icon colors will be incorrect, so such icons should be rendered as `<svg>`. Second issue is performance of icons without animations. Animated icons do perform much better as background or mask, but icons without animation usually perform better as `<svg>`.
What is default rendering mode? That depends on icon. If icon contains SVG 2 animation tags, icon is rendered as `<span>` with background or mask (mask for icons that contain `currentColor`, background for other icons), otherwise icon is rendered as `<svg>`.
2022-04-29 20:19:22 +00:00
## Iconify API
When you use an icon font, each visitor loads an entire font, even if your page only uses a few icons. This is a major downside of using icon fonts. That limits developers to one or two fonts or icon sets.
Unlike icon fonts, Iconify Icon web component does not load the entire icon set. Unlike fonts and SVG frameworks, Iconify only loads icons that are used on the current page instead of loading entire icon sets. How is it done? By serving icons dynamically from publicly available JSON API.
2022-04-29 20:19:22 +00:00
### Custom API
Relying on a third party service is often not an option. Many companies and developers prefer to keep everything on their own servers to have full control.
Iconify API and icon sets are all [available on GitHub](https://github.com/iconify), making it easy to host API on your own server.
For more details see [Iconify API documentation](https://docs.iconify.design/api/).
2022-04-29 20:19:22 +00:00
You can also create custom Iconify API to serve your own icons. For more details see [hosting custom icons in Iconify documentation](https://docs.iconify.design/api/hosting.html).
2022-04-29 20:19:22 +00:00
### Using Iconify offline
While the default method of retrieving icons is to retrieve them from API, there are other options. Iconify Icon web component is designed to be as flexible as possible.
2022-04-29 20:19:22 +00:00
Easiest option to serve icons without API is by creating icon bundles.
Icon bundles are small scripts that you can load after Iconify Icon web component or bundle it together in one file.
2022-04-29 20:19:22 +00:00
For more details see [icon bundles in Iconify documentation](https://docs.iconify.design/icon-components/bundles/).
2022-04-29 20:19:22 +00:00
Another option is to import icons and bundle them with Iconify, similar to React and Vue components. Example:
```js
// Installation: npm install --save-dev iconify-icon
2022-05-01 10:34:51 +00:00
import 'iconify-icon';
2022-04-29 20:19:22 +00:00
// Installation: npm install --save-dev @iconify/icons-dashicons
import adminUsers from '@iconify/icons-dashicons/admin-users';
// Unlike React and Vue components, in SVG framework each icon added with addIcon() name must have a
// prefix and a name. In this example prefix is "dashicons" and name is "admin-users".
addIcon('dashicons:admin-users', adminUsers);
2022-04-29 20:19:22 +00:00
```
```html
<iconify-icon icon="dashicons:admin-users"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
See [Iconify for React](https://docs.iconify.design/icon-components/react/) documentation for more details.
2022-04-29 20:19:22 +00:00
## Color
There are 2 types of icons: monotone and coloured.
- Monotone icons are icons that use only 1 colour and you can change that colour. Most icon sets fall into this category: FontAwesome, Unicons, Material Design Icons, etc.
- Coloured icons are icons that use the preset palette. Most emoji icons fall into this category: Noto Emoji, Emoji One, etc. You cannot change the palette for those icons.
Monotone icons use font colour, just like glyph fonts. To change colour, you can do this:
```html
<iconify-icon class="icon-bell" icon="vaadin-bell"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
and add this to CSS:
```css
.icon-bell {
color: #f80;
}
.icon-bell:hover {
color: #f00;
}
```
Sample:
&nbsp;&nbsp;&nbsp; ![Sample](https://iconify.design/samples/icon-color.png)
## Dimensions
By default all icons are scaled to 1em height. To control icon height use font-size:
```html
<iconify-icon class="icon-clipboard" icon="emojione-clipboard"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
and add this to css:
```css
.icon-clipboard {
font-size: 32px;
}
```
Sample:
&nbsp;&nbsp;&nbsp; ![Sample](https://iconify.design/samples/icon-size.png)
you might also need to set line-height:
```css
.icon-clipboard {
font-size: 32px;
line-height: 1em;
}
```
You can also set custom dimensions using `width` and `height` attributes:
2022-04-29 20:19:22 +00:00
```html
<iconify-icon icon="twemoji-ice-cream" width="32" height="32"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
Sample:
&nbsp;&nbsp;&nbsp; ![Sample](https://iconify.design/samples/icon-size2.png)
## Transformations
You can rotate and flip icon by adding `flip` and `rotate` attributes:
2022-04-29 20:19:22 +00:00
```html
<iconify-icon icon="twemoji-helicopter" flip="horizontal"></iconify-icon>
<iconify-icon icon="twemoji-helicopter" rotate="90deg"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
Possible values for `flip`: horizontal, vertical.
Possible values for `rotate`: 90deg, 180deg, 270deg.
2022-04-29 20:19:22 +00:00
If you use both flip and rotation, the icon is flipped first, then rotated.
To use custom transformations use CSS transform rule.
2022-04-29 20:19:22 +00:00
```html
<iconify-icon icon="twemoji-helicopter" class="icon-helicopter"></iconify-icon>
2022-04-29 20:19:22 +00:00
```
```css
.icon-helicopter {
transform: 45deg;
2022-04-29 20:19:22 +00:00
}
```
Samples:
&nbsp;&nbsp;&nbsp; ![Sample](https://iconify.design/samples/icon-transform.png)
## Available icons
There are over 100,000 icons to choose from.
Few popular icon sets (monotone icons):
2022-04-29 20:19:22 +00:00
- [Material Symbols](https://icon-sets.iconify.design/material-symbols/) (7000+ icons)
2022-04-29 20:19:22 +00:00
- [Material Design Icons](https://icon-sets.iconify.design/mdi/) (5000+ icons)
- [Carbon](https://icon-sets.iconify.design/carbon/) (1000+ icons)
2022-04-29 20:19:22 +00:00
- [Unicons](https://icon-sets.iconify.design/uil/) (1000+ icons)
- [Jam Icons](https://icon-sets.iconify.design/jam/) (900 icons)
- [IonIcons](https://icon-sets.iconify.design/ion/) (1200+ icons)
- [FontAwesome 6](https://icon-sets.iconify.design/fa6-solid/) (2000+ icons)
2022-04-29 20:19:22 +00:00
- [Bootstrap Icons](https://icon-sets.iconify.design/bi/) (500+ icons)
- [IcoMoon Free](https://icon-sets.iconify.design/icomoon-free/) (400+ icons)
- [Dashicons](https://icon-sets.iconify.design/dashicons/) (300 icons)
and many others.
Emoji collections (mostly colored icons):
- [Emoji One](https://icon-sets.iconify.design/emojione/) (1800+ colored version 2 icons, 1400+ monotone version 2 icons, 1200+ version 1 icons)
- [OpenMoji](https://icon-sets.iconify.design/openmoji/) (3500+ icons)
- [Noto Emoji](https://icon-sets.iconify.design/noto/) (2000+ icons for version 2, 2000+ icons for version 1)
- [Twitter Emoji](https://icon-sets.iconify.design/twemoji/) (2000+ icons)
- [Firefox OS Emoji](https://icon-sets.iconify.design/fxemoji/) (1000+ icons)
Also, there are several thematic collections, such as weather icons, map icons, etc.
You can use browse or search available icons on the Iconify website: https://icon-sets.iconify.design/
Click an icon to get HTML code.
## Browser support
Iconify web component supports all modern browsers.
2022-04-29 20:19:22 +00:00
## License
This package is licensed under MIT license.
`SPDX-License-Identifier: MIT`
This license does not apply to icons. Icons are released under different licenses, see each icon set for details.
Icons available by default are all licensed under some kind of open-source or free license.
© 2022 Vjacheslav Trushkin / Iconify OÜ