Direction-Aware Hover
Tiles whose caption, or a second photo, slides in from the edge the pointer comes from and leaves by the edge it goes out. The keyboard opens it from the bottom; on touch the caption sits under the photo.
View codeFull-height photo panels side by side: the one you hover, focus or tap widens as the others close in, its spine title slides away and rises upright with a line of text and a link. Stacked when narrow.
With your AI
Say it to your AI. It gets the exact code below, not its best guess, and knows where it goes.
Add the Kodza Expanding Panels to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-expanding-panels">
<ul class="kodza-expanding-panels__list">
<li class="kodza-expanding-panels__panel is-open">
<div class="kodza-expanding-panels__frame">
<img class="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-table-1400.webp" width="1400" height="1050" alt="A white table set with two glasses and a bottle, facing a misty sea with a sailboat" loading="lazy">
<button class="kodza-expanding-panels__toggle" type="button" aria-expanded="true">
<span class="kodza-expanding-panels__spine"><span class="kodza-expanding-panels__index">01</span> Étretat</span>
</button>
<div class="kodza-expanding-panels__content">
<h3 class="kodza-expanding-panels__title">Étretat</h3>
<p class="kodza-expanding-panels__meta">Normandy · 2 guests · €140 / night</p>
<p class="kodza-expanding-panels__text">A table, two glasses, the sea. The listing says what's in the photo.</p>
<a class="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li class="kodza-expanding-panels__panel">
<div class="kodza-expanding-panels__frame">
<img class="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-block-1400.webp" width="1120" height="1400" alt="A tall concrete slab standing alone on a bare floor" loading="lazy">
<button class="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span class="kodza-expanding-panels__spine"><span class="kodza-expanding-panels__index">02</span> Alentejo</span>
</button>
<div class="kodza-expanding-panels__content">
<h3 class="kodza-expanding-panels__title">Alentejo</h3>
<p class="kodza-expanding-panels__meta">Portugal · 4 guests · €120 / night</p>
<p class="kodza-expanding-panels__text">One wall, no neighbours. Silence is not an extra on the bill.</p>
<a class="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li class="kodza-expanding-panels__panel">
<div class="kodza-expanding-panels__frame">
<img class="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-columns-1400.webp" width="1120" height="1400" alt="A row of square concrete pillars under a flat roof, casting striped shadows" loading="lazy">
<button class="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span class="kodza-expanding-panels__spine"><span class="kodza-expanding-panels__index">03</span> Seville</span>
</button>
<div class="kodza-expanding-panels__content">
<h3 class="kodza-expanding-panels__title">Seville</h3>
<p class="kodza-expanding-panels__meta">Andalusia · 6 guests · €260 / night</p>
<p class="kodza-expanding-panels__text">Forty pillars of shade. At 4 pm, you'll want every one.</p>
<a class="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li class="kodza-expanding-panels__panel">
<div class="kodza-expanding-panels__frame">
<img class="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-gap-1400.webp" width="1400" height="583" alt="Two concrete walls with a narrow gap between them, light falling through" loading="lazy">
<button class="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span class="kodza-expanding-panels__spine"><span class="kodza-expanding-panels__index">04</span> Copenhagen</span>
</button>
<div class="kodza-expanding-panels__content">
<h3 class="kodza-expanding-panels__title">Copenhagen</h3>
<p class="kodza-expanding-panels__meta">Denmark · 3 guests · €210 / night</p>
<p class="kodza-expanding-panels__text">Two walls, one gap. The light comes through at noon, no smart bulb required.</p>
<a class="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li class="kodza-expanding-panels__panel">
<div class="kodza-expanding-panels__frame">
<img class="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-arch-1400.webp" width="1400" height="1400" alt="A concrete wall with a round-topped opening, sunlight pouring through it" loading="lazy">
<button class="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span class="kodza-expanding-panels__spine"><span class="kodza-expanding-panels__index">05</span> Tangier</span>
</button>
<div class="kodza-expanding-panels__content">
<h3 class="kodza-expanding-panels__title">Tangier</h3>
<p class="kodza-expanding-panels__meta">Morocco · 4 guests · €190 / night</p>
<p class="kodza-expanding-panels__text">One arch, facing west. Sunset included, no upgrade needed.</p>
<a class="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
</ul>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Expanding Panels
Full-height photo panels side by side, one open at a time: hover or focus one and it widens
while the others close in, each photo recropped, never stretched. The title lying on its
spine slides away as the same title rises upright from its mask, with a line of text and a
link. Stacked in narrow containers: the open panel grows in height.
Tuned with the --kz-expanding-panels-* variables; the script's timing sits under its SELECTOR. */
.kodza-expanding-panels {
--kz-expanding-panels-height: 520px; /* side by side */
--kz-expanding-panels-grow: 4; /* the open panel, against 1 for a closed one */
--kz-expanding-panels-gap: 8px;
--kz-expanding-panels-strip: 72px; /* a closed panel, stacked (under 600px of container) */
--kz-expanding-panels-open-height: 380px; /* the open panel, stacked */
--kz-expanding-panels-pad: 24px; /* title and text, from the photo's edges */
--kz-expanding-panels-radius: calc(16px * var(--kz-radius-scale, 1));
--kz-expanding-panels-bg: #1c1c1c; /* behind a photo still loading */
--kz-expanding-panels-fg: #ffffff;
--kz-expanding-panels-muted: rgba(255, 255, 255, 0.86);
--kz-expanding-panels-veil: rgba(10, 10, 10, 0.3); /* over a closed photo */
--kz-expanding-panels-shade: rgba(10, 10, 10, 0.72); /* at the foot of every photo, under the text */
--kz-expanding-panels-link-bg: #ffffff;
--kz-expanding-panels-link-fg: #0a0a0a;
--kz-expanding-panels-focus: #0a0a0a;
--kz-expanding-panels-line: transparent; /* a hairline round each photo, for dark photos on a dark page */
container: kodza-expanding-panels / inline-size;
}
.kodza-expanding-panels__list {
display: flex;
gap: var(--kz-expanding-panels-gap);
height: var(--kz-expanding-panels-height);
margin: 0;
padding: 0;
list-style: none;
}
/* The panel holds the place; only its frame takes the pointer, so a panel that slides under
a resting pointer never opens by itself */
.kodza-expanding-panels__panel {
position: relative;
flex: 1 1 0;
min-width: 0;
margin: 0;
padding: 0;
pointer-events: none;
}
.kodza-expanding-panels__panel.is-open {
flex-grow: var(--kz-expanding-panels-grow);
}
/* The script slides and resizes the frame from its old place to its new one */
.kodza-expanding-panels__frame {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
border-radius: var(--kz-expanding-panels-radius);
background: var(--kz-expanding-panels-bg);
pointer-events: auto;
}
.kodza-expanding-panels__frame:has(.kodza-expanding-panels__toggle:focus-visible) {
outline: 2px solid var(--kz-expanding-panels-focus);
outline-offset: 3px;
}
.kodza-expanding-panels__image {
display: block;
width: 100%;
max-width: none;
height: 100%;
object-fit: cover;
}
/* The veil darkens the closed photos and lifts off the open one; the shade keeps the text
readable at the foot of every photo */
.kodza-expanding-panels__frame::before,
.kodza-expanding-panels__frame::after {
content: "";
position: absolute;
inset: 0;
pointer-events: none;
}
.kodza-expanding-panels__frame::before {
background: var(--kz-expanding-panels-veil);
transition: opacity calc(0.5s * var(--kz-motion-scale, 1)) ease;
}
.kodza-expanding-panels__frame::after {
border-radius: inherit;
background: linear-gradient(to top, var(--kz-expanding-panels-shade), var(--kz-expanding-panels-shade) 22%, transparent 78%);
box-shadow: inset 0 0 0 1px var(--kz-expanding-panels-line);
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__frame::before {
opacity: 0;
}
/* The button covers the whole photo: hover, focus or tap it to open the panel */
.kodza-expanding-panels__toggle {
position: absolute;
inset: 0;
z-index: 1;
display: block;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
border-radius: 0;
background: transparent;
color: var(--kz-expanding-panels-fg);
font: inherit;
text-align: left;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.kodza-expanding-panels__toggle:focus-visible {
outline: none;
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__toggle {
cursor: default;
}
/* The title on the spine, read bottom to top like the back of a book. Opening, it slides out
past the photo's edge; closing, it comes back once the panel has closed in */
.kodza-expanding-panels__spine {
position: absolute;
bottom: var(--kz-expanding-panels-pad);
left: var(--kz-expanding-panels-pad);
display: block;
writing-mode: vertical-rl;
transform: rotate(180deg);
font-family: var(--kz-font-display, inherit);
font-size: calc(20px * var(--kz-font-display-scale, 1));
font-weight: var(--kz-font-display-weight, 500);
letter-spacing: var(--kz-font-display-tracking, -0.02em);
text-transform: var(--kz-font-display-case, inherit);
line-height: 1;
white-space: nowrap;
transition:
translate calc(0.5s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1) calc(0.2s * var(--kz-motion-scale, 1)),
opacity 0s linear calc(0.2s * var(--kz-motion-scale, 1));
}
.kodza-expanding-panels__index {
margin-bottom: 4px;
color: var(--kz-expanding-panels-muted);
font-family: var(--kz-font-label, var(--kz-font-mono, ui-monospace, "SF Mono", Menlo, monospace));
font-size: var(--kz-font-label-size, 11px);
font-weight: var(--kz-font-label-weight, 400);
letter-spacing: var(--kz-font-label-tracking, 0);
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__spine {
translate: calc(-100% - var(--kz-expanding-panels-pad) - 4px) 0;
opacity: 0;
transition:
translate calc(0.35s * var(--kz-motion-scale, 1)) cubic-bezier(0.65, 0, 0.35, 1),
opacity 0s linear calc(0.35s * var(--kz-motion-scale, 1));
}
/* The text, as wide as an open panel (--kz-expanding-panels-open, measured by the script):
it never rewraps while the panel grows, the panel's edge uncovers it */
.kodza-expanding-panels__content {
position: absolute;
bottom: var(--kz-expanding-panels-pad);
left: var(--kz-expanding-panels-pad);
z-index: 2;
width: calc(var(--kz-expanding-panels-open, 100%) - 2 * var(--kz-expanding-panels-pad));
box-sizing: border-box;
color: var(--kz-expanding-panels-fg);
visibility: hidden;
pointer-events: none;
transition: visibility 0s linear calc(0.2s * var(--kz-motion-scale, 1));
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__content {
visibility: visible;
transition-delay: 0s;
}
/* Each block rises from behind its own mask, one after the other (the clip moves with it:
together they show the block's final box only) */
.kodza-expanding-panels__content > * {
transform: translateY(100%);
clip-path: inset(-10px -20px 100% -20px);
transition:
transform calc(0.18s * var(--kz-motion-scale, 1)) cubic-bezier(0.65, 0, 0.35, 1),
clip-path calc(0.18s * var(--kz-motion-scale, 1)) cubic-bezier(0.65, 0, 0.35, 1);
}
.kodza-expanding-panels__content > :nth-child(2) {
--kz-expanding-panels-step: 1;
}
.kodza-expanding-panels__content > :nth-child(3) {
--kz-expanding-panels-step: 2;
}
.kodza-expanding-panels__content > :nth-child(4) {
--kz-expanding-panels-step: 3;
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__content > * {
transform: none;
clip-path: inset(-10px -20px -10px -20px);
transition:
transform calc(0.6s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1) calc((0.3s + var(--kz-expanding-panels-step, 0) * 0.07s) * var(--kz-motion-scale, 1)),
clip-path calc(0.6s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1) calc((0.3s + var(--kz-expanding-panels-step, 0) * 0.07s) * var(--kz-motion-scale, 1));
}
.kodza-expanding-panels__title {
margin: 0 0 8px;
color: inherit;
font-family: var(--kz-font-display, inherit);
font-size: calc(30px * var(--kz-font-display-scale, 1));
font-weight: var(--kz-font-display-weight, 600);
letter-spacing: var(--kz-font-display-tracking, -0.035em);
text-transform: var(--kz-font-display-case, inherit);
line-height: 1.1;
}
.kodza-expanding-panels__meta {
margin: 0 0 12px;
color: var(--kz-expanding-panels-muted);
font-family: var(--kz-font-label, var(--kz-font-mono, ui-monospace, "SF Mono", Menlo, monospace));
font-size: var(--kz-font-label-size, 12px);
font-weight: var(--kz-font-label-weight, inherit);
letter-spacing: var(--kz-font-label-tracking, inherit);
line-height: var(--kz-font-label-leading, 1.4);
}
.kodza-expanding-panels__text {
max-width: 36ch;
margin: 0 0 18px;
color: var(--kz-expanding-panels-muted);
font-size: 15px;
line-height: 1.5;
text-wrap: pretty;
}
.kodza-expanding-panels__link {
display: inline-flex;
align-items: center;
height: 40px;
padding: 0 18px;
box-sizing: border-box;
border-radius: var(--kz-radius-pill, 999px);
background: var(--kz-expanding-panels-link-bg);
color: var(--kz-expanding-panels-link-fg);
font-family: var(--kz-font-label, inherit);
font-size: var(--kz-font-label-size, 14px);
font-weight: var(--kz-font-label-weight, 500);
letter-spacing: var(--kz-font-label-tracking, inherit);
text-transform: var(--kz-font-label-case, inherit);
line-height: 1;
text-decoration: none;
white-space: nowrap;
}
/* A drawn chevron, nudged on hover */
.kodza-expanding-panels__link::after {
content: "";
width: 6px;
height: 6px;
margin-left: 9px;
border-top: 1.5px solid currentColor;
border-right: 1.5px solid currentColor;
transform: rotate(45deg);
transition: transform calc(0.2s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1);
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__link {
pointer-events: auto;
}
.kodza-expanding-panels__link:focus-visible {
outline: 2px solid var(--kz-expanding-panels-fg);
outline-offset: 3px;
}
@media (hover: hover) {
.kodza-expanding-panels__link:hover::after {
transform: translateX(3px) rotate(45deg);
}
}
/* Stacked: the panels pile up and the open one grows in height; the title lies flat */
@container kodza-expanding-panels (max-width: 599px) {
.kodza-expanding-panels__list {
flex-direction: column;
height: auto;
}
.kodza-expanding-panels__panel {
flex: none;
height: var(--kz-expanding-panels-strip);
}
.kodza-expanding-panels__panel.is-open {
height: var(--kz-expanding-panels-open-height);
}
.kodza-expanding-panels__spine {
top: calc(var(--kz-expanding-panels-strip) / 2);
bottom: auto;
writing-mode: horizontal-tb;
transform: translateY(-50%);
}
.kodza-expanding-panels__index {
margin: 0 4px 0 0;
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__spine {
translate: 0 calc(-1 * var(--kz-expanding-panels-strip));
}
.kodza-expanding-panels__text {
margin-bottom: 16px;
}
/* The text climbs higher on a short, wide photo: so does the shade */
.kodza-expanding-panels__frame::after {
background: linear-gradient(to top, var(--kz-expanding-panels-shade), var(--kz-expanding-panels-shade) 34%, transparent 92%);
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-expanding-panels__frame::before,
.kodza-expanding-panels__spine,
.kodza-expanding-panels__content,
.kodza-expanding-panels__content > *,
.kodza-expanding-panels__link::after {
transition-duration: 0.01ms !important;
transition-delay: 0s !important;
}
}
/* Theming example — on a dark background:
.dark-section .kodza-expanding-panels {
--kz-expanding-panels-bg: #1c1c1c;
--kz-expanding-panels-focus: #f2f2f0;
}
*/
/* kodza-guard 80180f194deb — generated by Kodza, do not edit.
Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
component. :not(#_) is always true and weighs as much as an id, so these lines win over
theme rules made of classes and tags. Customise the component through its --kz-* variables. */
/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */
:where(.kodza-expanding-panels__toggle):not(#_) {
outline: revert;
}
:where(.kodza-expanding-panels__link):not(#_) {
outline: revert;
outline-offset: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-expanding-panels:not(#_),
.kodza-expanding-panels__frame:not(#_),
.kodza-expanding-panels__spine:not(#_),
.kodza-expanding-panels__index:not(#_) {
box-sizing: revert;
}
.kodza-expanding-panels__list:not(#_) {
border: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-expanding-panels__panel:not(#_) {
border: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-expanding-panels__image:not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-expanding-panels__toggle:not(#_) {
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
white-space: revert;
min-height: revert;
}
.kodza-expanding-panels__title:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-style: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-expanding-panels__meta:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-style: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-expanding-panels__text:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-height: revert;
font-family: revert;
font-weight: revert;
font-style: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-expanding-panels__link:not(#_) {
border: revert;
margin: revert;
list-style: revert;
float: revert;
position: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-style: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-expanding-panels__panel:not(#_):where(:not([hidden])),
.kodza-expanding-panels__title:not(#_):where(:not([hidden])),
.kodza-expanding-panels__meta:not(#_):where(:not([hidden])),
.kodza-expanding-panels__text:not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-expanding-panels__panel:not(#_):where([hidden]),
.kodza-expanding-panels__title:not(#_):where([hidden]),
.kodza-expanding-panels__meta:not(#_):where([hidden]),
.kodza-expanding-panels__text:not(#_):where([hidden]) {
display: none;
}
.kodza-expanding-panels__frame:not(#_)::before,
.kodza-expanding-panels__frame:not(#_)::after,
.kodza-expanding-panels__link:not(#_)::after {
box-sizing: revert;
}
/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */
.kodza-expanding-panels__list:not(#_) {
display: flex;
margin: 0;
padding: 0;
list-style: none;
}
.kodza-expanding-panels__panel:not(#_) {
position: relative;
margin: 0;
padding: 0;
}
.kodza-expanding-panels__image:not(#_) {
display: block;
max-width: none;
}
.kodza-expanding-panels__toggle:not(#_) {
position: absolute;
inset: 0;
z-index: 1;
display: block;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
border-radius: 0;
background: transparent;
color: var(--kz-expanding-panels-fg);
font: inherit;
text-align: left;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.kodza-expanding-panels__toggle:focus-visible:not(#_) {
outline: none;
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__toggle:not(#_) {
cursor: default;
}
.kodza-expanding-panels__content > *:not(#_) {
transition: transform calc(0.18s * var(--kz-motion-scale, 1)) cubic-bezier(0.65, 0, 0.35, 1),
clip-path calc(0.18s * var(--kz-motion-scale, 1)) cubic-bezier(0.65, 0, 0.35, 1);
}
.kodza-expanding-panels__panel.is-open .kodza-expanding-panels__content > *:not(#_) {
transition: transform calc(0.6s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1) calc((0.3s + var(--kz-expanding-panels-step, 0) * 0.07s) * var(--kz-motion-scale, 1)),
clip-path calc(0.6s * var(--kz-motion-scale, 1)) cubic-bezier(0.22, 1, 0.36, 1) calc((0.3s + var(--kz-expanding-panels-step, 0) * 0.07s) * var(--kz-motion-scale, 1));
}
.kodza-expanding-panels__title:not(#_) {
margin: 0 0 8px;
color: inherit;
font-family: var(--kz-font-display, inherit);
font-size: calc(30px * var(--kz-font-display-scale, 1));
font-weight: var(--kz-font-display-weight, 600);
letter-spacing: var(--kz-font-display-tracking, -0.035em);
text-transform: var(--kz-font-display-case, inherit);
line-height: 1.1;
}
.kodza-expanding-panels__meta:not(#_) {
margin: 0 0 12px;
color: var(--kz-expanding-panels-muted);
font-family: var(--kz-font-label, var(--kz-font-mono, ui-monospace, "SF Mono", Menlo, monospace));
font-size: var(--kz-font-label-size, 12px);
font-weight: var(--kz-font-label-weight, inherit);
letter-spacing: var(--kz-font-label-tracking, inherit);
line-height: var(--kz-font-label-leading, 1.4);
}
.kodza-expanding-panels__text:not(#_) {
max-width: 36ch;
margin: 0 0 18px;
color: var(--kz-expanding-panels-muted);
font-size: 15px;
line-height: 1.5;
}
.kodza-expanding-panels__link:not(#_) {
display: inline-flex;
padding: 0 18px;
box-sizing: border-box;
border-radius: var(--kz-radius-pill, 999px);
background: var(--kz-expanding-panels-link-bg);
color: var(--kz-expanding-panels-link-fg);
font-family: var(--kz-font-label, inherit);
font-size: var(--kz-font-label-size, 14px);
font-weight: var(--kz-font-label-weight, 500);
letter-spacing: var(--kz-font-label-tracking, inherit);
text-transform: var(--kz-font-label-case, inherit);
line-height: 1;
text-decoration: none;
}
.kodza-expanding-panels__link:focus-visible:not(#_) {
outline: 2px solid var(--kz-expanding-panels-fg);
outline-offset: 3px;
}
@container kodza-expanding-panels (max-width: 599px) {
.kodza-expanding-panels__text:not(#_) {
margin-bottom: 16px;
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-expanding-panels__content > *:not(#_) {
transition-duration: 0.01ms !important;
transition-delay: 0s !important;
}
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Expanding Panels
// Opens one panel at a time, on hover (after a short rest, so a pointer passing through opens
// nothing), focus or tap: the panels slide and resize from where they were to where they are
// (the Make Way engine, measured before and after), the photos recropped as they go. The text
// keeps the open panel's width all along, so it never rewraps while the panel grows.
// Tune it with the --kz-expanding-panels-* variables in the CSS and the constants below.
(() => {
const SELECTOR = '.kodza-expanding-panels';
const MOVE = 750; // ms, the panels sliding to their new widths; the text rises while they move (CSS)
const MOVE_EASE = 'cubic-bezier(0.65, 0, 0.35, 1)';
const CAUGHT_EASE = 'cubic-bezier(0.33, 0.66, 0.4, 1)'; // a move caught mid-way goes on at speed, no stop
const HOVER_REST = 90; // ms the pointer rests on a panel before it opens (a wait, not motion: the pace leaves it)
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// The site's pace, --kz-motion-scale (set on :root, read on the instance): every duration of the
// script times it, and 0 moves nothing, like reduced motion
const paceOf = (el) => {
const pace = parseFloat(getComputedStyle(el).getPropertyValue('--kz-motion-scale'));
return pace >= 0 ? pace : 1;
};
// One instance, with its own state: two copies on a page never interfere. Everything it
// starts is tied to `signal` (listeners get { signal }, observers and timers stop on its
// 'abort' event), so kodza:destroy stops it all.
function mount(root, signal) {
const pace = paceOf(root);
const still = reduceMotion || !pace; // the still path: no motion asked, by the visitor or the site
const list = root.querySelector('.kodza-expanding-panels__list');
const panels = list ? [...list.children].filter((el) => el.matches('.kodza-expanding-panels__panel')) : [];
const frames = panels.map((panel) => panel.querySelector('.kodza-expanding-panels__frame'));
const toggles = panels.map((panel) => panel.querySelector('.kodza-expanding-panels__toggle'));
if (panels.length < 2 || [...frames, ...toggles].some((el) => !el)) return;
// The text's width: an open panel's, so it is laid out once and only uncovered as it opens
let current = 0;
const measure = () => root.style.setProperty('--kz-expanding-panels-open', `${panels[current].offsetWidth}px`);
// The engine moves the panels: they slide and resize from their old widths to their new ones
const engine = makeWay(list, frames, { duration: MOVE * pace, easing: MOVE_EASE, caught: CAUGHT_EASE });
const set = (next) => {
panels.forEach((panel, i) => {
panel.classList.toggle('is-open', i === next);
toggles[i].setAttribute('aria-expanded', String(i === next));
});
current = next;
measure();
};
const open = (next) => {
if (next === current) return;
if (still) set(next);
else engine.move(() => set(next));
};
// Hover opens after a short rest, with a mouse or a pen only: a finger taps
const canHover = window.matchMedia('(hover: hover)');
let timer = 0;
frames.forEach((frame, i) => {
frame.addEventListener('pointerenter', (event) => {
if (event.pointerType === 'touch' || !canHover.matches) return;
clearTimeout(timer);
timer = setTimeout(() => open(i), HOVER_REST);
}, { signal });
frame.addEventListener('pointerleave', () => clearTimeout(timer), { signal });
});
toggles.forEach((toggle, i) => {
toggle.addEventListener('click', () => open(i), { signal });
// From the keyboard only: a click opens on its own, and a window coming back to the front
// must not reopen the panel that kept the focus
toggle.addEventListener('focus', () => toggle.matches(':focus-visible') && open(i), { signal });
});
// The arrows move along the panels, and the panel that takes the focus opens
root.addEventListener('keydown', (event) => {
const at = toggles.indexOf(event.target);
const to = at < 0 ? undefined : { ArrowLeft: at - 1, ArrowUp: at - 1, ArrowRight: at + 1, ArrowDown: at + 1, Home: 0, End: toggles.length - 1 }[event.key];
if (to === undefined) return;
event.preventDefault();
toggles[(to + toggles.length) % toggles.length].focus();
}, { signal });
// Written open in the markup: it starts open (the first one otherwise)
set(Math.max(0, panels.findIndex((panel) => panel.classList.contains('is-open'))));
// A new width changes an open panel's width, so the text's
let width = list.clientWidth;
let raf = 0;
const observer = new ResizeObserver(() => {
if (list.clientWidth === width) return;
width = list.clientWidth;
cancelAnimationFrame(raf);
raf = requestAnimationFrame(() => {
engine.cancel();
measure();
});
});
observer.observe(root);
signal.addEventListener('abort', () => {
observer.disconnect();
cancelAnimationFrame(raf);
clearTimeout(timer);
engine.cancel();
});
}
// ---------- Make Way engine (copied as is by Expanding Panels) ----------
// move(change) measures every frame in the container's own pixels (a parent scaled by
// transform does not shift them), runs change() to give them their new places, measures again,
// then slides and resizes each frame from where it was to where it is. Caught mid-move, a frame
// starts again from where it is. The container's height follows, so the page below never
// jumps. A frame clips its picture (object-fit: cover): the picture grows with it, never stretched.
// timing: { duration, easing, caught } — caught, the easing of a move that starts mid-way.
function makeWay(container, frames, { duration, easing, caught = easing }) {
let moving = [];
const rects = () => {
const box = container.getBoundingClientRect();
const scale = box.width / container.offsetWidth || 1;
return frames.map((frame) => {
const rect = frame.getBoundingClientRect();
return { x: (rect.left - box.left) / scale, y: (rect.top - box.top) / scale, w: rect.width / scale, h: rect.height / scale };
});
};
const cancel = () => {
moving.forEach((animation) => animation.cancel());
moving = [];
};
const move = (change) => {
const before = rects();
const tall = container.offsetHeight;
const timing = { duration, easing: moving.some((a) => a.playState === 'running') ? caught : easing };
cancel();
change();
const after = rects();
frames.forEach((frame, i) => {
const [a, b] = [before[i], after[i]];
if (Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.w - b.w), Math.abs(a.h - b.h)) < 0.5) return;
moving.push(frame.animate([
{ transform: `translate(${a.x - b.x}px, ${a.y - b.y}px)`, width: `${a.w}px`, height: `${a.h}px` },
{ transform: 'translate(0px, 0px)', width: `${b.w}px`, height: `${b.h}px` },
], timing));
});
const height = container.offsetHeight;
if (height !== tall) moving.push(container.animate([{ height: `${tall}px` }, { height: `${height}px` }], timing));
// Resolves once everything has arrived, false when a newer move or a cancel cut it short
return Promise.all(moving.map((animation) => animation.finished)).then(() => true, () => false);
};
return { move, cancel };
}
// ---------- end of the engine ----------
// Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
// event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
// markup back. For themes and apps that swap content without a page load. Each running root
// keeps its markup as written under KODZA, shared by every Kodza script on the page: a Kodza
// component inside another one is saved as written, not half-started, and stopped with it. Two
// components on one root (a reveal on a stat card) both start, and stop together.
const KODZA = Symbol.for('kodza');
const RUNNING = Symbol.for(`kodza ${SELECTOR}`); // a root this component runs on, for every copy of this script
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
const attrsOf = (el) => [...el.attributes].map((a) => [a.name, a.value]);
const put = (el, saved) => {
[...el.attributes].forEach((a) => el.removeAttribute(a.name));
saved.attrs.forEach(([name, value]) => el.setAttribute(name, value));
el.innerHTML = saved.html;
};
// The markup inside a root as written: Kodza components already running in it give back their own
const written = (root) => {
const all = [...root.querySelectorAll('*')];
if (!all.some((el) => el[KODZA])) return root.innerHTML;
const copy = root.cloneNode(true);
const twins = copy.querySelectorAll('*');
let last = null;
all.forEach((el, i) => {
if (!el[KODZA] || last?.contains(el)) return;
last = el;
put(twins[i], el[KODZA]);
});
return copy.innerHTML;
};
const init = (scope) => find(scope).forEach((root) => {
// Already running, maybe from another copy of this script. Marked is-ready with no Kodza component
// running on it, a root is a copy of a started one (a cloned slide): it is left as it is
if (root[RUNNING] || (root.classList.contains('is-ready') && !root[KODZA])) return;
// Rendered by React (data-kodza-manual): React starts it, with an init aimed at that markup once
// it has hydrated it. Any earlier start would change markup React has not taken over yet
const owner = root.closest('[data-kodza-manual]');
if (owner && !(scope && owner.contains(scope))) return;
const controller = new AbortController();
// Another Kodza component already running on this root: its markup as written is kept, and the
// two stop together
const before = root[KODZA];
const saved = { html: before ? before.html : written(root), attrs: before ? before.attrs : attrsOf(root), stop: () => destroy(root) };
if (before) before.above = saved;
instances.set(root, { controller, saved, before });
root[KODZA] = saved;
root[RUNNING] = true;
mount(root, controller.signal);
root.classList.add('is-ready');
});
const destroy = (scope) => find(scope).forEach((root) => {
const instance = instances.get(root);
if (!instance) return;
instances.delete(root);
instance.saved.above?.stop(); // a Kodza component started after it on the same root stops first
// The Kodza components running inside it stop first: once its markup is put back, their own
// script could not find them any more
root.querySelectorAll('*').forEach((el) => el[KODZA]?.stop());
instance.controller.abort();
delete root[RUNNING];
// Started on top of another one: that one stops next, and puts the markup back
if (instance.before) {
delete instance.before.above;
root[KODZA] = instance.before;
return instance.before.stop();
}
delete root[KODZA];
put(root, instance.saved);
});
document.addEventListener('kodza:init', (event) => init(event.detail?.root));
document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
init();
// Loaded in <head>, the script runs before the markup exists: once more when it is parsed
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
'use client';
// Kodza — Expanding Panels, for React. From https://kodza.dev/components/expanding-panels/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: expanding-panels.css and expanding-panels.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
// data-kodza-manual keeps the script from starting it on its own: the effect below does, once
// React has hydrated the markup (on a page that streams in, the script can load first).
// Built from your data (tabs, rows, options)? Put what the markup is made of in the key, as plain
// values (ids, text, numbers): a change starts the script again on fresh markup. What the visitor
// changes (the open tab, the sort, what they type) is the script's: keep it out of the key, follow
// it with onClick or onInput on the root, and change it from your code as a visitor would (click
// the tab; set the field's value, then dispatch a bubbling input event).
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './expanding-panels.css';
export type ExpandingPanelsProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** side by side — default: 520px */
"--kz-expanding-panels-height"?: string | number;
/** the open panel, against 1 for a closed one — default: 4 */
"--kz-expanding-panels-grow"?: string | number;
/** default: 8px */
"--kz-expanding-panels-gap"?: string | number;
/** a closed panel, stacked (under 600px of container) — default: 72px */
"--kz-expanding-panels-strip"?: string | number;
/** the open panel, stacked — default: 380px */
"--kz-expanding-panels-open-height"?: string | number;
/** title and text, from the photo's edges — default: 24px */
"--kz-expanding-panels-pad"?: string | number;
/** default: calc(16px * var(--kz-radius-scale, 1)) */
"--kz-expanding-panels-radius"?: string | number;
/** behind a photo still loading — default: #1c1c1c */
"--kz-expanding-panels-bg"?: string | number;
/** default: #ffffff */
"--kz-expanding-panels-fg"?: string | number;
/** default: rgba(255, 255, 255, 0.86) */
"--kz-expanding-panels-muted"?: string | number;
/** over a closed photo — default: rgba(10, 10, 10, 0.3) */
"--kz-expanding-panels-veil"?: string | number;
/** at the foot of every photo, under the text — default: rgba(10, 10, 10, 0.72) */
"--kz-expanding-panels-shade"?: string | number;
/** default: #ffffff */
"--kz-expanding-panels-link-bg"?: string | number;
/** default: #0a0a0a */
"--kz-expanding-panels-link-fg"?: string | number;
/** default: #0a0a0a */
"--kz-expanding-panels-focus"?: string | number;
/** a hairline round each photo, for dark photos on a dark page — default: transparent */
"--kz-expanding-panels-line"?: string | number;
};
className?: string;
};
export function ExpandingPanels({ vars, className, style, ...rest }: ExpandingPanelsProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-expanding-panels", className].filter(Boolean).join(' ');
// Everything the markup is made of: when it changes, React gets a fresh element (see the top)
const key = JSON.stringify([classes, vars, style, rest]);
// Starts the script on this element once React has rendered it, stops it when it goes
useEffect(() => {
const root = ref.current;
let live = true;
// @ts-ignore: a plain script, no types to find
import('./expanding-panels.js').then(() => {
if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
});
return () => {
live = false;
document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
};
}, [key]);
return (
<div key={key} {...rest} className={classes} data-kodza-manual style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<ul className="kodza-expanding-panels__list">
<li className="kodza-expanding-panels__panel is-open">
<div className="kodza-expanding-panels__frame">
<img className="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-table-1400.webp" width="1400" height="1050" alt="A white table set with two glasses and a bottle, facing a misty sea with a sailboat" loading="lazy" />
{' '}
<button className="kodza-expanding-panels__toggle" type="button" aria-expanded="true">
<span className="kodza-expanding-panels__spine"><span className="kodza-expanding-panels__index">01</span> Étretat</span>
</button>
<div className="kodza-expanding-panels__content">
<h3 className="kodza-expanding-panels__title">Étretat</h3>
<p className="kodza-expanding-panels__meta">Normandy · 2 guests · €140 / night</p>
<p className="kodza-expanding-panels__text">A table, two glasses, the sea. The listing says what's in the photo.</p>
<a className="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li className="kodza-expanding-panels__panel">
<div className="kodza-expanding-panels__frame">
<img className="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-block-1400.webp" width="1120" height="1400" alt="A tall concrete slab standing alone on a bare floor" loading="lazy" />
{' '}
<button className="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span className="kodza-expanding-panels__spine"><span className="kodza-expanding-panels__index">02</span> Alentejo</span>
</button>
<div className="kodza-expanding-panels__content">
<h3 className="kodza-expanding-panels__title">Alentejo</h3>
<p className="kodza-expanding-panels__meta">Portugal · 4 guests · €120 / night</p>
<p className="kodza-expanding-panels__text">One wall, no neighbours. Silence is not an extra on the bill.</p>
<a className="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li className="kodza-expanding-panels__panel">
<div className="kodza-expanding-panels__frame">
<img className="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-columns-1400.webp" width="1120" height="1400" alt="A row of square concrete pillars under a flat roof, casting striped shadows" loading="lazy" />
{' '}
<button className="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span className="kodza-expanding-panels__spine"><span className="kodza-expanding-panels__index">03</span> Seville</span>
</button>
<div className="kodza-expanding-panels__content">
<h3 className="kodza-expanding-panels__title">Seville</h3>
<p className="kodza-expanding-panels__meta">Andalusia · 6 guests · €260 / night</p>
<p className="kodza-expanding-panels__text">Forty pillars of shade. At 4 pm, you'll want every one.</p>
<a className="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li className="kodza-expanding-panels__panel">
<div className="kodza-expanding-panels__frame">
<img className="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-gap-1400.webp" width="1400" height="583" alt="Two concrete walls with a narrow gap between them, light falling through" loading="lazy" />
{' '}
<button className="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span className="kodza-expanding-panels__spine"><span className="kodza-expanding-panels__index">04</span> Copenhagen</span>
</button>
<div className="kodza-expanding-panels__content">
<h3 className="kodza-expanding-panels__title">Copenhagen</h3>
<p className="kodza-expanding-panels__meta">Denmark · 3 guests · €210 / night</p>
<p className="kodza-expanding-panels__text">Two walls, one gap. The light comes through at noon, no smart bulb required.</p>
<a className="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
<li className="kodza-expanding-panels__panel">
<div className="kodza-expanding-panels__frame">
<img className="kodza-expanding-panels__image" src="https://kodza.dev/media/kz-arch-1400.webp" width="1400" height="1400" alt="A concrete wall with a round-topped opening, sunlight pouring through it" loading="lazy" />
{' '}
<button className="kodza-expanding-panels__toggle" type="button" aria-expanded="false">
<span className="kodza-expanding-panels__spine"><span className="kodza-expanding-panels__index">05</span> Tangier</span>
</button>
<div className="kodza-expanding-panels__content">
<h3 className="kodza-expanding-panels__title">Tangier</h3>
<p className="kodza-expanding-panels__meta">Morocco · 4 guests · €190 / night</p>
<p className="kodza-expanding-panels__text">One arch, facing west. Sunset included, no upgrade needed.</p>
<a className="kodza-expanding-panels__link" href="#">See the stay</a>
</div>
</div>
</li>
</ul>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.