Dock
A frosted glass dock of app icons, shown over a wash of blue light. Icons swell as the pointer passes, hop when opened and show their name above.
Options
Code
import { useRef, useState } from "react";
import "./dock.css";
const reach = 100;
const growth = 0.4;
export function Dock({ apps, label = "Apps", onOpen }) {
const dock = useRef(null);
const centres = useRef([]);
const width = useRef(0);
const [scales, setScales] = useState(null);
const [opening, setOpening] = useState(null);
function measure() {
centres.current = [...dock.current.children].map((app) => app.offsetLeft + app.offsetWidth / 2);
width.current = dock.current.offsetWidth;
}
function move(event) {
if (event.pointerType !== "mouse") return;
if (matchMedia("(prefers-reduced-motion: reduce)").matches) return;
if (!scales) measure();
const box = dock.current.getBoundingClientRect();
const x = (event.clientX - box.left) / box.width * width.current;
setScales(
centres.current.map((centre) => {
const away = Math.min(Math.abs(x - centre) / reach, 1);
return 1 + growth * (Math.cos(away * Math.PI) + 1) / 2;
}),
);
}
return (
<nav
className="dh-dock"
aria-label={label}
ref={dock}
data-near={scales ? "" : undefined}
onPointerMove={move}
onPointerLeave={() => setScales(null)}
>
{apps.map((app, index) => (
<a
key={app.name}
href={app.href ?? "#"}
data-running={app.running ? "" : undefined}
data-opening={opening === app.name ? "" : undefined}
style={scales ? { "--dh-dock-scale": scales[index].toFixed(3) } : undefined}
onClick={(event) => {
if (!app.href) event.preventDefault();
setOpening(app.name);
onOpen?.(app);
}}
onAnimationEnd={() => setOpening(null)}
>
<img src={app.icon} alt={app.name} width="44" height="44" />
<span aria-hidden="true">{app.name}</span>
</a>
))}
</nav>
);
}.dh-dock-frame {
display: grid;
place-items: center;
min-height: 360px;
padding: 40px 20px;
background: #0b2fb8 url("/blocks/dock-light.jpg") center / cover no-repeat;
}
.dh-dock {
--dh-dock-size: 44px;
display: flex;
align-items: flex-end;
height: calc(var(--dh-dock-size) + 16px);
padding: 0 5px 8px;
border-radius: 18px;
background: linear-gradient(180deg, rgb(255 255 255 / 0.34) 0%, rgb(255 255 255 / 0.16) 100%);
box-shadow:
inset 0 1px 0 0 rgb(255 255 255 / 0.55),
inset 0 0 0 1px rgb(255 255 255 / 0.22),
inset 0 -1px 0 0 rgb(5 20 90 / 0.12),
0 0 0 1px rgb(5 20 90 / 0.14),
0 1px 2px 0 rgb(5 20 90 / 0.3),
0 6px 10px -5px rgb(5 20 90 / 0.45);
-webkit-backdrop-filter: blur(24px) saturate(160%);
backdrop-filter: blur(24px) saturate(160%);
font-family: inherit;
}
.dh-dock a {
position: relative;
flex: none;
width: calc(var(--dh-dock-size) * var(--dh-dock-scale, 1));
height: calc(var(--dh-dock-size) * var(--dh-dock-scale, 1));
margin: 0 2.5px;
border-radius: 24%;
outline: none;
-webkit-tap-highlight-color: transparent;
transition:
width 180ms cubic-bezier(0.23, 1, 0.32, 1),
height 180ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-dock[data-near] a {
transition-duration: 90ms;
}
.dh-dock img {
display: block;
width: 100%;
height: 100%;
filter: drop-shadow(0 0 0.5px rgb(5 20 90 / 0.5)) drop-shadow(0 1px 1px rgb(5 20 90 / 0.35)) drop-shadow(0 3px 3px rgb(5 20 90 / 0.18));
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-dock a:active img {
transform: scale(0.92);
}
.dh-dock a:focus-visible {
box-shadow: 0 0 0 2px #fff;
}
.dh-dock a[data-running]::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 3px;
height: 3px;
margin-left: -1.5px;
border-radius: 50%;
background: rgb(255 255 255 / 0.9);
}
.dh-dock a[data-opening] img {
animation: dh-dock-hop 520ms cubic-bezier(0.3, 0, 0.3, 1);
}
.dh-dock span {
position: absolute;
left: 50%;
bottom: calc(100% + 8px);
padding: 2px 8px;
border-radius: 7px;
background: rgb(12 18 40 / 0.78);
box-shadow:
inset 0 1px 0 0 rgb(255 255 255 / 0.12),
0 1px 2px 0 rgb(5 20 90 / 0.35);
color: #fff;
font-size: 11px;
line-height: 16px;
white-space: nowrap;
opacity: 0;
filter: blur(4px);
transform: translate(-50%, 4px);
pointer-events: none;
transition:
opacity 150ms cubic-bezier(0.23, 1, 0.32, 1),
filter 150ms cubic-bezier(0.23, 1, 0.32, 1),
transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
-webkit-backdrop-filter: blur(12px);
backdrop-filter: blur(12px);
}
.dh-dock a:focus-visible span {
opacity: 1;
filter: none;
transform: translate(-50%, 0);
}
@media (hover: hover) {
.dh-dock a:hover span {
opacity: 1;
filter: none;
transform: translate(-50%, 0);
}
}
@keyframes dh-dock-hop {
0%, 100% { transform: translateY(0); }
40% { transform: translateY(-22%); }
70% { transform: translateY(0); }
85% { transform: translateY(-6%); }
}
@media (max-width: 420px) {
.dh-dock { --dh-dock-size: 40px; }
}
@media (prefers-reduced-motion: reduce) {
.dh-dock a,
.dh-dock img,
.dh-dock span { transition: none; }
.dh-dock a[data-opening] img { animation: none; }
}<section class="dh-dock-frame">
<nav class="dh-dock" aria-label="Apps">
<a href="#">
<img src="/blocks/dock-claude.png" alt="Claude" width="44" height="44" />
<span aria-hidden="true">Claude</span>
</a>
<a href="#" data-running>
<img src="/blocks/dock-figma.png" alt="Figma" width="44" height="44" />
<span aria-hidden="true">Figma</span>
</a>
<a href="#" data-running>
<img src="/blocks/dock-designs.svg" alt="designs.here" width="44" height="44" />
<span aria-hidden="true">designs.here</span>
</a>
<a href="#" data-running>
<img src="/blocks/dock-chrome.png" alt="Chrome" width="44" height="44" />
<span aria-hidden="true">Chrome</span>
</a>
<a href="#">
<img src="/blocks/dock-spotify.png" alt="Spotify" width="44" height="44" />
<span aria-hidden="true">Spotify</span>
</a>
</nav>
</section>.dh-dock-frame {
display: grid;
place-items: center;
min-height: 360px;
padding: 40px 20px;
background: #0b2fb8 url("/blocks/dock-light.jpg") center / cover no-repeat;
}
.dh-dock {
--dh-dock-size: 44px;
display: flex;
align-items: flex-end;
height: calc(var(--dh-dock-size) + 16px);
padding: 0 5px 8px;
border-radius: 18px;
background: linear-gradient(180deg, rgb(255 255 255 / 0.34) 0%, rgb(255 255 255 / 0.16) 100%);
box-shadow:
inset 0 1px 0 0 rgb(255 255 255 / 0.55),
inset 0 0 0 1px rgb(255 255 255 / 0.22),
inset 0 -1px 0 0 rgb(5 20 90 / 0.12),
0 0 0 1px rgb(5 20 90 / 0.14),
0 1px 2px 0 rgb(5 20 90 / 0.3),
0 6px 10px -5px rgb(5 20 90 / 0.45);
-webkit-backdrop-filter: blur(24px) saturate(160%);
backdrop-filter: blur(24px) saturate(160%);
font-family: inherit;
}
.dh-dock a {
position: relative;
flex: none;
width: calc(var(--dh-dock-size) * var(--dh-dock-scale, 1));
height: calc(var(--dh-dock-size) * var(--dh-dock-scale, 1));
margin: 0 2.5px;
border-radius: 24%;
outline: none;
-webkit-tap-highlight-color: transparent;
transition:
width 180ms cubic-bezier(0.23, 1, 0.32, 1),
height 180ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-dock[data-near] a {
transition-duration: 90ms;
}
.dh-dock img {
display: block;
width: 100%;
height: 100%;
filter: drop-shadow(0 0 0.5px rgb(5 20 90 / 0.5)) drop-shadow(0 1px 1px rgb(5 20 90 / 0.35)) drop-shadow(0 3px 3px rgb(5 20 90 / 0.18));
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-dock a:active img {
transform: scale(0.92);
}
.dh-dock a:focus-visible {
box-shadow: 0 0 0 2px #fff;
}
.dh-dock a[data-running]::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 3px;
height: 3px;
margin-left: -1.5px;
border-radius: 50%;
background: rgb(255 255 255 / 0.9);
}
.dh-dock a[data-opening] img {
animation: dh-dock-hop 520ms cubic-bezier(0.3, 0, 0.3, 1);
}
.dh-dock span {
position: absolute;
left: 50%;
bottom: calc(100% + 8px);
padding: 2px 8px;
border-radius: 7px;
background: rgb(12 18 40 / 0.78);
box-shadow:
inset 0 1px 0 0 rgb(255 255 255 / 0.12),
0 1px 2px 0 rgb(5 20 90 / 0.35);
color: #fff;
font-size: 11px;
line-height: 16px;
white-space: nowrap;
opacity: 0;
filter: blur(4px);
transform: translate(-50%, 4px);
pointer-events: none;
transition:
opacity 150ms cubic-bezier(0.23, 1, 0.32, 1),
filter 150ms cubic-bezier(0.23, 1, 0.32, 1),
transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
-webkit-backdrop-filter: blur(12px);
backdrop-filter: blur(12px);
}
.dh-dock a:focus-visible span {
opacity: 1;
filter: none;
transform: translate(-50%, 0);
}
@media (hover: hover) {
.dh-dock a:hover span {
opacity: 1;
filter: none;
transform: translate(-50%, 0);
}
}
@keyframes dh-dock-hop {
0%, 100% { transform: translateY(0); }
40% { transform: translateY(-22%); }
70% { transform: translateY(0); }
85% { transform: translateY(-6%); }
}
@media (max-width: 420px) {
.dh-dock { --dh-dock-size: 40px; }
}
@media (prefers-reduced-motion: reduce) {
.dh-dock a,
.dh-dock img,
.dh-dock span { transition: none; }
.dh-dock a[data-opening] img { animation: none; }
}document.querySelectorAll(".dh-dock").forEach((dock) => {
if (dock.dataset.wired) return;
dock.dataset.wired = "true";
const apps = [...dock.querySelectorAll("a")];
const calm = matchMedia("(prefers-reduced-motion: reduce)").matches;
const reach = 100;
const growth = 0.4;
let centres = [];
let width = 0;
const measure = () => {
centres = apps.map((app) => app.offsetLeft + app.offsetWidth / 2);
width = dock.offsetWidth;
};
const rest = () => {
dock.removeAttribute("data-near");
apps.forEach((app) => app.style.removeProperty("--dh-dock-scale"));
};
const swell = (x) => {
apps.forEach((app, index) => {
const away = Math.min(Math.abs(x - centres[index]) / reach, 1);
const scale = 1 + growth * (Math.cos(away * Math.PI) + 1) / 2;
app.style.setProperty("--dh-dock-scale", scale.toFixed(3));
});
};
if (!calm) {
dock.addEventListener("pointermove", (event) => {
if (event.pointerType !== "mouse") return;
if (!dock.hasAttribute("data-near")) measure();
const box = dock.getBoundingClientRect();
dock.setAttribute("data-near", "");
swell((event.clientX - box.left) / box.width * width);
});
dock.addEventListener("pointerleave", rest);
}
apps.forEach((app) =>
app.addEventListener("click", (event) => {
if (app.getAttribute("href") === "#") event.preventDefault();
app.setAttribute("data-running", "");
app.removeAttribute("data-opening");
void app.offsetWidth;
app.setAttribute("data-opening", "");
}),
);
dock.addEventListener("animationend", (event) => event.target.parentElement.removeAttribute("data-opening"));
});Dock is not in the Figma file yet.
Use the React or HTML code for now.