Voice warmth
for every reply
25%
FormalFriendly
Cards set on a turning ring. The one in front faces you; its neighbours have gone round the back, mirrored, with their colour wrapping away toward the edges.
FormalFriendly
NoneAll
010
EmptyFull
0100
import { useLayoutEffect, useRef, useState } from "react";
import "./card-ring.css";
const places = { 0: "front", 1: "right", [-1]: "left" };
const strips = 36;
const kept = 0.5;
const reach = 0.72;
const bend = (card, side) => {
if ((card.dataset.bend || "") === side) return;
card.querySelectorAll(".dh-ring-wing").forEach((wing) => wing.remove());
if (!side) return card.removeAttribute("data-bend");
card.dataset.bend = side;
const face = card.querySelector(".dh-ring-face");
const wide = card.offsetWidth;
const tall = card.offsetHeight;
const start = Math.round(wide * kept);
const taken = wide - start;
const out = taken + Math.round(wide * reach);
const power = out / taken;
const most = 1.75;
const source = (x) => start + taken * (1 - Math.pow(1 - x / out, power));
const growth = (x) => 1 + (most - 1) * Math.pow(Math.max(0, (x - taken) / (out - taken)), 1.5);
const wing = document.createElement("div");
wing.className = "dh-ring-wing";
wing.dataset.side = side;
wing.setAttribute("aria-hidden", "true");
wing.style.left = start + "px";
wing.style.width = out + "px";
wing.style.top = -(most - 1) * tall / 2 + "px";
wing.style.height = tall * most + "px";
const rim = document.createElement("i");
const body = document.createElement("div");
const edge = (inset) => {
const top = [];
const bottom = [];
for (let step = 0; step <= 24; step++) {
const x = step / 24 * out;
const half = growth(x) / most * 50 - inset * Math.max(0, (x - taken) / (out - taken));
top.push((x / out * 100).toFixed(2) + "% " + (50 - half).toFixed(2) + "%");
bottom.unshift((x / out * 100).toFixed(2) + "% " + (50 + half).toFixed(2) + "%");
}
return "polygon(" + top.concat(bottom).join(", ") + ")";
};
rim.style.clipPath = edge(0);
body.style.clipPath = edge(1.2);
for (let index = 0; index < strips * 2 + 1; index++) {
const under = index > strips;
const place = under ? index - strips - 1 : index - 0.5;
const left = Math.max(0, Math.round(place / strips * out));
const right = Math.min(out, Math.round((place + 1) / strips * out));
const begin = source(left);
const stretch = (right - left) / (source(right) - begin);
const grow = growth((left + right) / 2);
const until = source(right) + 2 / stretch;
const copy = face.cloneNode(true);
copy.style.inset = "auto";
copy.style.left = left + "px";
copy.style.top = (most - 1) * tall / 2 + "px";
copy.style.width = wide + "px";
copy.style.height = tall + "px";
copy.style.transform =
"translateX(" + -begin * stretch + "px) scale(" + stretch + ", " + grow + ")" +
(side === "start" ? " translateX(" + wide + "px) scaleX(-1)" : "");
copy.style.clipPath =
side === "start"
? "inset(0 " + begin + "px 0 " + Math.max(0, wide - until) + "px)"
: "inset(0 " + Math.max(0, wide - until) + "px 0 " + begin + "px)";
const past = (grow - 1) / (most - 1);
if (past > 0.01) copy.style.filter = "blur(" + (past * 7).toFixed(1) + "px)";
if (under) body.append(copy);
else body.prepend(copy);
}
wing.append(rim, body);
card.append(wing);
};
export function CardRing({ cards, label = "Cards" }) {
const [front, setFront] = useState(0);
const from = useRef(null);
const ring = useRef(null);
const turn = (by) => setFront((now) => (now + by + cards.length) % cards.length);
useLayoutEffect(() => {
const fit = () =>
ring.current.querySelectorAll(".dh-ring-card").forEach((card) => {
bend(card, "");
bend(card, card.dataset.at === "left" ? "end" : card.dataset.at === "right" ? "start" : "");
});
fit();
const watcher = new ResizeObserver(fit);
watcher.observe(ring.current);
return () => watcher.disconnect();
}, [front, cards]);
return (
<section className="dh-ring-frame">
<div
className="dh-ring"
ref={ring}
tabIndex={0}
role="group"
aria-roledescription="carousel"
aria-label={label}
onKeyDown={(event) => {
if (event.key === "ArrowLeft") turn(-1);
if (event.key === "ArrowRight") turn(1);
}}
onPointerDown={(event) => (from.current = event.clientX)}
onPointerUp={(event) => {
if (from.current === null) return;
const moved = event.clientX - from.current;
from.current = null;
if (Math.abs(moved) > 40) turn(moved < 0 ? 1 : -1);
}}
>
{cards.map((card, index) => {
let away = (index - front + cards.length) % cards.length;
if (away > cards.length / 2) away -= cards.length;
const at = places[away] || (away > 0 ? "far-right" : "far-left");
return (
<article
className="dh-ring-card"
key={card.title}
data-tone={card.tone}
data-at={at}
aria-hidden={away !== 0}
style={{ "--dh-ring-value": card.at + "%" }}
onClick={() => (at === "left" ? turn(-1) : at === "right" ? turn(1) : null)}
>
<div className="dh-ring-face">
<h3>{card.title}</h3>
<div className="dh-ring-figure">
<strong>
{card.value}
{card.unit && <sup>{card.unit}</sup>}
</strong>
<div className="dh-ring-meter">
<i />
</div>
<p>
<span>{card.low}</span>
<span>{card.high}</span>
</p>
</div>
<footer>{card.foot}</footer>
</div>
</article>
);
})}
</div>
<div className="dh-ring-steps">
<button type="button" aria-label="Previous card" onClick={() => turn(-1)}>
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="M9.5 3.5 5 8l4.5 4.5" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</button>
<button type="button" aria-label="Next card" onClick={() => turn(1)}>
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="M6.5 3.5 11 8l-4.5 4.5" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</button>
</div>
</section>
);
}.dh-ring-frame {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 36px;
overflow: hidden;
min-height: 680px;
padding: 48px 20px 36px;
background: #f1f1f2 url("/blocks/ring-pearl.jpg") center / 210% 210% no-repeat;
font-family: inherit;
}
.dh-ring {
position: relative;
width: 320px;
height: 420px;
outline: none;
perspective: 1600px;
transform-style: preserve-3d;
touch-action: pan-y;
}
.dh-ring-card {
--dh-ring-a: #2f6bff;
--dh-ring-b: #7fe3ff;
--dh-ring-c: #06103a;
--dh-ring-ink: #9fe6ff;
position: absolute;
inset: 0;
cursor: pointer;
transition:
transform 800ms cubic-bezier(0.3, 1, 0.3, 1),
opacity 400ms cubic-bezier(0.23, 1, 0.32, 1);
-webkit-tap-highlight-color: transparent;
}
.dh-ring-face {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 26px 26px 24px;
border-radius: 14px;
background:
radial-gradient(70% 55% at 100% 100%, var(--dh-ring-b) 0%, transparent 100%),
radial-gradient(80% 60% at 0% 100%, var(--dh-ring-a) 0%, transparent 100%),
radial-gradient(90% 60% at 80% 45%, var(--dh-ring-a) 0%, transparent 100%),
var(--dh-ring-c);
box-shadow:
inset 0 0 0 1px rgb(255 255 255 / 0.14),
inset 0 1px 0 0 rgb(255 255 255 / 0.3),
0 1px 2px 0 rgb(10 14 40 / 0.3),
0 14px 18px -12px rgb(10 14 40 / 0.5);
color: #fff;
font-size: 15px;
line-height: 20px;
}
.dh-ring-card[data-tone="violet"] {
--dh-ring-a: #a24dff;
--dh-ring-b: #f0b6ff;
--dh-ring-c: #2a0a5e;
--dh-ring-ink: #f3d2ff;
}
.dh-ring-card[data-tone="moss"] {
--dh-ring-a: #17b877;
--dh-ring-b: #d7ff8a;
--dh-ring-c: #03301f;
--dh-ring-ink: #d2ffc4;
}
.dh-ring-card[data-tone="amber"] {
--dh-ring-a: #ff8a1f;
--dh-ring-b: #ffe27a;
--dh-ring-c: #4a1503;
--dh-ring-ink: #ffe9b8;
}
.dh-ring-card[data-tone="rose"] {
--dh-ring-a: #ff3b6b;
--dh-ring-b: #ff9a5a;
--dh-ring-c: #4a0624;
--dh-ring-ink: #ffd3d8;
}
/* Where a card sits on the ring. The side cards have gone round the back, so
they are seen from behind and read mirrored. */
.dh-ring-card[data-at="front"] {
z-index: 1;
cursor: default;
}
.dh-ring-card[data-at="left"] {
transform: translateX(-104%) rotateY(-180deg) scale(0.8);
}
.dh-ring-card[data-at="right"] {
transform: translateX(104%) rotateY(180deg) scale(0.8);
}
.dh-ring-card[data-at="far-left"] {
transform: translateX(-190%) rotateY(-180deg) scale(0.8);
opacity: 0;
pointer-events: none;
}
.dh-ring-card[data-at="far-right"] {
transform: translateX(190%) rotateY(180deg) scale(0.8);
opacity: 0;
pointer-events: none;
}
/* The bend. The script cuts the outer part of a side card into thin strips, each
a copy of the card stretched a little more than the last, taller and softer,
so the card smears away toward the edge of the scene. The card itself is
trimmed where the strips take over. */
.dh-ring-card[data-bend] > .dh-ring-face {
box-shadow: none;
}
.dh-ring-card[data-bend="end"] > .dh-ring-face {
clip-path: inset(0 calc(50% - 4px) 0 0);
}
.dh-ring-card[data-bend="start"] > .dh-ring-face {
clip-path: inset(0 0 0 calc(50% - 4px));
}
.dh-ring-wing {
position: absolute;
pointer-events: none;
animation: dh-ring-bend 500ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-ring-wing[data-side="start"] {
left: auto !important;
right: 50%;
transform: scaleX(-1);
}
.dh-ring-wing > i,
.dh-ring-wing > div {
position: absolute;
inset: 0;
}
.dh-ring-wing > i {
background: linear-gradient(180deg, #a8f1ff 0%, var(--dh-ring-b) 30%, var(--dh-ring-a) 70%, #a8f1ff 100%);
}
.dh-ring-wing > div {
filter: blur(0.8px);
}
.dh-ring-wing .dh-ring-face {
border-radius: 0;
box-shadow: none;
transform-origin: 0 50%;
}
@keyframes dh-ring-bend {
from { opacity: 0; }
}
.dh-ring-card h3 {
margin: 0;
font-size: 17px;
font-weight: inherit;
line-height: 22px;
letter-spacing: -0.01em;
}
.dh-ring-figure strong {
display: flex;
justify-content: center;
color: var(--dh-ring-ink);
font-size: 104px;
font-weight: inherit;
line-height: 104px;
letter-spacing: -0.05em;
}
.dh-ring-figure sup {
margin: 10px 0 0 4px;
font-size: 34px;
line-height: 34px;
letter-spacing: 0;
}
.dh-ring-meter {
position: relative;
height: 2px;
margin-top: 14px;
border-radius: 2px;
background: linear-gradient(90deg, rgb(255 255 255 / 0.25), var(--dh-ring-ink));
}
.dh-ring-meter i {
position: absolute;
left: var(--dh-ring-value, 50%);
top: 50%;
width: 14px;
height: 14px;
margin: -7px 0 0 -7px;
border-radius: 50%;
background: #fff;
box-shadow:
0 0 0 1px rgb(10 14 40 / 0.12),
0 1px 2px 0 rgb(10 14 40 / 0.4),
0 0 12px 2px rgb(255 255 255 / 0.55);
}
.dh-ring-figure p {
display: flex;
justify-content: space-between;
margin: 12px 0 0;
color: rgb(255 255 255 / 0.8);
font-size: 12px;
line-height: 16px;
}
.dh-ring-card footer {
font-size: 17px;
line-height: 22px;
letter-spacing: -0.01em;
}
.dh-ring:focus-visible .dh-ring-card[data-at="front"] > .dh-ring-face {
outline: 2px solid #1c1c1c;
outline-offset: 4px;
}
.dh-ring-steps {
display: flex;
gap: 8px;
}
.dh-ring-steps button {
display: grid;
place-items: center;
width: 32px;
height: 32px;
padding: 0;
border: 0;
border-radius: 50%;
background: #fff;
box-shadow:
0 0 0 1px rgb(23 23 23 / 0.08),
0 1px 2px 0 rgb(23 23 23 / 0.12);
color: #1c1c1c;
cursor: pointer;
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-ring-steps button:active {
transform: scale(0.92);
}
.dh-ring-steps button:focus-visible {
outline: 2px solid #1c1c1c;
outline-offset: 2px;
}
.dh-ring-steps svg {
width: 16px;
height: 16px;
}
@media (max-width: 640px) {
.dh-ring-frame { min-height: 520px; }
.dh-ring { width: 248px; height: 330px; perspective: 800px; }
.dh-ring-face { padding: 20px; font-size: 14px; }
.dh-ring-card h3,
.dh-ring-card footer { font-size: 15px; line-height: 20px; }
.dh-ring-figure strong { font-size: 76px; line-height: 76px; }
.dh-ring-figure sup { font-size: 24px; line-height: 24px; }
}
@media (pointer: coarse) {
.dh-ring-steps button { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
.dh-ring-card { transition: opacity 200ms linear; }
.dh-ring-wing { animation: none; }
}<section class="dh-ring-frame">
<div class="dh-ring" tabindex="0" role="group" aria-roledescription="carousel" aria-label="Settings">
<article class="dh-ring-card" data-tone="ocean" data-at="front" style="--dh-ring-value:25%">
<div class="dh-ring-face">
<h3>Voice warmth<br />for every reply</h3>
<div class="dh-ring-figure">
<strong>25<sup>%</sup></strong>
<div class="dh-ring-meter"><i></i></div>
<p><span>Formal</span><span>Friendly</span></p>
</div>
<footer>Tone settings</footer>
</div>
</article>
<article class="dh-ring-card" data-tone="violet" data-at="right" style="--dh-ring-value:40%">
<div class="dh-ring-face">
<h3>Drafts kept<br />for each post</h3>
<div class="dh-ring-figure">
<strong>12</strong>
<div class="dh-ring-meter"><i></i></div>
<p><span>None</span><span>All</span></p>
</div>
<footer>Version history</footer>
</div>
</article>
<article class="dh-ring-card" data-tone="moss" data-at="far-right" style="--dh-ring-value:80%">
<div class="dh-ring-face">
<h3>Seats in use<br />on this plan</h3>
<div class="dh-ring-figure">
<strong>8</strong>
<div class="dh-ring-meter"><i></i></div>
<p><span>0</span><span>10</span></p>
</div>
<footer>Team and billing</footer>
</div>
</article>
<article class="dh-ring-card" data-tone="amber" data-at="far-left" style="--dh-ring-value:64%">
<div class="dh-ring-face">
<h3>Storage used<br />this month</h3>
<div class="dh-ring-figure">
<strong>64<sup>%</sup></strong>
<div class="dh-ring-meter"><i></i></div>
<p><span>Empty</span><span>Full</span></p>
</div>
<footer>Files and media</footer>
</div>
</article>
<article class="dh-ring-card" data-tone="rose" data-at="left" style="--dh-ring-value:72%">
<div class="dh-ring-face">
<h3>Render hours<br />left this week</h3>
<div class="dh-ring-figure">
<strong>72</strong>
<div class="dh-ring-meter"><i></i></div>
<p><span>0</span><span>100</span></p>
</div>
<footer>Render engine 2.0</footer>
</div>
</article>
</div>
<div class="dh-ring-steps">
<button type="button" aria-label="Previous card" data-ring-step="-1"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M9.5 3.5 5 8l4.5 4.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg></button>
<button type="button" aria-label="Next card" data-ring-step="1"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6.5 3.5 11 8l-4.5 4.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /></svg></button>
</div>
</section>.dh-ring-frame {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 36px;
overflow: hidden;
min-height: 680px;
padding: 48px 20px 36px;
background: #f1f1f2 url("/blocks/ring-pearl.jpg") center / 210% 210% no-repeat;
font-family: inherit;
}
.dh-ring {
position: relative;
width: 320px;
height: 420px;
outline: none;
perspective: 1600px;
transform-style: preserve-3d;
touch-action: pan-y;
}
.dh-ring-card {
--dh-ring-a: #2f6bff;
--dh-ring-b: #7fe3ff;
--dh-ring-c: #06103a;
--dh-ring-ink: #9fe6ff;
position: absolute;
inset: 0;
cursor: pointer;
transition:
transform 800ms cubic-bezier(0.3, 1, 0.3, 1),
opacity 400ms cubic-bezier(0.23, 1, 0.32, 1);
-webkit-tap-highlight-color: transparent;
}
.dh-ring-face {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 26px 26px 24px;
border-radius: 14px;
background:
radial-gradient(70% 55% at 100% 100%, var(--dh-ring-b) 0%, transparent 100%),
radial-gradient(80% 60% at 0% 100%, var(--dh-ring-a) 0%, transparent 100%),
radial-gradient(90% 60% at 80% 45%, var(--dh-ring-a) 0%, transparent 100%),
var(--dh-ring-c);
box-shadow:
inset 0 0 0 1px rgb(255 255 255 / 0.14),
inset 0 1px 0 0 rgb(255 255 255 / 0.3),
0 1px 2px 0 rgb(10 14 40 / 0.3),
0 14px 18px -12px rgb(10 14 40 / 0.5);
color: #fff;
font-size: 15px;
line-height: 20px;
}
.dh-ring-card[data-tone="violet"] {
--dh-ring-a: #a24dff;
--dh-ring-b: #f0b6ff;
--dh-ring-c: #2a0a5e;
--dh-ring-ink: #f3d2ff;
}
.dh-ring-card[data-tone="moss"] {
--dh-ring-a: #17b877;
--dh-ring-b: #d7ff8a;
--dh-ring-c: #03301f;
--dh-ring-ink: #d2ffc4;
}
.dh-ring-card[data-tone="amber"] {
--dh-ring-a: #ff8a1f;
--dh-ring-b: #ffe27a;
--dh-ring-c: #4a1503;
--dh-ring-ink: #ffe9b8;
}
.dh-ring-card[data-tone="rose"] {
--dh-ring-a: #ff3b6b;
--dh-ring-b: #ff9a5a;
--dh-ring-c: #4a0624;
--dh-ring-ink: #ffd3d8;
}
/* Where a card sits on the ring. The side cards have gone round the back, so
they are seen from behind and read mirrored. */
.dh-ring-card[data-at="front"] {
z-index: 1;
cursor: default;
}
.dh-ring-card[data-at="left"] {
transform: translateX(-104%) rotateY(-180deg) scale(0.8);
}
.dh-ring-card[data-at="right"] {
transform: translateX(104%) rotateY(180deg) scale(0.8);
}
.dh-ring-card[data-at="far-left"] {
transform: translateX(-190%) rotateY(-180deg) scale(0.8);
opacity: 0;
pointer-events: none;
}
.dh-ring-card[data-at="far-right"] {
transform: translateX(190%) rotateY(180deg) scale(0.8);
opacity: 0;
pointer-events: none;
}
/* The bend. The script cuts the outer part of a side card into thin strips, each
a copy of the card stretched a little more than the last, taller and softer,
so the card smears away toward the edge of the scene. The card itself is
trimmed where the strips take over. */
.dh-ring-card[data-bend] > .dh-ring-face {
box-shadow: none;
}
.dh-ring-card[data-bend="end"] > .dh-ring-face {
clip-path: inset(0 calc(50% - 4px) 0 0);
}
.dh-ring-card[data-bend="start"] > .dh-ring-face {
clip-path: inset(0 0 0 calc(50% - 4px));
}
.dh-ring-wing {
position: absolute;
pointer-events: none;
animation: dh-ring-bend 500ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.dh-ring-wing[data-side="start"] {
left: auto !important;
right: 50%;
transform: scaleX(-1);
}
.dh-ring-wing > i,
.dh-ring-wing > div {
position: absolute;
inset: 0;
}
.dh-ring-wing > i {
background: linear-gradient(180deg, #a8f1ff 0%, var(--dh-ring-b) 30%, var(--dh-ring-a) 70%, #a8f1ff 100%);
}
.dh-ring-wing > div {
filter: blur(0.8px);
}
.dh-ring-wing .dh-ring-face {
border-radius: 0;
box-shadow: none;
transform-origin: 0 50%;
}
@keyframes dh-ring-bend {
from { opacity: 0; }
}
.dh-ring-card h3 {
margin: 0;
font-size: 17px;
font-weight: inherit;
line-height: 22px;
letter-spacing: -0.01em;
}
.dh-ring-figure strong {
display: flex;
justify-content: center;
color: var(--dh-ring-ink);
font-size: 104px;
font-weight: inherit;
line-height: 104px;
letter-spacing: -0.05em;
}
.dh-ring-figure sup {
margin: 10px 0 0 4px;
font-size: 34px;
line-height: 34px;
letter-spacing: 0;
}
.dh-ring-meter {
position: relative;
height: 2px;
margin-top: 14px;
border-radius: 2px;
background: linear-gradient(90deg, rgb(255 255 255 / 0.25), var(--dh-ring-ink));
}
.dh-ring-meter i {
position: absolute;
left: var(--dh-ring-value, 50%);
top: 50%;
width: 14px;
height: 14px;
margin: -7px 0 0 -7px;
border-radius: 50%;
background: #fff;
box-shadow:
0 0 0 1px rgb(10 14 40 / 0.12),
0 1px 2px 0 rgb(10 14 40 / 0.4),
0 0 12px 2px rgb(255 255 255 / 0.55);
}
.dh-ring-figure p {
display: flex;
justify-content: space-between;
margin: 12px 0 0;
color: rgb(255 255 255 / 0.8);
font-size: 12px;
line-height: 16px;
}
.dh-ring-card footer {
font-size: 17px;
line-height: 22px;
letter-spacing: -0.01em;
}
.dh-ring:focus-visible .dh-ring-card[data-at="front"] > .dh-ring-face {
outline: 2px solid #1c1c1c;
outline-offset: 4px;
}
.dh-ring-steps {
display: flex;
gap: 8px;
}
.dh-ring-steps button {
display: grid;
place-items: center;
width: 32px;
height: 32px;
padding: 0;
border: 0;
border-radius: 50%;
background: #fff;
box-shadow:
0 0 0 1px rgb(23 23 23 / 0.08),
0 1px 2px 0 rgb(23 23 23 / 0.12);
color: #1c1c1c;
cursor: pointer;
transition: transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dh-ring-steps button:active {
transform: scale(0.92);
}
.dh-ring-steps button:focus-visible {
outline: 2px solid #1c1c1c;
outline-offset: 2px;
}
.dh-ring-steps svg {
width: 16px;
height: 16px;
}
@media (max-width: 640px) {
.dh-ring-frame { min-height: 520px; }
.dh-ring { width: 248px; height: 330px; perspective: 800px; }
.dh-ring-face { padding: 20px; font-size: 14px; }
.dh-ring-card h3,
.dh-ring-card footer { font-size: 15px; line-height: 20px; }
.dh-ring-figure strong { font-size: 76px; line-height: 76px; }
.dh-ring-figure sup { font-size: 24px; line-height: 24px; }
}
@media (pointer: coarse) {
.dh-ring-steps button { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
.dh-ring-card { transition: opacity 200ms linear; }
.dh-ring-wing { animation: none; }
}document.querySelectorAll(".dh-ring").forEach((ring) => {
if (ring.dataset.wired) return;
ring.dataset.wired = "true";
const cards = [...ring.querySelectorAll(".dh-ring-card")];
const places = { "0": "front", "1": "right", "-1": "left" };
let front = Math.max(0, cards.findIndex((card) => card.dataset.at === "front"));
const strips = 36;
const kept = 0.5;
const reach = 0.72;
const bend = (card, side) => {
if ((card.dataset.bend || "") === side) return;
card.querySelectorAll(".dh-ring-wing").forEach((wing) => wing.remove());
if (!side) return card.removeAttribute("data-bend");
card.dataset.bend = side;
const face = card.querySelector(".dh-ring-face");
const wide = card.offsetWidth;
const tall = card.offsetHeight;
const start = Math.round(wide * kept);
const taken = wide - start;
const out = taken + Math.round(wide * reach);
const power = out / taken;
const most = 1.75;
const source = (x) => start + taken * (1 - Math.pow(1 - x / out, power));
const growth = (x) => 1 + (most - 1) * Math.pow(Math.max(0, (x - taken) / (out - taken)), 1.5);
const wing = document.createElement("div");
wing.className = "dh-ring-wing";
wing.dataset.side = side;
wing.setAttribute("aria-hidden", "true");
wing.style.left = start + "px";
wing.style.width = out + "px";
wing.style.top = -(most - 1) * tall / 2 + "px";
wing.style.height = tall * most + "px";
const rim = document.createElement("i");
const body = document.createElement("div");
const edge = (inset) => {
const top = [];
const bottom = [];
for (let step = 0; step <= 24; step++) {
const x = step / 24 * out;
const half = growth(x) / most * 50 - inset * Math.max(0, (x - taken) / (out - taken));
top.push((x / out * 100).toFixed(2) + "% " + (50 - half).toFixed(2) + "%");
bottom.unshift((x / out * 100).toFixed(2) + "% " + (50 + half).toFixed(2) + "%");
}
return "polygon(" + top.concat(bottom).join(", ") + ")";
};
rim.style.clipPath = edge(0);
body.style.clipPath = edge(1.2);
for (let index = 0; index < strips * 2 + 1; index++) {
const under = index > strips;
const place = under ? index - strips - 1 : index - 0.5;
const left = Math.max(0, Math.round(place / strips * out));
const right = Math.min(out, Math.round((place + 1) / strips * out));
const begin = source(left);
const stretch = (right - left) / (source(right) - begin);
const grow = growth((left + right) / 2);
const until = source(right) + 2 / stretch;
const copy = face.cloneNode(true);
copy.style.inset = "auto";
copy.style.left = left + "px";
copy.style.top = (most - 1) * tall / 2 + "px";
copy.style.width = wide + "px";
copy.style.height = tall + "px";
copy.style.transform =
"translateX(" + -begin * stretch + "px) scale(" + stretch + ", " + grow + ")" +
(side === "start" ? " translateX(" + wide + "px) scaleX(-1)" : "");
copy.style.clipPath =
side === "start"
? "inset(0 " + begin + "px 0 " + Math.max(0, wide - until) + "px)"
: "inset(0 " + Math.max(0, wide - until) + "px 0 " + begin + "px)";
const past = (grow - 1) / (most - 1);
if (past > 0.01) copy.style.filter = "blur(" + (past * 7).toFixed(1) + "px)";
if (under) body.append(copy);
else body.prepend(copy);
}
wing.append(rim, body);
card.append(wing);
};
const show = () => {
cards.forEach((card, index) => {
let away = (index - front + cards.length) % cards.length;
if (away > cards.length / 2) away -= cards.length;
card.dataset.at = places[away] || (away > 0 ? "far-right" : "far-left");
card.setAttribute("aria-hidden", String(away !== 0));
bend(card, away === -1 ? "end" : away === 1 ? "start" : "");
});
};
const turn = (by) => {
front = (front + by + cards.length) % cards.length;
show();
};
cards.forEach((card) =>
card.addEventListener("click", () => {
if (card.dataset.at === "left") turn(-1);
if (card.dataset.at === "right") turn(1);
}),
);
ring.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") turn(-1);
if (event.key === "ArrowRight") turn(1);
});
let from = null;
ring.addEventListener("pointerdown", (event) => (from = event.clientX));
ring.addEventListener("pointerup", (event) => {
if (from === null) return;
const moved = event.clientX - from;
from = null;
if (Math.abs(moved) > 40) turn(moved < 0 ? 1 : -1);
});
ring.addEventListener("pointercancel", () => (from = null));
const steps = ring.parentElement.querySelectorAll("[data-ring-step]");
steps.forEach((step) => step.addEventListener("click", () => turn(Number(step.dataset.ringStep))));
show();
new ResizeObserver(() => {
cards.forEach((card) => bend(card, ""));
show();
}).observe(ring);
});Card ring is not in the Figma file yet.
Use the React or HTML code for now.
No designs match that search.