Flux Button
Async button with idle, loading, and success states.
Flux Button
Async button with idle, loading, and success states.
Press the inline Submit button — the surface springs down a hair, the label fluidly morphs into a spinning loader with Submitting, then resolves to a Submitted state with a checkmark before easing back to idle. The width animates between each label so the control never jumps or clips.
Installation
Install the component with the Craft-UI Blocks CLI — it drops flux-button.tsx into your project and wires up its runtime dependencies:
npx mvpblocks add flux-buttonpnpm dlx mvpblocks add flux-buttonyarn dlx mvpblocks add flux-buttonbunx mvpblocks add flux-buttonFile Structure
The CLI saves the component to your project's components/ui folder:
Import it from @/components/ui/flux-button.
Usage
"use client";
import { Check } from "lucide-react";
import { FluxButton } from "@/components/ui/flux-button";
export function FluxButtonPreview() {
return (
<div className="mx-auto max-w-2xl text-center">
<p className="flex flex-wrap items-center justify-center gap-x-2 gap-y-2 text-balance font-medium text-lg text-neutral-800 leading-snug tracking-tight sm:text-xl dark:text-neutral-100">
<span>When the form is ready,</span>
<span className="font-medium text-foreground">Default</span>
<span>Tap</span>
<span className="inline-flex translate-y-px align-middle">
<FluxButton
idleLabel="Submit"
loadingLabel="Submitting"
successIcon={
<Check aria-hidden className="size-4" strokeWidth={2.5} />
}
successLabel="Submitted"
onAction={async () => {
await new Promise((resolve) => setTimeout(resolve, 1500));
}}
type="button"
variant="default"
/>
</span>
<span>to finish.</span>
</p>
</div>
);
}Pass an onAction that returns a promise and the button drives the whole flow on its own — idle to loading while it runs, success when it resolves, then back to idle after successHold. Omit successIcon for a text-only success state, or pick a variant and size from the shared button set.
Theming
The button ships its own Iconiq token set, scoped to the component and mapped onto the standard shadcn variable names (--primary, --primary-foreground, --border, --background, --accent, --muted, and so on), so colors resolve with no separate theme install. In light mode the tokens are a white surface with #111111 ink and a #e3e7ec hairline; in dark mode they flip to a #111111 surface with #f6f3ec ink and a #2b2a25 hairline, driven entirely by dark: overrides on the same variables.
Each variant picks its surface from those tokens: default paints the primary color with primary-foreground ink, outline sits on the page background with a hairline border that softens to a translucent --button-input fill in dark mode, secondary uses a soft #eceff3 / #2a2a27 fill, ghost brightens an accent on hover, destructive is a soft color-mix destructive tint (90% light, 80% dark), and link strips the chrome to plain foreground text with a hover underline. The focus ring is ring-3 tinted from --button-ring (rgba(17,17,17,0.16) light, rgba(246,243,236,0.18) dark). Corners upgrade to a true squircle via corner-shape where the browser supports it, falling back to plain radii elsewhere.
Animations
- Fluid width: a
useMotionValuedrives the button width, springing between the measuredidle,loading, andsuccesslabel widths on a210 / 28 / 1.08spring with velocity handoff from the previous frame. Widths are read from a hiddenaria-hiddenclone through aResizeObserver, so the control morphs to fit whichever label is showing and never jumps or clips. Before the first interaction the surface is a square sized to its height. - Tap: the surface springs to
scale: 0.96on pointer-down with a stiff520 / 34 / 0.72spring and nudges down1px. The press state is dropped for thelinkvariant and while locked (disabled or busy). - Label crossfade: the idle, loading, and success labels cross-dissolve via opacity on a
340 / 32 / 0.92spring, with the loading and success labels sharing a single grid cell so they swap in place. - Icon slot: the built-in
Loader2enters by rotating72° → 0, scaling0.82 → 1, and fading in on a400 / 30 / 0.76spring while spinning; the success icon mirrors it from-72° → 0. The icon slot only reserves space when a loader or success icon is present. - Flow:
onActiondrives the phase machine —idle → loading → success → shrinking → idle. AftersuccessHold(default1000ms) the button eases back through a260 / 30 / 0.98shrinkingreveal, with a900msfallback so it always returns to idle.aria-busyis set while loading andaria-live="polite"announces each label change. - First paint: transitions collapse to a zero-duration swap until the button has been interacted with, so the initial mount never animates from an unmeasured state.
Props
FluxButton
Prop
Type
fluxButtonVariants
Prop
Type
Registry Bundle
Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together. Dependencies: @base-ui/react, class-variance-authority, lucide-react, motion.
Embedded Iconiq theme tokens ship inside the component, so colors resolve without a separate theme install. This page documents the Base UI install only, because Flux Button builds on the Base UI button primitive.
Contact
If you find any bug or issue, feel free to raise an issue.
Last updated on