Skip to content

Commit 06a995e

Browse files
docs: add a section on custom svg paths (#1368)
1 parent 71938d0 commit 06a995e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

readme.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ label.
1919

2020
The Ionicons Web Component is an easy and performant way to use Ionicons in your app. The component will dynamically load an SVG for each icon, so your app is only requesting the icons that you need.
2121

22-
Also note that only visible icons are loaded, and icons which are "below the fold" and hidden from the user's view do not make fetch requests for the svg resource.
22+
Also note that only visible icons are loaded, and icons that are "below the fold" and hidden from the user's view do not make fetch requests for the svg resource.
2323

2424
### Installation
2525

26-
If you're using [Ionic Framework](https://ionicframework.com/), Ionicons is packaged by default, so no installation is necessary. Want to use Ionicons without Ionic Framework? Place the following `<script>` near the end of your page, right before the closing </body> tag, to enable them.
26+
If you're using [Ionic Framework](https://ionicframework.com/), Ionicons is packaged by default, so no installation is necessary. Want to use Ionicons without Ionic Framework? Place the following `<script>` near the end of your page, right before the closing `</body>` tag, to enable them.
2727

2828
```html
2929
<script type="module" src="https://cdn.jsdelivr.net/npm/ionicons@latest/dist/ionicons/ionicons.esm.js"></script>
@@ -46,6 +46,24 @@ To use a custom SVG, provide its url in the `src` attribute to request the exter
4646
<ion-icon src="/path/to/external/file.svg"></ion-icon>
4747
```
4848

49+
#### Custom Asset Path
50+
51+
If you have a different set of icons you would like to load or if the Ionicon icons are hosted on a different page or path, you can set the asset url from which Ionicons pulls the icons via:
52+
53+
```ts
54+
import { setAssetPath } from '@stencil/core'
55+
56+
// set root path for loading icons to "<root>/public/svg"
57+
setAssetPath(`${window.location.origin}/public/svg/`);
58+
```
59+
60+
This allows the use of named icons like this:
61+
62+
```html
63+
<!-- now pulls the svg from "<root>/public/svg/heart.svg" -->
64+
<ion-icon name="heart"></ion-icon>
65+
```
66+
4967
## Variants
5068
Each app icon in Ionicons has a `filled`, `outline` and `sharp` variant. These different variants are provided to make your app feel native to a variety of platforms. The filled variant uses the default name without a suffix. Note: Logo icons do not have outline or sharp variants.
5169

@@ -56,7 +74,7 @@ Each app icon in Ionicons has a `filled`, `outline` and `sharp` variant. These d
5674
```
5775

5876
### Platform specificity
59-
When using icons in Ionic Framework you can specify different icons per platform. Use the `md` and `ios` attributes and provide the platform specific icon/variant name.
77+
When using icons in Ionic Framework you can specify different icons per platform. Use the `md` and `ios` attributes and provide the platform-specific icon/variant name.
6078

6179
```html
6280
<ion-icon ios="heart-outline" md="heart-sharp"></ion-icon>

0 commit comments

Comments
 (0)