Media & Presentation
Aspect Ratio
Keeps embedded media in a fixed width-to-height ratio using CSS aspect-ratio (shadcn-style API; no Radix dependency). Give media a predictable place in the layout while keeping the surrounding content readable during loading, playback or failure. Import it from @/components/kamod-ui/aspect-ratio.
Source · Design reference · API reference · Theming · Styles
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthInstallation
Import AspectRatio from @/components/kamod-ui/aspect-ratio.
pnpm add @kamod-ch/uiCopy an example with @kamod-ch/ui or the matching @kamod-ch/ui/… subpath. The code block switches between those two installs. Connect The Global Theme CSS and Tailwind Source Detection before your first render.
import { AspectRatio, Image } from "@kamod-ch/ui";
Usage
Pass ratio as a number (e.g. 16/9). Put the image (or video) inside and size it with h-full w-full object-cover so it fills the box.
import { AspectRatio } from "@kamod-ch/ui";Choose a complete composition from the examples below; required child components and props vary by pattern.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthComponent Examples & Variants
Explore Aspect Ratio in Different Contexts, from the starting pattern to the compositions below. Begin with Demo, then compare the examples that match your content, state and layout. These are working patterns to adapt, not a list of interchangeable variant values: check the API Reference before using a prop or combining behaviors. Look at the surrounding labels, supporting text and spacing as well as the component itself.
Read the Result and Its Implementation Together. Use each showcase’s Code view to inspect imports and composition, or its Prompt view to prepare a setup or adaptation brief. Try the narrow preview and local theme controls before connecting real data, and use Reset to return an example to its initial state. Keep layout changes in class utilities where appropriate; follow the Component Styles Guide for hierarchy and the Theming Guide for shared surfaces and colors. The Accessibility Notes explain what to preserve when making those changes.
Demo
Reserve the Media Space before It Loads. Use AspectRatio to reserve a widescreen frame before the image loads. A muted background and rounded corners define the media area; the ratio determines its height from the available width.
Choose whether the image should crop with object-cover or remain fully visible with object-contain; the ratio controls the frame, not which content may safely be cropped.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthSquare
Use a Predictable Thumbnail Rhythm. Set ratio={1 / 1} to keep the media frame square as its container grows or shrinks. Use this for consistent thumbnails, then choose how the image should fit inside that reserved space.
Check the focal point before cropping, provide useful alternative text, and avoid treating a decorative thumbnail as the only label for its destination.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthPortrait
Make Room for Vertical Content. Set ratio={9 / 16} for portrait media such as a vertical video preview. The frame remains proportional to its width, so the surrounding layout can reserve room without hard-coding a height.
Set a sensible surrounding width and inspect the crop with real media; use Video when the content also needs playback controls.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthProps and Data
Configure Aspect Ratio using the contracts below. Read the documented options alongside the Source Definitions to understand which values your application supplies and which details the component owns. Start with a prop or helper, then follow its type link to inspect the declaration without leaving the page.
Component overview.
Type cards are extracted from this checkout’s TypeScript source at build time. Props inherited through HTMLAttributes, Omit or variant helpers remain references in those declarations; their fields are not flattened here. Match the reference to your installed version, and check a package’s exports before writing an import type. A type exported by a source file is not necessarily re-exported by @kamod-ch/ui.
Component Props
? means a field can be omitted; it does not promise a fallback value. Existing documented defaults remain alongside the descriptions. For callbacks, check the argument and return types before connecting your own state or services.AspectRatio
AspectRatioProps
| Prop / type | Description |
|---|---|
children | Configure
|
class | Configure
|
ratio | Width ÷ height (e.g. `16 / 9`, `1`, `9 / 16`). Applied as CSS `aspect-ratio`.
|
style | Configure
|
Data Type Reference
Expand a card to inspect and copy the exact declaration. The code header identifies its repository file; follow imported or inherited types in the Implementation Source when you need the complete dependency chain. Required-field summaries cover fields declared directly in that type. Source-only helpers and inferred schema outputs describe the local implementation, not additional props you can pass to every component.
AspectRatio Props
2 declared fieldsAspectRatioPropsAspectRatio.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of AspectRatioProps before adapting it.ratioAccessibility
AspectRatio reserves a proportional layout box. It does not add an accessible name, image alternative, media controls or a semantic figure. Those responsibilities remain with the content placed inside it.
You have the pieces. Put them into one real interaction, keep its state in one place, and check the result with the content your application will actually show.
Connect the Foundation
Return to Choose and Compose Components to connect this reference to a working screen. Keep global CSS in one entrypoint and import only the components that screen needs.
Build the Surrounding Screen
Find a neighboring interaction in the Component Library, or start with a complete Block. Replace sample content and destinations before refining the layout; a local class change can stay with the composition.
Make the Result Hold Up
Use shared theme roles for changes that belong everywhere. Then review the whole journey: keyboard focus, long labels, narrow screens and a clear way to recover when something fails.
Keep a link to the source and note your intentional changes. Your next edit should begin with a clear decision, not another search.