Button
A dependable action, with clear emphasis and loading states.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/button.jsonUse it
Scroll horizontally for long lines
"use client";
import { useState, useEffect } from "react";
import { Badge } from "@/components/jez-ui/ui/badge";
import { Button } from "@/components/jez-ui/ui/button";
import { Plus, ArrowUpRight, Check } from "lucide-react";
export default function Example() {
const [buttonBusy, setButtonBusy] = useState(false);
useEffect(() => {
if (!buttonBusy) return;
const timer = setTimeout(() => {
setButtonBusy(false);
setNotice("Project published.");
}, 900);
return () => clearTimeout(timer);
}, [buttonBusy]);
const [notice, setNotice] = useState("");
const actions = [
{ label: "Duplicate", onSelect: () => setNotice("A copy is ready.") },
{ label: "Archive", onSelect: () => setNotice("Moved to archive.") },
];
return (
<>
<div className="grid w-full max-w-lg gap-6">
<div className="flex items-center justify-between border-b border-border pb-5">
<div>
<h3 className="text-lg font-semibold">Project actions</h3>
<p className="mt-1 text-sm text-muted-foreground">
Website refresh · Draft
</p>
</div>
<Badge>Draft</Badge>
</div>
<div className="flex flex-wrap items-center gap-3">
<Button
loading={buttonBusy}
onClick={() => setButtonBusy(true)}
>
<Plus size={16} />
Publish project
</Button>
<Button
variant="outline"
onClick={() => setNotice("Draft saved.")}
>
Save draft
</Button>
<Button
variant="ghost"
onClick={() => setNotice("Preview selected.")}
>
Preview <ArrowUpRight size={15} />
</Button>
</div>
<div className="flex flex-wrap items-center gap-3">
<Button
size="sm"
variant="secondary"
onClick={() => setNotice("Invitation link copied in this example.")}
>
Invite member
</Button>
<Button
size="sm"
variant="danger"
onClick={() => setNotice("Archive action selected.")}
>
Archive
</Button>
<Button
size="sm"
disabled
>
Up to date <Check size={14} />
</Button>
</div>
</div>
<p role="status">{notice}</p>
</>
);
}
Props & types
Scroll horizontally for long lines
export type ButtonProps = React.ComponentProps<"button"> & {
variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
size?: "sm" | "md" | "lg";
loading?: boolean;
asChild?: boolean;
};
ButtonPropsSource
View 2 source files
registry/ui/button.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Slot } from "radix-ui";
import { LoaderCircle } from "lucide-react";
import { cn } from "./utils";
export type ButtonProps = React.ComponentProps<"button"> & {
variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
size?: "sm" | "md" | "lg";
loading?: boolean;
asChild?: boolean;
};
export function Button({
variant = "primary",
size = "md",
loading,
asChild,
className,
children,
disabled,
...props
}: ButtonProps) {
const Comp = asChild ? Slot.Root : "button";
return (
<Comp
type={asChild ? undefined : "button"}
disabled={asChild ? undefined : disabled || loading}
aria-disabled={disabled || loading || undefined}
aria-busy={loading || undefined}
className={cn(
"relative inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent text-sm font-medium leading-none transition-[background-color,border-color,box-shadow,transform] duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary active:scale-[.98] disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none [&_svg]:shrink-0",
{
"bg-primary text-primary-foreground shadow-[inset_0_1px_0_#ffffff26,0_1px_2px_#00000012] hover:bg-primary/90":
variant === "primary",
"border-border/60 bg-muted text-foreground hover:bg-muted/70":
variant === "secondary",
"border-border bg-background text-foreground shadow-sm hover:bg-muted/60":
variant === "outline",
"text-muted-foreground hover:bg-muted hover:text-foreground":
variant === "ghost",
"bg-danger text-danger-foreground hover:bg-danger/90":
variant === "danger",
},
{
"h-8 px-3 text-xs": size === "sm",
"h-10 px-4": size === "md",
"h-12 px-6": size === "lg",
},
className,
)}
{...props}
>
{asChild ? (
children
) : (
<>
<span
className={cn(
"inline-flex min-w-0 flex-1 items-center justify-center gap-2",
loading && "invisible",
)}
>
{children}
</span>
{loading && (
<LoaderCircle
aria-hidden="true"
className="absolute size-4 animate-spin motion-reduce:animate-none"
/>
)}
</>
)}
</Comp>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
radix-ui@1.6.7 · lucide-react@0.577.0 · clsx@2.1.1 · tailwind-merge@3.5.0 · lucide-react@0.577.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →