Status

A coloured word with a dot, optionally live. Never a filled pill.

OperationalRenderingDegradedFailedQueued

Install

$ npx shadcn@latest add @nudgekit/status

Or with no config: npx shadcn@latest add https://ui.nudgekit.app/r/status.json

Usage

usage.tsx
import { Status } from "@/components/ui/status"

<Status tone="ok">Operational</Status>
<Status tone="ok" live>Rendering</Status>
<Status tone="bad">Failed</Status>

Do

  • Show status as a coloured word with a dot.
  • Use live only while something is happening.

Don't

  • Use filled coloured pills for status.
  • Colour a whole card border by status.

Code

What the CLI writes into your project. It is yours to change.

components/ui/status.tsx
import * as React from "react";

import { cn } from "@/lib/utils";

const tones = {
  ok: "text-success",
  warn: "text-warning",
  bad: "text-danger",
  neutral: "text-muted-foreground",
} as const;

export interface StatusProps extends React.HTMLAttributes<HTMLSpanElement> {
  tone?: keyof typeof tones;
  /** Adds a soft ping to the dot, for live states such as "Rendering". */
  live?: boolean;
}

/** Status is a coloured word with a dot. Never a filled pill. */
function Status({ tone = "ok", live = false, className, children, ...props }: StatusProps) {
  return (
    <span
      data-slot="status"
      className={cn("inline-flex items-center gap-2 text-sm font-medium", tones[tone], className)}
      {...props}
    >
      <span aria-hidden className="relative flex size-2">
        {live && (
          <span className="absolute inline-flex size-full animate-ping rounded-full bg-current opacity-40 motion-reduce:hidden" />
        )}
        <span className="relative inline-flex size-2 rounded-full bg-current" />
      </span>
      {children}
    </span>
  );
}

export { Status };