CraftUI

Button

A block button with a press animation, in five variants and three sizes.

Installation

npx shadcn@latest add @runqora/craft-button

This writes components/craft/button.tsx and button-variants.ts, and adds the CraftUI theme to your CSS. See Installation if you haven't added the registry yet.

Usage

import { Button } from "@/components/craft/button";

<Button>Play</Button>;

Examples

Sizes

Disabled and loading

A disabled button turns gray and can't be focused. A loading button keeps its color and its keyboard focus, shows a spinner, and ignores clicks until it's done, so someone using a keyboard doesn't lose their place.

Icons

Pass any icon as leadingIcon or trailingIcon. For a button with only an icon, use size="icon" and give it an aria-label.

Full width

Something that goes to another page should stay a real link. Apply buttonVariants to an <a>, or to your router's link component, so that assistive technology announces it as a link. It lives in its own file, so you can call it from a Server Component.

Props

Prop

Type

Button also accepts every attribute of a <button>.

Accessibility

  • Renders a native <button> with type="button", so it won't submit a form unless you ask it to with type="submit".
  • Works with Enter and Space, and shows a solid focus ring for keyboard users.
  • loading sets aria-busy and keeps the button focusable.
  • The hover color is brighter than in the game, so hovered primary and destructive buttons use a dark label to keep a contrast of at least 4.5:1.

Customization

Every color comes from a token, so you can change one button without touching the component.

To match the white hover label in the game, set --craft-primary-hover-fg: #ffffff. It falls below AA contrast, so it's not the default. For a change everywhere, edit the tokens in your CSS. See Themes.

Dependencies

  • @base-ui/react
  • class-variance-authority
  • shadcn's utils, and craft-theme

Source

On this page