Lab // Index

Total: 08

Component // Button

01 of 08

Tactile ButtonNew

A raised button whose surface gives when you press it while the label stays sharp and still, with a bars loader and a drawn check for loading and success. Black on a light page, white on a dark one

Demo // Live

Interactive
Variant
Size
States

Install // Steps

Total: 03

Step 01

Install dependencies

It also uses the cn() helper from shadcn/ui (clsx and tailwind-merge) and the shadcn colour roles: primary, primary-foreground and ring.

npm install class-variance-authority lucide-react

Step 02

Copy and paste the following code into your project.

One file. Every class means the same in Tailwind v3 and v4, so it needs no config changes in either.

import { ArrowRight, Download } from "lucide-react";
import { TactileButton } from "@/components/craft/tactile-button";

export default function Example() {
  return (
    <div className="flex flex-wrap items-center gap-4">
      <TactileButton>Continue</TactileButton>

      {/* Sizes: sm, md, lg (the default) */}
      <TactileButton size="md" iconStart={<Download />}>
        Download
      </TactileButton>

      {/* A pill, and the plain fill without the gradient or shadow */}
      <TactileButton rounded>Rounded</TactileButton>
      <TactileButton flat>Flat</TactileButton>

      {/* The label gives way to the bars loader, then to a drawn check */}
      <TactileButton loading>Save changes</TactileButton>
      <TactileButton success="Saved">Save changes</TactileButton>

      {/* Any element can take the button's look */}
      <TactileButton render={<a href="/docs" />} iconEnd={<ArrowRight />}>
        Read the docs
      </TactileButton>
    </div>
  );
}

Step 03

Add the success check to your global stylesheet.

The drawn check is the success-check transition from transitions.dev, tuned down to suit an icon inside a button. Without it the check simply appears.

:root {
  --check-opacity-dur: 500ms;
  --check-rotate-dur: 500ms;
  --check-rotate-from: 80deg;
  --check-bob-dur: 500ms;
  --check-y-amount: 40px;
  --check-blur-dur: 500ms;
  --check-blur-from: 10px;
  --check-path-dur: 500ms;
  --check-path-delay: 80ms;
  --check-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --check-ease-opacity: cubic-bezier(0.22, 1, 0.36, 1);
  --check-ease-rotate: cubic-bezier(0.22, 1, 0.36, 1);
  --check-ease-bob: cubic-bezier(0.34, 1.35, 0.64, 1);
  --check-ease-path: cubic-bezier(0.22, 1, 0.36, 1);
}
/* Inside a button the check is 14 to 20px, so it travels, turns and blurs far less */
.tactile-check {
  --check-y-amount: 6px;
  --check-rotate-from: 30deg;
  --check-blur-from: 3px;
}

.t-success-check {
  display: inline-block;
  transform-origin: center;
  opacity: 0;
  will-change: transform, opacity, filter;
}
.t-success-check svg { display: block; overflow: visible; }
.t-success-check svg path {
  stroke-dasharray: 23;
  stroke-dashoffset: 23;
}

.t-success-check[data-state="in"] {
  animation:
    t-check-fade   var(--check-opacity-dur) var(--check-ease-opacity) forwards,
    t-check-rotate var(--check-rotate-dur)  var(--check-ease-rotate)  forwards,
    t-check-blur   var(--check-blur-dur)    var(--check-ease-out)     forwards,
    t-check-bob    var(--check-bob-dur)     var(--check-ease-bob)     forwards;
}
.t-success-check[data-state="in"] svg path {
  animation: t-check-draw var(--check-path-dur) var(--check-ease-path) var(--check-path-delay, 0ms) forwards;
}

@keyframes t-check-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes t-check-rotate {
  from { transform: rotate(var(--check-rotate-from)); }
  to   { transform: rotate(0deg); }
}
@keyframes t-check-blur {
  from { filter: blur(var(--check-blur-from)); }
  to   { filter: blur(0); }
}
@keyframes t-check-bob {
  from { translate: 0 var(--check-y-amount); }
  to   { translate: 0 0; }
}
@keyframes t-check-draw { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .t-success-check { animation: none !important; opacity: 1; }
  .t-success-check svg path { animation: none !important; stroke-dashoffset: 0 !important; }
}

Spec // Features

Total: 08
  • 01

    The surface presses, the label does not

    Fill, border and shadow live on a pseudo-element, and only that layer scales, so the text never blurs or shifts

  • 02

    A border that belongs to the gradient

    The edge is the exact colour the gradient ends on, worked out from the fill, so it holds in both themes

  • 03

    Loading and success without a resize

    Label, loader and success mark share one grid cell, so the button keeps the width of the widest

  • 04

    A classic bars loader

    Twelve bars turned one step at a time, drawn in the label's colour

  • 05

    Keyboard and menu aware

    Enter presses the surface like a click does, and a button that opens a popup stays still so the popup does not shift

  • 06

    Optical icon padding

    An icon sits a little closer to the edge than text would, so the content reads as centred

  • 07

    Any element

    Pass render to draw it as a link or any other tag

  • 08

    Respects reduced motion

    No press scale, no label blur, and the check appears already drawn

Spec // Props

Total: 10
Tactile Button props
PropTypeDefaultDescription
childrenReactNode-The label
classNamestring-Extra classes on the button
variant"default"defaultThe only look for now
size"sm" | "md" | "lg"lgHeight, padding, type and icon size
roundedbooleanfalseA pill instead of rounded corners
flatbooleanfalseDrops the gradient, lit edge and shadow
loadingbooleanfalseShows the bars loader and ignores clicks
successReactNode-Shows a drawn check and this text; true for the check alone
iconStart, iconEndReactNode-An icon before or after the label
renderelement-Replaces the rendered tag
Every other prop of a button (disabled, onClick, type and so on) is passed through.