import { MediaStack, fit } from '@hanzo/ui'
A photograph fitted inside the box the layout reserves for it.
export function Default() {return <MediaStack media={{ img: photo }} constrainTo={{ w: 320, h: 240 }} />}
The same source in three boxes; each keeps the aspect ratio and reserves its space before the bytes arrive.
export function Constrained() {return (<XStack flexWrap="wrap" gap="$4" items="flex-end">{[{ w: 240, h: 240 },{ w: 160, h: 240 },{ w: 320, h: 120 },].map((box) => (<YStack key={`${box.w}x${box.h}`} gap="$2" items="center"><MediaStack media={{ img: photo }} constrainTo={box} /><Text fontSize={12} color="$color10">{box.w} × {box.h}</Text></YStack>))}</XStack>)}
The arithmetic the stack uses, exposed for a layout that needs the numbers.
export function Fit() {const fitted = fit(photo.dim, { w: 320, h: 240 })return (<Text fontFamily="$mono" fontSize={13} color="$color11">{`fit(${photo.dim.w}×${photo.dim.h}, 320×240) → ${Math.round(fitted.w)}×${Math.round(fitted.h)}`}</Text>)}
export type MediaStackProps = Omit<React.ComponentProps<typeof Box>, 'children'> & {media: MediaStackDef/** The box the media must fit inside. */constrainTo: Dimensions}