Duolith docs

inputs-and-media

The kit's pickers (DatePicker, TimePicker, Stepper), search, chips and tabs, and media (Image with its placeholder, fade and fallback, the zoomable ImageViewer, Skeleton), with local images in public/.

Run it

cargo run -p duolith-cli -- dev examples/inputs-and-media     # live, reloads on save
cargo run -p duolith-cli -- build examples/inputs-and-media   # static output in examples/inputs-and-media/dist

The folder on the web: examples/inputs-and-media.

Features it shows

FeatureWhereScreenshot
public/ filesgallery public/images/; inputs-and-media public/photos/gallery-inputs-and-media-images.png
TimePicker, Steppergallery pages/inputs-and-media.duo; inputs-and-media pages/pickers.duoinputs-and-media-pickers.png
Image (placeholder, fade, fallback)gallery pages/inputs-and-media.duo; inputs-and-media pages/media.duogallery-inputs-and-media-images.png, inputs-and-media-media-fallback.png

Source

components/Header.duo
---
import { props } from "@duolith/client";

let { title, subtitle } = props<{ title: string; subtitle?: string }>();
---

<view class="gap-2">
  <view href="/" class="back row items-center gap-1 self-start text-primary">
    <icon name="chevron-left" />
    <text class="text-label">Inputs and media</text>
  </view>
  <text role="heading" class="text-title text-ink">{title}</text>
  <show when={subtitle}>
    <text class="text-body text-muted">{subtitle}</text>
  </show>
</view>

<style>
  .back {
    min-height: 32px;
  }
</style>
pages/filters.duo
---
import { derived, state } from "@duolith/client";
import { Card, Chip, ChipGroup, ListRow, SearchField, Section, Tabs } from "@duolith/kit";
import Header from "../components/Header.duo";

let query = state("");
let searched = state("");
let sort = state("near");
let diets = state(["vegetarian"]);
let openNow = state(true);
let tab = state("menu");

const places = [
  { name: "Lakeside Café", diet: "vegetarian", open: true },
  { name: "Ember Grill", diet: "", open: false },
  { name: "Green Bowl", diet: "vegan", open: true },
  { name: "Dune Bakery", diet: "gluten-free", open: true },
];
let shown = derived(() =>
  places.filter(
    (place) =>
      (!openNow || place.open) &&
      (diets.length === 0 || diets.includes(place.diet)) &&
      place.name.toLowerCase().includes(query.toLowerCase()),
  ),
);
---

<screen title="Search, filters and tabs" class="bg-canvas">
  <view class="page gap-6 p-4 md:p-8">
    <Header
      title="Search, filters and tabs"
      subtitle={`Searched for: ${searched || "nothing yet"}.`}
    />

    <view class="gap-6 md:row md:items-start">
      <view class="column gap-6">
        <Card title="SearchField" subtitle="Enter searches; Escape or the clear button empties it">
          <SearchField
            label="Search places"
            placeholder="Cafés, bakeries…"
            bind:value={query}
            onSubmit={(text) => (searched = text)}
          />
          <SearchField label="Disabled search" disabled />
        </Card>

        <Card title="ChipGroup" subtitle="One at a time, or several with multiple">
          <ChipGroup
            label="Sort by"
            options={[
              { value: "near", label: "Nearest", icon: "location" },
              { value: "rated", label: "Top rated", icon: "star" },
              { value: "new", label: "Newest" },
            ]}
            bind:value={sort}
          />
          <ChipGroup
            label="Diet"
            multiple
            options={[
              { value: "vegetarian", label: "Vegetarian" },
              { value: "vegan", label: "Vegan" },
              { value: "gluten-free", label: "Gluten-free" },
            ]}
            bind:values={diets}
          />
          <ChipGroup
            label="Disabled"
            value="a"
            disabled
            options={[
              { value: "a", label: "Chosen" },
              { value: "b", label: "Not chosen" },
            ]}
          />
        </Card>

        <Card title="Chip" subtitle="On its own, bound to a true or false">
          <view class="row wrap gap-2">
            <Chip label="Open now" icon="clock" bind:selected={openNow} />
            <Chip label="Favourites" icon="heart" />
            <Chip label="Unavailable" disabled />
          </view>
        </Card>
      </view>

      <view class="column gap-6">
        <Section title={shown.length === 1 ? "1 place" : `${shown.length} places`}>
          <list each={shown} as="place" key={place.name}>
            <ListRow
              title={place.name}
              subtitle={place.open ? "Open now" : "Closed"}
              icon="location"
            />
          </list>
        </Section>

        <Card title="Tabs" subtitle="Arrow keys move between tabs and show them">
          <Tabs
            label="Place details"
            tabs={[
              { value: "menu", label: "Menu" },
              { value: "reviews", label: "Reviews", icon: "star" },
              { value: "photos", label: "Photos", icon: "image" },
              { value: "events", label: "Events", disabled: true },
            ]}
            bind:selected={tab}
          >
            <show when={tab === "menu"}>
              <text class="text-body text-ink">
                Soup of the day, sourdough, and a seasonal tart.
              </text>
            </show>
            <show when={tab === "reviews"}>
              <text class="text-body text-ink">“The best view of the lake in town.” ★★★★★</text>
            </show>
            <show when={tab === "photos"}>
              <text class="text-body text-ink">12 photos from visitors.</text>
            </show>
          </Tabs>
        </Card>
      </view>
    </view>
  </view>
</screen>

<style>
  .page {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
  }
  .column {
    flex: 1 1 0;
    min-width: 0;
  }
</style>
pages/index.duo
---
import { Badge, ListRow, Section } from "@duolith/kit";
---

<screen title="Inputs and media" class="bg-canvas">
  <view class="page gap-6 p-4 md:p-8">
    <view class="gap-1">
      <text role="heading" class="text-title text-ink">Inputs and media</text>
      <text class="text-body text-muted">
        The kit's pickers, filters, tabs, placeholders and images, in every variant and state.
      </text>
    </view>

    <Section title="Families" footer="Each page works in light and dark.">
      <ListRow
        title="Pickers"
        subtitle="DatePicker, TimePicker, Stepper"
        icon="calendar"
        href="/pickers"
        chevron
      >
        <Badge label="3" />
      </ListRow>
      <ListRow
        title="Search, filters and tabs"
        subtitle="SearchField, Chip, ChipGroup, Tabs"
        icon="filter"
        href="/filters"
        chevron
      >
        <Badge label="4" />
      </ListRow>
      <ListRow
        title="Media and loading"
        subtitle="Image, ImageViewer, Skeleton"
        icon="image"
        href="/media"
        chevron
      >
        <Badge label="3" />
      </ListRow>
    </Section>
  </view>
</screen>

<style>
  .page {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
  }
</style>
pages/media.duo
---
import { state } from "@duolith/client";
import { Button, Card, Image, ImageViewer, Skeleton } from "@duolith/kit";
import Header from "../components/Header.duo";

let loading = state(true);
let viewing = state(false);
---

<screen title="Media and loading" class="bg-canvas">
  <view class="page gap-6 p-4 md:p-8">
    <Header
      title="Media and loading"
      subtitle="Each address is fetched and decoded once, however often it is shown."
    />

    <view class="gap-6 md:row md:items-start">
      <view class="column gap-6">
        <Card title="Image" subtitle="Press the lake to open it full screen and zoom">
          <Image
            src="/photos/lake.svg"
            alt="A lake below mountains at sunset"
            ratio="16:9"
            zoomable
          />
          <view class="row gap-3">
            <view class="grow">
              <Image
                src="/photos/forest.svg"
                alt="Pine trees in mist"
                ratio="3:4"
                placeholder="#9fbf9f"
              />
            </view>
            <view class="grow">
              <Image
                src="/photos/dunes.svg"
                alt="Sand dunes under a blue sky"
                ratio="3:4"
                fit="contain"
              />
            </view>
          </view>
          <view class="row items-center gap-3">
            <view class="thumb">
              <Image
                src="/photos/city.svg"
                alt="A city skyline at dusk"
                ratio="1:1"
                radius="full"
              />
            </view>
            <view class="thumb">
              <Image src="/photos/lake.svg" decorative ratio="1:1" radius="lg" />
            </view>
            <text class="grow text-caption text-muted">
              The second lake is the same address: no second request.
            </text>
          </view>
        </Card>

        <Card title="When an image cannot load" subtitle="The fallback piece, or the stock one">
          <view class="row gap-3">
            <view class="grow">
              <Image src="/photos/not-a-photo.svg" alt="A file that is not a photo" ratio="1:1" />
            </view>
            <view class="grow">
              <Image src="/photos/not-a-photo.svg" alt="Profile photo" ratio="1:1">
                <piece name="fallback">
                  <icon name="user" class="w-8 h-8" />
                  <text class="text-caption">No photo yet</text>
                </piece>
              </Image>
            </view>
          </view>
        </Card>

        <Card title="ImageViewer on its own">
          <Button
            label="Open the city"
            icon="image"
            variant="secondary"
            onPress={() => (viewing = true)}
          />
          <ImageViewer src="/photos/city.svg" alt="A city skyline at dusk" bind:open={viewing} />
        </Card>
      </view>

      <view class="column gap-6">
        <Card title="Skeleton" subtitle="Shimmers, unless reduced motion is on">
          <Button
            label={loading ? "Show the content" : "Show the skeleton"}
            variant="secondary"
            onPress={() => (loading = !loading)}
          />
          <show when={loading}>
            <view class="row items-center gap-3">
              <Skeleton shape="circle" label="Loading the profile" />
              <view class="grow gap-2">
                <Skeleton width="1/2" />
                <Skeleton width="1/3" />
              </view>
            </view>
            <Skeleton shape="block" />
            <Skeleton lines={3} />
          </show>
          <otherwise>
            <view class="row items-center gap-3">
              <view class="avatar">
                <Image src="/photos/dunes.svg" alt="Dune profile" ratio="1:1" radius="full" />
              </view>
              <view class="grow gap-1">
                <text class="text-label text-ink">Dune Bakery</text>
                <text class="text-caption text-muted">Open until 6pm</text>
              </view>
            </view>
            <Image src="/photos/city.svg" alt="The bakery's street at dusk" ratio="16:9" />
            <text class="text-body text-ink">
              Sourdough every morning, cardamom buns on Fridays, and coffee from the roaster next
              door.
            </text>
          </otherwise>
        </Card>

        <Card title="Skeleton shapes and sizes">
          <view class="row items-center gap-3">
            <Skeleton shape="circle" size="sm" />
            <Skeleton shape="circle" />
            <Skeleton shape="circle" size="lg" />
          </view>
          <Skeleton shape="block" size="sm" />
          <Skeleton width="3/4" />
        </Card>
      </view>
    </view>
  </view>
</screen>

<style>
  .page {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
  }
  .column {
    flex: 1 1 0;
    min-width: 0;
  }
  .thumb {
    width: 72px;
    flex: none;
  }
  .avatar {
    width: 48px;
    flex: none;
  }
</style>
pages/pickers.duo
---
import { state } from "@duolith/client";
import { Card, DatePicker, Stepper, TimePicker } from "@duolith/kit";
import Header from "../components/Header.duo";

let day = state("2026-11-14");
let trip = state("2026-11-20");
let alarm = state("07:30");
let meeting = state("14:45");
let guests = state(2);
let weight = state(1.5);

// Weekends cannot be booked.
const isWeekend = (date: string) => [0, 6].includes(new Date(`${date}T00:00:00Z`).getUTCDay());
---

<screen title="Pickers" class="bg-canvas">
  <view class="page gap-6 p-4 md:p-8">
    <Header
      title="Pickers"
      subtitle={`Day: ${day}. Trip: ${trip}. Alarm: ${alarm}. Meeting: ${meeting}. Guests: ${guests}.`}
    />

    <view class="gap-6 md:row md:items-start">
      <view class="column gap-6">
        <Card
          title="DatePicker"
          subtitle="Arrows move a day or a week, PageUp and PageDown a month"
        >
          <DatePicker label="Day" bind:value={day} />
        </Card>
        <Card
          title="With limits"
          subtitle="Weekdays from 10 to 28 November, US week starting Sunday"
        >
          <DatePicker
            label="Trip"
            locale="en-US"
            min="2026-11-10"
            max="2026-11-28"
            disabledDates={isWeekend}
            bind:value={trip}
          />
        </Card>
        <Card title="In French">
          <DatePicker label="Jour" locale="fr-FR" value="2026-12-24" />
        </Card>
        <Card title="Disabled">
          <DatePicker label="Closed" value="2026-11-14" disabled />
        </Card>
      </view>

      <view class="column gap-6">
        <Card title="TimePicker" subtitle="12 or 24 hours, from the locale">
          <TimePicker label="Alarm" locale="en-GB" bind:value={alarm} />
          <TimePicker label="Meeting" locale="en-US" step={15} bind:value={meeting} />
          <TimePicker label="Disabled" value="18:00" disabled />
        </Card>

        <Card title="Stepper">
          <Stepper label="Guests" min={1} max={8} bind:value={guests} />
          <Stepper label="Weight" min={0.5} max={5} step={0.5} unit=" kg" bind:value={weight} />
          <Stepper label="At the limit" min={0} max={3} value={3} />
          <Stepper label="Disabled" value={4} disabled />
        </Card>
      </view>
    </view>
  </view>
</screen>

<style>
  .page {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
  }
  .column {
    flex: 1 1 0;
    min-width: 0;
  }
</style>