Fragiola

API: components

AspectRatio

A box that keeps its content at a width-to-height ratio with one structural style, in each framework.

Keeps its content at a ratio: an image frame, a video embed, a map tile. It is one div with a structural aspect-ratio, and no behaviour. It is a markup-and-CSS component, which the scope rule gives to Fragiola UI; it is here because the stage 2 list has it, and kept to that one style. The APG has no pattern for it; it follows the CSS aspect-ratio property, not a pattern.

Image frame
Gallery

Behaviour

  • Ratio: the width over the height (16 / 9); its width is the layout's, its height follows. A ratio that is not a positive finite number is 1.
  • Strict: min-height: 0, so a taller child overflows the box instead of stretching it: clip it (overflow: hidden) or fit it (object-fit: cover).
  • Nothing else: no role, no state attribute, no focus, no key.

Anatomy

partelementdata-primitives-partrole
AspectRatiodivaspect-ratio-rootthe box

Usage

import { AspectRatio } from "@fragiola/primitives-react/aspect-ratio";

<AspectRatio ratio={16 / 9}>
    <img src="/hills.jpg" alt="Hills under the sun" className="size-full object-cover" />
</AspectRatio>;

Props

It also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards.

AspectRatio

proptypedefaultdescription
rationumber1the width over the height

State and part attributes

None but its part attribute. Structural style: aspect-ratio: <ratio>, min-height: 0.

Keyboard

None.

Exports

entryexports
@fragiola/primitives-react/aspect-ratioAspectRatio, AspectRatioProps, AspectRatioState, RenderProp
@fragiola/primitives-vue/aspect-ratioAspectRatio, AspectRatioProps, AspectRatioState, RenderSlotProps
@fragiola/primitives-angular/aspect-ratioAspectRatio, AspectRatioState