Dice UI

Pending

Buttons 27

About

A utility component and hook that applies pending/loading state to any interactive element, blocking clicks and keyboard activation with proper ARIA attributes.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Pending to your project and fits it to your theme.

Code

How Pending is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import { usePending } from "@/components/ui/pending";
import { Loader2 } from "lucide-react";
import * as React from "react";
import { Button } from "@/components/ui/button";

export default function PendingDemo() {
  const [isSubmitting, setIsSubmitting] = React.useState(false);
  const { pendingProps, isPending } = usePending({ isPending: isSubmitting });

  const onSubmit = React.useCallback(() => {
    setIsSubmitting(true);
    // Simulate API call
    setTimeout(() => {
      setIsSubmitting(false);
    }, 2000);
  }, []);

  return (
    <div className="flex flex-col items-center gap-4">
      <Button onClick={onSubmit} {...pendingProps}>
        {isPending && <Loader2 className="size-4 animate-spin" />}
        {isPending ? "Submitting..." : "Submit"}
      </Button>

      <p className="text-muted-foreground text-sm">
        {isPending
          ? "Button is pending - try tabbing to it and pressing Enter"
          : "Click the button to see pending state"}
      </p>
    </div>
  );
}

Dependencies

More by Dice UI

View all
  • Compare Slider

    Compare Slider

    75
  • Sortable

    Sortable

    49
  • Circular Progress

    Circular Progress

    41
  • Status

    Status

    28
  • Banner

    Banner

    19
  • Stack

    Stack

    8
  • Scroller

    Scroller

    5
  • Mention

    Mention

    4

More in Buttons

View all
  • Button

    Button

    14
  • Button

    Button

    34
  • Texture Button

    Texture Button

    92
  • Button Save

    Button Save

    46
  • Button

    Button

    64
  • Button Group

    Button Group

    3
  • Notification Button

    Notification Button

    103
  • Button

    Button