Button

Primary, secondary, ghost, danger and link. 4px corners, fixed heights, no shadow. An optional arrow slides on hover.

Install

$ npx shadcn@latest add @nudgekit/button

Or with no config: npx shadcn@latest add https://ui.nudgekit.app/r/button.json

Brings in @radix-ui/react-slot, class-variance-authority, lucide-react, and the theme.

Usage

usage.tsx
import { Button, buttonVariants } from "@/components/ui/button"

<Button arrow>Start for free</Button>
<Button variant="secondary">Read the docs</Button>
<Button variant="ghost" size="sm">Edit</Button>

// A link that looks like a button
<a href="/docs" className={buttonVariants({ variant: "secondary" })}>Read the docs</a>

Do

  • One primary button per screen, for the main action.
  • Put secondary next to primary for the second choice.
  • Use the arrow only on the main call to action.

Don't

  • Add a shadow or lift the button on hover.
  • Use two primary buttons side by side.
  • Use danger anywhere except a destructive confirm.

Code

What the CLI writes into your project. It is yours to change.

components/ui/button.tsx
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { ArrowRight } from "lucide-react";

import { cn } from "@/lib/utils";

const buttonVariants = cva(
  "group inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md border font-medium transition-colors duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
  {
    variants: {
      variant: {
        primary: "border-primary bg-primary text-primary-foreground hover:border-brand-ink hover:bg-brand-ink",
        secondary: "border-line-strong bg-background text-foreground hover:bg-surface",
        ghost: "border-transparent bg-transparent text-brand-ink hover:bg-brand-tint",
        danger: "border-danger bg-background text-danger hover:bg-danger/5",
        link: "h-auto border-transparent px-0 text-brand-ink underline-offset-4 hover:underline",
      },
      size: {
        sm: "h-9 px-3.5 text-sm",
        md: "h-11 px-5 text-[15px]",
        lg: "h-12 px-6 text-base",
        icon: "size-9 p-0",
      },
    },
    compoundVariants: [{ variant: "link", className: "h-auto px-0" }],
    defaultVariants: { variant: "primary", size: "md" },
  },
);

export interface ButtonProps
  extends React.ButtonHTMLAttributes<HTMLButtonElement>,
    VariantProps<typeof buttonVariants> {
  /** Render the child element with button styles. For links, prefer <a className={buttonVariants()}>, which works with every shadcn style. */
  asChild?: boolean;
  /** Adds a trailing arrow that slides on hover. Use on the main call to action. */
  arrow?: boolean;
}

function Button({ className, variant, size, asChild = false, arrow = false, children, ...props }: ButtonProps) {
  const Comp = asChild ? Slot : "button";
  return (
    <Comp data-slot="button" className={cn(buttonVariants({ variant, size }), className)} {...props}>
      {asChild ? (
        children
      ) : (
        <>
          {children}
          {arrow && (
            <ArrowRight
              aria-hidden
              className="transition-transform duration-150 group-hover:translate-x-0.5 motion-reduce:transition-none"
            />
          )}
        </>
      )}
    </Comp>
  );
}

export { Button, buttonVariants };