Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit b50f8f2

Browse files
committed
docs: update icon docs with adding custom icons
1 parent 5b537a5 commit b50f8f2

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

packages/c-icon/README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,57 @@ A component to display icons in the browser
88
yarn add @chakra-ui/c-icon
99
# or
1010
npm i @chakra-ui/c-icon
11-
```
11+
```
12+
13+
### Adding custom icons
14+
All Chakra icons are registered in the Chakra plugin under the `icons.extend` key. So you
15+
can extend this object to add your own icons. Here are the steps:
16+
17+
- Export the icon's `svg` from Figma, Sketch, etc.
18+
- Use a tool like [SvgOmg](https://svgomg.firebaseapp.com) to reduce the size
19+
and minify the markup.
20+
- Add the icon to the theme object.
21+
22+
> Add the `fill=currentColor` attribute to the `path` or `g` so that when you
23+
> this `<Icon color="gray.200"/>`, it works correctly.
24+
25+
<br />
26+
27+
```js
28+
// Step 1: Each icon should be stored as an object of `path` and `viewBox`
29+
const customIcons = {
30+
icon1: {
31+
path: `<path fill="currentColor" d="..." />`,
32+
// If the icon's viewBox is `0 0 24 24`, you can ignore `viewBox`
33+
viewBox: "0 0 40 40",
34+
},
35+
icon2: {
36+
path: `
37+
<g fill="currentColor">
38+
<path d="..."/>
39+
</g>
40+
`
41+
}
42+
};
43+
44+
// Step 2: Add the custom icon to the Chakra plugin
45+
Vue.use(Chakra, {
46+
icons: {
47+
// ...
48+
extend: {
49+
...customIcons
50+
}
51+
}
52+
})
53+
```
54+
55+
You can now consume your custom icons in your template like this:
56+
57+
```vue
58+
<template>
59+
<c-icon name="icon1" color="yellow.600" />
60+
<c-icon name="icon2" color="green.300" />
61+
</template>
62+
```
63+
64+
> You can access the full merged icons object under `this.$chakra.icons` in your Vue components.

0 commit comments

Comments
 (0)