For photos take CdsImage — it is built on
CdsResponsiveand can also do lazy loading, a placeholder and cropping. If you need the columns of a page rather than the shape of a single block, take CdsGrid.
Variations
Aspect ratio
The aspect-ratio prop accepts a fraction (16/9) or a number (1.7778). The width comes from the parent, the height is calculated by the component itself — and recalculated on every change of the width. The calculated height works as a minimum: content that does not fit into it stretches the frame and breaks the proportions.
Sizes
By default the frame takes the whole width of its parent. The width, max-width and min-width props limit it, and height, max-height and min-height limit its height; numbers turn into pixels, strings go into CSS as they are.
Layout
The inline prop turns the frame into inline-flex — it stops stretching and stands in a row with its neighbors. Set the width yourself in this case: it will not take it from the content.
Slots
The height of the frame is held by an invisible spacer, and the content lies on top of it. Hence two slots with different jobs.
| Slot | Description |
|---|---|
default | The main content inside a wrapper — it takes the whole frame |
additional | Content without a wrapper, on top of the spacer — for backdrops and absolute layers |
The content-class prop puts classes on the wrapper of the default slot — that is how the inner paddings and the layout are set. The root of the component is positioned (position: relative), so the elements from additional can be placed absolutely relative to the frame.
Guidelines
Scenarios
An embedded map or video
Maps and video players arrive in an iframe with proportions of their own. Wrap the iframe into a CdsResponsive with the right aspect-ratio and stretch it with the h-full w-full classes — the player will look the same on a wide monitor and on a phone.
A grid of tiles
In a grid of categories the tiles have to be square regardless of the length of the caption. The aspect-ratio="1" value gives a square, and the width of every tile comes from the grid column — the number of columns changes the size, not the shape.
Space for a widget while it loads
A report, a chart or a map arrives from the server a second or two later. A frame with proportions takes their place right away: while the loader spins inside, the caption and the buttons below the widget stay exactly where they will end up after the loading.
Switching the proportions
The aspect-ratio value is reactive and the change of the height is animated — a crop switcher does not jerk the neighboring blocks.
API
Props
| Name | Type | Default | Description |
|---|---|---|---|
aspectRatio | string | number | undefined | — | Aspect ratio of the content. For example 1.7778 (16/9) or '4/3'. |
contentClass | any | — | CSS class applied to the content wrapper. |
height | string | number | undefined | — | Component height |
inline | boolean | undefined | — | Renders the component as an inline block (inline-flex) instead of a block one. |
maxHeight | string | number | undefined | — | Maximum component height |
maxWidth | string | number | undefined | — | Maximum component width |
minHeight | string | number | undefined | — | Minimum component height |
minWidth | string | number | undefined | — | Minimum component width |
width | string | number | undefined | — | Component width |
Slots
| Name | Type | Description |
|---|---|---|
additional | any | Extra content rendered on top of the sizer, outside the content wrapper. |
default | any | The main content of the component, wrapped so the aspect ratio is kept. |