shadcn.io is not affiliated with official shadcn/ui
Favorites Gallery Block for React
Eight drawn prints, each in its own frame with a heart toggle, and a Favourites only switch with a count, a Clear favourites button and an empty state.
Installation
Overview
A gallery of favourites for React with Base UI, for Wallmark, a print shop. A start-aligned header carries a "Favourites only" switch at its end with a count ("3 favourites"), over eight drawn prints, each in its own frame with + marks that overshoot its corners. Every print has a heart toggle on its corner: pressed, the heart is filled in your text colour. Turning the switch on keeps only the hearted prints, a polite line says "Showing 3 of 8 prints", "Clear favourites" takes every heart back, and no hearts with the switch on shows an empty state. The hearts live in the page only and nothing is saved; the demo starts with three. An unseen copy of all eight holds the block's height. On a phone the prints are two across. It's built from Toggle, Switch, Button, Empty and Guides. The shop and its prints are made up for the example.
FAQ
Where are the favourites kept?
In the block's own state, so they reset when the page reloads. To keep them, store the list of ids (hearts) where you like (local storage, your account) and read it back as the initial state. The heart is a Toggle whose pressed state is the id being in that list.
What does Favourites only do?
It filters the prints to the hearted ones, in the shop's order. With it on, taking a heart back removes the print from the view, so focus moves to the count line. With it on and no hearts, an empty state says so and offers a button that turns the switch off.
Why doesn't the page jump when the pictures change?
An unseen copy of all eight pictures (hidden from assistive technology and from the keyboard) sits in the same grid cell as the live set, so the block is always as tall as the full gallery and the shown pictures stay at the top. Nothing below the block moves.
How does it work with a keyboard?
Every heart is a toggle button named "Favourite: <print>" with its pressed state, and the switch is a labelled switch; Space or Enter flips either. "Clear favourites" is a button and keeps its place (hidden but not removed) when there are none.
How do I use my own photographs?
Each picture is typed data with a description (its alt text), a scene and a ratio. Add your image's address to it, then replace the Scene in its tile with <img alt="" className="size-full object-cover" src={…} />: the caption already names the picture, and the role="img" wrapper's label can move to the alt. The comment above Scene says where. Tiles crop to a fixed shape, so keep object-cover.
How are the pictures drawn?
Each one is a scene: a kind (a room, a lamp, a bridge, a pattern…) and three numbers, light, horizon and a seed that moves ridgelines, lights windows and turns tiles. Each kind is a function that returns the picture as SVG paths painted with a few inks mixed from your theme's colours, so two pictures of one kind with different numbers differ. Nothing is random at render time: the server and the browser draw the same picture.
Related
- Pro
Rate a Picture Rating Gallery
Select and actSix dishes with a five-star rating each, a seeded average and count that your vote joins, and a Sort group for top rated and most rated.
- Pro
Multi-Select Bulk Actions Gallery
Select and actEight drawn scans on shared hairlines, each with a checkbox, a Select all box that shows a mixed state, Shift to take a run, and a bar with Download, Share and an undoable Delete.
- Pro
Filterable Gallery
Filter, sort and tabsTwelve drawn pictures on shared hairlines with a band of chips, each with a count, that keeps only one kind of work and says how many are showing.
- Pro
Lightbox Gallery
Stage and thumbnailsNine pictures of a photography studio's year on shared hairlines, a featured frame and a caption under each, where every frame opens one viewer dialog with the whole picture, its credit, Previous and Next, a counter, arrow keys and a swipe.
- Pro
Reading List Blog
Reading toolsFive saved articles with a bookmark toggle on each: un-saving strikes the row through in place with an Undo link, and the foot reads the derived totals, like 5 saved, 46 min to read.
- Pro
Pinned Posts Blog
Reading toolsThree pin slots in a tinted band above a list of posts: a pin toggle on each row fills the first empty slot, an empty slot reads Pin a post, and the band counts pinned posts.