Button
One button in three sizes and four looks. It squeezes a little when pressed.
Installation
Terminal
npx shadcn@latest add https://fabrickit.org/r/button.jsonTerminal
pnpm dlx shadcn@latest add https://fabrickit.org/r/button.jsonTerminal
yarn shadcn@latest add https://fabrickit.org/r/button.jsonTerminal
bunx --bun shadcn@latest add https://fabrickit.org/r/button.jsonThis copies the component into components/fabricui. It's your code from then on. First time? Add the theme once: see Installation.
Step 1: Add the theme (once)
Every colour, radius and curve the components use, as --fabric-* variables. Save it as fabric.css next to your global CSS and import it there. If you've added another Fabric Kit component before, skip this.globals.css@import "./fabric.css";fabric.css/* * fabric.css — Fabric Kit's theme: every colour, radius, ring and curve the * components use, as --fabric-* variables (prefixed, so they never clash * with your own shadcn theme). Installed by `shadcn add @fabrickit/theme` * (it lands in your global CSS) — or import this file once, globally. * Dark by default. For light, put data-theme="light" on <html> (or on any * element: the tokens follow it down the tree; data-theme="dark" turns back). */ :root, [data-theme="dark"] { --fabric-page: #111111; --fabric-surface: #191919; /* triggers, recessed tiles */ --fabric-panel: #202020; /* open panels */ --fabric-raised: #2a2a2a; /* hover, range band */ --fabric-raised-hi: #343434; /* hover inside a band */ --fabric-preview: #252525; /* soft preview fills */ --fabric-text: #e0e0e0;Step 2: Copy the Button files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/button.tsximport * as React from "react"; import "./button.css"; export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & { /** primary: the one main action · ghost: secondary · soft: small inline actions · danger: destructive */ variant?: "primary" | "ghost" | "soft" | "danger"; /** sm 28px (inside rows) · md 34px (inside panels) · lg 38px (on the page) */ size?: "sm" | "md" | "lg"; }; /** * Button. Squeezes a little when pressed; shows Fabric Kit's focus ring for * the keyboard. Put an icon (an <svg>) before or after the label. */ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button( { variant = "primary", size = "md", className, type = "button", ...props },components/fabricui/button.css/* * Button — sizes sm (28px), md (34px, the default), lg (38px); looks primary, * ghost, soft, danger. Corners follow Fabric Kit's roundness rule (40% of the * height), so every size is the same shape. Squeezes a little when pressed; * a ring shows for keyboard focus. */ .fui-btn { all: unset; box-sizing: border-box; flex: none; --h: 34px; height: var(--h); padding: 0 14px; display: inline-flex; align-items: center; justify-content: center;Step 3: Check the import paths
The files import each other through the @/ alias (the shadcn default, there in a new Next.js app). If your project doesn't have it, add it to tsconfig.json, or change the imports to relative paths.tsconfig.json{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } }Step 4: Use it
Import it from @/components/fabricui/button. The Usage example below shows it in a page.
Code
components/fabricui/button.tsx
import * as React from "react";
import "./button.css";
export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
/** primary: the one main action · ghost: secondary · soft: small inline actions · danger: destructive */
variant?: "primary" | "ghost" | "soft" | "danger";
/** sm 28px (inside rows) · md 34px (inside panels) · lg 38px (on the page) */
size?: "sm" | "md" | "lg";
};
/**
* Button. Squeezes a little when pressed; shows Fabric Kit's focus ring for
* the keyboard. Put an icon (an <svg>) before or after the label.
*/
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button(
{ variant = "primary", size = "md", className, type = "button", ...props },components/fabricui/button.css
/*
* Button — sizes sm (28px), md (34px, the default), lg (38px); looks primary,
* ghost, soft, danger. Corners follow Fabric Kit's roundness rule (40% of the
* height), so every size is the same shape. Squeezes a little when pressed;
* a ring shows for keyboard focus.
*/
.fui-btn {
all: unset;
box-sizing: border-box;
flex: none;
--h: 34px;
height: var(--h);
padding: 0 14px;
display: inline-flex;
align-items: center;
justify-content: center;Usage
Usage
import { Button } from "@/components/fabricui/button";
export function Actions() {
return (
<div className="flex gap-2">
<Button>Save changes</Button>
<Button variant="ghost">Cancel</Button>
</div>
);
}Props
| Prop | Type | Default |
|---|---|---|
| variant primary for the one main action, ghost for secondary, soft for small inline actions, danger for destructive ones. | "primary" | "ghost" | "soft" | "danger" | "primary" |
| size sm (28px) inside rows, md (34px) inside panels, lg (38px) on the page. | "sm" | "md" | "lg" | "md" |
| ...props Anything a <button> takes: onClick, disabled, type, aria-*. | ButtonHTMLAttributes | — |