Valyro Русская версия

Compare Tray

Collect items from a catalog and compare them in a table. Free, MIT · Data and metrics › Tables

A shelf that collects items from a catalog for comparison: thumbnails with remove buttons, a count, Clear and Compare. Compare opens a semantic table in a dialog (or your view, or your own page through onCompare). The catalog buttons and the tray share one selectedIds; toggleCompare gives the buttons the same rules.

Installation

npx valyro-cli@latest add compare-tray
npx shadcn@latest add https://valyro.xyz/r/compare-tray.json
npm install valyro-ui

import 'valyro-ui/styles.css';
import { CompareTray } from 'valyro-ui';

Props

PropTypeDefault
items *ComparableItem[]Every item that can be compared (usually the catalog).
fieldsCompareField[][]Rows of the built-in table, in order.
selectedIdsstring[]Picked ids, shared with the catalog's compare buttons (see toggleCompare).
defaultSelectedIdsstring[][]Initial selectedIds when uncontrolled.
onSelectedIdsChange(ids: string[]) => voidCalled with the new selectedIds when it changes.
maxItemsnumber3Most items in the tray. Default 3.
minItemsnumber2Fewest items to open the comparison. Default 2.
placement'inline' | 'fixed-bottom''inline'inline (default) in the page flow; fixed-bottom pinned to the viewport, with its height reserved in the flow.
onCompare(ids: string[]) => voidHands the comparison to the app (a page, a route). Not together with renderComparison.
renderComparison(items: ComparableItem[], close: () => void) => ReactNodeYour own comparison view inside the dialog, instead of the built-in table.
labelsPartial<CompareTrayLabels>Overrides for the built-in English text; keys left out keep their defaults.

Related components

  • Data Table — Tables with search and sorting
  • Virtual List — Virtual list for 100,000 rows
  • Description List — Key–value list: stacked, inline or a grid with icons
  • Tree View — Tree structures
  • Collapsible — One section that unfolds, or a "show more" preview
  • Accordion — Collapsible sections
  • Sortable — Drag-and-drop sorting
  • Timeline — Event timeline
  • Card — All-purpose cards
  • Image — Pictures without layout shift: placeholder, soft fade-in, fallback, a dark-mode source
  • Carousel — Carousel: scroll snap, swipe, autoplay, thumbnails
  • Empty State — No-data screen

Previous: Virtual List · Next: Description List · All Data and metrics