Components

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 it
ratio
scheme
direction

Basic #

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.

The recipe ↗This code ↗

Keyboard and accessibility

  • A plain div that 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 Image takes its alt, a figure its caption.

Images, icons and codes in the README ↗