Image Viewer
A thumbnail that opens the image in a zoomable lightbox.
ImageViewer is new in v0.4. It renders a thumbnail button; clicking it opens the full image over the page, with zoom controls.
Installation
bash
shellui add image-viewer
Usage
Basic
Size the thumbnail with Class. The image covers it.
<ImageViewer Src="@Image" Alt="Landscape illustration" Class="h-40 w-64" />
@code {
private const string Image = "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='800' height='500'><defs><linearGradient id='s' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='%2393c5fd'/><stop offset='1' stop-color='%23fde68a'/></linearGradient></defs><rect width='800' height='500' fill='url(%23s)'/><circle cx='620' cy='140' r='60' fill='%23fbbf24'/><path d='M0 380 L200 220 L360 360 L520 240 L800 400 L800 500 L0 500 Z' fill='%2334d399'/><path d='M0 430 L260 300 L460 440 L800 330 L800 500 L0 500 Z' fill='%23059669'/></svg>";
}Gallery
Each viewer opens its own image. Pass a small ThumbnailSrc to keep a grid light and load the full Src only in the lightbox.
<div class="grid w-full max-w-md grid-cols-3 gap-2">
@foreach (var (sky, hill) in palettes)
{
<ImageViewer Src="@Image(sky, hill)" Alt="@($"Landscape in {sky}")" Class="aspect-square w-full" ImageClass="rounded-md" />
}
</div>
@code {
private readonly (string Sky, string Hill)[] palettes =
[
("93c5fd", "059669"),
("fda4af", "7c3aed"),
("fde68a", "ea580c"),
];
private static string Image(string sky, string hill) =>
$"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='800' height='800'><rect width='800' height='800' fill='%23{sky}'/><circle cx='600' cy='200' r='80' fill='%23ffffff'/><path d='M0 560 L260 360 L460 540 L800 420 L800 800 L0 800 Z' fill='%23{hill}'/></svg>";
}Keyboard
| Key | Action |
|---|---|
Esc |
Close |
+ or = |
Zoom in |
- |
Zoom out |
0 |
Reset zoom |
Zoom runs from 50% to 400% in steps of 25%. Clicking the backdrop also closes the viewer.
API Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
Src |
string |
"" |
The full-size image |
ThumbnailSrc |
string? |
null |
Image for the thumbnail; defaults to Src |
Alt |
string |
"" |
Alternative text |
Class |
string? |
null |
Classes for the thumbnail button, such as its size |
ImageClass |
string? |
null |
Classes for the thumbnail image |
Accessibility
- The thumbnail is a button labelled "View" plus the
Alttext - The lightbox is
role="dialog"witharia-modal="true"and takes focus when it opens - The zoom and close buttons have labels