Interactive Answers

Result Carousel

A row of result cards — image, title, meta and an action — with snap scrolling and arrows.

3 variantsMIT

Preview

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest add https://uilab.tmih06.com/r/result-carousel.json

Usage

Pass your own data and wire the callbacks to your agent runtime.

import { ResultCarousel } from "@/components/ui/result-carousel";

// Render search results the agent found; the action hands the pick back to it.
export function HotelsAnswer({ results }: { results: Hotel[] }) {
  return (
    <ResultCarousel
      title="Hotels in Lisbon"
      subtitle="Nov 14–17 · 2 guests"
      data={results.map((h) => ({
        id: h.id,
        title: h.name,
        meta: h.area,
        price: `${h.rate} / night`,
        rating: h.rating,
        image: h.photoUrl,
        action: "Book",
      }))}
      onAction={(item) => agent.send(`Book ${item.title}`)}
    />
  );
}

// While the search runs, pass null — the cards load as blank placeholders the
// arrows can't scroll, with the title and search criteria still visible.
export function HotelsLoading({ search }: { search: HotelSearch }) {
  return (
    <ResultCarousel
      title="Hotels in Lisbon"
      subtitle="Nov 14–17 · 2 guests"
      data={search.results ?? null}
      loading={search.isRefetching}
      skeleton={{ count: 3 }}
      onAction={(item) => agent.send(`Book ${item.title}`)}
    />
  );
}

Props

PropTypeDefaultDescription
data*ResultItem[] | null—Cards in order. New items can be appended while results stream in. Pass null while they load — an empty array is a valid empty result set.
loadingbooleanfalseForce the layout-preserving skeleton while refetching, even when stale results are available.
skeleton{ count?: number }—Shape hints for the loading state; count is the number of placeholder cards.
title*string—Header title and the carousel's accessible name.
subtitlestring—Replaces the default result count.
compactbooleanfalseNarrower cards without the image area.
onAction(item: ResultItem) => void—Adds a button to each card; the first card's button is primary.
onOpen(item: ResultItem) => void—Makes the title and image open the item.
labelsPartial<ResultCarouselLabels>—Your own UI strings (results, Previous / Next, the loading announcement, screen-reader text). Right-to-left works under `dir="rtl"`; paging and the arrows flip.
classNamestring—Extra classes for the root element.
type ResultItem = {
  id: string;
  title: string;
  meta?: string;   // one line under the title
  price?: string;  // right-aligned, e.g. "$214 / night"
  rating?: number; // 0–5
  image?: string;  // URL; without it a gradient from `tint`
  tint?: string;
  badge?: string;  // e.g. "Best match"
  action?: string; // button label, default "Select"
};

// The track scrolls with snap; arrows page by one card and disable at the ends.