Promo-banner

PreviousNext

This component displays a promotional banner indicating progress towards unlocking a free shipping offer based on a spending threshold. It features a progress bar and dynamically updates the user's remaining balance to qualify for free shipping.

Docs
shadcnblocksblock

Preview

Loading preview…
code/block/promo-banner1.tsx
import { Truck, X } from "lucide-react";

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

import { Progress } from "@/components/ui/progress";

interface PromoBanner1Props {
  threshold?: number;
  currentAmount?: number;
  className?: string;
}

const PromoBanner1 = ({
  threshold = 75,
  currentAmount = 45,
  className,
}: PromoBanner1Props) => {
  const progress = Math.min((currentAmount / threshold) * 100, 100);
  const remaining = threshold - currentAmount;
  const hasQualified = remaining <= 0;

  return (
    <div
      className={cn(
        "w-full bg-emerald-600 text-emerald-50",
        className,
      )}
    >
      <div className="container flex items-center justify-center gap-3 py-2.5">
        <Truck className="size-4 shrink-0" />
        {hasQualified ? (
          <p className="text-sm font-medium">
            🎉 You&apos;ve unlocked FREE shipping!
          </p>
        ) : (
          <div className="flex items-center gap-3">
            <p className="text-sm">
              Spend <span className="font-semibold">${remaining.toFixed(2)}</span>{" "}
              more for <span className="font-semibold">FREE shipping</span>
            </p>
            <Progress
              value={progress}
              className="hidden h-1.5 w-24 bg-emerald-500 sm:block [&>div]:bg-white"
            />
          </div>
        )}
      </div>
    </div>
  );
};

export { PromoBanner1 };

Installation

npx shadcn@latest add @shadcnblocks/promo-banner1

Usage

import { PromoBanner1 } from "@/components/promo-banner1"
<PromoBanner1 />