Aspect ratio
A frame held at one ratio, so the space is reserved before its content arrives.
Previews are drawn in the theme you made.
Edit itBasic #
Reserved before it loads
import { AspectRatio, AspectRatioSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { t } from '../../snippets/theme.js'
// The frame holds its ratio before its content arrives, so nothing below it
// moves when the picture does. The content fills it; the ratio is the style's.
export default example({
title: 'Basic',
slots: AspectRatioSlots,
recipe: Recipes.AspectRatio,
view: ({ style, h }) =>
h.div(
[h.Style({ inlineSize: 'min(100%, 20rem)' })],
[
AspectRatio.view(
{
content: h.div(
[
h.Style({
display: 'grid',
placeItems: 'center',
blockSize: '100%',
background: t.surface.subtle,
}),
],
['Reserved before it loads'],
),
style,
},
h,
),
],
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Usage
Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.
Keyboard and accessibility
- A plain
divthat holds a ratio: it has no role and no name, so it adds nothing to what a screen reader announces. - What it holds carries its own text alternative: an
Imagetakes itsalt, a figure its caption.