Burger Button
A menu button: the lines meet, then cross, and Menu rolls to Close at a fixed width. It follows aria-expanded and fires kodza:burger, so it drives the menu you already have.
View codeA menu that comes down under your header like a shutter: each link rises as the edge reaches it, Menu rolls to Close. The panel is a native popover, so Escape, a click outside and focus return come free.
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 Shutter Menu to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-shutter">
<button class="kodza-shutter__toggle" type="button" aria-expanded="false"><span class="kodza-shutter__lines" aria-hidden="true"></span><span class="kodza-shutter__label"><span class="kodza-shutter__say">Menu</span><span class="kodza-shutter__say" aria-hidden="true">Close</span></span></button>
<div class="kodza-shutter__panel" popover aria-label="Menu">
<nav class="kodza-shutter__nav" aria-label="Main">
<a class="kodza-shutter__link" href="#"><span class="kodza-shutter__index">01</span><span class="kodza-shutter__mask"><span class="kodza-shutter__word">Work</span></span></a>
<a class="kodza-shutter__link" href="#"><span class="kodza-shutter__index">02</span><span class="kodza-shutter__mask"><span class="kodza-shutter__word">Services</span></span></a>
<a class="kodza-shutter__link" href="#"><span class="kodza-shutter__index">03</span><span class="kodza-shutter__mask"><span class="kodza-shutter__word">Journal</span></span></a>
<a class="kodza-shutter__link" href="#"><span class="kodza-shutter__index">04</span><span class="kodza-shutter__mask"><span class="kodza-shutter__word">Contact</span></span></a>
</nav>
<div class="kodza-shutter__info">
<p>Mon–Fri, 9 to 6. Closed when it's done.</p>
<p class="kodza-shutter__socials"><a href="#">GitHub</a><a href="#">X</a><a href="#">RSS</a></p>
</div>
</div>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Shutter Menu
The menu comes down from under your header like a shop shutter, and each link rises from its
mask as the edge gets to it. The button stays in view: its lines cross, Menu rolls to Close.
The panel is a native popover: Escape, a click outside and the focus going back to the button
are the browser's own. Everything is tuned with the --kz-shutter-* variables. */
.kodza-shutter {
--kz-shutter-bg: #0a0a0a; /* the menu */
--kz-shutter-fg: #f2f2f0;
--kz-shutter-muted: rgba(242, 242, 240, 0.62);
--kz-shutter-line: rgba(242, 242, 240, 0.16);
--kz-shutter-ink: #0a0a0a; /* the Menu button, on the page */
--kz-shutter-on-ink: #ffffff;
--kz-shutter-top: auto; /* where the shutter starts; auto = the bottom of the header that holds the button */
--kz-shutter-side: 24px;
--kz-shutter-size: clamp(36px, min(9cqw, calc((100cqh - 190px) / 4.9)), 112px);
--kz-shutter-duration: 0.8s;
--kz-shutter-ease: cubic-bezier(0.76, 0, 0.24, 1);
display: inline-block;
}
/* The button: two lines meet, then cross; the label rolls without changing the width */
.kodza-shutter__toggle {
display: inline-flex;
align-items: center;
gap: 10px;
height: 40px;
margin: 0;
padding: 0 18px 0 16px;
border: 0;
border-radius: 999px;
background: var(--kz-shutter-ink);
color: var(--kz-shutter-on-ink);
font: inherit;
font-size: 15px;
font-weight: 500;
line-height: 1;
letter-spacing: -0.01em;
white-space: nowrap;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.kodza-shutter__toggle:focus-visible {
outline: 2px solid var(--kz-shutter-ink);
outline-offset: 3px;
}
.kodza-shutter__lines {
position: relative;
flex: none;
width: 14px;
height: 8px;
}
.kodza-shutter__lines::before,
.kodza-shutter__lines::after {
content: "";
position: absolute;
left: 0;
width: 100%;
height: 1.5px;
border-radius: 1px;
background: currentColor;
/* On its own layer: drawn the same way at rest and while turning, so no snap at the end */
will-change: transform;
/* Closing: they uncross first, then part */
transition:
rotate 0.22s cubic-bezier(0.65, 0, 0.35, 1),
translate 0.22s cubic-bezier(0.65, 0, 0.35, 1) 0.18s,
clip-path 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.kodza-shutter__lines::before {
top: 0;
}
.kodza-shutter__lines::after {
top: 6px; /* whole pixels: both lines sit on the pixel grid the same way */
}
/* Whole at rest, as an inset: the pointer slides it to a shorter one (from none it would jump) */
.kodza-shutter__lines::after {
clip-path: inset(0 0 0 0);
}
.kodza-shutter__toggle:hover .kodza-shutter__lines::after {
clip-path: inset(0 45% 0 0);
}
.kodza-shutter__toggle[aria-expanded="true"] .kodza-shutter__lines::before,
.kodza-shutter__toggle[aria-expanded="true"] .kodza-shutter__lines::after {
clip-path: inset(0 0 0 0);
transition:
translate 0.2s cubic-bezier(0.65, 0, 0.35, 1),
rotate 0.3s cubic-bezier(0.22, 1, 0.36, 1) 0.17s,
clip-path 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.kodza-shutter__toggle[aria-expanded="true"] .kodza-shutter__lines::before {
translate: 0 3px;
rotate: 45deg;
}
.kodza-shutter__toggle[aria-expanded="true"] .kodza-shutter__lines::after {
translate: 0 -3px;
rotate: -45deg;
}
.kodza-shutter__label {
display: grid;
margin: -3px 0;
padding: 3px 0;
overflow: hidden;
}
/* The script rolls the words both ways: the old one goes up, the new one comes up from below */
.kodza-shutter__say {
grid-area: 1 / 1;
}
.kodza-shutter__say + .kodza-shutter__say {
translate: 0 115%;
}
.kodza-shutter__toggle[aria-expanded="true"] .kodza-shutter__say {
translate: 0 -115%;
}
.kodza-shutter__toggle[aria-expanded="true"] .kodza-shutter__say + .kodza-shutter__say {
translate: 0 0;
}
/* The shutter: from the bottom of your header to the bottom of the screen, rolled up until it opens */
.kodza-shutter__panel {
position: fixed;
inset: var(--kz-shutter-from, 0px) 0 0 0;
box-sizing: border-box;
width: 100%;
height: auto;
max-width: none;
max-height: none;
margin: 0;
padding: 0 var(--kz-shutter-side);
border: 0;
overflow: hidden auto;
overscroll-behavior: contain;
background: var(--kz-shutter-bg);
color: var(--kz-shutter-fg);
font: inherit;
font-size: 15px;
line-height: 1.4;
text-align: left;
container-type: size;
z-index: 99990;
/* Here and not on the open state: the panel keeps its rows while it rolls back up */
grid-template-rows: 1fr auto;
-webkit-font-smoothing: antialiased;
clip-path: inset(0 0 100% 0);
/* Closing: quicker than it came down */
transition:
clip-path calc(var(--kz-shutter-duration) * 0.7) var(--kz-shutter-ease),
display calc(var(--kz-shutter-duration) * 0.7) allow-discrete,
overlay calc(var(--kz-shutter-duration) * 0.7) allow-discrete;
}
.kodza-shutter__panel:popover-open {
display: grid;
clip-path: inset(0 0 0 0);
transition:
clip-path var(--kz-shutter-duration) var(--kz-shutter-ease),
display var(--kz-shutter-duration) allow-discrete,
overlay var(--kz-shutter-duration) allow-discrete;
}
@starting-style {
.kodza-shutter__panel:popover-open {
clip-path: inset(0 0 100% 0);
}
}
.kodza-shutter__nav {
align-self: center;
display: grid;
padding: 28px 0;
}
/* Each row: its hairline draws in, then the word rises from its mask */
.kodza-shutter__link {
position: relative;
display: grid;
grid-template-columns: clamp(44px, 9cqw, 132px) minmax(0, 1fr);
align-items: start;
padding: 14px 0 10px;
color: inherit;
text-decoration: none;
outline: none;
}
.kodza-shutter__link::before {
content: "";
position: absolute;
inset: 0 0 auto;
height: 1px;
background: var(--kz-shutter-line);
scale: 0 1;
transform-origin: left center;
transition: scale 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}
.kodza-shutter__index {
padding-top: 0.4em;
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
line-height: 1.4;
color: var(--kz-shutter-muted);
opacity: 0;
transition: opacity 0.2s, color 0.25s;
}
/* The mask has the size of its word, so its room for descenders (g, j, p, q, y) and its step
aside are measured on the word */
.kodza-shutter__mask {
display: block;
margin: -0.06em 0 -0.24em;
padding: 0.06em 0 0.24em;
overflow: hidden;
font-size: var(--kz-shutter-size);
transition: translate 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.kodza-shutter__word {
display: block;
font-size: var(--kz-shutter-size);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
translate: 0 135%;
/* Closing: the words drop back into their masks while the shutter rolls up */
transition: translate 0.32s cubic-bezier(0.65, 0, 0.35, 1);
}
.kodza-shutter__info {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 8px 24px;
padding: 18px 0 22px;
border-top: 1px solid var(--kz-shutter-line);
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
line-height: 1.4;
color: var(--kz-shutter-muted);
opacity: 0;
translate: 0 8px;
transition: opacity 0.2s, translate 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}
.kodza-shutter__info p {
margin: 0;
}
.kodza-shutter__socials {
display: flex;
gap: 20px;
}
.kodza-shutter__socials a {
color: inherit;
text-decoration: none;
transition: color 0.2s;
}
/* Open: each part starts when the edge reaches it (the script sets --kz-shutter-delay) */
.kodza-shutter__panel.is-open .kodza-shutter__link::before {
scale: 1 1;
transition: scale 0.9s cubic-bezier(0.22, 1, 0.36, 1) var(--kz-shutter-delay, 0s);
}
.kodza-shutter__panel.is-open .kodza-shutter__index {
opacity: 1;
transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1) calc(var(--kz-shutter-delay, 0s) + 0.12s), color 0.25s;
}
.kodza-shutter__panel.is-open .kodza-shutter__word {
translate: 0 0;
transition: translate 0.75s cubic-bezier(0.22, 1, 0.36, 1) var(--kz-shutter-delay, 0s);
}
.kodza-shutter__panel.is-open .kodza-shutter__info {
opacity: 1;
translate: 0 0;
transition:
opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1) var(--kz-shutter-delay, 0s),
translate 0.7s cubic-bezier(0.22, 1, 0.36, 1) var(--kz-shutter-delay, 0s);
}
/* Pointed at: the word steps aside and its number lights up */
.kodza-shutter__link:hover .kodza-shutter__mask,
.kodza-shutter__link:focus-visible .kodza-shutter__mask {
translate: 0.14em 0;
}
.kodza-shutter__link:hover .kodza-shutter__index,
.kodza-shutter__link:focus-visible .kodza-shutter__index,
.kodza-shutter__socials a:hover {
color: var(--kz-shutter-fg);
}
.kodza-shutter__link:focus-visible .kodza-shutter__word {
text-decoration: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.12em;
}
.kodza-shutter__socials a:focus-visible {
outline: 2px solid var(--kz-shutter-fg);
outline-offset: 4px;
}
@media (prefers-reduced-motion: reduce) {
.kodza-shutter__panel,
.kodza-shutter__panel *,
.kodza-shutter__panel *::before,
.kodza-shutter__toggle *,
.kodza-shutter__toggle *::before,
.kodza-shutter__toggle *::after {
transition-duration: 0.01ms !important;
transition-delay: 0s !important;
}
}
/* kodza-guard f2b6a432fe24 — 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-shutter__toggle):not(#_),
:where(.kodza-shutter__socials a:where(:not([class*="kodza-"]))):not(#_) {
outline: revert;
outline-offset: revert;
}
:where(.kodza-shutter__nav):not(#_),
:where(.kodza-shutter__link):not(#_),
:where(.kodza-shutter__socials):not(#_),
:where(.kodza-shutter__info p:where(:not([class*="kodza-"]):not(.kodza-shutter__info [class*="kodza-"] *))):not(#_) {
transition-duration: revert;
transition-delay: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-shutter:not(#_),
.kodza-shutter__lines:not(#_),
.kodza-shutter__label:not(#_),
.kodza-shutter__say:not(#_),
.kodza-shutter__index:not(#_),
.kodza-shutter__mask:not(#_),
.kodza-shutter__word:not(#_),
.kodza-shutter__info:not(#_) {
box-sizing: revert;
}
.kodza-shutter__toggle:not(#_) {
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
min-height: revert;
}
.kodza-shutter__nav:not(#_) {
border: revert;
margin: 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;
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;
transition-property: revert;
transition-timing-function: revert;
}
.kodza-shutter__link:not(#_) {
border: revert;
margin: revert;
border-radius: 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;
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;
transition-property: revert;
transition-timing-function: revert;
}
.kodza-shutter__socials:not(#_),
.kodza-shutter__info p:where(:not([class*="kodza-"]):not(.kodza-shutter__info [class*="kodza-"] *)):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;
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;
transition-property: revert;
transition-timing-function: revert;
}
.kodza-shutter__socials a:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: 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-shutter__info p:where(:not([class*="kodza-"]):not(.kodza-shutter__info [class*="kodza-"] *)):not(#_):where(:not([hidden])),
.kodza-shutter__socials a:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-shutter__info p:where(:not([class*="kodza-"]):not(.kodza-shutter__info [class*="kodza-"] *)):not(#_):where([hidden]),
.kodza-shutter__socials a:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
display: none;
}
.kodza-shutter__lines:not(#_)::before,
.kodza-shutter__lines:not(#_)::after,
.kodza-shutter__link:not(#_)::before {
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-shutter__toggle:not(#_) {
display: inline-flex;
align-items: center;
gap: 10px;
height: 40px;
margin: 0;
padding: 0 18px 0 16px;
border: 0;
border-radius: 999px;
background: var(--kz-shutter-ink);
color: var(--kz-shutter-on-ink);
font: inherit;
font-size: 15px;
font-weight: 500;
line-height: 1;
letter-spacing: -0.01em;
white-space: nowrap;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.kodza-shutter__toggle:focus-visible:not(#_) {
outline: 2px solid var(--kz-shutter-ink);
outline-offset: 3px;
}
.kodza-shutter__nav:not(#_) {
display: grid;
padding: 28px 0;
}
.kodza-shutter__link:not(#_) {
position: relative;
display: grid;
padding: 14px 0 10px;
color: inherit;
text-decoration: none;
outline: none;
}
.kodza-shutter__info p:not(#_) {
margin: 0;
}
.kodza-shutter__socials:not(#_) {
display: flex;
}
.kodza-shutter__socials a:not(#_) {
color: inherit;
text-decoration: none;
transition: color 0.2s;
}
.kodza-shutter__socials a:hover:not(#_) {
color: var(--kz-shutter-fg);
}
.kodza-shutter__socials a:focus-visible:not(#_) {
outline: 2px solid var(--kz-shutter-fg);
outline-offset: 4px;
}
@media (prefers-reduced-motion: reduce) {
.kodza-shutter__panel *:where(nav, a, p):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 — Shutter Menu
// The panel is a native popover: the button opens and closes it, Escape and a click outside close
// it, and the focus goes back to the button. The script starts the shutter under your header,
// times each link to rise when the edge reaches it, and keeps the page still while it is open.
(() => {
const SELECTOR = '.kodza-shutter';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// When (0 to 1 of the duration) a cubic-bezier curve gets to the progress p
const timeAt = ([x1, y1, x2, y2], p) => {
const at = (a, b, s) => 3 * a * s * (1 - s) ** 2 + 3 * b * s * s * (1 - s) + s ** 3;
let lo = 0;
let hi = 1;
for (let i = 0; i < 24; i++) {
const mid = (lo + hi) / 2;
if (at(y1, y2, mid) < p) lo = mid;
else hi = mid;
}
return at(x1, x2, (lo + hi) / 2);
};
// A wheel or a swipe only scrolls what can scroll in the panel, under the pointer
const scrollsInside = (panel, target, x, y, dy) => {
for (let el = target; el instanceof Element && panel.contains(el); el = el.parentElement) {
const box = el.getBoundingClientRect();
if (x < box.left || x > box.right || y < box.top || y > box.bottom) continue;
if (!/(auto|scroll)/.test(getComputedStyle(el).overflowY) || el.scrollHeight <= el.clientHeight + 1) continue;
if (dy > 0 ? el.scrollTop + el.clientHeight < el.scrollHeight - 1 : el.scrollTop > 0) return true;
}
return false;
};
// One instance, with its own state: two copies on a page never interfere. Everything it
// starts is tied to `signal`, so kodza:destroy stops it all.
function mount(root, signal) {
const toggle = root.querySelector('.kodza-shutter__toggle');
const panel = root.querySelector('.kodza-shutter__panel');
if (!toggle || !panel || !('popover' in panel)) return;
toggle.popoverTargetElement = panel;
const words = [...toggle.querySelectorAll('.kodza-shutter__say')];
const parts = [...panel.querySelectorAll('.kodza-shutter__link, .kodza-shutter__info')];
let open = false;
let started = 0;
let held = null;
const rolls = new Map();
// The shutter starts under the header that holds the button (or at --kz-shutter-top)
const place = () => {
const top = getComputedStyle(root).getPropertyValue('--kz-shutter-top').trim();
if (top && top !== 'auto') {
panel.style.setProperty('--kz-shutter-from', top);
return;
}
// Under the header, or just under the button when there is none: Close always stays in view
const bar = root.closest('header, [role="banner"]');
const below = toggle.getBoundingClientRect().bottom;
const edge = bar ? Math.max(bar.getBoundingClientRect().bottom, below) : below + 16;
panel.style.setProperty('--kz-shutter-from', `${Math.max(0, Math.round(edge))}px`);
};
// Each row starts when the edge of the shutter gets to it
const time = () => {
const style = getComputedStyle(root);
const raw = style.getPropertyValue('--kz-shutter-duration').trim();
const duration = reduceMotion ? 0 : parseFloat(raw) * (/ms$/.test(raw) ? 1 : 1000) || 800;
const match = style.getPropertyValue('--kz-shutter-ease').match(/cubic-bezier\(([^)]+)\)/);
const curve = match ? match[1].split(',').map(Number) : [0.76, 0, 0.24, 1];
const box = panel.getBoundingClientRect();
const late = performance.now() - started;
parts.forEach((part) => {
const p = Math.min(1, Math.max(0, (part.getBoundingClientRect().top - box.top) / (box.height || 1)));
const delay = Math.max(0, duration * timeAt(curve, p) - late - 40);
part.style.setProperty('--kz-shutter-delay', `${Math.round(delay)}ms`);
});
};
// Menu rolls to Close and back the same way: the old word goes up, the new one comes from below.
// A click during the roll turns it back from where the words are
const roll = () => {
if (reduceMotion || words.length < 2) return;
words.forEach((word, i) => {
const coming = i === Number(open);
const from = rolls.has(word) ? getComputedStyle(word).translate : coming ? '0 115%' : '0 0';
rolls.get(word)?.cancel();
const run = word.animate(
{ translate: [from, coming ? '0 0' : '0 -115%'] },
{ duration: 500, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' },
);
rolls.set(word, run);
run.finished.then(() => rolls.get(word) === run && rolls.delete(word), () => {});
});
};
// While it is open the page stays where it is
const hold = () => {
held = new AbortController();
const s = held.signal;
const at = [scrollX, scrollY];
let last = 0;
document.addEventListener('wheel', (event) => {
if (!scrollsInside(panel, event.target, event.clientX, event.clientY, event.deltaY)) event.preventDefault();
}, { passive: false, signal: s });
document.addEventListener('touchstart', (event) => (last = event.touches[0].clientY), { passive: true, signal: s });
document.addEventListener('touchmove', (event) => {
const touch = event.touches[0];
const dy = last - touch.clientY;
last = touch.clientY;
if (!scrollsInside(panel, event.target, touch.clientX, touch.clientY, dy)) event.preventDefault();
}, { passive: false, signal: s });
// A scrollbar dragged anyway: the page goes back to where it was
window.addEventListener('scroll', () => {
if (scrollX !== at[0] || scrollY !== at[1]) window.scrollTo({ left: at[0], top: at[1], behavior: 'instant' });
}, { signal: s });
window.addEventListener('resize', place, { signal: s });
};
const release = () => {
held?.abort();
held = null;
};
panel.addEventListener('beforetoggle', (event) => {
open = event.newState === 'open';
toggle.setAttribute('aria-expanded', String(open));
words.forEach((word, i) => (i === Number(open) ? word.removeAttribute('aria-hidden') : word.setAttribute('aria-hidden', 'true')));
roll();
if (open) {
started = performance.now();
place();
hold();
} else {
panel.classList.remove('is-open');
release();
}
}, { signal });
panel.addEventListener('toggle', (event) => {
if (event.newState !== 'open' || !open) return;
time();
panel.classList.add('is-open');
}, { signal });
// Tab past the last link, or a link followed: the shutter rolls back up
panel.addEventListener('focusout', (event) => {
const next = event.relatedTarget;
if (open && next && !panel.contains(next) && next !== toggle) panel.hidePopover();
}, { signal });
panel.addEventListener('click', (event) => {
if (open && event.target.closest('a[href]')) panel.hidePopover();
}, { signal });
signal.addEventListener('abort', () => {
rolls.forEach((run) => run.cancel());
release();
if (open) panel.hidePopover();
});
}
// 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.
const KODZA = Symbol.for('kodza');
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) => {
if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
const controller = new AbortController();
const saved = { html: written(root), attrs: attrsOf(root), stop: () => destroy(root) };
instances.set(root, { controller, saved });
root[KODZA] = saved;
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);
// 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[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 — Shutter Menu, for React. From https://kodza.dev/components/shutter-menu/
// 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: shutter-menu.css and shutter-menu.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.
// 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 './shutter-menu.css';
export type ShutterMenuProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** the menu — default: #0a0a0a */
"--kz-shutter-bg"?: string | number;
/** default: #f2f2f0 */
"--kz-shutter-fg"?: string | number;
/** default: rgba(242, 242, 240, 0.62) */
"--kz-shutter-muted"?: string | number;
/** default: rgba(242, 242, 240, 0.16) */
"--kz-shutter-line"?: string | number;
/** the Menu button, on the page — default: #0a0a0a */
"--kz-shutter-ink"?: string | number;
/** default: #ffffff */
"--kz-shutter-on-ink"?: string | number;
/** where the shutter starts; auto = the bottom of the header that holds the button — default: auto */
"--kz-shutter-top"?: string | number;
/** default: 24px */
"--kz-shutter-side"?: string | number;
/** default: clamp(36px, min(9cqw, calc((100cqh - 190px) / 4.9)), 112px) */
"--kz-shutter-size"?: string | number;
/** default: 0.8s */
"--kz-shutter-duration"?: string | number;
/** default: cubic-bezier(0.76, 0, 0.24, 1) */
"--kz-shutter-ease"?: string | number;
};
className?: string;
};
export function ShutterMenu({ vars, className, style, ...rest }: ShutterMenuProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-shutter", 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('./shutter-menu.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} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<button className="kodza-shutter__toggle" type="button" aria-expanded="false">
<span className="kodza-shutter__lines" aria-hidden="true" />
<span className="kodza-shutter__label">
<span className="kodza-shutter__say">Menu</span>
<span className="kodza-shutter__say" aria-hidden="true">Close</span>
</span>
</button>
<div className="kodza-shutter__panel" popover="" aria-label="Menu">
<nav className="kodza-shutter__nav" aria-label="Main">
<a className="kodza-shutter__link" href="#">
<span className="kodza-shutter__index">01</span>
<span className="kodza-shutter__mask">
<span className="kodza-shutter__word">Work</span>
</span>
</a>
{' '}
<a className="kodza-shutter__link" href="#">
<span className="kodza-shutter__index">02</span>
<span className="kodza-shutter__mask">
<span className="kodza-shutter__word">Services</span>
</span>
</a>
{' '}
<a className="kodza-shutter__link" href="#">
<span className="kodza-shutter__index">03</span>
<span className="kodza-shutter__mask">
<span className="kodza-shutter__word">Journal</span>
</span>
</a>
{' '}
<a className="kodza-shutter__link" href="#">
<span className="kodza-shutter__index">04</span>
<span className="kodza-shutter__mask">
<span className="kodza-shutter__word">Contact</span>
</span>
</a>
</nav>
<div className="kodza-shutter__info">
<p>Mon–Fri, 9 to 6. Closed when it's done.</p>
<p className="kodza-shutter__socials">
<a href="#">GitHub</a>
<a href="#">X</a>
<a href="#">RSS</a>
</p>
</div>
</div>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.