# Feature bento with live product tiles (带真实产品界面的特性网格)

A left-aligned heading above a two-over-three grid of hairline tiles. Each tile is a small working piece of an analytics product (retention chart, plain-language query, funnel, alert rules, saved cohorts) with its title and one line underneath.

- Ref: `component/feature-bento` (component · bento)
- Page: https://uifino.com/en/components/bento/feature-bento
- Markdown: https://uifino.com/md/components/feature-bento.md
- Preview image: https://uifino.com/blocks/covers/feature-bento-dark.webp

## Install

- shadcn: `npx shadcn@latest add "https://uifino.com/r/blocks/feature-bento.json"`
- UIFino CLI: `npx uifino@latest add component/feature-bento`

## Dependencies

`lucide-react`

## shadcn/ui components it builds on

- `avatar`, `badge`, `button`, `progress`, `switch`. The shadcn CLI installs them together with the block.

## Layout borrowed from

- https://resend.com: Borrowed the hairline-bordered tile grid, product UI on top with title and one line below, and the restrained dark palette. Tile contents are original.

## Theme

The block reads the project's shadcn theme variables, so it follows whatever DESIGN.md the project uses and needs no options of its own.
To give the project the look of a UIFino brand or style, install its theme: `npx shadcn@latest add "https://uifino.com/r/themes/linear.json"`.

## Usage

The files under `examples/` show the block wired with content, including its loading, empty and error states where it has them.

## Files

| Path | Role | Size |
| :--- | :--- | ---: |
| components/blocks/feature-bento/examples/content.ts | demo | 5.1 KB |
| components/blocks/feature-bento/examples/default.tsx | demo | 225 B |
| components/blocks/feature-bento/feature-bento.tsx | source | 10.7 KB |

### components/blocks/feature-bento/feature-bento.tsx

```tsx
"use client";

import { useEffect, useState, type ReactNode } from "react";
import { LoaderCircle, Play } from "lucide-react";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
import { Switch } from "@/components/ui/switch";
import { cn } from "@/lib/utils";

export interface FeatureBentoProps {
  readonly title: string;
  readonly description: string;
  readonly retention: {
    readonly title: string;
    readonly description: string;
    readonly metric: string;
    readonly axis: readonly [string, string];
    readonly value: string;
    readonly delta: string;
    readonly series: readonly { readonly label: string; readonly points: readonly number[] }[];
  };
  readonly query: {
    readonly title: string;
    readonly description: string;
    readonly prompt: string;
    readonly sql: string;
    readonly rows: readonly { readonly label: string; readonly value: string }[];
    readonly run: string;
  };
  readonly onRun?: () => void;
  readonly funnel: {
    readonly title: string;
    readonly description: string;
    readonly steps: readonly {
      readonly label: string;
      readonly count: string;
      readonly share: number;
    }[];
  };
  readonly alerts: {
    readonly title: string;
    readonly description: string;
    readonly rules: readonly { readonly label: string; readonly on: boolean }[];
  };
  readonly cohorts: {
    readonly title: string;
    readonly description: string;
    readonly items: readonly {
      readonly name: string;
      readonly detail: string;
      readonly size: string;
      readonly owner: string;
    }[];
  };
}

const CHART_W = 400;
const CHART_H = 120;
const seriesStyles = [
  { color: "text-chart-1", dash: undefined, swatch: "bg-current" },
  { color: "text-muted-foreground", dash: "4 3", swatch: "border-t-2 border-dashed border-current" },
  { color: "text-chart-2", dash: "1 3", swatch: "border-t-2 border-dotted border-current" }
] as const;

function seriesStyle(index: number) {
  return seriesStyles[index % seriesStyles.length] ?? seriesStyles[0];
}

function toPath(points: readonly number[]) {
  return points
    .map((p, i) => {
      const x = (i / (points.length - 1)) * CHART_W;
      const y = CHART_H - 6 - (p / 100) * (CHART_H - 12);
      return `${i === 0 ? "M" : "L"}${x.toFixed(1)} ${y.toFixed(1)}`;
    })
    .join(" ");
}

function endY(points: readonly number[]) {
  const last = points[points.length - 1] ?? 0;
  return CHART_H - 6 - (last / 100) * (CHART_H - 12);
}

function initials(name: string) {
  return name
    .split(" ")
    .map((part) => part[0])
    .join("")
    .slice(0, 2);
}

function Tile({
  title,
  description,
  className,
  children
}: {
  readonly title: string;
  readonly description: string;
  readonly className?: string;
  readonly children: ReactNode;
}) {
  return (
    <article className={cn("bg-card grid min-w-0 grid-rows-[auto_1fr] @3xl:row-span-2 @3xl:grid-rows-subgrid", className)}>
      <div className="px-4 pt-4 @3xl:px-6 @3xl:pt-6">
        <h3 className="text-lg font-medium">{title}</h3>
        <p className="text-muted-foreground mt-1 text-sm text-pretty">{description}</p>
      </div>
      <div className="overflow-hidden p-4 @3xl:p-6">{children}</div>
    </article>
  );
}

function RetentionTile({ retention }: { readonly retention: FeatureBentoProps["retention"] }) {
  return (
    <Tile title={retention.title} description={retention.description} className="@3xl:col-span-4">
      <div className="flex items-end justify-between gap-4">
        <div>
          <p className="text-muted-foreground text-sm">{retention.metric}</p>
          <p className="mt-1 text-3xl font-medium tracking-tight tabular-nums">{retention.value}</p>
        </div>
        <Badge variant="secondary" className="text-chart-2 shrink-0">
          {retention.delta}
        </Badge>
      </div>
      <div className="relative mt-6">
        <svg
          viewBox={`0 0 ${CHART_W} ${CHART_H}`}
          preserveAspectRatio="none"
          className="h-32 w-full"
          role="img"
          aria-label={retention.metric}
        >
          {[0, 1, 2, 3].map((i) => (
            <line
              key={i}
              x1={0}
              x2={CHART_W}
              y1={6 + (i * (CHART_H - 12)) / 3}
              y2={6 + (i * (CHART_H - 12)) / 3}
              className="stroke-border"
              strokeWidth={1}
              vectorEffect="non-scaling-stroke"
            />
          ))}
          {retention.series.map((s, i) => (
            <path
              key={s.label}
              d={toPath(s.points)}
              fill="none"
              stroke="currentColor"
              strokeWidth={2}
              strokeLinejoin="round"
              strokeDasharray={seriesStyle(i).dash}
              vectorEffect="non-scaling-stroke"
              className={seriesStyle(i).color}
            />
          ))}
        </svg>
        <span
          className="bg-chart-1 absolute right-0 size-2 translate-x-1/2 -translate-y-1/2 rounded-full"
          style={{ top: `${(endY(retention.series[0]?.points ?? []) / CHART_H) * 100}%` }}
        />
      </div>
      <div className="text-muted-foreground mt-2 flex justify-between text-sm">
        <span>{retention.axis[0]}</span>
        <span>{retention.axis[1]}</span>
      </div>
      <ul className="text-muted-foreground mt-3 flex gap-4 text-sm">
        {retention.series.map((s, i) => (
          <li key={s.label} className="flex items-center gap-2">
            <span
              className={cn(
                "h-0.5 w-3",
                seriesStyle(i).color,
                seriesStyle(i).swatch
              )}
            />
            {s.label}
          </li>
        ))}
      </ul>
    </Tile>
  );
}

function QueryTile({
  query,
  onRun
}: {
  readonly query: FeatureBentoProps["query"];
  readonly onRun?: () => void;
}) {
  const [running, setRunning] = useState(false);

  useEffect(() => {
    if (!running) return;
    const timer = setTimeout(() => setRunning(false), 700);
    return () => clearTimeout(timer);
  }, [running]);

  return (
    <Tile title={query.title} description={query.description} className="@3xl:col-span-2">
      <div className="flex items-start gap-3">
        <p className="min-w-0 flex-1 pt-1 text-sm text-pretty">{query.prompt}</p>
        <Button
          size="sm"
          className="shrink-0"
          disabled={running}
          onClick={() => {
            setRunning(true);
            onRun?.();
          }}
        >
          {running ? <LoaderCircle className="animate-spin" /> : <Play />}
          {query.run}
        </Button>
      </div>
      <p className="bg-muted text-muted-foreground mt-4 rounded-md p-3 font-mono text-sm break-words whitespace-pre-wrap">
        {query.sql}
      </p>
      <dl
        className={cn(
          "mt-3 flex flex-col gap-1.5 text-sm transition-opacity",
          running && "opacity-40"
        )}
        aria-busy={running}
      >
        {query.rows.map((row) => (
          <div key={row.label} className="flex justify-between gap-3">
            <dt className="text-muted-foreground">{row.label}</dt>
            <dd className="font-medium tabular-nums">{row.value}</dd>
          </div>
        ))}
      </dl>
    </Tile>
  );
}

function FunnelTile({ funnel }: { readonly funnel: FeatureBentoProps["funnel"] }) {
  return (
    <Tile title={funnel.title} description={funnel.description} className="@3xl:col-span-2">
      <ul className="flex flex-col gap-4">
        {funnel.steps.map((step) => (
          <li key={step.label}>
            <div className="flex justify-between gap-3 text-sm">
              <span className="truncate">{step.label}</span>
              <span className="text-muted-foreground shrink-0 tabular-nums">{step.count}</span>
            </div>
            <Progress value={step.share} aria-label={step.label} className="mt-2 h-1.5" />
          </li>
        ))}
      </ul>
    </Tile>
  );
}

function AlertsTile({ alerts }: { readonly alerts: FeatureBentoProps["alerts"] }) {
  const [enabled, setEnabled] = useState(() => alerts.rules.map((rule) => rule.on));
  return (
    <Tile title={alerts.title} description={alerts.description} className="@3xl:col-span-2">
      <ul className="flex flex-col divide-y border-y">
        {alerts.rules.map((rule, i) => (
          <li key={rule.label} className="flex items-center justify-between gap-3 py-3">
            <span className="min-w-0 text-sm">{rule.label}</span>
            <Switch
              checked={enabled[i]}
              onCheckedChange={(next) =>
                setEnabled((prev) => prev.map((v, j) => (j === i ? next : v)))
              }
              aria-label={rule.label}
            />
          </li>
        ))}
      </ul>
    </Tile>
  );
}

function CohortsTile({ cohorts }: { readonly cohorts: FeatureBentoProps["cohorts"] }) {
  return (
    <Tile title={cohorts.title} description={cohorts.description} className="@3xl:col-span-2">
      <ul className="flex flex-col gap-4">
        {cohorts.items.map((item) => (
          <li key={item.name} className="flex items-center gap-3">
            <Avatar className="size-8 shrink-0">
              <AvatarFallback className="text-sm">{initials(item.owner)}</AvatarFallback>
            </Avatar>
            <div className="min-w-0 flex-1">
              <p className="truncate text-sm font-medium">{item.name}</p>
              <p className="text-muted-foreground line-clamp-2 text-sm text-pretty">{item.detail}</p>
            </div>
            <Badge variant="secondary" className="shrink-0 tabular-nums">
              {item.size}
            </Badge>
          </li>
        ))}
      </ul>
    </Tile>
  );
}

export { Tile as FeatureBentoTile };

export function FeatureBento({
  title,
  description,
  retention,
  query,
  onRun,
  funnel,
  alerts,
  cohorts
}: FeatureBentoProps) {
  return (
    <section className="bg-background text-foreground @container">
      <div className="mx-auto w-full max-w-6xl px-4 py-16 @3xl:px-8 @3xl:py-24">
        <h2 className="font-heading max-w-2xl text-3xl font-medium tracking-tight text-balance @3xl:text-5xl">
          {title}
        </h2>
        <p className="text-muted-foreground mt-4 max-w-xl text-base @3xl:text-lg">{description}</p>
        <div className="bg-border mt-12 grid gap-px overflow-hidden rounded-xl border @3xl:mt-16 @3xl:grid-cols-6">
          <RetentionTile retention={retention} />
          <QueryTile query={query} onRun={onRun} />
          <FunnelTile funnel={funnel} />
          <AlertsTile key={alerts.rules.map((rule) => `${rule.label}:${rule.on}`).join("|")} alerts={alerts} />
          <CohortsTile cohorts={cohorts} />
        </div>
      </div>
    </section>
  );
}
```

Not inlined (2 files, 5.3 KB). Full sources: https://uifino.com/r/blocks/feature-bento.json
