Skip to content
Control Components

Image

An image input control.

Important: This component has some rough edges, and should be considered experimental.

Integrates the tweakpane-image-plugin, incorporating work by Florian Morel, Matheus Dias, Palash Bansal, and others.

There is currently a known bug where change events' origin values are sometimes incorrect. (This issue is limited to this component.)

Usage outside of a <Pane> component will implicitly wrap the image control in <Pane position="inline">.

Note that Svelte Tweakpane UI embeds a functionally identical fork of the plugin with build optimizations. The fork also changes the package name to @kitschpatrol/tweakpane-plugin-image for consistency with other plugins.


Example

🔗

Demo

🔗

Tap “No Image” above to load an image from disk.

Code

🔗
ImageExample.svelte
<script lang="ts">
import { Button, Image } from 'svelte-tweakpane-ui';
let source = 'placeholder';
async function getRandomKittenUrl() {
const { url } = await fetch(
'https://source.unsplash.com/800x800/?kitten',
{ method: 'HEAD', redirect: 'follow' }
);
return url;
}
</script>
<Image bind:value={source} fit="contain" label="Image" />
<Button
on:click={async () => {
source = await getRandomKittenUrl();
}}
label="Random Placeholder"
title="Load Kitten"
/>
<div class="demo">
{#if source === 'placeholder'}
<p>Tap “No Image” above to load an image from disk.</p>
{:else}
<img alt="" src={source} />
{/if}
</div>
<style>
div.demo {
display: flex;
align-items: center;
justify-content: center;
aspect-ratio: 1;
width: 100%;
background: linear-gradient(magenta, orange);
}
div.demo > img {
max-width: 80%;
max-height: 80%;
}
div.demo > p {
max-width: 50%;
color: white;
text-align: center;
}
</style>

Props

🔗

value

🔗
bindablerequired
Description

Image data

TypeImageValue

extensions

🔗
optional
Description

Array of image extension types to accept.

Typestring[]
Default['.jpg', '.png', '.gif']

fit

🔗
optional
Description

How to display the image in the preview pane.

Renamed from imageFit in tweakpane-image-plugin for concision.

Type'contain' | 'cover'
Default'cover'

disabled

🔗
optional
Description

Prevent interactivity and gray out the control.

Typeboolean
Defaultfalse

label

🔗
optional
Description

Text displayed next to control.

Typestring
Defaultundefined

options

🔗
optional
Description

Tweakpane's internal options object.

See BindingParams.

Valid types are contingent on the type of the value key points to in object.

This is intended internal use, when implementing convenience components wrapping Binding's functionality. Options of interest are instead exposed as top-level props in Svelte Tweakpane UI.

TypeBaseInputParams
Defaultundefined

theme

🔗
optional
Description

Custom color scheme.

TypeTheme
Defaultundefined
Inherits default Tweakpane theme equivalent to ThemeUtils.presets.standard, or the theme set with setGlobalDefaultTheme().

Events

🔗

change

🔗
Description

Fires when value changes.

This event is provided for advanced use cases. It's usually preferred to bind to the value prop instead.

The event.details payload includes a copy of the value and an origin field to distinguish between user-interactive changes (internal) and changes resulting from programmatic manipulation of the value (external).

ExtendsValueChangeEvent
TypeImageChangeEvent