Aspect Ratio PickerPRO
Segmented ratios with a live preview frame that morphs and re-crops the image.
Code
2 files · 252 lines of TypeScriptPRO
Aspect Ratio Picker is part of Pro
Get its source, the one-paste agent prompt and all 113 components, for a one-time $99.
Motion notes
- The frame springs its real width and height rather than scaling, so object-fit: cover recomputes the crop every frame and the image never stretches.
- Going from wide to tall passes through square on the way, which reads as the same canvas reshaping rather than a swap.
- The selection pill slides on the same layout spring as the frame, and the output size rolls digit by digit, so all three move as one.
- A radio group with arrow-key navigation. With reduced motion the frame and pill change instantly.
Usage
Example
const [ratio, setRatio] = useState("3:4");
<AspectRatioPicker src={reference.url} value={ratio} onValueChange={setRatio} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | — | Previewed inside the frame, cropped to the chosen ratio. |
| alt | string | — | Alt text for the preview. |
| options | string[] | ["1:1", "3:4", "4:3", "16:9", "9:16"] | Ratios as "w:h". |
| value | string | — | Controlled ratio. |
| defaultValue | string | — | Starting ratio when uncontrolled. Defaults to the first option. |
| onValueChange | (value: string) => void | — | Called when a ratio is picked. |
| base | number | 1024 | Output size of the short side, in px, for the readout. |
| label | string | "Aspect ratio" | Accessible name for the options. |
| className | string | — | Classes for the card; the default is w-80. |