Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Density Switch Testimonials Block for React

Twelve customer quotes from Lantern's support teams in one hairline grid, with a density switch in the header: Comfortable, Compact or Quotes only re-tunes the same cells, from roomy with stars and roles down to the bare words.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

One grid of twelve customer quotes, three ways to read it. A compact header carries a segmented switch named Density that sets how much each cell shows: Comfortable gives every quote room, a star rating, a full avatar and the author's role in three columns; Compact tightens the padding, shrinks the avatar, drops the stars and fits four columns; Quotes only strips each cell to the words and a name. The cells share their hairlines, and the grid's rules meet the page rails in + marks. The cells are the same twelve elements throughout, so nothing is rebuilt or reordered. On a phone the first three quotes show, and a ghost button opens the other nine. A Shine Button under the grid links to all the stories. For pages where a visitor may want a quick skim or a slow read.

FAQ

How does the switch change the cells?

The switch writes its value to a data-density attribute on the list. The list's columns, and each cell's padding, text size, avatar, stars and role line, are plain Tailwind variants keyed on that attribute, such as group-data-[density=compact]/density:hidden. There is one set of markup, so changing the density never remounts a cell or loses its place. The hairlines are the one-pixel gap between cells on the border colour, so they stay correct at every column count.

How do I add or change a density?

Add an entry to DENSITIES with a label and a value, then add the variant classes for that value where the cells use them. The GRID, CELL, QUOTE_TEXT, STARS_ROW, AVATAR and ROLE strings at the top of the file hold every density-dependent class, so they are the only places to edit. Keep the number of quotes a multiple of 12 so every column count ends on a full row.

What do keyboard and screen reader users get?

The switch is a named group of three radio options: the arrow keys move between them and the choice applies at once. A status line announces the new density and the count of quotes; from md it is also shown beside the switch, and on a phone it is read by screen readers only, since the switch already shows the choice. In Compact and Quotes only, the stars and role are hidden for everyone, screen readers included, as they are not rendered; every cell is still a figure with a blockquote and a figcaption.

What happens on a phone?

The grid is one column, and only the first three quotes show. A ghost button, "Show 9 more quotes", opens the rest; it has aria-expanded and aria-controls, and turns into "Show fewer quotes". From md all twelve show and the button is gone. The switch fits at 320 px, and changing the density on a phone changes the padding, the text and what each cell shows.

Why do the stars disappear in the denser views?

Stars are the first thing to go when space is tight: they say less than the words. Only Comfortable shows them, in the text colour (empty ones in the border colour), with a "Rated 5 out of 5" text for screen readers. To keep them in Compact, change STARS_ROW to hide only in quotes.

What moves, and can I turn it off?

The block fades up once on load, with plain CSS transitions and no animation library, and the segmented switch slides its highlight to the chosen option. The grid itself re-lays out at once when the density changes. With reduced motion on, the block appears in place and the highlight does not slide. The Shine Button's light only fades in.

  • Pro

    Masonry Testimonials

    Walls and lanes

    A masonry wall of twelve notes from runners in CSS columns inside a framed figure: cards of every length stack tight, from one column on a phone to four on a wide screen.

  • Pro

    A wall of twenty-four short customer notes for a component kit, set as a masonry band that shares its hairlines and fades out under a mask until a Show all button opens the rest.

  • Pro

    Waterfall Testimonials

    Walls and lanes

    Nine customer quotes for a deploy platform in a staircase of three columns, one per stage of being a customer, each starting a step lower, in cells whose lines overshoot their corners.

  • Pro

    Eight square tiles in a hairline grid, each holding a one-line customer quote at the top and its author at the foot, with the one Shine Button in the header row.

  • Pro

    Filterable Testimonials

    Filter and search

    Role chips with live counts filter a wall of eight customer quotes, with a status line, a clear button and an empty state. A hairline band holds the controls and the cells' lines overshoot their corners.

  • Pro

    A centred showcase hero with a headline, a Shine Button and an outline action over a wall of six customer quotes in cells that share their hairlines, a snap carousel on a phone.