Aspect Morph
betaA picture that smoothly reshapes between aspect ratios, picked from a segmented control with a sliding thumb.
- Display
- 1 file
- 1 npm package
- Accessibility notes
pnpm dlx @dowel-ui/cli add aspect-morphnpm packages installed: class-variance-authority.
import { AspectMorph } from "@/components/ui/aspect-morph";Default
Gallery
Custom Ratios
Controlled
Right To Left
<AspectMorph>
| Prop | Type | Default |
|---|---|---|
altNames the picture (role="img"). Without it the picture is decorative. | string | — |
cornerCorner radius of the picture in px. | number | 18 |
defaultValueInitial value when uncontrolled. Defaults to the first ratio. | string | — |
disabledDisables the ratio picker. | boolean | false |
labelAccessible name of the radiogroup. | string | "Aspect ratio" |
morphSpeed, 0–100: 0 morphs over 832ms, 50 over 520ms, 100 over 208ms. | number | 50 |
onValueChangeCalled with the newly selected ratio value. | (value: string) => void | — |
ratiosThe shapes to choose between. | AspectMorphRatio[] | defaultAspectMorphRatios |
sizeSide of the square box the picture is fitted into, in px. | number | 276 |
srcPicture URL, drawn as a cover-cropped background. | string | — |
valueControlled selected ratio value. | string | — |
childrenCustom picture content (an <img>, <video>, canvas…); cropped to the frame. | ReactNode | — |
Plus every attribute of <div> except defaultValue, onChange.
10/10
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — passes
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — passes
- No fixed widths — passes