Aspect Ratio

Keeps media at a fixed width-to-height ratio. Optionally wrap content in a sketch frame.

Media slot
<AspectRatio ratio={16 / 9} bordered roughness={1.5}>
  <img src="..." alt="" />
</AspectRatio>

CLI install

npx doodleui-react add aspect-ratio

Usage

import { AspectRatio } from "doodleui-react";

<AspectRatio ratio={16 / 9} bordered>
  <img src="/photo.jpg" alt="Studio" style={{ width: "100%", height: "100%", objectFit: "cover" }} />
</AspectRatio>

Props

PropTypeDefaultNotes
rationumber16 / 9Width divided by height for the content box.
borderedbooleanfalseWrap content in a hand-drawn SketchBox frame.
animatebooleantrueDraw-in the frame when bordered is true. Overrides DoodleUIProvider. Reduced motion disables this unless the provider set forceAnimate.
roughnessnumber1.5How wobbly the stroke is. 0 is almost geometric. 3+ is messy.
seednumberprovider / randomLocks the sketch. Omit to follow SketchSeedProvider (Shuffle) or a mount-time random seed.
sketchColorstring#1f1d1aStroke color. Also tints primary/accent fills where relevant.
classNamestringundefinedPassed through to the root element.
styleCSSPropertiesundefinedPassed through to the root element.