Feedback

Banner

Full-width announcement above the app shell — trials, outages and launches.

react-aria-componentslucide-react

Preview

AI research briefs are live.Try it
Your trial ends in 3 days.Upgrade
Email sending is paused.

Installation

Components are copied into your project — no runtime package.

  1. Install the following dependencies:

    terminal
    npm install react-aria-components lucide-react
  2. Create a banner.tsx file and paste the following code into it.

    src/components/ui/banner.tsx
    "use client";
    
    import { X } from "lucide-react";
    import type { ReactNode } from "react";
    import { Button as AriaButton } from "react-aria-components";
    import { cx } from "@/utils/cx";
    import type { StatusTone } from "./alert";
    
    const solid: Record<StatusTone, string> = {
      info: "bg-info text-white",
      success: "bg-success text-white",
      warning: "bg-warning text-white",
      error: "bg-error text-white",
      feature: "bg-linear-to-r from-accent-light to-accent text-white",
    };
    const soft: Record<StatusTone, string> = {
      info: "bg-info-soft text-fg border-info-border",
      success: "bg-success-soft text-fg border-success-border",
      warning: "bg-warning-soft text-fg border-warning-border",
      error: "bg-error-soft text-fg border-error-border",
      feature: "bg-accent-soft text-fg border-accent-soft-border",
    };
    
    export interface BannerProps {
      tone?: StatusTone;
      variant?: "solid" | "soft";
      icon?: ReactNode;
      title: ReactNode;
      description?: ReactNode;
      action?: ReactNode;
      onDismiss?: () => void;
      className?: string;
    }
    
    /** Full-width, edge-to-edge announcement above the app shell (trial ending, outage, new feature). */
    export function Banner({ tone = "feature", variant = "solid", icon, title, description, action, onDismiss, className }: BannerProps) {
      const isSolid = variant === "solid";
      return (
        <div role="status" className={cx("relative flex min-h-10 items-center justify-center gap-2.5 px-12 py-2 text-center text-base", isSolid ? [solid[tone], "[&_a]:!text-white [&_[role=link]]:!text-white"] : ["border-b", soft[tone]], className)}>
          {icon && <span className={cx("shrink-0 [&_svg]:size-4", !isSolid && "text-accent")}>{icon}</span>}
          <span className="font-medium">{title}</span>
          {description && <span className={cx("hidden sm:inline", isSolid ? "text-white/80" : "text-fg-secondary")}>{description}</span>}
          {action}
          {onDismiss && (
            <AriaButton
              aria-label="Dismiss banner"
              onPress={onDismiss}
              className={cx(
                "absolute right-3 inline-flex size-6 items-center justify-center rounded-xs outline-none data-focus-visible:shadow-focus",
                isSolid ? "text-white/70 data-hovered:text-white" : "text-fg-muted data-hovered:text-fg",
              )}
            >
              <X className="size-4" />
            </AriaButton>
          )}
        </div>
      );
    }
  3. Create a alert.tsx file and paste the following code into it.

    src/components/ui/alert.tsx
    "use client";
    
    import { AlertTriangle, CheckCircle2, Info, Sparkles, X, XCircle } from "lucide-react";
    import type { ReactNode } from "react";
    import { Button as AriaButton } from "react-aria-components";
    import { cx } from "@/utils/cx";
    
    export type StatusTone = "info" | "success" | "warning" | "error" | "feature";
    export type AlertVariant = "soft" | "solid" | "outline";
    
    const tones: Record<StatusTone, { soft: string; solid: string; icon: string; Icon: typeof Info }> = {
      info: { soft: "bg-info-soft border-info-border", solid: "bg-info", icon: "text-info", Icon: Info },
      success: { soft: "bg-success-soft border-success-border", solid: "bg-success", icon: "text-success", Icon: CheckCircle2 },
      warning: { soft: "bg-warning-soft border-warning-border", solid: "bg-warning", icon: "text-warning", Icon: AlertTriangle },
      error: { soft: "bg-error-soft border-error-border", solid: "bg-error", icon: "text-error", Icon: XCircle },
      feature: { soft: "bg-accent-soft border-accent-soft-border", solid: "bg-linear-to-b from-accent-light to-accent", icon: "text-accent", Icon: Sparkles },
    };
    
    export interface AlertProps {
      tone?: StatusTone;
      /** `soft` tinted surface (default) · `solid` filled · `outline` white with border and shadow. */
      variant?: AlertVariant;
      /** `md` stacks title + description; `sm` is a single 36px line. */
      size?: "sm" | "md";
      title: ReactNode;
      children?: ReactNode;
      /** Inline actions, typically <LinkButton>s. */
      actions?: ReactNode;
      /** Deprecated alias of `actions` kept for compatibility. */
      action?: ReactNode;
      onDismiss?: () => void;
      className?: string;
    }
    
    /** Inline alert for sync issues, limits and compliance notes. Four tones + feature, three styles, two sizes. */
    export function Alert({ tone = "info", variant = "soft", size = "md", title, children, actions, action, onDismiss, className }: AlertProps) {
      const t = tones[tone];
      const solid = variant === "solid";
      const acts = actions ?? action;
      const dismiss = onDismiss && (
        <AriaButton
          aria-label="Dismiss"
          onPress={onDismiss}
          className={cx(
            "-m-0.5 inline-flex size-5 shrink-0 items-center justify-center rounded-xs outline-none data-focus-visible:shadow-focus",
            solid ? "text-white/70 data-hovered:text-white" : "text-fg-muted data-hovered:text-fg",
          )}
        >
          <X className="size-3.5" />
        </AriaButton>
      );
    
      return (
        <div
          role={tone === "error" ? "alert" : "status"}
          className={cx(
            "flex gap-2.5 rounded-md",
            variant === "soft" && ["border", t.soft],
            variant === "outline" && "border border-line bg-surface shadow-card",
            solid && [t.solid, "text-white [&_a]:!text-white [&_[role=link]]:!text-white"],
            size === "sm" ? "min-h-9 items-center px-3 py-2" : "items-start px-3.5 py-3",
            className,
          )}
        >
          <t.Icon aria-hidden className={cx("size-4 shrink-0", size === "md" && "mt-px", solid ? "text-white" : t.icon)} />
          {size === "sm" ? (
            <>
              <div className={cx("min-w-0 flex-1 truncate text-sm font-medium", solid ? "text-white" : "text-fg")}>{title}</div>
              {acts}
              {dismiss}
            </>
          ) : (
            <>
              <div className="min-w-0 flex-1">
                <div className={cx("text-base font-medium", solid ? "text-white" : "text-fg")}>{title}</div>
                {children && <div className={cx("mt-0.5 text-sm", solid ? "text-white/80" : "text-fg-secondary")}>{children}</div>}
                {acts && <div className="mt-2.5 flex flex-wrap items-center gap-3">{acts}</div>}
              </div>
              {dismiss}
            </>
          )}
        </div>
      );
    }
  4. Add the theme tokens and the cx helper from Installation if you haven’t yet, then update the import paths to match your project setup.