import { ArrowUpIcon } from "lucide-react"
import { Button } from "@/components/ui/button"Installation#
pnpm dlx shadcn@latest add https://ui.tyap.me/r/styles/base/button.jsonnpx shadcn@latest add https://ui.tyap.me/r/styles/base/button.jsonyarn dlx shadcn@latest add https://ui.tyap.me/r/styles/base/button.jsonbunx --bun shadcn@latest add https://ui.tyap.me/r/styles/base/button.json
Install the following dependencies:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
Copy and paste the following code into your project.
import * as React from "react"
import { Button as ButtonPrimitive } from "@base-ui/react/button"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
[
"group/button inline-flex shrink-0 items-center justify-center whitespace-nowrap",
"rounded-4xl border border-transparent bg-clip-padding",
"text-sm font-medium",
"transition-[color,background-color,border-color,box-shadow,opacity,transform]",
"duration-150 ease-out",
"outline-none select-none",
"active:not-aria-[haspopup]:translate-y-px active:not-aria-[haspopup]:opacity-75",
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
"aria-invalid:border-destructive aria-invalid:ring-[3px] aria-invalid:ring-destructive/20",
"dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
"disabled:pointer-events-none disabled:opacity-50",
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
].join(" "),
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/80",
outline:
"border-input bg-input/30 text-foreground hover:bg-input/50 hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/70 aria-expanded:bg-secondary",
ghost:
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
destructive:
"border-destructive/15 bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
xs: "h-6 gap-1 px-2.5 text-xs has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3",
sm: "h-8 gap-1 px-3 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
default:
"h-9 gap-1.5 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
lg: "h-10 gap-1.5 px-5 has-data-[icon=inline-end]:pr-4 has-data-[icon=inline-start]:pl-4",
"icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",
"icon-sm": "size-8",
icon: "size-9",
"icon-lg": "size-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
type ButtonProps = ButtonPrimitive.Props &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}
function Button({
asChild,
children,
className,
variant = "default",
size = "default",
render,
nativeButton,
...props
}: ButtonProps) {
const resolvedRender =
asChild && React.isValidElement(children) ? children : render
const resolvedNativeButton = nativeButton ?? (resolvedRender ? false : true)
return (
<ButtonPrimitive
data-slot="button"
className={cn(buttonVariants({ variant, size, className }))}
render={resolvedRender}
nativeButton={resolvedNativeButton}
{...props}
>
{asChild ? undefined : children}
</ButtonPrimitive>
)
}
export { Button, buttonVariants }
Update the import paths to match your project setup.
Usage#
import { Button } from "@/components/ui/button"<Button variant="outline">Button</Button>Cursor#
Tailwind v4 switched from cursor: pointer to cursor: default for the button component.
If you want to keep the cursor: pointer behavior, add the following code to your CSS file:
You can also enable this during project setup with npx shadcn@latest init --pointer.
@layer base {
button:not(:disabled),
[role="button"]:not(:disabled) {
cursor: pointer;
}
}Examples#
Size#
Use the size prop to change the size of the button.
import { ArrowUpRightIcon } from "lucide-react"
import { Button } from "@/components/ui/button"Default#
import { Button } from "@/components/ui/button"
export function ButtonDefault() {Outline#
import { Button } from "@/components/ui/button"
export function ButtonOutline() {Secondary#
import { Button } from "@/components/ui/button"
export function ButtonSecondary() {Ghost#
import { Button } from "@/components/ui/button"
export function ButtonGhost() {Destructive#
import { Button } from "@/components/ui/button"
export function ButtonDestructive() {Link#
import { Button } from "@/components/ui/button"
export function ButtonLink() {Icon#
import { CircleFadingArrowUpIcon } from "lucide-react"
import { Button } from "@/components/ui/button"With Icon#
Remember to add the data-icon="inline-start" or data-icon="inline-end" attribute to the icon for the correct spacing.
import { IconGitBranch, IconGitFork } from "@tabler/icons-react"
import { Button } from "@/components/ui/button"Rounded#
Use the rounded-full class to make the button rounded.
import { ArrowUpIcon } from "lucide-react"
import { Button } from "@/components/ui/button"Spinner#
Render a <Spinner /> component inside the button to show a loading state. Remember to add the data-icon="inline-start" or data-icon="inline-end" attribute to the spinner for the correct spacing.
import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"
Button Group#
To create a button group, use the ButtonGroup component. See the Button Group documentation for more details.
"use client"
import * as React from "react"As Link#
You can use the buttonVariants helper to make a link look like a button.
Do not use <Button render={<a />} nativeButton={false} /> for links. The Base UI Button component always applies role="button", which overrides the semantic link role on <a> elements. Use buttonVariants with a plain <a> tag instead.
import { buttonVariants } from "@/components/ui/button"
export function ButtonRender() {RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import { ArrowRightIcon, PlusIcon } from "lucide-react"API Reference#
Button#
The Button component is a wrapper around the button element that adds a variety of styles and functionality.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "ghost" | "destructive" | "secondary" | "link" | "default" |
size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "default" |