Media gallery
Keep image tiles the same shape while assets load.
Components / Layout
A CSS aspect-ratio wrapper for media and previews.
Last changed in version 0.13.0: Add avatar groups and chips, expand the block gallery, and improve component colors, spacing, and motion.
Designing calmer project handoffs
A 16:9 media card that stays stable at every width.
bunx --bun @getweini/cli@latest add aspect-ratioImport the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.
<script setup lang="ts">
import AspectRatio from './components/ui/aspect-ratio/AspectRatio.vue'
const landscape =
'data:image/svg+xml,' +
encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 480"><rect width="640" height="480" fill="#e4e4e7"/><path d="M0 480 240 100 440 480Z" fill="#71717a"/><path d="m180 480 250-310 210 310Z" fill="#a1a1aa"/></svg>',
)
</script>
<template>
<AspectRatio :ratio="4 / 3" as="figure">
<img :src="landscape" alt="Mountain landscape" class="h-full w-full object-cover">
</AspectRatio>
</template>Give images meaningful alternative text when they convey information.
Keep image tiles the same shape while assets load.
Preserve a widescreen preview inside a flexible card.
The wrapper sets shape while the image fills it.
<script setup lang="ts">
import AspectRatio from './components/ui/aspect-ratio/AspectRatio.vue'
const landscape =
'data:image/svg+xml,' +
encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 480"><rect width="640" height="480" fill="#e4e4e7"/><path d="M0 480 240 100 440 480Z" fill="#71717a"/><path d="m180 480 250-310 210 310Z" fill="#a1a1aa"/></svg>',
)
</script>
<template>
<AspectRatio :ratio="4 / 3" as="figure">
<img :src="landscape" alt="Mountain landscape" class="h-full w-full object-cover">
</AspectRatio>
</template>A string ratio can represent a familiar format.
<script setup lang="ts">
import AspectRatio from './components/ui/aspect-ratio/AspectRatio.vue'
</script>
<template>
<AspectRatio ratio="16 / 9">
<iframe
title="Widescreen content preview"
srcdoc="<p>A self-contained widescreen embed.</p>"
class="h-full w-full border-0"
/>
</AspectRatio>
</template>Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
ratioprop | string | number | undefined | 16 / 9 | ratio accepts a number or a valid CSS aspect-ratio string. |
asprop | "div" | "figure" | undefined | "div" | Choose the HTML element or Vue component used for this control. |
defaultslot | {} | Optional | Content shown inside AspectRatio. |
// packages/frameworks/vue/components/aspect-ratio/types.ts
// ------- TYPES -------
export interface AspectRatioProps {
ratio?: number | string
as?: 'div' | 'figure'
}