Skip to content

Commit

Permalink
docs(image-loader): add "Dynamic image source" example
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Feb 24, 2024
1 parent 0f318aa commit c6af8bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/src/pages/components/ImageLoader.svx
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ Set `fadeIn` to `true` to fade in the image if successfully loaded.

In this example, a component reference is obtained to programmatically trigger the `loadImage` method.

<FileSource src="/framed/ImageLoader/ProgrammaticImageLoader" />
<FileSource src="/framed/ImageLoader/ProgrammaticImageLoader" />

## Dynamic image source

The same `ImageLoader` instance can be used to load different images.

<FileSource src="/framed/ImageLoader/DynamicImageLoader" />
25 changes: 25 additions & 0 deletions docs/src/pages/framed/ImageLoader/DynamicImageLoader.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script>
import { ImageLoader, Button } from "carbon-components-svelte";
const images = [
"https://upload.wikimedia.org/wikipedia/commons/1/1b/Svelte_Logo.svg",
"https://upload.wikimedia.org/wikipedia/commons/b/b9/Carbon-design-system-logo.png",
];
let index = 0;
$: src = images[index];
</script>

<Button
kind="ghost"
on:click="{() => {
index = index === 0 ? 1 : 0;
}}"
>
Toggle image
</Button>

<div style:margin-top="1rem" style:width="100%" style:max-width="120px">
<ImageLoader ratio="1x1" fadeIn src="{src}" alt="{src}" />
</div>

0 comments on commit c6af8bd

Please sign in to comment.