Shelf
ProOne row of cards that scrolls sideways, with part of the next card showing at its end and Previous and Next at its sides for a mouse. Not an M3 component (@windmorph/react-pro).
import { Shelf, ShelfPlaceholder } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
One row of your own cards that scrolls sideways, with part of the next card showing at its end to say there is more, and Previous and Next at its sides for a mouse. A page shows many sets of things (videos, products, people, articles) this way without each taking a whole grid. The cards are untouched: the shelf adds no fill, clipping or corners.
To screen readers it is a plain list, named by its heading, not a carousel. Use the core Carousel for M3's look, pictures that change size as they scroll; a FeaturedCarousel for one large slide at a time at the top of a page; a grid when every item must be seen at once.
Behaviour
- One line at every width. The number of cards to a line follows the shelf's own width (a size container), never whole numbers, so part of a card always shows at the end: wide cards (
per="wide", the default) 1.35 under 600px, 3.15 to 840px, 4.15 to 1200px, 5.15 to 1600px and 6.15 beyond; tall cards (per="tall") 2.4, 4.6, 6.3, 7.3 and 9.3. Beside a navigation rail the shelf is narrower than the window, so it steps down a size earlier than the page does.cardWidthgives every card one CSS length instead, for cards that shouldn't grow. - A swipe or a trackpad scrolls it natively, each scroll ending on a card's start; a fling may cross several. Tab moves card by card, bringing each wholly into view with its focus ring. Nothing moves by itself.
- With a mouse, at any width, Previous and Next fade in while the pointer is on the shelf or focus is in it. Each moves 85% of the row (
pageShare, or the--wm-shelf-page-sharetoken) to the card start nearest that distance, the one the row's snap would pick, so no card is passed over or left cut at the edge, in Safari too; under reduced motion it jumps. The one at an end is dimmed andaria-disabled, kept so focus on it isn't lost. On touch, and when every card fits, there are none. - The arrows are centred on the row;
arrowsAlign="media"centres them on the element markeddata-shelf-mediain the first card (its picture), measured on each resize, and--wm-side-arrow-offsetmoves them by a length of your own. onEndReachedis called when the row reaches its end, for an app that loads more.- Compact shelves (under 600px) run to the edges, the first card resting 12px in and the cards scrolling over the padding. Every card is in the server's HTML, sized by CSS; the arrows appear once the row is measured.
ShelfPlaceholder, a server component, lays out the same row without scrolling or arrows, for skeleton cards while the real ones load; nothing moves when they arrive.
When not to use
For M3's carousel of pictures that change size as they scroll, use a Carousel; when every item must be seen at once, a grid of Cards.
See also
- Carousel: A scrollable row of items that resize along keylines: multi-browse, uncontained, multi-aspect, hero or full-screen.
- Media grid: Square photo tiles, a sideways row on compact windows and a grid from medium up; a press on a tile reports it (`onAction`), for the app to open the viewer. Not an M3 component (@windmorph/react-pro).
- Card: A container for related content in three forms: static, pressable or a link.