Media Frame
Media Frame component
Install
npx ui8kit add media-framePulls in: box, compose, image, kit-box, kit-image, presets, utils
Preview
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-cdnnpx ui8kit add media-frame// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Data of MediaFrame: long values (pictures as data URIs) kept out of the component file.
export const PLACEHOLDER: Record<string, string> = {
"light": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
"dark": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
};
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one
of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it
shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out
before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is
switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the
corners are the plain theme radius.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import { variants } from "../utils";
/** MediaFrame: the classes of each value (shadcn/cva style). */
export const mediaFrameVariants = variants({
base: "relative w-full overflow-hidden bg-muted text-muted-foreground inset-ring inset-ring-border rounded",
variants: {
ratio: {
"16/9": "aspect-video",
"4/3": "aspect-4/3",
"1/1": "aspect-square",
"3/4": "aspect-3/4",
"21/9": "aspect-21/9",
},
},
defaultVariants: { ratio: "16/9" },
});
export type MediaFrameProps = {
alt: string;
src?: string;
darkSrc?: string;
ratio?: "16/9" | "4/3" | "1/1" | "3/4" | "21/9";
class?: string;
};
</script>
<script lang="ts">
import Box from "../compose/Box.svelte";
import Image from "../compose/Image.svelte";
import { at, cn, urlOf } from "../utils";
import { PLACEHOLDER } from "./media-frame.assets";
let { alt, src, darkSrc, ratio = "16/9", class: className }: MediaFrameProps = $props();
const lightSrc = $derived(src ? src : at(PLACEHOLDER, "light"));
const nightSrc = $derived(darkSrc ? darkSrc : (src ? src : at(PLACEHOLDER, "dark")));
const shownAlt = $derived(src ? alt : "");
const loadHint = $derived(src ? "lazy" : undefined);
const decodeHint = $derived(src ? "async" : undefined);
</script>
<Box
class={cn(mediaFrameVariants({ ratio: ratio }), className)}
data-slot="media-frame"
data-placeholder={(src ? "false" : "true")}
>
<Image
src={urlOf(lightSrc, true)}
alt={shownAlt}
loading={loadHint}
decoding={decodeHint}
class="absolute inset-0 size-full object-cover dark:hidden"
data-theme-src="light"
/>
<Image
src={urlOf(nightSrc, true)}
alt={shownAlt}
loading={loadHint}
decoding={decodeHint}
class="absolute inset-0 hidden size-full object-cover dark:block"
data-theme-src="dark"
/>
</Box>
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-cdnnpx ui8kit add media-frame// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Data of MediaFrame: long values (pictures as data URIs) kept out of the component file.
export const PLACEHOLDER: Record<string, string> = {
"light": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
"dark": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
};
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one
* of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it
* shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out
* before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is
* switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the
* corners are the plain theme radius.
*/
import { type ReactNode } from "react";
import { Box, Image } from "../compose";
import { at, cn, urlOf, variants } from "../utils";
import { PLACEHOLDER } from "./media-frame.assets";
/** MediaFrame: the classes of each value (shadcn/cva style). */
export const mediaFrameVariants = variants({
base: "relative w-full overflow-hidden bg-muted text-muted-foreground inset-ring inset-ring-border rounded",
variants: {
ratio: {
"16/9": "aspect-video",
"4/3": "aspect-4/3",
"1/1": "aspect-square",
"3/4": "aspect-3/4",
"21/9": "aspect-21/9",
},
},
defaultVariants: { ratio: "16/9" },
});
export type MediaFrameProps = {
alt: string;
src?: string;
darkSrc?: string;
ratio?: "16/9" | "4/3" | "1/1" | "3/4" | "21/9";
className?: string;
};
export function MediaFrame({ alt, src, darkSrc, ratio = "16/9", className }: MediaFrameProps) {
const lightSrc = src ? src : at(PLACEHOLDER, "light");
const nightSrc = darkSrc ? darkSrc : (src ? src : at(PLACEHOLDER, "dark"));
const shownAlt = src ? alt : "";
const loadHint = src ? "lazy" : undefined;
const decodeHint = src ? "async" : undefined;
return (
<Box
className={cn(mediaFrameVariants({ ratio: ratio }), className)}
data-slot="media-frame"
data-placeholder={(src ? "false" : "true")}
>
<Image
src={urlOf(lightSrc, true)}
alt={shownAlt}
loading={loadHint}
decoding={decodeHint}
className="absolute inset-0 size-full object-cover dark:hidden"
data-theme-src="light"
/>
<Image
src={urlOf(nightSrc, true)}
alt={shownAlt}
loading={loadHint}
decoding={decodeHint}
className="absolute inset-0 hidden size-full object-cover dark:block"
data-theme-src="dark"
/>
</Box>
);
}
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-cdnnpx ui8kit add media-frame// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Data of MediaFrame: long values (pictures as data URIs) kept out of the component file.
export const PLACEHOLDER: Record<string, string> = {
"light": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
"dark": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
};
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one
of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it
shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out
before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is
switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the
corners are the plain theme radius.
-->
<script lang="ts">
import { variants } from "../utils";
/** MediaFrame: the classes of each value (shadcn/cva style). */
export const mediaFrameVariants = variants({
base: "relative w-full overflow-hidden bg-muted text-muted-foreground inset-ring inset-ring-border rounded",
variants: {
ratio: {
"16/9": "aspect-video",
"4/3": "aspect-4/3",
"1/1": "aspect-square",
"3/4": "aspect-3/4",
"21/9": "aspect-21/9",
},
},
defaultVariants: { ratio: "16/9" },
});
export type MediaFrameProps = {
alt: string;
src?: string;
darkSrc?: string;
ratio?: "16/9" | "4/3" | "1/1" | "3/4" | "21/9";
class?: string;
};
</script>
<script setup lang="ts">
import { computed } from "vue";
import Box from "../compose/Box.vue";
import Image from "../compose/Image.vue";
import { at, cn, urlOf } from "../utils";
import { PLACEHOLDER } from "./media-frame.assets";
const { alt, src, darkSrc, ratio = "16/9", class: className } = defineProps<MediaFrameProps>();
const lightSrc = computed(() => src ? src : at(PLACEHOLDER, "light"));
const nightSrc = computed(() => darkSrc ? darkSrc : (src ? src : at(PLACEHOLDER, "dark")));
const shownAlt = computed(() => src ? alt : "");
const loadHint = computed(() => src ? "lazy" : undefined);
const decodeHint = computed(() => src ? "async" : undefined);
</script>
<template>
<Box
:class="cn(mediaFrameVariants({ ratio: ratio }), className)"
data-slot="media-frame"
:data-placeholder="(src ? 'false' : 'true')"
>
<Image
:src="urlOf(lightSrc, true)"
:alt="shownAlt"
:loading="loadHint"
:decoding="decodeHint"
class="absolute inset-0 size-full object-cover dark:hidden"
data-theme-src="light"
/>
<Image
:src="urlOf(nightSrc, true)"
:alt="shownAlt"
:loading="loadHint"
:decoding="decodeHint"
class="absolute inset-0 hidden size-full object-cover dark:block"
data-theme-src="dark"
/>
</Box>
</template>
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-cdnnpx ui8kit add media-frame// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Data of MediaFrame: long values (pictures as data URIs) kept out of the component file.
export const PLACEHOLDER: Record<string, string> = {
"light": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
"dark": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
};
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one
* of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it
* shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out
* before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is
* switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the
* corners are the plain theme radius.
*/
import { type JSX } from "solid-js";
import { Box, Image } from "../compose";
import { at, cn, urlOf, variants } from "../utils";
import { PLACEHOLDER } from "./media-frame.assets";
/** MediaFrame: the classes of each value (shadcn/cva style). */
export const mediaFrameVariants = variants({
base: "relative w-full overflow-hidden bg-muted text-muted-foreground inset-ring inset-ring-border rounded",
variants: {
ratio: {
"16/9": "aspect-video",
"4/3": "aspect-4/3",
"1/1": "aspect-square",
"3/4": "aspect-3/4",
"21/9": "aspect-21/9",
},
},
defaultVariants: { ratio: "16/9" },
});
export type MediaFrameProps = {
alt: string;
src?: string;
darkSrc?: string;
ratio?: "16/9" | "4/3" | "1/1" | "3/4" | "21/9";
class?: string;
};
export function MediaFrame({ alt, src, darkSrc, ratio = "16/9", class: className }: MediaFrameProps) {
const lightSrc = src ? src : at(PLACEHOLDER, "light");
const nightSrc = darkSrc ? darkSrc : (src ? src : at(PLACEHOLDER, "dark"));
const shownAlt = src ? alt : "";
const loadHint = src ? "lazy" : undefined;
const decodeHint = src ? "async" : undefined;
return (
<Box
class={cn(mediaFrameVariants({ ratio: ratio }), className)}
data-slot="media-frame"
data-placeholder={(src ? "false" : "true")}
>
<Image
src={urlOf(lightSrc, true)}
alt={shownAlt}
loading={loadHint}
decoding={decodeHint}
class="absolute inset-0 size-full object-cover dark:hidden"
data-theme-src="light"
/>
<Image
src={urlOf(nightSrc, true)}
alt={shownAlt}
loading={loadHint}
decoding={decodeHint}
class="absolute inset-0 hidden size-full object-cover dark:block"
data-theme-src="dark"
/>
</Box>
);
}
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-cdnnpx ui8kit add media-frame// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/patterns/media-frame.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/ui/image"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// MediaFrameProps are the props of MediaFrame; the values are the JSON shapes of the TypeScript props.
type MediaFrameProps struct {
Alt any `json:"alt"`
Src any `json:"src"`
DarkSrc any `json:"darkSrc"`
Ratio any `json:"ratio"`
Class string `json:"className"`
}
var mediaFramePlaceholder = map[string]any{
"light": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
"dark": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+",
}
// A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the corners are the plain theme radius.
templ MediaFrame(p MediaFrameProps) {
{{ vAlt := p.Alt }}
{{ vSrc := p.Src }}
{{ vDarkSrc := p.DarkSrc }}
{{ vRatio := uiutils.Def(p.Ratio, "16/9") }}
{{ vLightSrc := any(uiutils.Cond(uiutils.T(vSrc), vSrc, uiutils.At(mediaFramePlaceholder, "light"))) }}
{{ vNightSrc := any(uiutils.Cond(uiutils.T(vDarkSrc), vDarkSrc, uiutils.Cond(uiutils.T(vSrc), vSrc, uiutils.At(mediaFramePlaceholder, "dark")))) }}
{{ vShownAlt := any(uiutils.Cond(uiutils.T(vSrc), vAlt, "")) }}
{{ vLoadHint := any(uiutils.Cond(uiutils.T(vSrc), "lazy", nil)) }}
{{ vDecodeHint := any(uiutils.Cond(uiutils.T(vSrc), "async", nil)) }}
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv(recipeMediaFrame.Of(map[string]any{"ratio": vRatio}), p.Class)), Attrs: uiutils.Attrs("data-slot", "media-frame", "data-placeholder", uiutils.Cond(uiutils.T(vSrc), "false", "true"))}}) {
@compose.Image(compose.ImageProps{ImageProps: image.ImageProps{Src: uiutils.URL(vLightSrc, true), Alt: uiutils.S(vShownAlt), Loading: uiutils.S(vLoadHint), Decoding: uiutils.S(vDecodeHint), Class: "absolute inset-0 size-full object-cover dark:hidden", Attrs: uiutils.Attrs("data-theme-src", "light")}})
@compose.Image(compose.ImageProps{ImageProps: image.ImageProps{Src: uiutils.URL(vNightSrc, true), Alt: uiutils.S(vShownAlt), Loading: uiutils.S(vLoadHint), Decoding: uiutils.S(vDecodeHint), Class: "absolute inset-0 hidden size-full object-cover dark:block", Attrs: uiutils.Attrs("data-theme-src", "dark")}})
}
}
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-cdnnpx ui8kit add media-frame{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/patterns/media-frame.json
A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the corners are the plain theme radius.
Props (p): alt, src, darkSrc, ratio, className. -#}
{%- set k_PLACEHOLDER = {'light': 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+', 'dark': 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+'} -%}
{%- set v_alt = (p.alt ?? null) -%}
{%- set v_src = (p.src ?? null) -%}
{%- set v_darkSrc = (p.darkSrc ?? null) -%}
{%- set v_ratio = (p.ratio ?? '16/9') -%}
{%- set v_lightSrc = (og_t(v_src) ? v_src : og_at(k_PLACEHOLDER, 'light')) -%}
{%- set v_nightSrc = (og_t(v_darkSrc) ? v_darkSrc : (og_t(v_src) ? v_src : og_at(k_PLACEHOLDER, 'dark'))) -%}
{%- set v_shownAlt = (og_t(v_src) ? v_alt : '') -%}
{%- set v_loadHint = (og_t(v_src) ? 'lazy' : null) -%}
{%- set v_decodeHint = (og_t(v_src) ? 'async' : null) -%}
{%- set c_1 -%}
{{ include('compose/Image.html.twig', {'src': og_url(og_s(v_lightSrc), true), 'alt': og_s(v_shownAlt), 'loading': og_s(v_loadHint), 'decoding': og_s(v_decodeHint), 'class': 'absolute inset-0 size-full object-cover dark:hidden', 'attrs': og_attrs(['data-theme-src', 'light'])}, with_context = false) }}
{{ include('compose/Image.html.twig', {'src': og_url(og_s(v_nightSrc), true), 'alt': og_s(v_shownAlt), 'loading': og_s(v_loadHint), 'decoding': og_s(v_decodeHint), 'class': 'absolute inset-0 hidden size-full object-cover dark:block', 'attrs': og_attrs(['data-theme-src', 'dark'])}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s(og_cnv([og_recipe('blocks/recipes/media-frame.variants.json', {'ratio': v_ratio}), (p.className ?? '')])), 'attrs': og_attrs(['data-slot', 'media-frame', 'data-placeholder', (og_t(v_src) ? 'false' : 'true')]), 'children': c_1}, with_context = false) }}
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-cdnnpx ui8kit add media-frame{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/patterns/media-frame.json
A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the corners are the plain theme radius.
Props (p): alt, src, darkSrc, ratio, className. *}
{var $k_PLACEHOLDER = ['light' => 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+', 'dark' => 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+']}
{var $v_alt = ($p['alt'] ?? null)}
{var $v_src = ($p['src'] ?? null)}
{var $v_darkSrc = ($p['darkSrc'] ?? null)}
{var $v_ratio = ($p['ratio'] ?? '16/9')}
{var $v_lightSrc = (og_t($v_src) ? $v_src : og_at($k_PLACEHOLDER, 'light'))}
{var $v_nightSrc = (og_t($v_darkSrc) ? $v_darkSrc : (og_t($v_src) ? $v_src : og_at($k_PLACEHOLDER, 'dark')))}
{var $v_shownAlt = (og_t($v_src) ? $v_alt : '')}
{var $v_loadHint = (og_t($v_src) ? 'lazy' : null)}
{var $v_decodeHint = (og_t($v_src) ? 'async' : null)}
{capture $c_1}
{=og_include('compose/Image.latte', ['src' => og_url(og_s($v_lightSrc), true), 'alt' => og_s($v_shownAlt), 'loading' => og_s($v_loadHint), 'decoding' => og_s($v_decodeHint), 'class' => 'absolute inset-0 size-full object-cover dark:hidden', 'attrs' => og_attrs(['data-theme-src', 'light'])])|noescape}
{=og_include('compose/Image.latte', ['src' => og_url(og_s($v_nightSrc), true), 'alt' => og_s($v_shownAlt), 'loading' => og_s($v_loadHint), 'decoding' => og_s($v_decodeHint), 'class' => 'absolute inset-0 hidden size-full object-cover dark:block', 'attrs' => og_attrs(['data-theme-src', 'dark'])])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s(og_cnv([og_recipe('blocks/recipes/media-frame.variants.json', ['ratio' => $v_ratio]), ($p['className'] ?? '')])), 'attrs' => og_attrs(['data-slot', 'media-frame', 'data-placeholder', (og_t($v_src) ? 'false' : 'true')]), 'children' => (string) $c_1])|noescape}
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-cdnnpx ui8kit add media-frame{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/patterns/media-frame.json
A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the corners are the plain theme radius.
Props (p): alt, src, darkSrc, ratio, className. -#}
{%- set k_PLACEHOLDER = {'light': 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiNlMmU4ZjAiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiNjYmQ1ZTEiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjOTRhM2I4IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+', 'dark': 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MDAgMzAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBzbGljZSI+PHJlY3Qgd2lkdGg9IjQwMCIgaGVpZ2h0PSIzMDAiIGZpbGw9IiMxZTI5M2IiLz48Y2lyY2xlIGN4PSIyOTYiIGN5PSI5NiIgcj0iMzAiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDBWMjE0bDk2LTc2IDg4IDcwIDY0LTQ4IDE1MiA5NnY0NHoiIGZpbGw9IiMzMzQxNTUiLz48cGF0aCBkPSJNMCAzMDB2LTUybDEyMC02MCAxMTAgNjIgNjAtMzAgMTEwIDgwdjB6IiBmaWxsPSIjNDc1NTY5IiBvcGFjaXR5PSIwLjU1Ii8+PC9zdmc+'} -%}
{%- set v_alt = og_def(p['alt'], none) -%}
{%- set v_src = og_def(p['src'], none) -%}
{%- set v_darkSrc = og_def(p['darkSrc'], none) -%}
{%- set v_ratio = og_def(p['ratio'], '16/9') -%}
{%- set v_lightSrc = (v_src if og_t(v_src) else og_at(k_PLACEHOLDER, 'light')) -%}
{%- set v_nightSrc = (v_darkSrc if og_t(v_darkSrc) else (v_src if og_t(v_src) else og_at(k_PLACEHOLDER, 'dark'))) -%}
{%- set v_shownAlt = (v_alt if og_t(v_src) else '') -%}
{%- set v_loadHint = ('lazy' if og_t(v_src) else none) -%}
{%- set v_decodeHint = ('async' if og_t(v_src) else none) -%}
{%- set c_1 -%}
{{ og_include('compose/image.html.j2', {'p': {'Src': og_url(og_s(v_lightSrc), true), 'Alt': og_s(v_shownAlt), 'Loading': og_s(v_loadHint), 'Decoding': og_s(v_decodeHint), 'Class': 'absolute inset-0 size-full object-cover dark:hidden', 'Attrs': og_attrs(['data-theme-src', 'light'])}}) }}
{{ og_include('compose/image.html.j2', {'p': {'Src': og_url(og_s(v_nightSrc), true), 'Alt': og_s(v_shownAlt), 'Loading': og_s(v_loadHint), 'Decoding': og_s(v_decodeHint), 'Class': 'absolute inset-0 hidden size-full object-cover dark:block', 'Attrs': og_attrs(['data-theme-src', 'dark'])}}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(og_cnv([og_recipe('blocks/recipes/media-frame.variants.json', {'ratio': v_ratio}), og_def(p['className'], '')])), 'Attrs': og_attrs(['data-slot', 'media-frame', 'data-placeholder', ('false' if og_t(v_src) else 'true')])}, 'children': c_1}) }}
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.
A picture in a fixed ratio that follows the theme. `src` is the picture of the light theme, `darkSrc` the one of the dark theme (without it the dark theme shows `src`). Without both (an empty string counts as none) it shows the built-in neutral placeholders (base64 data URIs, one light and one dark), so a page can be laid out before it has pictures; the placeholder is decorative (`alt` is empty), stands in for a real `src` and is switched by the theme token. A real picture gets `alt` and loads lazily. `ratio` comes from the recipe; the corners are the plain theme radius.
| Prop | Type | Default | Description |
|---|---|---|---|
| alt (required) | string | - | accessible name of the picture; used only when there is a `src` (the placeholder is decorative) |
| src | string | - | address of the picture (light theme); none or empty: the built-in light placeholder |
| darkSrc | string | - | address of the picture for the dark theme; none or empty: `src`, or the built-in dark placeholder when there is no `src` |
| ratio | "16/9" | "4/3" | "1/1" | "3/4" | "21/9" | "16/9" | width to height |
Used in
- about-company
- about-me
- auth-layout
- backdrop
- bento-grid
- cart-list
- cart-summary-card
- cart-table
- cta-band
- cta-proof
- cut-cards
- dish-bento
- dish-card
- dish-cart-grid
- dish-showcase
- dish-strip
- drawer-lines
- empty-panel
- error-page
- faq-split
- feature-accordion
- feature-rows
- feature-showcase
- feature-split
- feature-sticky
- feature-tabs
- footer-split
- grocery-list
- hero-classic
- hero-split-extras
- hero-split-media
- lightbox-gallery
- lightbox-stage
- meat-cards
- media-list
- mega-menu
- member-row
- milestone-timeline
- newsletter-form
- offer-media
- over-media
- photo-gallery
- pizza-picker
- post-author
- post-card
- post-feature
- post-header
- post-mini-card
- post-overlay-card
- post-showcase
- post-split
- product-card
- product-gallery
- profile-form
- project-grid
- project-tiles
- quote-card
- quote-split
- recipe-kits
- review-list
- shell-topbar
- shopping-cart
- sidebar-nav
- store-locations
- story-tabs
- sushi-sets
- team-grid
- template-grid
- veggie-box
- video-grid
- video-modal
- week-menu