# Button

shadcn button reskinned with pixel borders and offset shadows.

Source: https://www.ui95.dev/ui/button

## Examples

```tsx
import { Plus } from "lucide-react"

import { Button } from "@/components/ui/button"

import type { ShowcaseDemo } from "../types"

type ButtonVariant = "default" | "outline" | "secondary" | "ghost" | "destructive" | "link"

const VARIANTS: readonly ButtonVariant[] = [
  "default",
  "outline",
  "secondary",
  "ghost",
  "destructive",
  "link",
]

const TEXT_SIZES = [
  { size: "xs", label: "XS" },
  { size: "sm", label: "SM" },
  { size: "default", label: "MD" },
  { size: "lg", label: "LG" },
] as const

const ICON_SIZES = ["icon-xs", "icon-sm", "icon", "icon-lg"] as const

function renderSizes(variant: ButtonVariant) {
  return (
    <div className="flex flex-col items-start gap-3">
      <div className="flex flex-wrap items-center gap-3">
        {TEXT_SIZES.map(({ size, label }) => (
          <Button key={size} variant={variant} size={size}>
            {label}
          </Button>
        ))}
      </div>
      <div className="flex flex-wrap items-center gap-3">
        {ICON_SIZES.map((size) => (
          <Button key={size} variant={variant} size={size} aria-label={`${variant} ${size}`}>
            <Plus shapeRendering="crispEdges" strokeWidth={3} />
          </Button>
        ))}
      </div>
    </div>
  )
}

function renderDisabled() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      {VARIANTS.map((variant) => (
        <Button key={variant} variant={variant} size="sm" disabled>
          {variant}
        </Button>
      ))}
    </div>
  )
}

export const demo: ShowcaseDemo = {
  span: "large",
  variants: [
    ...VARIANTS.map((variant) => ({ label: variant, render: () => renderSizes(variant) })),
    { label: "disabled", render: renderDisabled },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/button.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn class-variance-authority radix-ui
```

`components/ui/button.tsx`

```tsx
"use client"

import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { Slot } from "radix-ui"
import * as React from "react"

const buttonVariants = cva(
  "group/button relative inline-flex shrink-0 items-center justify-center pixel-border border-border font-pixel text-[16px] leading-none whitespace-nowrap uppercase outline-none select-none disabled:pointer-events-none disabled:text-muted-foreground disabled:offset-shadow-none disabled:dither-50 aria-invalid:border-destructive [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
  {
    variants: {
      variant: {
        default:
          "bg-card text-card-foreground offset-shadow-1 bevel-raised hover:bg-foreground hover:text-card active:not-aria-[haspopup]:translate-x-[calc(var(--pixel)*1.2)] active:not-aria-[haspopup]:translate-y-[calc(var(--pixel)*1.2)] active:not-aria-[haspopup]:offset-shadow-none aria-expanded:bg-foreground aria-expanded:text-card",
        outline:
          "bg-transparent text-foreground offset-shadow-1 hover:bg-muted aria-expanded:bg-muted active:not-aria-[haspopup]:translate-x-[calc(var(--pixel)*1.2)] active:not-aria-[haspopup]:translate-y-[calc(var(--pixel)*1.2)] active:not-aria-[haspopup]:offset-shadow-none",
        secondary:
          "bg-secondary text-secondary-foreground bevel-raised offset-shadow-1 active:not-aria-[haspopup]:translate-x-[calc(var(--pixel)*1.2)] active:not-aria-[haspopup]:translate-y-[calc(var(--pixel)*1.2)] active:not-aria-[haspopup]:offset-shadow-none active:not-aria-[haspopup]:bevel-sunken aria-expanded:bevel-sunken",
        ghost:
          "border-transparent bg-transparent text-foreground hover:border-current aria-expanded:border-current",
        destructive:
          "bg-foreground text-card offset-shadow-1 hover:bg-card hover:text-card-foreground active:not-aria-[haspopup]:translate-x-[calc(var(--pixel)*1.2)] active:not-aria-[haspopup]:translate-y-[calc(var(--pixel)*2)] active:not-aria-[haspopup]:offset-shadow-none",
        link: "border-transparent bg-transparent text-foreground decoration-[length:var(--pixel)] underline-offset-4 hover:underline",
      },
      size: {
        default: "h-10 gap-2 px-4",
        xs: "h-6 gap-1 px-1.5 text-sm [&_svg:not([class*='size-'])]:size-3",
        sm: "h-8 gap-1.5 px-2.5 [&_svg:not([class*='size-'])]:size-3.5",
        lg: "h-12 gap-2 px-6 text-[24px]",
        icon: "size-9",
        "icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",
        "icon-sm": "size-7 [&_svg:not([class*='size-'])]:size-3.5",
        "icon-lg": "size-11",
      },
    },
    defaultVariants: {
      variant: "default",
      size: "default",
    },
  }
)

function Button({
  className,
  variant = "default",
  size = "default",
  asChild = false,
  ...props
}: React.ComponentProps<"button"> &
  VariantProps<typeof buttonVariants> & {
    asChild?: boolean
  }) {
  const Comp = asChild ? Slot.Root : "button"
  return (
    <Comp
      data-slot="button"
      data-variant={variant}
      data-size={size}
      className={cn(buttonVariants({ variant, size, className }))}
      {...props}
    />
  )
}

export { Button, buttonVariants }
```

## API reference

### Button

| Prop | Type | Default |
| --- | --- | --- |
| `variant` | `"link" \| "default" \| "outline" \| "secondary" \| "ghost" \| "destructive"` | `"default"` |
| `size` | `"sm" \| "lg" \| "default" \| "xs" \| "icon" \| "icon-xs" \| "icon-sm" \| "icon-lg"` | `"default"` |
| `asChild` | `boolean` | `false` |

## Used by

- [dialog](https://www.ui95.dev/ui/dialog)
- [alert-dialog](https://www.ui95.dev/ui/alert-dialog)
- [sheet](https://www.ui95.dev/ui/sheet)
- [pagination](https://www.ui95.dev/ui/pagination)
- [input-group](https://www.ui95.dev/ui/input-group)
- [sidebar](https://www.ui95.dev/ui/sidebar)
- [calendar](https://www.ui95.dev/ui/calendar)
- [carousel](https://www.ui95.dev/ui/carousel)
- [window](https://www.ui95.dev/ui/window)
- [error-dialog](https://www.ui95.dev/ui/error-dialog)
- [taskbar](https://www.ui95.dev/ui/taskbar)

## Sounds

- `button.press`
- `button.release`
- `small-button.press`
- `small-button.release`
