Skip to content

Add AspectRatio component with preset ratios and radius variants#38

Merged
jalexw merged 1 commit intomainfrom
claude/determined-feynman-m3TAI
May 8, 2026
Merged

Add AspectRatio component with preset ratios and radius variants#38
jalexw merged 1 commit intomainfrom
claude/determined-feynman-m3TAI

Conversation

@jalexw
Copy link
Copy Markdown
Contributor

@jalexw jalexw commented May 8, 2026

Summary

Introduces a new AspectRatio component that constrains content to fixed width-to-height ratios. This component is useful for images, videos, iframes, and embedded media that need to maintain consistent proportions across different viewport sizes.

Key Changes

  • New AspectRatio component (src/components/ui/aspect-ratio/aspect-ratio.tsx)

    • Supports both numeric ratio prop (e.g., 16 / 9) and named preset identifiers
    • Nine preset ratios: square, video, photo, wide, ultrawide, cinema, portrait, classic-portrait, story
    • Built on CSS aspect-ratio property with automatic fill behavior for <img>, <video>, and <iframe> children
    • Configurable border radius via radius variant (none, sm, md, lg, xl, 2xl, full)
    • Optional bordered variant for visual containment
    • Supports asChild prop via Radix Slot for applying aspect ratio directly to child elements
  • Comprehensive Storybook stories (src/components/ui/aspect-ratio/AspectRatio.stories.tsx)

    • Default video (16:9) example
    • Individual preset showcases (Square, Ultrawide, VerticalStory)
    • Custom numeric ratio example
    • Placeholder/fallback state
    • Iframe embedding example
    • Interactive video thumbnail with hover effects
    • Grid displays of all presets and radius variants
    • Media card composition example
  • Module exports (src/components/ui/aspect-ratio/index.ts)

    • Exports component, variants, preset/radius identifiers, and preset ratio values
  • Updated main UI exports (src/components/ui/index.ts)

    • Added AspectRatio to main component barrel export
  • Version bump (package.json)

    • Updated from 0.38.1 to 0.39.0

Implementation Details

  • Uses CVA (class-variance-authority) for variant management
  • Numeric ratio prop takes precedence over preset when both are provided
  • Defaults to video (16:9) preset if neither ratio nor preset is specified
  • Direct children (img, video, iframe) automatically fill container with object-cover
  • Supports all standard div props and custom className composition via cn() utility

https://claude.ai/code/session_016mDrJ8fdfxHjs7jyZzHd3A

…d width-to-height ratio. Fills a gap in the library: there was no primitive for keeping images, videos, and iframes at a consistent shape across viewport sizes. Implementation uses the modern CSS aspect-ratio property (no padding-bottom hack, no new Radix dependency required) and applies sensible defaults so direct <img>, <video>, and <iframe> children fill the container automatically (h-full w-full + object-cover for img/video; border-0 for iframe). Two ways to set the ratio: a numeric `ratio` prop (e.g. 16 / 9) for arbitrary values, or a named `preset` for common ratios (square 1:1, video 16:9, photo 4:3, wide 3:2, ultrawide 21:9, cinema ~2.35:1, portrait 3:4, classic-portrait 2:3, story 9:16). cva-driven `radius` variant (none, sm, md, lg, xl, 2xl, full) and `bordered` variant (uses border-border from @schemavaults/theme so it inherits brightness/contrast theming). asChild via Radix Slot so the aspect ratio can be applied directly to a child element (e.g. an <img> styled as a circular thumbnail). data-slot=aspect-ratio and data-preset attributes set on the root for downstream styling. Storybook story covers Default, Square, Ultrawide, VerticalStory, CustomRatio, Placeholder (icon + label inside a bordered box), IframeEmbed, VideoThumbnail (with hover-scale play icon overlay), AsChild, MediaCard (composing inside a card surface), and AllPresets / AllRadii grid views for at-a-glance comparison.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ui Ready Ready Preview, Comment May 8, 2026 10:53pm

Request Review

@jalexw jalexw self-assigned this May 8, 2026
@jalexw jalexw merged commit 503e186 into main May 8, 2026
8 checks passed
@jalexw jalexw deleted the claude/determined-feynman-m3TAI branch May 8, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants