Aspect-ratio
cubby-ui/aspect-ratioFreeComponent
A aspect-ratio component.
Live preview
live · rendered by the registry
Rendered by cubby-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://cubby-ui.dev/r/aspect-ratio.jsonSource
1import * as React from "react";23import { cn } from "@/lib/utils";45export interface AspectRatioProps extends React.HTMLAttributes<HTMLDivElement> {6 ratio?: number | `${number}/${number}`;7}89function AspectRatio({10 children,11 className,12 ratio = 1,13 style,14 ...props15}: AspectRatioProps) {16 const aspectRatio =17 typeof ratio === "string"18 ? ratio19 .split("/")20 .map(Number)21 .reduce((a, b) => a / b)22 : ratio;2324 return (25 <div26 data-slot="aspect-ratio"27 style={{28 ...style,29 aspectRatio: aspectRatio.toString(),30 }}31 className={cn("w-full", className)}32 {...props}33 >34 {children}35 </div>36 );37}3839export { AspectRatio };
Files it writes
More from cubby-ui
All 79 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | cubby-ui | Components | Free | 2 deps | |
| Alertalert | cubby-ui | Components | Free | 1 dep | |
| Alert-dialogalert-dialog | cubby-ui | Components | Free | 2 deps | |
| Autocompleteautocomplete | cubby-ui | Components | Free | 2 deps | |
| Avataravatar | cubby-ui | Components | Free | 1 dep | |
| Badgebadge | cubby-ui | Components | Free | 1 dep | |
| Base Drawerbase-drawer | cubby-ui | Components | Free | 2 deps | |
| Breadcrumbsbreadcrumbs | cubby-ui | Components | Free | 2 deps |
