Cómo funciona
A preserve-3d ring tipped toward the viewer, rolled a little and turned by one angle in degrees. Each slim card stands on the ring at its own place and is then turned about its own upright by the fan angle, so neighbours overlap like the pages of a fanned ribbon; with more places than items the items repeat. In CSS each card takes the cosine of the way it faces and brightens toward the front. Pointing at a card lifts it out of the ribbon; the card in front is lifted too and takes an accent rim. Pressing a card turns it to the front by the shortest way round; pressing the front card, double-clicking any card, Enter or the name under the ring opens it: the ring dims and blurs behind, and the card rises large and flat over it. Escape, the close button or the name lays it back. One frame loop handles the tweens, the coast after a throw and the slow drift.
Úsalo para
- A showcase of many small, mostly visual items on a landing page or a portfolio: swatches, covers, screens, tickets.
- Twenty or more places; with a short list, set slots so the items repeat and the ribbon looks full.
Busca otra opción cuando
- Not for text people must read in the ribbon: the cards are slim and turned; put the words in the open card.
Uso
import { RibbonRing } from './RibbonRing.jsx'
const swatches = [
{ id: 'slate', name: 'Mineral Slate', hex: '#5B6770' },
{ id: 'linen', name: 'Warm Linen', hex: '#E9DFCF' },
{ id: 'moss', name: 'Forest Moss', hex: '#4F6B3A' },
{ id: 'terracotta', name: 'Terracotta', hex: '#C4623F' },
]
export function Swatches() {
return (
<RibbonRing
items={swatches}
slots={24}
label="Material swatches"
renderCard={(s) => <div style={{ height: '60%', background: s.hex }} />}
renderDetail={(s) => (
<div style={{ height: '100%', display: 'grid', gridTemplateRows: '1fr auto' }}>
<div style={{ background: s.hex }} />
<strong style={{ padding: 14 }}>{s.name}</strong>
</div>
)}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
items | T[] | [] | The cards, in order round the ring. |
renderCard | (item, { index, front }) => ReactNode | — | Content of a slim card in the ribbon. Keep it graphic: a colour, a picture, two lines. |
renderDetail | (item, { index }) => ReactNode | — | Content of the open card, shown large over the ring. Falls back to renderCard. |
getLabel | (item, index) => string | — | Name of each card, shown under the ring and read by screen readers. Defaults to item.title or item.name. |
index | number | — | Controlled current card. Omit to let the ring keep its own. |
defaultIndex | number | 0 | First current card for an uncontrolled ring. |
onIndexChange | (index, item) => void | — | Called when another card comes to the front. |
open | boolean | — | Controlled open state of the current card. Omit to let the ring keep its own. |
defaultOpen | boolean | false | Initial open state for an uncontrolled ring. |
onOpenChange | (open: boolean) => void | — | Called when a press, a double-click, Enter, Escape or the close button asks to open or close the current card. |
slots | number | 0 | Places round the ring. When larger than the number of items the items repeat (copies are hidden from screen readers); a ribbon needs about 20 or more. |
cardWidth | number | 70 | Width of a slim card in pixels. |
cardRatio | number | 1.45 | Card height over width. |
radius | number | 170 | Radius of the ring in pixels. The scene scales down to fit narrow containers. |
fan | number | 62 | How far each card turns about its own upright, in degrees: 0 faces out like a cylinder, near 90 stands edge-on like the pages of a book. |
tilt | number | 20 | How far the ring is tipped toward the viewer, in degrees. |
roll | number | -14 | Sideways roll of the whole ring, in degrees. |
autoSpin | boolean | true | Drift slowly on its own. It stops while the ring is pointed at, focused or open, adds a pause button and never runs under reduced motion. |
speed | number | 7 | Drift speed in degrees per second. |
paused | boolean | false | Holds the drift from outside. |
controls | boolean | true | Show previous and next, the current card's name (a button that opens it) and the pause button under the ring. |
label | string | 'Collection' | Accessible name of the carousel. |
labels | { previous?, next?, open?, close?, pause?, play?, slide?, hint? } | — | Replaces the built-in English text; slide is a function of (n, total). |
Accesibilidad
- The section is a carousel (aria-roledescription) and each original card a slide named by its label and position; repeated copies are aria-hidden.
- The ring is one focusable stop: Left and Right bring the previous or next card to the front, Home and End the ends, Enter or Space opens the current card.
- Opening moves focus to the close button and makes the ring inert; Escape or the close button closes it and returns focus to the ring. The name under the ring is a button with aria-expanded that does the same for pointers and touch.
- The drift stops while the ring is pointed at, focused or open, and the pause button stops it for good (aria-pressed). A polite live region names the current card except while the ring drifts.
- A finger must move sideways before the ring turns, so a vertical page scroll that starts on it still works; on touch a tap turns a card to the front and a second tap opens it.
- Under reduced motion there is no drift and no coasting: the ring steps straight to the chosen card, and the open card appears in place without rising.
Movimiento
A chosen card turns to the front in 680 ms on an ease-out cubic; a throw coasts with friction and settles in 420 ms; the drift resumes 0.9 s after the last touch. A card lifts in 240 ms; the open card rises in 360 ms while the ring dims. Under reduced motion every change is immediate.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
RibbonRing.jsxribbon-ring.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.





