Skip to content
ui8kit

primitive / primitives

Image

Image primitive

Install

npx ui8kit add image

Pulls in: kit-image, recipes, utils

Preview

aspect: auto
aspect: square
aspect: video
fit: contain
fit: cover
fit: fill
fit: none
fit: scale-down

Code

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdn
npx ui8kit add image
compose/Image.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Image: Image + recipe image. -->
<script lang="ts">
  import type { ComponentProps, Snippet } from "svelte";
  import Prim from "../kit/ui/image/Image.svelte";
  import { cn } from "../kit/utils";
  import { rc } from "./recipes";

  let { "aspect": v_aspect, "fit": v_fit, "position": v_position, "size": v_size, "variant": v_variant, class: className, children, ...rest }: ComponentProps<typeof Prim> & { "aspect"?: string | number; "fit"?: string | number; "position"?: string | number; "size"?: string | number; "variant"?: string | number; class?: string; children?: Snippet } = $props();
  const cls = $derived(cn(rc("image", { "aspect": v_aspect, "fit": v_fit, "position": v_position, "size": v_size, "variant": v_variant }), className));
</script>

<Prim class={cls} {...rest} />

Svelte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdn
npx ui8kit add image
compose/image.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Image as Prim } from "../kit/ui/image/image";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type ImageProps = Omit<ComponentProps<typeof Prim>, "tag" | "aspect" | "fit" | "position" | "size" | "variant"> & { "aspect"?: string | number; "fit"?: string | number; "position"?: string | number; "size"?: string | number; "variant"?: string | number; className?: string };

/** Image: Image + recipe image. */
export function Image({ "aspect": v_aspect, "fit": v_fit, "position": v_position, "size": v_size, "variant": v_variant, className, ...rest }: ImageProps) {
  return <Prim className={cn(rc("image", { "aspect": v_aspect, "fit": v_fit, "position": v_position, "size": v_size, "variant": v_variant }), className)} {...rest} />;
}

React registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdn
npx ui8kit add image
compose/Image.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Image: Image + recipe image. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/image/Image.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

defineOptions({ name: "Image", inheritAttrs: false });
const props = defineProps<{ "aspect"?: string | number; "fit"?: string | number; "position"?: string | number; "size"?: string | number; "variant"?: string | number; alt: string }>();
const attrs = useAttrs();
const rest = computed(() => {
  const { class: _class, ...r } = attrs;
  return r;
});
const cls = computed(() => cn(rc("image", { "aspect": props["aspect"], "fit": props["fit"], "position": props["position"], "size": props["size"], "variant": props["variant"] }), attrs.class as string | undefined));
const tagValue = computed(() => "");
</script>

<template>
  <Prim :alt="props.alt" :class="cls" v-bind="rest" />
</template>

Vue registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdn
npx ui8kit add image
compose/image.solid.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import { splitProps, type ComponentProps } from "solid-js";
import { Image as Prim } from "../kit/ui/image/image.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type ImageProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className" | "aspect" | "fit" | "position" | "size" | "variant"> & { "aspect"?: string | number; "fit"?: string | number; "position"?: string | number; "size"?: string | number; "variant"?: string | number; class?: string; className?: string };

/** Image: Image + recipe image. */
export function Image(props: ImageProps) {
  const [local, rest] = splitProps(props, ["aspect", "fit", "position", "size", "variant", "class", "className"]);
  return <Prim class={cn(rc("image", { "aspect": local["aspect"], "fit": local["fit"], "position": local["position"], "size": local["size"], "variant": local["variant"] }), local.class ?? local.className)} {...rest} />;
}

Solid registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdn
npx ui8kit add image
compose/image.templ
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.

package compose

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

// ImageProps: Image: Image + recipe image.
type ImageProps struct {
	Aspect string
	Fit string
	Position string
	Size string
	Variant string
	image.ImageProps
}

func imageInner(p ImageProps) image.ImageProps {
	in := p.ImageProps
	in.Class = Join(Rc("image", map[string]string{"aspect": p.Aspect, "fit": p.Fit, "position": p.Position, "size": p.Size, "variant": p.Variant}), p.ImageProps.Class)
	return in
}

// Image renders Image with the composition classes.
templ Image(p ImageProps) {
	@image.Image(imageInner(p))
}

templ registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdn
npx ui8kit add image
compose/Image.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Image: Image + recipe image. Params: aspect, fit, position, size, variant, class, attrs + the params of Image. #}
{% include 'ui/image/Image.html.twig' with compose_props('Image', _context) only %}

Twig registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdn
npx ui8kit add image
compose/Image.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Image: Image + recipe image. *}
{parameters
  string $class = '',
  ?string $src = null,
  string $alt = '',
  ?string $srcSet = null,
  ?string $sizes = null,
  ?string $width = null,
  ?string $height = null,
  ?string $loading = null,
  ?string $decoding = null,
  array $attrs = [],
  $aspect = null,
  $fit = null,
  $position = null,
  $size = null,
  $variant = null,
}
{include '../ui/image/Image.latte', ...\CodegenX\Compose\Latte\Compose::props('Image', ['class' => $class, 'src' => $src, 'alt' => $alt, 'srcSet' => $srcSet, 'sizes' => $sizes, 'width' => $width, 'height' => $height, 'loading' => $loading, 'decoding' => $decoding, 'attrs' => $attrs, 'aspect' => $aspect, 'fit' => $fit, 'position' => $position, 'size' => $size, 'variant' => $variant])}

Latte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdn
npx ui8kit add image
compose/image.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
    Image: Image + recipe image. Props (p): Aspect, Fit, Position, Size, Variant, Class, Attrs + the props of Image. -#}
{%- with p = compose_props('Image', p) %}{% include 'ui/image/image.html.j2' %}{% endwith %}

Jinja2 registry item (JSON)

Props

Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.

Image renders an img element; alt is always emitted.

Props of Image
PropTypeDefault Description
alt (required)string-alternative text; empty string for decorative images