Skip to content

Latest commit

 

History

History
418 lines (275 loc) · 12.4 KB

image.md

File metadata and controls

418 lines (275 loc) · 12.4 KB

Image

ui.image · parts: Image, Picture, Source · elements: <img>, <picture>, <source>

Purpose

Image renders img, picture, and source. Alt is required; pass an empty string for decorative images.

Notes

  • alt is required (use alt="" for decorative images).
  • Art direction: Picture with Source children and an Image fallback.

Image

Image renders an img element; alt is always emitted.

Props

Canonical (templ, Jinja2, MiniJinja) React / Solid HTML (Svelte, Vue, WC) Type Default Kind Description
Src src src string — passthrough attr
Alt alt alt string (required) — prop alternative text; empty string for decorative images
SrcSet srcSet srcset string — passthrough attr
Sizes sizes sizes string — passthrough attr
Width width width string — passthrough attr
Height height height string — passthrough attr
Loading loading loading string — passthrough attr
Decoding decoding decoding string — passthrough attr

Also accepts: class (className in React), extra attributes (rest props in UI frameworks, Attrs in templ/Jinja2/MiniJinja, attrs in Twig/Latte; caller wins).

Variants

No variants: the primitive ships no visual classes; style it with token classes via class.

Children

Void / self-contained element: children are not accepted.

ARIA

  • No ARIA attributes are rendered by the primitive; rely on native semantics. Pass extra aria-* through attrs.

Classes escape hatch

Compose the part's classes without rendering it (custom root element, no asChild outside React):

Runtime Helper
React / Solid / Vue / Svelte / WC imageClasses({ ... }) from image/image.shared.ts
templ image.ImageClasses(image.ImageProps{...})
Twig ui8kit_classes('imageClasses', { class: '…' })
Latte \UI8Kit\Latte\Classes::imageClasses(['class' => '…'])
Jinja2 image_classes(p)
MiniJinja image_classes(p) (registered by ui8kit_minijinja::register)

Rendered DOM per state

Canonical renderer output (children = Content); all 10 runtimes are parity-tested to produce this DOM.

State Props HTML
defaults — <img alt="">
img {"Src":"/a.png","Alt":"A cat","Width":"64","Height":"64","Loading":"lazy","Decoding":"async"} <img src="/a.png" alt="A cat" width="64" height="64" loading="lazy" decoding="async">
decorative {"Src":"/b.png","Alt":""} <img src="/b.png" alt="">
source {"SrcSet":"/a.webp","Sizes":"100vw"} <img alt="" srcset="/a.webp" sizes="100vw">

Usage

Fixture img ({"Src":"/a.png","Alt":"A cat","Width":"64","Height":"64","Loading":"lazy","Decoding":"async"}) — every snippet renders:

<img src="/a.png" alt="A cat" width="64" height="64" loading="lazy" decoding="async">

React (runtime notes)

import { Image } from "./ui/image/image";

<Image alt="A cat" src="/a.png" width="64" height="64" loading="lazy" decoding="async" />

Vue 3 (runtime notes)

<script setup lang="ts">
import Image from "./ui/image/Image.vue";
</script>

<template>
  <Image alt="A cat" src="/a.png" width="64" height="64" loading="lazy" decoding="async" />
</template>

Svelte 5 (runtime notes)

<script lang="ts">
  import Image from "./ui/image/Image.svelte";
</script>

<Image alt="A cat" src="/a.png" width="64" height="64" loading="lazy" decoding="async" />

SolidJS (runtime notes)

import { Image } from "./ui/image/image.solid";

<Image alt="A cat" src="/a.png" width="64" height="64" loading="lazy" decoding="async" />

Web Components (runtime notes)

import { renderImage } from "./ui/image/image.wc";

document.body.append(renderImage({ alt: "A cat", src: "/a.png", width: "64", height: "64", loading: "lazy", decoding: "async" }));

Go templ (runtime notes)

import "github.com/ui8kit/codegen/generated/templ/ui/image"

@image.Image(image.ImageProps{Src: "/a.png", Alt: "A cat", Width: "64", Height: "64", Loading: "lazy", Decoding: "async"})

Twig (runtime notes)

{% include 'image/Image.html.twig' with { src: '/a.png', alt: 'A cat', width: '64', height: '64', loading: 'lazy', decoding: 'async' } only %}

Latte (runtime notes)

{include 'image/Image.latte', src: '/a.png', alt: 'A cat', width: '64', height: '64', loading: 'lazy', decoding: 'async'}

Jinja2 (runtime notes)

{% with p = {'Src': '/a.png', 'Alt': 'A cat', 'Width': '64', 'Height': '64', 'Loading': 'lazy', 'Decoding': 'async'} %}{% include 'ui/image/image.html.j2' %}{% endwith %}

MiniJinja (Rust) (runtime notes)

{% import 'ui8kit.html' as ui %}
{{ ui.image({'Src': '/a.png', 'Alt': 'A cat', 'Width': '64', 'Height': '64', 'Loading': 'lazy', 'Decoding': 'async'}) }}

Picture

Picture wraps Source candidates and a fallback Image.

Props

No typed props (only class / attrs / children).

Also accepts: class (className in React), extra attributes (rest props in UI frameworks, Attrs in templ/Jinja2/MiniJinja, attrs in Twig/Latte; caller wins), children.

Variants

No variants: the primitive ships no visual classes; style it with token classes via class.

Children

Accepts children (default slot / children / { children... } / trusted HTML string in Twig, Latte, Jinja2, MiniJinja — see runtimes). Void tags selected via tag render no children.

ARIA

  • No ARIA attributes are rendered by the primitive; rely on native semantics. Pass extra aria-* through attrs.

Classes escape hatch

Compose the part's classes without rendering it (custom root element, no asChild outside React):

Runtime Helper
React / Solid / Vue / Svelte / WC pictureClasses({ ... }) from image/image.shared.ts
templ image.PictureClasses(image.PictureProps{...})
Twig ui8kit_classes('pictureClasses', { class: '…' })
Latte \UI8Kit\Latte\Classes::pictureClasses(['class' => '…'])
Jinja2 picture_classes(p)
MiniJinja picture_classes(p) (registered by ui8kit_minijinja::register)

Rendered DOM per state

Canonical renderer output (children = Content); all 10 runtimes are parity-tested to produce this DOM.

State Props HTML
defaults — <picture>Content</picture>

Usage

Fixture defaults ({}) — every snippet renders:

<picture>Content</picture>

React (runtime notes)

import { Picture } from "./ui/image/image";

<Picture>Content</Picture>

Vue 3 (runtime notes)

<script setup lang="ts">
import Picture from "./ui/image/Picture.vue";
</script>

<template>
  <Picture>Content</Picture>
</template>

Svelte 5 (runtime notes)

<script lang="ts">
  import Picture from "./ui/image/Picture.svelte";
</script>

<Picture>Content</Picture>

SolidJS (runtime notes)

import { Picture } from "./ui/image/image.solid";

<Picture>Content</Picture>

Web Components (runtime notes)

import { renderPicture } from "./ui/image/image.wc";

document.body.append(renderPicture({}, "Content"));

Go templ (runtime notes)

import "github.com/ui8kit/codegen/generated/templ/ui/image"

@image.Picture(image.PictureProps{}) {
	Content
}

Twig (runtime notes)

{% include 'image/Picture.html.twig' with { children: 'Content' } only %}

Latte (runtime notes)

{include 'image/Picture.latte', children: 'Content'}

Jinja2 (runtime notes)

{% with p = {}, children = 'Content' %}{% include 'ui/image/picture.html.j2' %}{% endwith %}

MiniJinja (Rust) (runtime notes)

{% import 'ui8kit.html' as ui %}
{{ ui.picture({}, children='Content') }}

Source

Source renders a source candidate inside picture.

Props

Canonical (templ, Jinja2, MiniJinja) React / Solid HTML (Svelte, Vue, WC) Type Default Kind Description
SrcSet srcSet srcset string — passthrough attr
Media media media string — passthrough attr
Type type type string — passthrough attr
Sizes sizes sizes string — passthrough attr

Also accepts: extra attributes (rest props in UI frameworks, Attrs in templ/Jinja2/MiniJinja, attrs in Twig/Latte; caller wins).

Variants

No variants: the primitive ships no visual classes; style it with token classes via class.

Children

Void / self-contained element: children are not accepted.

ARIA

  • No ARIA attributes are rendered by the primitive; rely on native semantics. Pass extra aria-* through attrs.

Rendered DOM per state

Canonical renderer output (children = Content); all 10 runtimes are parity-tested to produce this DOM.

State Props HTML
defaults — <source>
source {"SrcSet":"/a.webp","Type":"image/webp","Media":"(min-width: 40rem)","Sizes":"100vw"} <source srcset="/a.webp" media="(min-width: 40rem)" type="image/webp" sizes="100vw">

Usage

Fixture source ({"SrcSet":"/a.webp","Type":"image/webp","Media":"(min-width: 40rem)","Sizes":"100vw"}) — every snippet renders:

<source srcset="/a.webp" media="(min-width: 40rem)" type="image/webp" sizes="100vw">

React (runtime notes)

import { Source } from "./ui/image/image";

<Source srcSet="/a.webp" type="image/webp" media="(min-width: 40rem)" sizes="100vw" />

Vue 3 (runtime notes)

<script setup lang="ts">
import Source from "./ui/image/Source.vue";
</script>

<template>
  <Source srcset="/a.webp" type="image/webp" media="(min-width: 40rem)" sizes="100vw" />
</template>

Svelte 5 (runtime notes)

<script lang="ts">
  import Source from "./ui/image/Source.svelte";
</script>

<Source srcset="/a.webp" type="image/webp" media="(min-width: 40rem)" sizes="100vw" />

SolidJS (runtime notes)

import { Source } from "./ui/image/image.solid";

<Source srcset="/a.webp" type="image/webp" media="(min-width: 40rem)" sizes="100vw" />

Web Components (runtime notes)

import { renderSource } from "./ui/image/image.wc";

document.body.append(renderSource({ srcset: "/a.webp", type: "image/webp", media: "(min-width: 40rem)", sizes: "100vw" }));

Go templ (runtime notes)

import "github.com/ui8kit/codegen/generated/templ/ui/image"

@image.Source(image.SourceProps{SrcSet: "/a.webp", Type: "image/webp", Media: "(min-width: 40rem)", Sizes: "100vw"})

Twig (runtime notes)

{% include 'image/Source.html.twig' with { srcSet: '/a.webp', type: 'image/webp', media: '(min-width: 40rem)', sizes: '100vw' } only %}

Latte (runtime notes)

{include 'image/Source.latte', srcSet: '/a.webp', type: 'image/webp', media: '(min-width: 40rem)', sizes: '100vw'}

Jinja2 (runtime notes)

{% with p = {'SrcSet': '/a.webp', 'Type': 'image/webp', 'Media': '(min-width: 40rem)', 'Sizes': '100vw'} %}{% include 'ui/image/source.html.j2' %}{% endwith %}

MiniJinja (Rust) (runtime notes)

{% import 'ui8kit.html' as ui %}
{{ ui.source({'SrcSet': '/a.webp', 'Type': 'image/webp', 'Media': '(min-width: 40rem)', 'Sizes': '100vw'}) }}

Rules: contract · Index: docs