# Relief Feature

> A feature section on reading every ticket: pick a channel (email, chat, phone, social) and each topic on the wall rises as high as its share of that channel's tickets, while a ranked list beside it says the numbers.

A Feature Section block from KeyframeUI: a whole landing-page section built around the Relief component, free to install as source with the shadcn CLI. Built with React and Tailwind CSS.

- Live preview: https://keyframeui.com/blocks/feature-sections/relief-feature
- Category: Feature Sections
- Built with: [Relief](https://keyframeui.com/components/relief.md)
- npm dependencies: clsx, tailwind-merge

## Installation

Register the @keyframeui registry in `components.json` once per project:

```json
{
  "registries": {
    "@keyframeui": "https://keyframeui.com/r/{name}.json"
  }
}
```

Then add the block. It lands in `components/relief-feature.tsx`, and the CLI also adds the components it's built with (`components/ui/relief.tsx`) and `lib/utils.ts`, and installs the npm dependencies:

```bash
npx shadcn@latest add @keyframeui/relief-feature
```

Or install by URL, without registering the namespace:

```bash
npx shadcn@latest add https://keyframeui.com/r/relief-feature.json
```

## Usage

Put it where the section goes. The copy, links and data sit in constants at the top of the file; edit them there.

```tsx
import { ReliefFeature } from "@/components/relief-feature";

export default function Page() {
  return <ReliefFeature />;
}
```

## Source

```tsx title="components/relief-feature.tsx"
"use client";

import * as React from "react";

import { Relief } from "@/components/ui/relief";

/* ── Content ─────────────────────────────────────────────────
 * Everything you'd change to make the section yours: the copy,
 * the channels and what customers write in about on each. A
 * topic's height on the wall is its share of the picked
 * channel's tickets; the list beside it says the numbers.
 * ─────────────────────────────────────────────────────────── */

/** The section's accent, for the picked channel's count and the focus rings. Light and dark. */
const ACCENT = { light: "#008a48", dark: "#34d399" };
/** The wall's inks, low to high: deep green through mint to amber and orange. */
const INKS = ["#053b2a", "#00663a", "#00a35a", "#5fd99a", "#effff6", "#fde68a", "#f59e0b", "#ff5a1f"];

const HEADLINE = "Every ticket, read before anyone opens it.";
const LEDE =
  "Sorrel reads each message the moment it lands and files it under what it's really about. Pick a channel to see what people write in about this week, and how much.";
const LINK = { label: "See how tagging works", href: "https://sorrel.example/docs/topics" };

type Channel = {
  id: string;
  label: string;
  /** Tickets per topic this week. */
  topics: Record<string, number>;
};

const CHANNELS: Channel[] = [
  {
    id: "email",
    label: "Email",
    topics: {
      Refunds: 412, Invoices: 356, Billing: 298, Returns: 240, Shipping: 214, Cancel: 188, Warranty: 150, Tax: 122,
      Receipts: 110, Address: 96, Exchange: 80, Damaged: 72, Login: 64, Password: 58, Tracking: 52, Coupons: 40,
      Delivery: 36, Sizes: 30, Gift: 24, Stock: 20, Pickup: 14, Reviews: 12, Points: 10, Duties: 34,
    },
  },
  {
    id: "chat",
    label: "Chat",
    topics: {
      Tracking: 520, Delivery: 468, Sizes: 380, Stock: 344, Coupons: 290, Login: 240, Password: 216, Shipping: 198,
      Exchange: 160, Gift: 132, Points: 118, Pickup: 96, Returns: 90, Refunds: 74, Address: 60, Billing: 52,
      Invoices: 20, Damaged: 34, Cancel: 44, Warranty: 18, Tax: 10, Receipts: 14, Reviews: 24, Duties: 12,
    },
  },
  {
    id: "phone",
    label: "Phone",
    topics: {
      Damaged: 260, Cancel: 232, Refunds: 210, Delivery: 176, Address: 150, Billing: 128, Warranty: 120, Password: 96,
      Login: 88, Exchange: 70, Returns: 64, Tracking: 58, Shipping: 46, Invoices: 40, Pickup: 34, Duties: 28,
      Tax: 22, Gift: 18, Sizes: 14, Stock: 12, Coupons: 10, Points: 8, Receipts: 16, Reviews: 6,
    },
  },
  {
    id: "social",
    label: "Social",
    topics: {
      Reviews: 330, Delivery: 274, Damaged: 228, Stock: 196, Coupons: 170, Shipping: 140, Gift: 112, Points: 92,
      Sizes: 80, Tracking: 72, Refunds: 64, Returns: 52, Exchange: 40, Pickup: 30, Cancel: 26, Login: 22,
      Password: 12, Billing: 18, Invoices: 8, Warranty: 14, Tax: 6, Receipts: 6, Address: 10, Duties: 8,
    },
  },
];

const TOPICS = Object.keys(CHANNELS[0].topics);
/** Only the channel's busiest few topics rise; the rest stay flat type. */
const TOP = 5;

/* ── Section ─────────────────────────────────────────────── */

const total = (channel: Channel) => Object.values(channel.topics).reduce((sum, n) => sum + n, 0);
const format = (n: number) => n.toLocaleString("en-US");

export function ReliefFeature() {
  const [picked, setPicked] = React.useState(CHANNELS[0].id);
  const [origin, setOrigin] = React.useState<[number, number]>([0.5, 0.5]);
  const wallRef = React.useRef<HTMLDivElement>(null);
  const channel = CHANNELS.find((c) => c.id === picked) ?? CHANNELS[0];

  const heights = React.useMemo(() => {
    const max = Math.max(...Object.values(channel.topics));
    const out: Record<string, number> = {};
    // The busiest few, each as high as its share of the busiest one; the rest stay flat type.
    const ranked = [...TOPICS].sort((a, b) => (channel.topics[b] ?? 0) - (channel.topics[a] ?? 0)).slice(0, TOP);
    for (const topic of ranked) out[topic] = Math.max(0.3, (channel.topics[topic] ?? 0) / max);
    return out;
  }, [channel]);
  const top = React.useMemo(
    () => [...TOPICS].sort((a, b) => (channel.topics[b] ?? 0) - (channel.topics[a] ?? 0)).slice(0, 4),
    [channel],
  );
  const sum = total(channel);

  function pick(id: string, button: HTMLElement) {
    const wall = wallRef.current?.getBoundingClientRect();
    const box = button.getBoundingClientRect();
    if (wall) {
      // The new heights ripple out from the side of the wall nearest the tab that asked for them.
      const x = (box.left + box.width / 2 - wall.left) / wall.width;
      const y = (box.top + box.height / 2 - wall.top) / wall.height;
      setOrigin([Math.min(1, Math.max(0, x)), Math.min(1, Math.max(0, y))]);
    }
    setPicked(id);
  }

  // Arrow keys move between channels, as a radio group does.
  function onKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
    const step = event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : event.key === "ArrowLeft" || event.key === "ArrowUp" ? -1 : 0;
    if (!step) return;
    event.preventDefault();
    const i = CHANNELS.findIndex((c) => c.id === picked);
    const next = CHANNELS[(i + step + CHANNELS.length) % CHANNELS.length];
    const button = event.currentTarget.querySelector<HTMLElement>(`[data-channel="${next.id}"]`);
    if (button) {
      button.focus();
      pick(next.id, button);
    }
  }

  return (
    <section
      style={{ "--accent": ACCENT.light, "--accent-dark": ACCENT.dark } as React.CSSProperties}
      className="bg-white text-zinc-950 dark:bg-[#09090b] dark:text-white"
    >
      <div className="mx-auto grid max-w-6xl grid-cols-1 gap-x-14 gap-y-10 px-6 py-20 sm:py-24 lg:grid-cols-[minmax(0,0.85fr)_minmax(0,1.15fr)] lg:items-center">
        <div className="min-w-0">
          <h2 className="max-w-md text-3xl leading-[1.08] font-semibold tracking-[-0.03em] text-balance sm:text-[2.6rem]">
            {HEADLINE}
          </h2>
          <p className="mt-4 max-w-md text-base leading-relaxed text-zinc-600 dark:text-zinc-400">{LEDE}</p>

          <div
            role="radiogroup"
            aria-label="Channel"
            onKeyDown={onKeyDown}
            className="mt-8 grid max-w-lg grid-cols-2 gap-2 sm:grid-cols-4 lg:max-w-none lg:grid-cols-2 xl:grid-cols-4"
          >
            {CHANNELS.map((c) => {
              const on = c.id === picked;
              return (
                <button
                  key={c.id}
                  type="button"
                  role="radio"
                  aria-checked={on}
                  tabIndex={on ? 0 : -1}
                  data-channel={c.id}
                  onClick={(event) => pick(c.id, event.currentTarget)}
                  className={`flex flex-col items-start rounded-xl border px-3.5 py-2.5 text-left transition-colors duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--accent)] dark:focus-visible:outline-[var(--accent-dark)] ${
                    on
                      ? "border-zinc-950 bg-zinc-950 text-white dark:border-white dark:bg-white dark:text-zinc-950"
                      : "border-zinc-200 text-zinc-800 hover:border-zinc-300 hover:bg-zinc-50 dark:border-white/10 dark:text-zinc-200 dark:hover:border-white/20 dark:hover:bg-white/5"
                  }`}
                >
                  <span className="text-sm font-medium">{c.label}</span>
                  <span className="sr-only">, </span>
                  <span
                    className={`text-xs tabular-nums ${on ? "text-white/70 dark:text-zinc-950/60" : "text-zinc-500 dark:text-zinc-400"}`}
                  >
                    {format(total(c))} tickets
                  </span>
                </button>
              );
            })}
          </div>

          <div className="mt-8 max-w-lg border-t border-zinc-200 pt-5 lg:max-w-none dark:border-white/10">
            <p className="text-xs font-medium text-zinc-500 dark:text-zinc-400">
              Top topics on {channel.label.toLowerCase()} this week
            </p>
            <ol className="mt-3 space-y-2.5" aria-live="polite">
              {top.map((topic, i) => {
                const n = channel.topics[topic] ?? 0;
                return (
                  <li key={topic} className="flex items-center gap-3 text-sm">
                    <span className="w-3 text-xs tabular-nums text-zinc-400 dark:text-zinc-500">{i + 1}</span>
                    <span className="flex-1 text-zinc-900 dark:text-zinc-100">{topic}</span>
                    <span className="tabular-nums text-zinc-500 dark:text-zinc-400">{format(n)}</span>
                    <span className="w-11 text-right text-xs font-medium tabular-nums text-[var(--accent)] dark:text-[var(--accent-dark)]">
                      {Math.round((n / sum) * 100)}%
                    </span>
                  </li>
                );
              })}
            </ol>
            <a
              href={LINK.href}
              className="mt-6 inline-flex items-center gap-1.5 rounded-sm text-sm font-medium text-zinc-950 underline decoration-zinc-300 underline-offset-4 transition-colors duration-150 hover:decoration-zinc-950 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-[var(--accent)] dark:text-white dark:decoration-white/30 dark:hover:decoration-white dark:focus-visible:outline-[var(--accent-dark)]"
            >
              {LINK.label}
              <span aria-hidden>→</span>
            </a>
          </div>
        </div>

        <div className="min-w-0 overflow-hidden rounded-2xl border border-zinc-200 dark:border-white/10">
          <Relief
            ref={wallRef}
            words={TOPICS}
            raise={heights}
            origin={origin}
            inks={INKS}
            duration={1}
            seed="sorrel-feature"
            label={`Support topics by tickets on ${channel.label.toLowerCase()} this week`}
            className="h-[22rem] w-full bg-white sm:h-[28rem] dark:bg-[#07080c]"
            wordClassName="font-semibold text-zinc-400 dark:text-zinc-600"
          />
        </div>
      </div>
    </section>
  );
}
```
