mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 23:00:56 +00:00
Update Svelte readme and Sapper demo
This commit is contained in:
parent
941547e5e5
commit
37130be48a
@ -16,7 +16,7 @@
|
|||||||
let postIcon;
|
let postIcon;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
let promises = [
|
const promises = [
|
||||||
import('@iconify/svelte'),
|
import('@iconify/svelte'),
|
||||||
import('@iconify/icons-bi/link-45deg'),
|
import('@iconify/icons-bi/link-45deg'),
|
||||||
];
|
];
|
||||||
|
@ -315,6 +315,53 @@ Visual example to show the difference between inline and block modes:
|
|||||||
|
|
||||||
![Inline icon](https://iconify.design/assets/images/inline.png)
|
![Inline icon](https://iconify.design/assets/images/inline.png)
|
||||||
|
|
||||||
|
## Sapper
|
||||||
|
|
||||||
|
The icon component works with Sapper.
|
||||||
|
|
||||||
|
If you use the component as shown in examples above, SVG will be rendered on the server and sent to visitor as HTML code.
|
||||||
|
|
||||||
|
If you are rendering multiple identical icons, rendering them on server is not optimal. It is much better to render them once using JavaScript in browser. How to do that with this icon component? By loading both component and icon data asynchronously.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
<script>
|
||||||
|
// Dynamically load icon component, icon data and render it on client side
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
let IconifyIcon;
|
||||||
|
let postIcon;
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const promises = [
|
||||||
|
import('@iconify/svelte'), // Component
|
||||||
|
import('@iconify/icons-bi/link-45deg'), // Icon #1
|
||||||
|
];
|
||||||
|
const results = await Promise.all(promises);
|
||||||
|
IconifyIcon = results[0].default; // Component
|
||||||
|
postIcon = results[1].default; // Icon #1
|
||||||
|
});
|
||||||
|
|
||||||
|
export let posts;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{#each posts as post}
|
||||||
|
<li>
|
||||||
|
<svelte:component this={IconifyIcon} icon={postIcon} />
|
||||||
|
<a rel="prefetch" href="blog/{post.slug}">{post.title}</a>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
```
|
||||||
|
|
||||||
|
This example adds icon stored in `postIcon` to every list item. If it was rendered on the server, HTML would send SVG element multiple times. But because it is rendered in browser, icon data and component needs to be sent to browser only once.
|
||||||
|
|
||||||
|
Instead of using `<IconifyIcon />`, you must use `<svelte:component />` to make sure component is rendered dynamically.
|
||||||
|
|
||||||
|
This example is based on Iconify Sapper demo: https://github.com/iconify/iconify/blob/master/packages/sapper-demo/src/routes/blog/index.svelte
|
||||||
|
|
||||||
## Icon Sets
|
## Icon Sets
|
||||||
|
|
||||||
You can find all available icons at https://iconify.design/icon-sets/
|
You can find all available icons at https://iconify.design/icon-sets/
|
||||||
@ -371,14 +418,14 @@ npm install --save-dev @iconify/icons-ri
|
|||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
```jsx
|
```html
|
||||||
<script>
|
<script>
|
||||||
import IconifyIcon from '@iconify/svelte';
|
import IconifyIcon from '@iconify/svelte';
|
||||||
import alertLine from '@iconify/icons-ri/alert-line';
|
import alertLine from '@iconify/icons-ri/alert-line';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.alert {
|
.alert {
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 8px;
|
margin: 8px;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
@ -404,8 +451,8 @@ import alertLine from '@iconify/icons-ri/alert-line';
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="alert">
|
<div class="alert">
|
||||||
<IconifyIcon icon={alertLine} />
|
<IconifyIcon icon="{alertLine}" />
|
||||||
Important notice with alert icon!
|
Important notice with alert icon!
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user