1import { Button } from "@/components/ui/pxl/button";2
3export default function ButtonPreview() {4 return (5 <Button>This is a Button</Button>6 );7}Installation
Section titled “Installation”pnpm dlx shadcn@latest add pxl-ui/registry/button
Install the following dependencies:
pnpm add @base-ui/react
Copy and paste the following code into your project.
1import { Button as ButtonPrimitive } from "@base-ui/react/button";2import { cva, type VariantProps } from "class-variance-authority";3
4import { cn } from "@/lib/utils";5
6const buttonVariants = cva(7 "group/button inline-flex shrink-0 items-center justify-center bg-clip-padding font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-1 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='fill-'])]:fill-current",8 {9 defaultVariants: {10 border: "default",11 variant: "default",12 size: "default",13 },14 variants: {15 border: {16 default:17 "pixel-border pixel-rounded pixel-size-md pixel-color-[transparent]",18 none: "",19 outline: "pixel-border pixel-rounded pixel-size-md",20 },21 variant: {22 default: "bg-foreground text-background hover:bg-foreground/80",23 primary: "bg-primary text-primary-foreground hover:bg-primary/80",24 outline:25 "pixel-color-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:pixel-color-input dark:bg-input/30 dark:hover:bg-input/50",26 secondary:27 "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",28 ghost:29 "pixel-color-[transparent] hover:bg-muted hover:pixel-color-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:pixel-color-muted aria-expanded:text-foreground dark:hover:bg-muted/50 dark:hover:pixel-color-muted/50",30 destructive:31 "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",32 link: "pixel-color-[transparent] text-primary-foreground underline-offset-4 hover:underline",33 info: "bg-info text-info-foreground fill-info-foreground hover:bg-info/80",34 success:35 "bg-success text-success-foreground fill-success-foreground hover:bg-success/80",36 warning:37 "bg-warning text-warning-foreground fill-warning-foreground hover:bg-warning/80",38 danger:39 "bg-danger text-danger-foreground fill-danger-foreground hover:bg-danger/80",40 },41 size: {42 default:43 "h-8 gap-1.5 px-2.5 text-sm has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-4",44 "4xs":45 "h-2.5 gap-0.5 px-0.5 text-4xs has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",46 "3xs":47 "h-3 gap-0.5 px-0.5 text-3xs has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",48 "2xs":49 "h-4 gap-0.5 px-1 text-2xs has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",50 xs: "h-6 gap-1 px-2 text-xs has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",51 sm: "h-7 gap-1 px-2.5 text-sm has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",52 md: "h-8 gap-1.5 px-2.5 text-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-4",53 lg: "h-9 gap-1.5 px-2.5 text-lg has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-4",54 icon: "size-8 [&_svg:not([class*='size-'])]:size-4",55 "icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",56 "icon-sm": "size-7 [&_svg:not([class*='size-'])]:size-3.5",57 "icon-md": "size-8 [&_svg:not([class*='size-'])]:size-4",58 "icon-lg": "size-9 [&_svg:not([class*='size-'])]:size-4.5",59 },60 },61 compoundVariants: [62 {63 border: "default",64 size: "4xs",65 className: "pixel-size-sm",66 },67 {68 border: "outline",69 size: "4xs",70 className: "pixel-size-sm",71 },72 {73 border: "default",74 size: "3xs",75 className: "pixel-size-sm",76 },77 {78 border: "outline",79 size: "3xs",80 className: "pixel-size-sm",81 },82 {83 border: "outline",84 variant: "default",85 className: "pixel-color-border hover:pixel-color-border/80",86 },87 {88 border: "outline",89 variant: "destructive",90 className: "pixel-color-destructive hover:pixel-color-destructive/80",91 },92 {93 border: "outline",94 variant: "primary",95 className:96 "pixel-color-primary-foreground hover:pixel-color-primary-foreground/80",97 },98 {99 border: "outline",100 variant: "secondary",101 className:102 "pixel-color-secondary-foreground hover:pixel-color-[color-mix(in_oklch,var(--secondary-foreground),var(--foreground)_5%)] aria-expanded:pixel-color-secondary-foreground",103 },104 {105 border: "outline",106 variant: "info",107 className:108 "pixel-color-info-foreground hover:pixel-color-info-foreground/80",109 },110 {111 border: "outline",112 variant: "success",113 className:114 "pixel-color-success-foreground hover:pixel-color-success-foreground/80",115 },116 {117 border: "outline",118 variant: "danger",119 className:120 "pixel-color-danger-foreground hover:pixel-color-danger-foreground/80",121 },122 {123 border: "outline",124 variant: "warning",125 className:126 "pixel-color-warning-foreground hover:pixel-color-warning-foreground/80",127 },128 ],129 },130);131
132function Button({133 border = "default",134 className,135 variant,136 size,137 ...props138}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {139 return (140 <ButtonPrimitive141 data-slot="button"142 data-variant={variant}143 data-size={size}144 className={cn(buttonVariants({ border, variant, size, className }))}145 {...props}146 />147 );148}149
150export { Button, buttonVariants };Update the import paths to match your project setup.
import { Button } from "@/components/ui/pxl/button"<Button variant="outline">Button</Button>Use the size prop to change the size of the button.
1import { Button } from "@/components/ui/pxl/button";2
3export default function ButtonSizesExample() {4 return (5 <div className="w-full flex flex-col gap-4 items-center">6 <div className="flex flex-row flex-wrap gap-2.5">7 <Button size="4xs">4XS</Button>8 <Button size="3xs">3XS</Button>9 <Button size="2xs">2XS</Button>10 <Button size="xs">XS</Button>11 <Button size="sm">SM</Button>12 <Button size="md">MD</Button>13 <Button size="lg">LG</Button>14 </div>15 <div className="flex flex-row flex-wrap gap-2.5">16 <Button size="icon-xs">17 <svg18 xmlns="http://www.w3.org/2000/svg"19 viewBox="0 0 24 24"20 >21 <path d="M10 18H8v-2h2zm-2-2H6v-2h2zm4-2v2h-2v-2zm-6 0H4v-2h2zm8 0h-2v-2h2zm2-2h-2v-2h2zm2-2h-2V8h2zm2-2h-2V6h2z"></path>22 </svg>23 </Button>24 <Button size="icon-sm">25 <svg26 xmlns="http://www.w3.org/2000/svg"27 viewBox="0 0 24 24"28 >29 <path d="M10 18H8v-2h2zm-2-2H6v-2h2zm4-2v2h-2v-2zm-6 0H4v-2h2zm8 0h-2v-2h2zm2-2h-2v-2h2zm2-2h-2V8h2zm2-2h-2V6h2z"></path>30 </svg>31 </Button>32 <Button size="icon">33 <svg34 xmlns="http://www.w3.org/2000/svg"35 viewBox="0 0 24 24"36 >37 <path d="M10 18H8v-2h2zm-2-2H6v-2h2zm4-2v2h-2v-2zm-6 0H4v-2h2zm8 0h-2v-2h2zm2-2h-2v-2h2zm2-2h-2V8h2zm2-2h-2V6h2z"></path>38 </svg>39 </Button>40 <Button size="icon-lg">41 <svg42 xmlns="http://www.w3.org/2000/svg"43 viewBox="0 0 24 24"44 >45 <path d="M10 18H8v-2h2zm-2-2H6v-2h2zm4-2v2h-2v-2zm-6 0H4v-2h2zm8 0h-2v-2h2zm2-2h-2v-2h2zm2-2h-2V8h2zm2-2h-2V6h2z"></path>46 </svg>47 </Button>48 </div>49 </div>50 );51}Variants
Section titled “Variants”Use the variant prop to change the colors of the button.
1import { Button } from "@/components/ui/pxl/button";2
3export default function ButtonVariantsExample() {4 return (5 <div className="flex flex-row flex-wrap gap-2.5">6 <Button variant="primary">Primary</Button>7 <Button variant="success">Success</Button>8 <Button variant="danger">Danger</Button>9 <Button variant="warning">Warning</Button>10 <Button variant="info">Info</Button>11 <Button variant="secondary">Secondary</Button>12 <Button variant="ghost">Ghost</Button>13 <Button variant="outline">Outline</Button>14 <Button variant="link">Link</Button>15 </div>16 );17}Borders
Section titled “Borders”Use the border prop to change the border of the button.
1import { Button } from "@/components/ui/pxl/button";2
3export default function ButtonBordersExample() {4 return (5 <div className="flex flex-row flex-wrap gap-2.5">6 <Button variant="default" border="none">None</Button>7 <Button variant="default" border="default">Default</Button>8 <Button variant="primary" border="outline">Outline</Button>9 </div>10 );11}API Reference
Section titled “API Reference”Button
Section titled “Button”The Button component is a wrapper around the button element that adds a variety of styles and functionality.
| Prop | Type | Default |
|---|---|---|
variant |
"default" | "primary" | "outline" | "ghost" | "destructive" | "secondary" | "link" | "success" | "warning" | "danger" |
"default" |
size |
"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" |
"default" |
border |
"default" | "none" | "outline" |
"default" |