Media components
Components of the Media group of frame_demo_umami: pictures from Drupal's media library, logos and a video.
Gallery
components/gallery, React. Pictures in a grid or in columns of their own height, with captions; a click opens them large in a lightbox.
| Prop | |
|---|---|
heading | above the pictures |
images | the list: image (from the media library) and caption |
layout | Grid (every picture the same shape, cropped) or Columns (each its own height) |
shape | in the grid: square, landscape or portrait |
columns | 2–5 on a wide screen; phones show two, tablets three at most |
gap | a step of the theme's spacing scale |
lightbox | open large on a click |
captions | captions under the pictures; without, they show only in the lightbox |
Each picture is a prop of type: object with x-builder-widget: image, so the component gets more than a URL: url, alt (from the media item), width and height (no layout shift while loading). The server prints the pictures as links to themselves; React (index.jsx) turns them into buttons that open the lightbox.
The lightbox is a native <dialog> opened with showModal(): the focus stays inside it, Escape closes it, the arrow keys and a swipe move to the next and previous picture, the neighbours are loaded ahead, and the focus goes back to the picture that was opened. It works in the editor too.
Limitations. The grid and the lightbox use the same image style, the one chosen for each picture: choose a large one. Without pictures the gallery shows a placeholder.
$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
name: Gallery
status: experimental
description: 'Pictures from the media library in a grid or in columns of their own height, with captions. A click opens them large in a lightbox, browsed with the arrows, a swipe or the keyboard. React.'
group: Media
help: |
Add the pictures under Pictures; each can have a caption. The image style chosen for a picture is used for the grid and for the lightbox, so choose a large one.
The lightbox is a dialog: Escape closes it, the arrow keys move to the next and previous picture, and the focus goes back to the picture that was opened.
props:
type: object
properties:
heading:
type: string
title: Heading
examples: ['In the kitchen']
images:
type: array
title: Pictures
x-builder-summary: caption
items:
type: object
properties:
image:
type: object
title: Picture
x-builder-widget: image
properties: { url: { type: string }, alt: { type: string }, width: { type: integer }, height: { type: integer } }
caption:
type: string
title: Caption
examples: [[]]
layout:
type: string
title: Arrangement
enum: [grid, masonry]
meta:enum: { grid: 'Grid of the same shape', masonry: 'Columns, each picture its own height' }
examples: [grid]
shape:
type: string
title: 'Shape in the grid'
enum: [square, landscape, portrait]
meta:enum: { square: Square, landscape: Landscape, portrait: Portrait }
examples: [landscape]
columns:
type: integer
title: Columns
description: 'On a wide screen. Phones show two, tablets three at most.'
enum: [2, 3, 4, 5]
examples: [3]
gap:
type: string
title: 'Space between pictures'
x-builder-widget: length
examples: ['0.5rem']
lightbox:
type: boolean
title: 'Open large on a click'
examples: [true]
captions:
type: boolean
title: 'Captions under the pictures'
description: 'Without it captions show only in the lightbox.'
examples: [false]
thirdPartySettings:
frame_editor:
icon: image
example: { type: 'frame_demo_umami:gallery', props: { heading: 'In the kitchen', layout: masonry, columns: 3, lightbox: true, images: [ { image: { media: 12 }, caption: 'Fresh tagliatelle' }, { image: { media: 14 }, caption: 'The wood oven' } ] } }
libraryOverrides:
js:
../../assets/gallery.js: { attributes: { type: module } }
css:
theme:
../../assets/gallery.css: { }
dependencies:
- frame/react{#
/**
* @file
* Gallery. The server prints the pictures as links to themselves; React (index.jsx) opens them in a lightbox.
*/
#}
{% set images = images|default([])|filter(item => item.image.url is defined and item.image.url) %}
{% set data = { heading: heading, images: images, lightbox: lightbox is same as(false) ? false : true, captions: captions ? true : false } %}
<section {{ attributes.addClass('gallery', 'gallery--' ~ layout|default('grid'), 'gallery--' ~ shape|default('landscape'), 'gallery--cols-' ~ columns|default(3)).setAttribute('data-props', data|json_encode) }}>
{% if heading %}<h2 class="gallery__heading">{{ heading }}</h2>{% endif %}
{% if images %}
<ul class="gallery__items"{% if gap %} style="--gallery-gap: {{ gap }}"{% endif %}>
{% for item in images %}
<li class="gallery__item">
<figure>
<a class="gallery__open" href="{{ item.image.url }}">
<img src="{{ item.image.url }}" alt="{{ item.image.alt }}"{% if item.image.width %} width="{{ item.image.width }}" height="{{ item.image.height }}"{% endif %} loading="lazy">
</a>
{% if item.caption and captions %}<figcaption>{{ item.caption }}</figcaption>{% endif %}
</figure>
</li>
{% endfor %}
</ul>
{% else %}
<p class="gallery__empty"><i class="bi bi-images" aria-hidden="true"></i> {{ 'Add pictures to the gallery.'|t }}</p>
{% endif %}
</section>import { createRoot } from 'react-dom/client';
import { Gallery } from './Gallery';
import './gallery.scss';
(function (Drupal, once) {
const roots = new WeakMap();
const mount = (element) => {
const props = JSON.parse(element.dataset.props || '{}');
// The layout is the server's (CSS variables on the list); React keeps it.
const style = element.querySelector('.gallery__items')?.getAttribute('style') || '';
if (!props.images?.length) return;
const root = createRoot(element);
roots.set(element, root);
root.render(<Gallery {...props} listStyle={style} />);
};
Drupal.behaviors.frameDemoGallery = {
attach(context) {
once('react', '.gallery', context).forEach((element) => executeWhenVisible(element, mount, 'gallery'));
},
detach(context, settings, trigger) {
if (trigger !== 'unload') return;
once.remove('react', '.gallery', context).forEach((element) => roots.get(element)?.unmount());
},
};
})(Drupal, once);import { useCallback, useEffect, useRef, useState } from 'react';
/** "a: b; c: d" as a React style object, for the CSS variables the server set. */
export const parseStyle = (text = '') => Object.fromEntries(
text.split(';').map((part) => part.split(':').map((s) => s.trim())).filter(([key, value]) => key && value),
);
export function Lightbox({ images, index, onClose, onMove }) {
const dialog = useRef(null);
const touch = useRef(null);
const item = images[index];
const count = images.length;
useEffect(() => {
const element = dialog.current;
if (element.showModal && !element.open) element.showModal();
else element.setAttribute('open', '');
return () => element.close?.();
}, []);
// The neighbours load while this picture is looked at.
useEffect(() => {
[index - 1, index + 1].forEach((n) => {
const url = images[(n + count) % count]?.image?.url;
if (url) new Image().src = url;
});
}, [index]);
const onKeyDown = (event) => {
const step = { ArrowLeft: -1, ArrowRight: 1 }[event.key];
if (step) {
event.preventDefault();
onMove(document.dir === 'rtl' ? -step : step);
}
};
return (
<dialog
ref={dialog}
className="gallery__lightbox"
aria-label={Drupal.t('Picture @index of @count', { '@index': index + 1, '@count': count })}
onKeyDown={onKeyDown}
onCancel={(event) => { event.preventDefault(); onClose(); }}
onClick={(event) => { if (event.target === dialog.current) onClose(); }}
onTouchStart={(event) => { touch.current = event.touches[0].clientX; }}
onTouchEnd={(event) => {
const delta = event.changedTouches[0].clientX - (touch.current ?? event.changedTouches[0].clientX);
if (Math.abs(delta) > 50) onMove(delta < 0 ? 1 : -1);
}}
>
<figure className="gallery__large">
<img key={item.image.url} src={item.image.url} alt={item.image.alt || ''} />
<figcaption>
{item.caption && <span>{item.caption}</span>}
<span className="gallery__count" aria-hidden="true">{index + 1} / {count}</span>
</figcaption>
</figure>
{count > 1 && (
<>
<button type="button" className="gallery__nav gallery__nav--previous" onClick={() => onMove(-1)} aria-label={Drupal.t('Previous picture')}>
<i className="bi bi-chevron-left" aria-hidden="true" />
</button>
<button type="button" className="gallery__nav gallery__nav--next" onClick={() => onMove(1)} aria-label={Drupal.t('Next picture')}>
<i className="bi bi-chevron-right" aria-hidden="true" />
</button>
</>
)}
<button type="button" className="gallery__close" onClick={onClose} aria-label={Drupal.t('Close')} autoFocus>
<i className="bi bi-x-lg" aria-hidden="true" />
</button>
</dialog>
);
}
export function Gallery({ heading, images = [], lightbox = true, captions = false, listStyle = '' }) {
const [open, setOpen] = useState(null);
const openers = useRef([]);
const close = useCallback(() => {
const opener = openers.current[open];
setOpen(null);
// The focus goes back to the picture that was opened.
requestAnimationFrame(() => opener?.focus());
}, [open]);
const move = (step) => setOpen((current) => (current + step + images.length) % images.length);
return (
<>
{heading && <h2 className="gallery__heading">{heading}</h2>}
<ul className="gallery__items" style={parseStyle(listStyle)}>
{images.map((item, index) => {
const picture = <img src={item.image.url} alt={item.image.alt || ''} width={item.image.width} height={item.image.height} loading="lazy" />;
return (
<li className="gallery__item" key={index}>
<figure>
{lightbox
? (
<button type="button" className="gallery__open" ref={(element) => { openers.current[index] = element; }} onClick={() => setOpen(index)} aria-haspopup="dialog" aria-label={item.image.alt || item.caption || Drupal.t('Picture @index', { '@index': index + 1 })}>
{picture}
<span className="gallery__zoom" aria-hidden="true"><i className="bi bi-arrows-fullscreen" /></span>
</button>
)
: picture}
{captions && item.caption && <figcaption>{item.caption}</figcaption>}
</figure>
</li>
);
})}
</ul>
{open !== null && <Lightbox images={images} index={open} onClose={close} onMove={move} />}
</>
);
}@use 'frame/tokens' as frame;
.gallery {
--gallery-gap: #{frame.space(s)};
--gallery-accent: var(--frame-accent, #{frame.color(green)});
margin-block: 0 frame.space(l);
}
.gallery__heading { margin: 0 0 frame.space(m); }
.gallery__items {
--gallery-n: 2;
display: grid;
grid-template-columns: repeat(var(--gallery-n), minmax(0, 1fr));
gap: var(--gallery-gap);
margin: 0;
padding: 0;
list-style: none;
@include frame.breakpoint(tablet) {
.gallery:not(.gallery--cols-2) & { --gallery-n: 3; }
}
@include frame.breakpoint(desktop) {
.gallery--cols-4 & { --gallery-n: 4; }
.gallery--cols-5 & { --gallery-n: 5; }
}
}
.gallery__item figure { margin: 0; }
.gallery__item figcaption { margin-top: 0.4rem; font-size: 0.875rem; opacity: 0.8; }
.gallery__open {
position: relative;
display: block;
width: 100%;
padding: 0;
overflow: hidden;
border: 0;
border-radius: 0.5rem;
background: rgb(0 0 0 / 5%);
cursor: zoom-in;
img { display: block; width: 100%; height: auto; transition: transform 0.4s ease; }
&:hover img { transform: scale(1.04); }
&:focus-visible { outline: 3px solid color-mix(in srgb, var(--gallery-accent) 50%, transparent); outline-offset: 2px; }
}
.gallery__zoom {
position: absolute;
inset-block-end: 0.5rem;
inset-inline-end: 0.5rem;
display: grid;
place-items: center;
width: 2rem;
height: 2rem;
border-radius: 50%;
background: rgb(0 0 0 / 55%);
color: #fff;
font-size: 0.85rem;
opacity: 0;
transition: opacity 0.2s;
.gallery__open:is(:hover, :focus-visible) & { opacity: 1; }
}
// Grid: every picture the same shape, cropped.
.gallery--grid .gallery__open img { aspect-ratio: 3 / 2; object-fit: cover; }
.gallery--grid.gallery--square .gallery__open img { aspect-ratio: 1; }
.gallery--grid.gallery--portrait .gallery__open img { aspect-ratio: 3 / 4; }
// Columns: each picture its own height.
.gallery--masonry .gallery__items {
display: block;
columns: var(--gallery-n);
column-gap: var(--gallery-gap);
}
.gallery--masonry .gallery__item {
break-inside: avoid;
margin-bottom: var(--gallery-gap);
}
.gallery__empty {
display: grid;
place-items: center;
min-height: 10rem;
margin: 0;
border: 2px dashed rgb(0 0 0 / 15%);
border-radius: 0.75rem;
opacity: 0.7;
}
.gallery__lightbox {
width: 100vw;
max-width: none;
height: 100dvh;
max-height: none;
margin: 0;
padding: 0;
border: 0;
background: rgb(10 10 10 / 92%);
color: #fff;
&::backdrop { background: transparent; }
}
.gallery__large {
display: grid;
grid-template-rows: minmax(0, 1fr) auto;
place-items: center;
height: 100%;
margin: 0;
padding: 3.5rem 4rem 1rem;
box-sizing: border-box;
pointer-events: none;
img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
border-radius: 0.25rem;
animation: gallery-in 0.25s ease;
pointer-events: auto;
}
figcaption {
display: flex;
gap: 1rem;
justify-content: center;
padding-top: 0.75rem;
font-size: 0.95rem;
}
}
.gallery__count { opacity: 0.7; font-variant-numeric: tabular-nums; }
.gallery__nav,
.gallery__close {
position: absolute;
display: grid;
place-items: center;
width: 3rem;
height: 3rem;
padding: 0;
border: 1px solid rgb(255 255 255 / 35%);
border-radius: 50%;
background: rgb(255 255 255 / 10%);
color: #fff;
font-size: 1.25rem;
cursor: pointer;
&:hover { background: rgb(255 255 255 / 22%); }
&:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
}
.gallery__nav { top: calc(50% - 1.5rem); }
.gallery__nav--previous { inset-inline-start: 0.75rem; }
.gallery__nav--next { inset-inline-end: 0.75rem; }
.gallery__close { top: 0.75rem; inset-inline-end: 0.75rem; }
[dir='rtl'] .gallery__nav .bi { transform: scaleX(-1); }
@media (max-width: 47.99em) {
.gallery__large { padding-inline: 0.5rem; }
.gallery__nav { top: auto; bottom: 0.75rem; }
}
@keyframes gallery-in {
from { opacity: 0; transform: scale(0.98); }
}
@media (prefers-reduced-motion: reduce) {
.gallery__open img, .gallery__large img { transition: none; animation: none; }
}Gallery item and Gallery grid
components/gallery-item and components/gallery-grid. A picture with a caption, cropped to a shape (square, landscape, portrait or original), and a grid that wraps a list of them. There is no lightbox: for that use the Gallery above. They are made for a media field: Show as: Components, Item component: Gallery item, Wrapper: Gallery grid (Fields with many values).
| Prop | |
|---|---|
image, caption | Gallery item: the picture and the text under it |
ratio, rounded | Gallery item: the shape and the corners |
columns, gap | Gallery grid: the most columns, and the space between |
The grid takes its number of columns from the width of the place it is in (container queries, as the carousel does), not from the screen, so it works in a narrow column of a page and in a card. The slot of the grid is items; listWrapper in its component file makes it a wrapper for lists.
$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
name: Gallery item
status: experimental
description: 'A picture with a caption in a shape you choose (square, landscape, portrait), cropped to fill it. One item of a gallery, no lightbox.'
group: Media
help: |
Made for the items of a media field: in the settings of the Field block choose Show as: Components, then Gallery item, and Wrapper: Gallery grid. Choose an image style that is large enough for the biggest column.
The picture is cropped to the shape. Choose Original to keep its own proportions.
props:
type: object
properties:
image:
type: string
title: Image
description: 'Picked from the media library.'
contentMediaType: 'image/*'
x-builder-picture: image_picture
# The parts of the image, for a template that writes the <img> itself (without Frame's markup).
x-builder-srcset: srcset
x-builder-sizes: sizes
x-builder-alt: alt
x-builder-width: width
x-builder-height: height
image_picture:
type: string
title: Image markup
description: 'Filled by Frame: the image as Drupal renders it.'
x-builder-widget: hidden
srcset:
type: string
title: Image srcset
description: 'Filled by Frame for a responsive image style.'
x-builder-widget: hidden
sizes:
type: string
title: Image sizes
description: 'Filled by Frame for a responsive image style.'
x-builder-widget: hidden
width:
type: integer
title: Image width
description: 'Filled by Frame: the width of the image shown.'
x-builder-widget: hidden
height:
type: integer
title: Image height
description: 'Filled by Frame: the height of the image shown.'
x-builder-widget: hidden
alt:
type: string
title: Alternative text
description: 'Filled by Frame from the media item or the image field.'
x-builder-widget: hidden
caption:
type: string
title: Caption
ratio:
type: string
title: Shape
enum: [square, landscape, portrait, original]
meta:enum: { square: Square, landscape: Landscape, portrait: Portrait, original: Original }
examples: [landscape]
fit:
type: string
title: Fit
description: 'How the picture fills its box when the box has other proportions. Like CSS object-fit. Cover fills the box and crops, Contain shows all of it, Fill stretches it, None keeps its size, Scale down is None or Contain, the smaller.'
enum: [auto, cover, contain, fill, none, scale-down]
meta:enum: { auto: Automatic, cover: Cover, contain: Contain, fill: Fill, none: None, scale-down: Scale down }
examples: [auto]
position:
type: string
title: Position
description: 'Which part of the picture stays in view when it is cropped or smaller than its box. Like CSS object-position.'
enum: [center, top, bottom, left, right]
meta:enum: { center: Center, top: Top, bottom: Bottom, left: Left, right: Right }
examples: [center]
x-builder-show-when: { fit: [cover, contain, none, scale-down] }
rounded:
type: boolean
title: 'Rounded corners'
examples: [true]
thirdPartySettings:
frame_editor:
icon: image
provides: [image, media]
item: [image, media]
example: { type: 'frame_demo_umami:gallery-item', props: { image: { media: 12 }, caption: 'Tagliatelle', ratio: landscape, rounded: true } }$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
name: Gallery grid
status: experimental
description: 'A responsive grid for pictures: the number of columns follows the width of the place it is in, not the screen. The wrapper for a list of Gallery items.'
group: Layout
help: |
Put Gallery items (or Images, Cards) into Items. The columns shown at most are set with Columns; a narrow place shows fewer. All rows have the same height as their tallest item, with no masonry.
In a Field block, choose Show as: Components and Wrapper: Gallery grid.
props:
type: object
properties:
columns:
type: integer
title: Columns
description: 'In a wide place. A narrower one shows fewer, down to one.'
enum: [2, 3, 4, 5]
examples: [3]
gap:
type: string
title: Gap
description: 'Space between the items.'
x-builder-widget: length
examples: ['1rem']
slots:
items:
title: Items
description: 'One block per cell.'
thirdPartySettings:
frame_editor:
icon: columns
listWrapper: { slot: items, props: { columns: 3 } }
example: { type: 'frame_demo_umami:gallery-grid', props: { columns: 3, gap: '1rem', items: [ { type: 'frame_demo_umami:gallery-item', props: { image: { media: 12 }, caption: 'Pasta' } }, { type: 'frame_demo_umami:gallery-item', props: { image: { media: 14 }, caption: 'Bread' } } ] } }/* Gallery grid: one column, two from 24em, up to the chosen number from 44em of the width of the container. */
.gallery-grid { container-type: inline-size; --grid-gap: var(--frame-space-m, 1rem); }
.gallery-grid__items { --grid-n: 1; display: grid; grid-template-columns: repeat(var(--grid-n), minmax(0, 1fr)); gap: var(--grid-gap); }
@container (min-width: 24em) { .gallery-grid__items { --grid-n: min(2, var(--grid-k)); } }
@container (min-width: 36em) { .gallery-grid__items { --grid-n: var(--grid-k-tablet); } }
@container (min-width: 48em) { .gallery-grid__items { --grid-n: var(--grid-k); } }Logo cloud
components/logo-cloud. Logos of partners, clients or press, in rows or as a band that scrolls by itself.
| Prop | |
|---|---|
heading | a short line above the logos |
logos | the list: name, logo (an image object), url |
mode | In rows or Scrolling band |
speed | of the band |
muted | grey until hovered |
logo_height | a length of the theme's scale |
A name without a logo is shown as a word mark in the display font of the theme, so the component looks right before the logos are uploaded. The band is CSS only: the list is printed twice (the copy hidden from screen readers and out of the tab order) and moves by the width of one. It stops while the pointer or the focus is on it, moves the other way in right-to-left languages, and becomes rows for visitors who prefer less motion.
Uses images in a list, a Twig macro, Width (Full width makes the band reach the edges of the page).
$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
name: 'Logo cloud'
status: experimental
description: 'Logos of partners, clients or press, in a row or as a band that scrolls by itself. A name without a logo is shown as a word mark.'
group: Media
props:
type: object
properties:
heading:
type: string
title: Heading
description: 'A short line above the logos: "As seen in".'
examples: ['Our partners']
logos:
type: array
title: Logos
x-builder-summary: name
minItems: 1
items:
type: object
properties:
name:
type: string
title: Name
description: 'The alternative text of the logo, or the word mark when there is no logo.'
examples: ['Partner']
logo:
type: object
title: Logo
x-builder-widget: image
properties: { url: { type: string }, alt: { type: string }, width: { type: integer }, height: { type: integer } }
url:
type: string
title: Link
format: uri-reference
required: [name]
examples:
- - { name: 'Mercato Centrale' }
- { name: 'Forno Rossi' }
- { name: 'La Cucina' }
- { name: 'Caseificio Alpino' }
- { name: 'Olio Verde' }
- { name: 'Vino & Co' }
mode:
type: string
title: Arrangement
description: 'A band that scrolls stops while the pointer or the keyboard is on it, and stands still for visitors who prefer less motion.'
enum: [row, marquee]
meta:enum: { row: 'In rows', marquee: 'Scrolling band' }
examples: [marquee]
speed:
type: string
title: Speed
enum: [slow, normal, fast]
meta:enum: { slow: Slow, normal: Normal, fast: Fast }
examples: [normal]
muted:
type: boolean
title: 'Grey until hovered'
examples: [true]
logo_height:
type: string
title: 'Height of the logos'
x-builder-widget: length
examples: ['2.5rem']
required: [logos]
thirdPartySettings:
frame_editor:
icon: 'bi bi-buildings'
example: { type: 'frame_demo_umami:logo-cloud', props: { heading: 'As seen in', mode: marquee, speed: slow, muted: true, logos: [ { name: 'Gazzetta del Gusto', logo: { media: 21 } }, { name: 'Cucina Oggi' } ], _width: full } }{#
/**
* @file
* Logo cloud. The scrolling band repeats the list once, hidden from screen readers, so that it loops without a gap.
*/
#}
{% import _self as cloud %}
{% set mode = mode|default('marquee') %}
{% macro logo(item, copy) %}
{% set mark %}
{%- if item.logo.url -%}
<img src="{{ item.logo.url }}" alt="{{ copy ? '' : item.name }}"{% if item.logo.width %} width="{{ item.logo.width }}"{% endif %}{% if item.logo.height %} height="{{ item.logo.height }}"{% endif %} loading="lazy">
{%- else -%}
<span class="logo-cloud__wordmark">{{ item.name }}</span>
{%- endif -%}
{% endset %}
<li class="logo-cloud__item">
{%- if item.url %}<a href="{{ item.url }}"{% if copy %} tabindex="-1"{% endif %}>{{ mark }}</a>{% else %}{{ mark }}{% endif -%}
</li>
{% endmacro %}
<section {{ attributes.addClass('logo-cloud', 'logo-cloud--' ~ mode, 'logo-cloud--' ~ speed|default('normal'), muted is same as(false) ? null : 'logo-cloud--muted') }}>
{% if heading %}<h2 class="logo-cloud__heading">{{ heading }}</h2>{% endif %}
<div class="logo-cloud__viewport"{% if logo_height %} style="--logo-height: {{ logo_height }}"{% endif %}>
<div class="logo-cloud__track">
<ul class="logo-cloud__list">
{% for item in logos %}{{ cloud.logo(item, false) }}{% endfor %}
</ul>
{% if mode == 'marquee' %}
<ul class="logo-cloud__list logo-cloud__list--copy" aria-hidden="true">
{% for item in logos %}{{ cloud.logo(item, true) }}{% endfor %}
</ul>
{% endif %}
</div>
</div>
</section>.logo-cloud { --logo-gap: clamp(2rem, 5vw, 4rem); --logo-duration: 40s; margin-block: 0 var(--frame-space-l, 2rem); }
.logo-cloud--slow { --logo-duration: 60s; }
.logo-cloud--fast { --logo-duration: 22s; }
.logo-cloud__viewport { --logo-height: 2.5rem; }
.logo-cloud__heading { margin: 0 0 var(--frame-space-m, 1rem); font-family: var(--font-body, inherit); font-size: 0.8125rem; font-weight: 700; letter-spacing: 0.12em; text-align: center; text-transform: uppercase; opacity: 0.7; }
.logo-cloud__list { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--frame-space-m, 1rem) var(--logo-gap); margin: 0; padding: 0; list-style: none; }
.logo-cloud__item { display: flex; flex: none; align-items: center; }
.logo-cloud__item a { display: flex; align-items: center; color: inherit; text-decoration: none; }
.logo-cloud__item img { display: block; width: auto; height: var(--logo-height); max-width: 10rem; object-fit: contain; }
.logo-cloud__wordmark { display: block; font-family: var(--font-display, serif); font-size: calc(var(--logo-height) * 0.6); line-height: var(--logo-height); white-space: nowrap; }
.logo-cloud--muted .logo-cloud__item { opacity: 0.6; filter: grayscale(1); transition: opacity 0.2s, filter 0.2s; }
.logo-cloud--muted .logo-cloud__item:is(:hover, :focus-within) { opacity: 1; filter: none; }
.logo-cloud__item a:focus-visible { outline: 3px solid color-mix(in srgb, var(--frame-accent, #008068) 40%, transparent); outline-offset: 4px; border-radius: 0.25rem; }
/* Scrolling band: two copies of the list move by the width of one. */
.logo-cloud--marquee .logo-cloud__viewport { overflow: hidden; mask-image: linear-gradient(to right, transparent, #000 8%, #000 92%, transparent); }
.logo-cloud--marquee .logo-cloud__track { display: flex; width: max-content; animation: logo-cloud-scroll var(--logo-duration) linear infinite; }
.logo-cloud--marquee .logo-cloud__list { flex-wrap: nowrap; padding-inline-end: var(--logo-gap); }
.logo-cloud--marquee:is(:hover, :focus-within) .logo-cloud__track { animation-play-state: paused; }
[dir="rtl"] .logo-cloud { --logo-shift: 50%; }
@keyframes logo-cloud-scroll {
to { transform: translateX(var(--logo-shift, -50%)); }
}
@media (prefers-reduced-motion: reduce) {
.logo-cloud--marquee .logo-cloud__viewport { mask-image: none; }
.logo-cloud--marquee .logo-cloud__track { width: auto; animation: none; }
.logo-cloud--marquee .logo-cloud__list { flex-wrap: wrap; padding: 0; }
.logo-cloud__list--copy { display: none; }
}Hero with video
components/media-hero. The opening of a page over a silent looping video or a picture.
| Prop | |
|---|---|
eyebrow, heading, text | the text; the eyebrow is a pill above the heading |
image | a picture from the media library, as Drupal renders it (x-builder-picture): with a responsive image style it is a <picture> |
video | the address of an MP4 file: muted, looping, plays by itself |
shade, shade_color | a tint over the picture, in a colour of the theme, for readable text |
height | medium, tall, or as tall as the screen |
align | text at the start or centred |
scroll_cue | an arrow that scrolls past the hero |
slot actions | buttons |
The picture is the poster of the video: it shows until the video plays, on slow connections, and for visitors who prefer less motion. media-hero.js adds a pause button (a video that moves for more than five seconds needs one, WCAG 2.2.2) and keeps the video still for those visitors. With neither picture nor video the hero is a gradient of the accent colour.
Uses a responsive picture, a URL field, the colour widget, a slot, Width (Full width), and a style of its own on an inner element so that the features of Layout and style stay on the root element.
Limitations. The video is a file address, not a media item, and has no captions: use it for mood, not for content.
$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
name: 'Hero with video'
status: experimental
description: 'The opening of a page over a silent looping video or a picture, with a tinted shade in a colour of the theme, a line above the heading and buttons. A pause button stops the video.'
group: Media
help: |
Give it a picture, a video, or both: the picture is shown until the video plays, on slow connections, and for visitors who prefer less motion.
The video is a link to an MP4 file (for example uploaded to the files of the site). It has no sound and loops; keep it short and small. Set Width to Full width to reach the edges of the page.
props:
type: object
properties:
eyebrow:
type: string
title: 'Line above the heading'
examples: ['New season']
heading:
type: string
title: Heading
examples: ['Cook the Italian way']
heading_level:
type: string
title: 'Heading level'
description: 'The rank of the heading in the outline of the page, for search engines and screen readers. Keep the levels in order and use one Heading 1 per page. It does not change how large the heading looks.'
enum: [h1, h2, h3, h4, h5, h6]
meta:enum: { h1: 'Heading 1 (page title)', h2: 'Heading 2 (section)', h3: 'Heading 3 (sub-section)', h4: 'Heading 4', h5: 'Heading 5', h6: 'Heading 6' }
examples: [h1]
text:
type: string
title: Text
x-builder-widget: textarea
examples: ['Hands-on classes with the chefs of Milan, every evening of the week.']
image:
type: string
title: Picture
description: 'Behind the text, and the first frame of the video.'
contentMediaType: 'image/*'
x-builder-picture: image_picture
image_picture:
type: string
title: 'Picture markup'
x-builder-widget: hidden
video:
type: string
title: 'Video (MP4)'
description: 'Address of an MP4 file. Silent, looping, plays by itself.'
format: uri-reference
shade:
type: string
title: Shade
description: 'How much the colour covers the picture: more shade, more readable text.'
enum: [none, light, medium, strong]
meta:enum: { none: None, light: Light, medium: Medium, strong: Strong }
examples: [medium]
shade_color:
type: string
title: 'Shade colour'
description: 'A colour of the theme. Without one, black.'
x-builder-widget: color
height:
type: string
title: Height
enum: [m, l, screen]
meta:enum: { m: Medium, l: Tall, screen: 'As tall as the screen' }
examples: [l]
align:
type: string
title: 'Text position'
enum: [start, center]
meta:enum: { start: 'At the start', center: Centred }
examples: [center]
scroll_cue:
type: boolean
title: 'Arrow to scroll down'
examples: [false]
required: [heading]
slots:
actions:
title: Actions
description: 'Buttons under the text.'
thirdPartySettings:
frame_editor:
icon: video
example: { type: 'frame_demo_umami:media-hero', props: { eyebrow: 'New season', heading: 'Cook the Italian way', text: 'Hands-on classes with the chefs of Milan.', image: { media: 12 }, video: '/sites/default/files/kitchen.mp4', shade: medium, shade_color: green, height: l, align: center, _width: full, actions: [ { type: 'frame:button', props: { label: 'Book a class', url: '/classes', variant: primary, size: l } } ] } }
libraryOverrides:
dependencies:
- core/drupal
- core/once{#
/**
* @file
* Hero with video: a picture and a muted looping video behind the text. media-hero.js adds the pause button and
* keeps the video still for visitors who prefer less motion.
*/
#}
{% set heading_tag = heading_level in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] ? heading_level : 'h1' %}
{% set has_media = image_picture or image or video %}
<section {{ attributes.addClass('media-hero', 'media-hero--' ~ height|default('l'), 'media-hero--align-' ~ align|default('center'), 'media-hero--shade-' ~ (has_media ? shade|default('medium') : 'none'), has_media ? null : 'media-hero--plain').setAttribute('data-media-hero', '') }}>
<div class="media-hero__media">
{% if image_picture %}
{{ image_picture }}
{% elseif image %}
<img src="{{ image }}" alt="">
{% endif %}
{% if video %}
<video class="media-hero__video" src="{{ video }}"{% if image %} poster="{{ image }}"{% endif %} autoplay muted loop playsinline preload="metadata" aria-hidden="true"></video>
{% endif %}
{# The shade is an element of its own: the root element's style belongs to the features of Frame. #}
<div class="media-hero__shade"{% if shade_color %} style="--media-hero-shade: {{ shade_color }}"{% endif %}></div>
</div>
<div class="media-hero__inner">
{% if eyebrow %}<p class="media-hero__eyebrow">{{ eyebrow }}</p>{% endif %}
<{{ heading_tag }} class="media-hero__heading">{{ heading }}</{{ heading_tag }}>
{% if text %}<p class="media-hero__text">{{ text }}</p>{% endif %}
<div class="media-hero__actions">{% block actions %}{% endblock %}</div>
</div>
{% if video %}
<button type="button" class="media-hero__pause" data-media-hero-pause hidden aria-pressed="false">
<i class="bi bi-pause-fill" aria-hidden="true"></i><span class="visually-hidden">{{ 'Pause the video'|t }}</span>
</button>
{% endif %}
{% if scroll_cue %}
<a class="media-hero__cue" href="#after-hero" data-media-hero-cue><i class="bi bi-chevron-down" aria-hidden="true"></i><span class="visually-hidden">{{ 'Scroll to the content'|t }}</span></a>
{% endif %}
</section>/**
* @file
* Hero with video: the pause button (WCAG 2.2.2), less motion, and the arrow that scrolls past the hero.
*/
((Drupal, once) => {
function init(root) {
const video = root.querySelector('.media-hero__video');
const pause = root.querySelector('[data-media-hero-pause]');
if (video && pause) {
const label = pause.querySelector('.visually-hidden');
const icon = pause.querySelector('.bi');
const show = (playing) => {
pause.setAttribute('aria-pressed', String(!playing));
label.textContent = playing ? Drupal.t('Pause the video') : Drupal.t('Play the video');
icon.className = `bi bi-${playing ? 'pause-fill' : 'play-fill'}`;
};
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
video.pause();
video.removeAttribute('autoplay');
}
video.addEventListener('play', () => show(true));
video.addEventListener('pause', () => show(false));
pause.addEventListener('click', () => (video.paused ? video.play() : video.pause()));
show(!video.paused);
pause.hidden = false;
}
const cue = root.querySelector('[data-media-hero-cue]');
if (cue) {
cue.addEventListener('click', (event) => {
event.preventDefault();
const next = root.nextElementSibling || root.parentElement.nextElementSibling;
const top = next ? next.getBoundingClientRect().top + window.scrollY : root.getBoundingClientRect().bottom + window.scrollY;
window.scrollTo({ top, behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth' });
});
}
}
Drupal.behaviors.frameDemoMediaHero = {
attach(context) {
once('frame-demo-media-hero', '[data-media-hero]', context).forEach(init);
},
};
})(Drupal, once);