Aspect Ratio
solid-ui/aspect-ratioFreeComponent
An aspect ratio component
Live preview
live · rendered by the registry
Rendered by solid-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.solid-ui.com/r/aspect-ratio.jsonSource
1import type { Component, ComponentProps } from "solid-js"2import { mergeProps, splitProps } from "solid-js"34type AspectRatioProps = ComponentProps<"div"> & { ratio?: number }56const AspectRatio: Component<AspectRatioProps> = (rawProps) => {7 const props = mergeProps({ ratio: 1 / 1 }, rawProps)8 const [local, others] = splitProps(props, ["ratio"])9 return (10 <div11 style={{12 position: "relative",13 width: "100%",14 "padding-bottom": `${100 / local.ratio}%`15 }}16 >17 <div18 style={{19 position: "absolute",20 top: 0,21 right: 0,22 bottom: 0,23 left: 024 }}25 {...others}26 />27 </div>28 )29}3031export { AspectRatio }
What it pulls in
npm packages
Files it writes
More from solid-ui
All 55 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | solid-ui | Components | Free | 2 deps | |
| Alertalert | solid-ui | Components | Free | 3 deps | |
| Alert Dialogalert-dialog | solid-ui | Components | Free | 2 deps | |
| Avataravatar | solid-ui | Components | Free | 2 deps | |
| Badgebadge | solid-ui | Components | Free | 2 deps | |
| Badge Deltabadge-delta | solid-ui | Components | Free | 2 deps | |
| Bar Listbar-list | solid-ui | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | solid-ui | Components | Free | 2 deps |
