# AI Order Status
> A live delivery card in the reply. The courier moves along the route while the ETA counts down, and the route turns green on arrival.

Source: https://kokonutui.com/docs/ai/ai-order-status

## Installation

```bash
npx shadcn@latest add @kokonutui/ai-order-status
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `prompt?` | `string` |  | The user's message, drawn as a bubble. Only the demo draws one by default. |
| `message?` | `string` |  | What the assistant says above the card. |
| `order?` | `DeliveryOrder` | `demo` |  |
| `status?` | `OrderStatus` |  | Pass it to drive the card from your tracking updates: the courier glides to each new `progress` and the ETA shows `minutes` as given. Leave it out and the ETA counts down on `minuteMs`. |
| `delivered?` | `string` |  | Shown once it has arrived. |
| `minuteMs?` | `number` | `700` | Demo only: real ms per minute of ETA. |
| `onMessage?` | `() => void` |  | Shows a Message button for reaching the courier. |
| `className?` | `string` |  | Extra classes for the root element. |

### DeliveryOrder

| Field | Type | Description |
| --- | --- | --- |
| `merchant` | `string` |  |
| `orderId` | `string` |  |
| `courier` | `string` |  |
| `vehicle` | `string` |  |
| `minutes` | `number` | Minutes left. Live, pass the latest ETA; the demo counts down from it. |
| `progress` | `number` | How far along the route the courier is, 0 to 1. |
| `arriveAt` | `string` | When it should arrive, as shown. |

### OrderStatus

Where the order is, from your delivery provider.

```ts
type OrderStatus = "on-the-way" | "delivered";
```

## Source

```tsx
"use client";

/**
 * @author: @kokonutui
 * @description: AI Order Status
 * @version: 1.1.0
 * @date: 2026-11-05
 * @license: MIT
 * @website: https://kokonutui.com
 * @github: https://github.com/kokonut-labs/kokonutui
 */

import { Bike, Check, Home, MessageCircle, Store } from "lucide-react";
import {
  AnimatePresence,
  animate,
  MotionConfig,
  motion,
  useMotionValue,
  useMotionValueEvent,
  useReducedMotion,
} from "motion/react";
import {
  type CSSProperties,
  type ReactNode,
  useEffect,
  useLayoutEffect,
  useRef,
  useState,
} from "react";
import { cn } from "@/lib/utils";

export interface DeliveryOrder {
  merchant: string;
  orderId: string;
  courier: string;
  vehicle: string;
  /** Minutes left. Live, pass the latest ETA; the demo counts down from it. */
  minutes: number;
  /** How far along the route the courier is, 0 to 1. */
  progress: number;
  /** When it should arrive, as shown. */
  arriveAt: string;
}

/** Where the order is, from your delivery provider. */
export type OrderStatus = "on-the-way" | "delivered";

export interface AIOrderStatusProps {
  /** The user's message, drawn as a bubble. Only the demo draws one by default. */
  prompt?: string;
  /** What the assistant says above the card. */
  message?: string;
  order?: DeliveryOrder;
  /**
   * Pass it to drive the card from your tracking updates: the courier
   * glides to each new `progress` and the ETA shows `minutes` as given.
   * Leave it out and the ETA counts down on `minuteMs`.
   */
  status?: OrderStatus;
  /** Shown once it has arrived. */
  delivered?: string;
  /** Demo only: real ms per minute of ETA. */
  minuteMs?: number;
  /** Shows a Message button for reaching the courier. */
  onMessage?: () => void;
  className?: string;
}

/** A 4×4 Bayer matrix: the order in which pixels switch on as density rises. */
const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];

/** An inline SVG of 1-bit pixels, used as a mask so any background color shows through. */
function pixelMask(
  columns: number,
  rows: number,
  densityAt: (row: number) => number,
  cell: number
): CSSProperties {
  let rects = "";
  for (let y = 0; y < rows; y++) {
    const on = Math.round(densityAt(y) * 16);
    for (let x = 0; x < columns; x++) {
      if (BAYER[(y % 4) * 4 + (x % 4)] < on) {
        rects += `<rect x='${x}' y='${y}' width='1' height='1'/>`;
      }
    }
  }
  const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${columns}' height='${rows}' shape-rendering='crispEdges'>${rects}</svg>`;
  const image = `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
  const size = `${columns * cell}px ${rows * cell}px`;
  return {
    maskImage: image,
    WebkitMaskImage: image,
    maskSize: size,
    WebkitMaskSize: size,
    maskPosition: "left bottom",
    WebkitMaskPosition: "left bottom",
  };
}

const PARK_ROWS = 28;
/** Fades in from the top, denser toward the road below it. */
const PARK_DITHER: CSSProperties = {
  ...pixelMask(4, PARK_ROWS, (row) => 0.06 + (row / PARK_ROWS) * 0.44, 2),
  maskRepeat: "repeat-x",
  WebkitMaskRepeat: "repeat-x",
};

const EASE_OUT = [0.23, 1, 0.32, 1] as const;
const W = 320;
const H = 96;
const ROUTE = "M28 70 C 72 70, 82 30, 128 30 S 182 72, 226 64 S 270 26, 292 26";
const START = { x: 28, y: 70 };
const END = { x: 292, y: 26 };

const DEMO_ORDER: DeliveryOrder = {
  merchant: "Bloom & Stem",
  orderId: "4821",
  courier: "Leo",
  vehicle: "Grey scooter",
  minutes: 12,
  progress: 0.42,
  arriveAt: "2:14 pm",
};

const DEMO = {
  prompt: "Where are my flowers?",
  message: "They’re on the way with Leo. I’ll keep this updated.",
  delivered:
    "Delivered. Leo left them with the concierge, and the card is tucked in the front.",
};

/** The chat text around the card: the demo's only when it's the demo. */
function shownText(
  text: Pick<AIOrderStatusProps, "prompt" | "message" | "delivered">,
  isDemo: boolean
) {
  if (!isDemo) {
    return text;
  }
  return {
    prompt: text.prompt ?? DEMO.prompt,
    message: text.message ?? DEMO.message,
    delivered: text.delivered ?? DEMO.delivered,
  };
}

/**
 * The ETA and the courier's place on the route. Live, both follow `order`;
 * in the demo the ETA counts down and the courier moves with it.
 */
function useEta(
  order: DeliveryOrder,
  status: OrderStatus | undefined,
  minuteMs: number,
  reduce: boolean
) {
  const driven = status !== undefined;
  const [counted, setMinutes] = useState(order.minutes);
  const minutes = driven ? order.minutes : counted;
  const arrived = driven ? status === "delivered" : minutes <= 0;
  const progress = useMotionValue(order.progress);
  // Live: glides the courier to each new position you report.
  useEffect(() => {
    if (!driven) {
      return;
    }
    const controls = animate(progress, arrived ? 1 : order.progress, {
      duration: reduce ? 0 : 0.8,
      ease: EASE_OUT,
    });
    return () => controls.stop();
  }, [driven, arrived, order.progress, progress, reduce]);

  // Demo: counts the ETA down, and moves the courier with it.
  useEffect(() => {
    if (arrived || driven) {
      return;
    }
    const t = setTimeout(() => {
      const next = minutes - 1;
      setMinutes(next);
      const target =
        order.progress + (1 - order.progress) * (1 - next / order.minutes);
      animate(progress, target, {
        duration: reduce ? 0 : minuteMs / 1000,
        ease: "linear",
      });
    }, minuteMs);
    return () => clearTimeout(t);
  }, [minutes, arrived, minuteMs, order, progress, reduce, driven]);

  return { minutes, arrived, progress };
}

export default function AIOrderStatus({
  prompt,
  message,
  order = DEMO_ORDER,
  status,
  delivered,
  minuteMs = 700,
  onMessage,
  className,
}: AIOrderStatusProps) {
  const reduce = useReducedMotion();
  const driven = status !== undefined;
  const isDemo = !driven && order === DEMO_ORDER;
  const shown = shownText({ prompt, message, delivered }, isDemo);
  const { minutes, arrived, progress } = useEta(
    order,
    status,
    minuteMs,
    Boolean(reduce)
  );
  const x = useMotionValue(START.x);
  const y = useMotionValue(START.y);
  const pathRef = useRef<SVGPathElement>(null);

  // Keeps the courier on the route as progress moves.
  const place = (v: number) => {
    const path = pathRef.current;
    if (!path) {
      return;
    }
    const point = path.getPointAtLength(v * path.getTotalLength());
    x.set(point.x);
    y.set(point.y);
  };
  useMotionValueEvent(progress, "change", place);
  // biome-ignore lint/correctness/useExhaustiveDependencies: places once on mount
  useLayoutEffect(() => place(progress.get()), []);

  return (
    <MotionConfig reducedMotion="user">
      <div
        className={cn("flex w-full max-w-md flex-col gap-4", className)}
        data-state={arrived ? "delivered" : "on-the-way"}
      >
        {shown.prompt ? (
          <p className="max-w-[85%] self-end text-pretty rounded-2xl rounded-br-md bg-zinc-100 px-3.5 py-2 text-[14px] text-zinc-800 leading-snug dark:bg-zinc-800 dark:text-zinc-100">
            {shown.prompt}
          </p>
        ) : null}
        {shown.message ? (
          <p className="text-pretty text-[15px] text-zinc-800 leading-7 dark:text-zinc-200">
            {shown.message}
          </p>
        ) : null}

        <div className="rounded-[22px] bg-black/[0.04] p-1 dark:bg-white/[0.06]">
          <div className="flex h-8 items-center justify-between px-3 text-[12px] text-zinc-500 dark:text-zinc-400">
            <span className="truncate">
              <span className="font-medium text-zinc-700 dark:text-zinc-300">
                {order.merchant}
              </span>{" "}
              · Order #{order.orderId}
            </span>
            <span className="flex shrink-0 items-center gap-1.5">
              <span
                className={cn(
                  "size-1.5 rounded-full transition-colors duration-300",
                  arrived ? "bg-emerald-500" : "bg-blue-500"
                )}
              />
              {arrived ? "Delivered" : "Live"}
            </span>
          </div>

          <div className="overflow-hidden rounded-[18px] bg-white shadow-[0_1px_2px_rgb(0_0_0/0.04)] ring-1 ring-black/[0.06] dark:bg-zinc-900 dark:ring-white/[0.08]">
            <div className="flex items-end justify-between gap-3 px-4 pt-3.5">
              <div className="min-w-0">
                <p className="text-[12px] text-zinc-500 dark:text-zinc-400">
                  {arrived
                    ? `Arrived at ${order.arriveAt}`
                    : `Arriving around ${order.arriveAt}`}
                </p>
                <div className="mt-0.5 h-8 overflow-hidden font-semibold text-[26px] text-zinc-900 tracking-tight dark:text-zinc-100">
                  <AnimatePresence initial={false} mode="popLayout">
                    <motion.span
                      animate={{ y: 0, opacity: 1, filter: "blur(0px)" }}
                      className="block leading-8"
                      exit={{ y: -14, opacity: 0, filter: "blur(2px)" }}
                      initial={{ y: 14, opacity: 0, filter: "blur(2px)" }}
                      key={arrived ? "done" : minutes}
                      transition={{ duration: 0.3, ease: EASE_OUT }}
                    >
                      {arrived ? (
                        "Delivered"
                      ) : (
                        <>
                          <span className="tabular-nums">{minutes}</span>
                          <span className="ml-1 font-medium text-[15px] text-zinc-500 tracking-normal dark:text-zinc-400">
                            min
                          </span>
                        </>
                      )}
                    </motion.span>
                  </AnimatePresence>
                </div>
              </div>
              <Steps arrived={arrived} />
            </div>

            <div className="relative mt-2">
              {/* A dithered park, so the map has texture without a tile
                  service. */}
              <span
                aria-hidden="true"
                className="absolute bg-emerald-500/80 dark:bg-emerald-400/50"
                style={{
                  ...PARK_DITHER,
                  left: "32.5%",
                  top: "58%",
                  width: "26%",
                  height: "42%",
                }}
              />
              <svg
                aria-hidden="true"
                className="block h-auto w-full"
                viewBox={`0 0 ${W} ${H}`}
              >
                <g className="stroke-zinc-100 dark:stroke-white/[0.05]">
                  <path d="M0 48 H320" strokeWidth="6" />
                  <path d="M96 0 V96" strokeWidth="5" />
                  <path d="M200 0 L250 96" strokeWidth="5" />
                  <path d="M0 14 L140 4" strokeWidth="4" />
                </g>
                <path
                  className="stroke-zinc-300 dark:stroke-zinc-600"
                  d={ROUTE}
                  fill="none"
                  ref={pathRef}
                  strokeDasharray="2 5"
                  strokeLinecap="round"
                  strokeWidth="2"
                />
                <motion.path
                  className={cn(
                    "transition-colors duration-500",
                    arrived
                      ? "stroke-emerald-500"
                      : "stroke-blue-600 dark:stroke-blue-400"
                  )}
                  d={ROUTE}
                  fill="none"
                  strokeLinecap="round"
                  strokeWidth="2.5"
                  style={{ pathLength: progress }}
                />
                <Pin x={START.x} y={START.y}>
                  <Store height={11} width={11} x={-5.5} y={-5.5} />
                </Pin>
                <Pin done={arrived} x={END.x} y={END.y}>
                  <AnimatePresence initial={false} mode="popLayout">
                    <motion.g
                      animate={{ opacity: 1 }}
                      exit={{ opacity: 0 }}
                      initial={{ opacity: 0 }}
                      key={arrived ? "check" : "home"}
                      transition={{ duration: 0.2, delay: arrived ? 0.15 : 0 }}
                    >
                      {arrived ? (
                        <Check
                          height={12}
                          strokeWidth={3}
                          width={12}
                          x={-6}
                          y={-6}
                        />
                      ) : (
                        <Home height={11} width={11} x={-5.5} y={-5.5} />
                      )}
                    </motion.g>
                  </AnimatePresence>
                </Pin>
                <AnimatePresence>
                  {!arrived && (
                    <motion.g exit={{ opacity: 0 }} style={{ x, y }}>
                      <circle
                        className="fill-blue-500/15 dark:fill-blue-400/20"
                        r="18"
                      />
                      <circle
                        className="fill-blue-600 stroke-white dark:fill-blue-500 dark:stroke-zinc-900"
                        r="12"
                        strokeWidth="2"
                      />
                      <Bike
                        className="text-white"
                        height={13}
                        width={13}
                        x={-6.5}
                        y={-6.5}
                      />
                    </motion.g>
                  )}
                </AnimatePresence>
              </svg>
            </div>

            <CourierRow
              onMessage={onMessage ?? (isDemo ? () => undefined : undefined)}
              order={order}
            />
          </div>
        </div>

        <AnimatePresence>
          {arrived && shown.delivered ? (
            <motion.p
              animate={{ opacity: 1, filter: "blur(0px)", y: 0 }}
              className="text-pretty text-[15px] text-zinc-800 leading-7 dark:text-zinc-200"
              initial={{ opacity: 0, filter: "blur(4px)", y: 4 }}
              transition={{ duration: 0.4, ease: EASE_OUT, delay: 0.5 }}
            >
              {shown.delivered}
            </motion.p>
          ) : null}
        </AnimatePresence>
        <p aria-live="polite" className="sr-only">
          {arrived ? "Delivered" : ""}
        </p>
      </div>
    </MotionConfig>
  );
}

/** The courier, with a Message button when you pass `onMessage`. */
function CourierRow({
  order,
  onMessage,
}: {
  order: DeliveryOrder;
  onMessage?: () => void;
}) {
  return (
    <div className="flex items-center gap-3 border-black/[0.06] border-t px-4 py-3 dark:border-white/[0.08]">
      <span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-sky-100 font-semibold text-[12px] text-sky-800 dark:bg-sky-500/20 dark:text-sky-200">
        {order.courier.slice(0, 1)}
      </span>
      <span className="min-w-0 flex-1">
        <span className="block truncate font-medium text-[13.5px] text-zinc-900 dark:text-zinc-100">
          {order.courier}
        </span>
        <span className="block truncate text-[12px] text-zinc-500 dark:text-zinc-400">
          {order.vehicle}
        </span>
      </span>
      {onMessage ? (
        <button
          className="flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[12.5px] text-zinc-700 outline-hidden ring-1 ring-black/[0.08] transition-colors duration-150 hover:bg-zinc-50 focus-visible:ring-2 focus-visible:ring-blue-500/50 active:bg-zinc-100 dark:text-zinc-200 dark:ring-white/10 dark:active:bg-white/[0.08] dark:hover:bg-white/[0.05]"
          onClick={onMessage}
          type="button"
        >
          <MessageCircle aria-hidden="true" className="size-3.5" />
          Message
        </button>
      ) : null}
    </div>
  );
}

const STEPS = ["Packed", "On the way", "Delivered"];

/** Three short ticks under the ETA: where the order is at a glance. */
function Steps({ arrived }: { arrived: boolean }) {
  const at = arrived ? 2 : 1;
  return (
    <ol className="mb-1.5 flex shrink-0 gap-1" title={STEPS[at]}>
      {STEPS.map((s, i) => (
        <li
          aria-current={i === at ? "step" : undefined}
          className="relative h-1 w-6 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700"
          key={s}
        >
          <span className="sr-only">{s}</span>
          <motion.span
            animate={{ scaleX: i <= at ? 1 : 0 }}
            className={cn(
              "absolute inset-0 origin-left rounded-full",
              arrived ? "bg-emerald-500" : "bg-blue-600 dark:bg-blue-400"
            )}
            initial={false}
            transition={{ duration: 0.4, ease: EASE_OUT }}
          />
        </li>
      ))}
    </ol>
  );
}

function Pin({
  x,
  y,
  done = false,
  children,
}: {
  x: number;
  y: number;
  done?: boolean;
  children: ReactNode;
}) {
  return (
    <g transform={`translate(${x} ${y})`}>
      <circle
        className={cn(
          "transition-colors duration-500",
          done
            ? "fill-emerald-500 stroke-emerald-500"
            : "fill-white stroke-zinc-300 dark:fill-zinc-900 dark:stroke-zinc-600"
        )}
        r="11"
        strokeWidth="1.5"
      />
      <g
        className={cn(
          "transition-colors duration-500",
          done ? "text-white" : "text-zinc-500 dark:text-zinc-400"
        )}
      >
        {children}
      </g>
    </g>
  );
}
```

## Usage

With no props it plays the demo, counting the ETA down. Pass `status` and it follows your tracking updates instead: each new `order.progress` (0 to 1 along the route) glides the courier there, the ETA shows `order.minutes` as given, and `delivered` turns it green and shows your closing line. The Message button only shows when you pass `onMessage`, and the chat lines only when you pass `prompt` and `message`.

```tsx
"use client";

import AIOrderStatus from "@/components/kokonutui/ai-order-status";

/** `tracking` comes from your delivery provider's webhook or polling. */
export function OrderCard({
  tracking,
  openChat,
}: {
  tracking: { eta: number; progress: number; delivered: boolean; arriveAt: string };
  openChat: () => void;
}) {
  return (
    <AIOrderStatus
      delivered="Delivered. Ana left it at the door."
      onMessage={openChat}
      order={{
        merchant: "Noodle Bar",
        orderId: "7310",
        courier: "Ana",
        vehicle: "Blue bike",
        minutes: tracking.eta,
        progress: tracking.progress,
        arriveAt: tracking.arriveAt,
      }}
      status={tracking.delivered ? "delivered" : "on-the-way"}
    />
  );
}
```

From an AI SDK tool, return the same fields from a `track_order` tool and pass its `output` in; call the tool again (or stream data parts) for fresh positions.

<Demo(mdx/demos/ai-order-status-stream) />
