Flip Button
Button whose label leaves at the top while a copy rises from below.
$npx shadcn@latest add https://framebrick.co/r/flip-button.jsonFrom the Findit template, see it in context.
import { FlipButton } from "@/components/ui/flip-button";
export default function FlipButtonDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#">Book a viewing</FlipButton>
<FlipButton variant="outline" pill>
All listings
</FlipButton>
<FlipButton variant="ghost" size="sm">
Contact
</FlipButton>
</div>
);
}Examples
With arrow
An arrow after the label that nudges to the right as the label rolls.
import { FlipButton } from "@/components/ui/flip-button";
/* The arrow nudges 5px to the right as the label rolls. */
export default function FlipButtonArrowDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" arrow>
Book a viewing
</FlipButton>
<FlipButton href="#" arrow variant="outline">
All listings
</FlipButton>
</div>
);
}<FlipButton href="/contact" arrow>Book a viewing</FlipButton>
<FlipButton href="/listings" arrow variant="outline">All listings</FlipButton>Turning arrow
The label rolls while an up-right arrow turns 45° to point right, on a spring with a little bounce.
import { FlipButton } from "@/components/ui/flip-button";
/* The arrow turns 45° from up-right to right, on a slight overshoot, while the label rolls. */
export default function FlipButtonArrowTurnDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" arrow="turn" pill>
Contact us
</FlipButton>
<FlipButton href="#" arrow="turn" pill variant="outline">
Our projects
</FlipButton>
</div>
);
}<FlipButton href="/contact" arrow="turn" pill>Contact us</FlipButton>
<FlipButton href="/projects" arrow="turn" pill variant="outline">Our projects</FlipButton>Sliding arrow
The label rolls while the arrow leaves to the right and a copy of it comes in from the left.
import { FlipButton } from "@/components/ui/flip-button";
/* The label rolls while the arrow leaves to the right and a copy of it comes in from the left. */
export default function FlipButtonArrowSlideDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" arrow="slide">
Book a session
</FlipButton>
<FlipButton href="#" arrow="slide" variant="outline">
Explore programs
</FlipButton>
</div>
);
}<FlipButton href="/contact" arrow="slide">Book a session</FlipButton>
<FlipButton href="/service" arrow="slide" variant="outline">Explore programs</FlipButton>Side flip
The label leaves to the right while its copy comes in from the left.
import { FlipButton } from "@/components/ui/flip-button";
/* The label leaves to the right while its copy comes in from the left. */
export default function FlipButtonSideDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" direction="right">
Book an appointment
</FlipButton>
<FlipButton href="#" direction="right" variant="outline" blur={2}>
Our services
</FlipButton>
</div>
);
}<FlipButton href="/book" direction="right">Book an appointment</FlipButton>Icon box
A square with an icon at the end: its cover rolls with the label.
import { FlipButton } from "@/components/ui/flip-button";
const icon = (
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round">
<path d="M4.5 11.5l7-7M5.5 4.5h6v6" />
</svg>
);
/* The square at the end holds two covers: the one you see leaves to the right and the other comes in from the left, with the label. */
export default function FlipButtonIconBoxDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" iconBox={icon}>
Book now
</FlipButton>
<FlipButton href="#" variant="secondary" iconBox={icon}>
Learn more
</FlipButton>
<FlipButton href="#" variant="outline" iconBox={icon} aria-label="Open the booking page" />
</div>
);
}<FlipButton href="/book" iconBox={<ArrowUpRight />}>Book now</FlipButton>
// an icon-only button needs a name
<FlipButton href="/book" variant="outline" iconBox={<ArrowUpRight />} aria-label="Open the booking page" />Letters
Pointing at a link writes its label again, letter by letter.
import { FlipButton } from "@/components/ui/flip-button";
/* Point at a link: its label is written again letter by letter, each rising from 10 px below; leave, and it comes back from above. */
export default function FlipButtonLettersDemo() {
return (
<nav aria-label="Menu" className="flex items-center gap-1">
{["Services", "About", "Contact"].map((name) => (
<FlipButton key={name} href="#" variant="ghost" size="sm" by="letter">
{name}
</FlipButton>
))}
</nav>
);
}<FlipButton href="/services" variant="ghost" size="sm" by="letter">Services</FlipButton>Face flip
The whole face rolls: the fill, the line and the label leave together and another face takes their place.
import { FlipButton } from "@/components/ui/flip-button";
/* The whole face rolls: the fill, the line and the label leave together and another face takes their place. */
export default function FlipButtonFaceDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" face="secondary">
Book a viewing
</FlipButton>
<FlipButton href="#" variant="outline" face="default">
See all homes
</FlipButton>
</div>
);
}<FlipButton href="/viewings" face="secondary">Book a viewing</FlipButton>
<FlipButton href="/homes" variant="outline" face="default">See all homes</FlipButton>Blur
The label that leaves blurs while the one that arrives sharpens.
import { FlipButton } from "@/components/ui/flip-button";
/* The label rolls while the one that leaves blurs and the one that arrives sharpens. */
export default function FlipButtonBlurDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" blur={2}>
Book a call
</FlipButton>
<FlipButton href="#" blur={2} variant="outline">
Our approach
</FlipButton>
</div>
);
}<FlipButton href="/contact" blur={2}>Book a call</FlipButton>
// a stronger blur: blur={5}Ring
The label rolls while an 8 px ring shrinks to 4 px and fills.
import { FlipButton } from "@/components/ui/flip-button";
/* The label rolls while an 8px ring shrinks to 4px and fills. */
export default function FlipButtonDotRingDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" dot="ring">
Let's talk
</FlipButton>
<FlipButton href="#" dot="ring" variant="outline">
Our services
</FlipButton>
</div>
);
}<FlipButton href="/contact" dot="ring">Let's talk</FlipButton>
// the same dot, grown instead: a 6 px dot at 60% that grows to 8 px and turns solid
<FlipButton href="/contact" dot="grow">Let's talk</FlipButton>Growing dot
The label rolls while a 6 px dot grows to 8 px and turns solid.
import { FlipButton } from "@/components/ui/flip-button";
/* The label rolls while a 6px dot grows to 8px and turns solid. */
export default function FlipButtonDotGrowDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-4">
<FlipButton href="#" dot="grow">
Let's talk
</FlipButton>
<FlipButton href="#" dot="grow" variant="outline">
Our services
</FlipButton>
</div>
);
}<FlipButton href="/services" dot="grow" variant="outline">Our services</FlipButton>Installation
$ npx shadcn@latest add https://framebrick.co/r/flip-button.json1. Install the dependencies.
npm install motion clsx tailwind-merge2. Add
cn()tolib/utils.ts(skip if shadcn already created it).import { clsx, type ClassValue } from "clsx"; import { extendTailwindMerge } from "tailwind-merge"; /* tailwind-merge must know the site's type scale (globals.css) is a font size, not a text color — otherwise cn("text-h6 text-muted-foreground") drops text-h6. */ const twMerge = extendTailwindMerge({ extend: { classGroups: { "font-size": [{ text: ["display", "h1", "h2", "h3", "h4", "h5", "h6"] }] } }, }); export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); }3. Copy the component into
components/ui/flip-button.tsx."use client"; import * as React from "react"; import Link from "next/link"; import { motion, type HTMLMotionProps, type Transition } from "motion/react"; import { cn } from "@/lib/utils"; /* * Flip Button — the label leaves at the top while a second copy rises from below (from the Findit "Button/Primary"). * Framer's soft spring drives it: spring, bounce 0, duration 0.4s. The copy is aria-hidden, so the label is read once. * Pass `href` to render a Next.js link; external http(s) links open in a new tab. * * `arrow` is from the Semono "Button/Primary": an arrow after the label that nudges 5px to the right while the label * rolls, on the same spring. It sits in a box 5px wider than itself, so the nudge stays inside the button, and the * padding on that side is 5px smaller, so the gap at rest is the same on both sides. * * `arrow="turn"` is the Compose Digi "Button/Primary" (and Lookis', and Catchup's): the arrow points up-right and turns 45° * to point right while the label rolls, on a second spring, bounce 0.2, duration 0.4s — Spring Button's arrow in this * button. It has no nudge, so it needs no spare room: the padding is the size's own. * * `arrow="slide"` is the Metuo "Button/Primary": the arrow leaves to the right while a copy of it comes in from the left, as the * label rolls, both on the bounce-0 spring (Metuo: 19px for a 14px arrow and a 5px gap; here 21px for a 16px one). It is * Arrow Flip Link's `direction="right"` inside a button. The pair stays inside a window one arrow wide, so, like the turn, it * needs no spare room. * * `dot` is a small dot after the label instead of an arrow, decoration only (aria-hidden), in a fixed 8px box so the label * never moves, on the label's bounce-0 spring. "ring" is the Cerette "Button/Primary": an 8px ring with a 1px line shrinks to 4px * and fills (measured: 6.4px at 77ms, 5 at 132, 4.2 at 215; the fill 0.59 at 97ms, 0.9 at 180, 1 at ~300). "grow" is Kalme's: a * 6px dot at 60% grows to 8px and turns solid. Both animate width and height, as Framer does, so the ring's line stays 1px * (a scale would thin it); MotionConfig skips size keys under reduced motion, so the dot jumps to its hovered size and the fill * still fades. It is drawn in the label's colour, so it passes wherever the label does; a brand colour is the caller's `hover:` classes. * * `blur` is from the Balancee "Button/Primary" (and Kalme's, at 5px): while the label rolls, the one that leaves blurs from 0 to * n px and the copy that arrives sharpens from n px to 0, on the same spring as the roll (Balancee: 200ms linear; the spring * stands in, as it does for arrow="turn"). Default 0 draws nothing extra: the markup is as it was. Filter is not a transform * or a size key, so <MotionConfig> would not skip it; the blur is switched off for reduced motion in CSS * (motion-reduce:filter-none!, which beats the inline style), so the markup never depends on the preference. The roll itself * is skipped by MotionConfig. * * `face` is from the Goeboek "Button/Secondary" (and the filter chips): the whole face rolls, not only the label. A block two faces * tall holds the resting face (`variant`: its fill, its line, its label) over the face that takes its place (`face`); on hover and * focus the block rises one face, so the fill, the line and the label all go at once, and back when the pointer leaves * (Framer measured 26px at 100ms, 43.8 at 250, 48.1 at 450 and 48.8 at 800 for a 48.8px face, on spring 500 / 60; here the * component's own bounce-0, 0.4s spring does it, one spring for the whole button, with the same end). The distance is one * face, so every size works. Each face carries its own fill, with no hover fade, and the second is aria-hidden, so the label is * read once. `arrow`, `dot` and `blur` are left out with it: they would roll with the face and say the same thing twice, so they * are ignored. Rise is a transform, which MotionConfig skips for reduced motion (the second face is shown at once). Without * `face` the button is as it was. * * Three more are from KorDent (every button of it is one of these, in eight variants). `direction="right"`: the label does not * rise, it leaves to the right while its copy comes in from the left, on the same spring (KorDent: a strip of two copies 10px * apart slides from right: 0 to left: 0; here each copy moves its own width, the window clips them, so the gap is not needed). It * works on keyboard focus too, which KorDent's port does not. `iconBox` is an icon in a 28px square at the end of the button: the * square holds a strip of two covers twice its width, and on hover the strip moves half of itself, so the cover you see leaves to * the right and the other comes in from the left, with the label, while the icon stays put and takes the other cover's colour. Each * variant picks two covers and two icon colours from the theme's own pairs. With no label the square is the whole button (then give * it an aria-label). `by="letter"` (KorDent's menu links): on hover the label is written again letter by letter, each rising from * 10px below and fading in 0.075s after the one before (spring bounce 0.2, 0.2s), and when the pointer leaves it comes back the same * way from 10px above; nothing moves before the first hover. One aria-hidden span per character, the label read once from an * invisible copy, and a mouse or the keyboard focus starts it, not a touch. Reduced motion: the letters fade without rising * (motion-reduce:transform-none!, which beats the inline transform, so the markup never depends on the preference). The label must * be plain text for it. `direction="right"` and `blur` do not combine with `by="letter"`, and `iconBox` ignores `arrow` and * `dot`, both at the end of the button: the ignored ones are not drawn. */ const soft: Transition = { type: "spring", bounce: 0, duration: 0.4 }; /* The turning arrow's spring: a slight overshoot (45.6° for 45°) that the label's bounce-0 roll does not have. */ const turn: Transition = { type: "spring", bounce: 0.2, duration: 0.4 }; /* The default variant hovers to 95% of the fill, not shadcn's 90%: fading toward the page lightens a dark fill under its light label, and at 90% that is 4.3:1 in a themed project (the Blocks "soft" sample theme, light). At 95% the label keeps 4.7:1 or better in all four sample themes, light and dark (docs/playbook/ui.md → hover fills). */ const variantClasses = { default: "bg-primary text-primary-foreground hover:bg-primary/95", secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80", outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50", ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50", } as const; const sizeClasses = { sm: "h-8 px-3", default: "h-9 px-4", lg: "h-10 px-6", } as const; /* The faces of `face`: the fill and the line only, with no hover fade, since the face that rises is the hover. */ const faceClasses = { default: "bg-primary text-primary-foreground", secondary: "bg-secondary text-secondary-foreground", outline: "border bg-background shadow-xs dark:border-input dark:bg-input/30", ghost: "bg-transparent", } as const; /* iconBox: two covers, which one shows at rest and which comes in, and the icon's colour for each (theme pairs, 3:1 or better for the icon on its cover). */ const iconBoxClasses = { default: { rest: "bg-primary-foreground", icon: "text-primary group-hover/flip:text-background group-focus-visible/flip:text-background", hover: "bg-foreground" }, secondary: { rest: "bg-foreground", icon: "text-background group-hover/flip:text-foreground group-focus-visible/flip:text-foreground", hover: "bg-background" }, outline: { rest: "bg-foreground", icon: "text-background group-hover/flip:text-foreground group-focus-visible/flip:text-foreground", hover: "bg-background" }, ghost: { rest: "bg-foreground", icon: "text-background group-hover/flip:text-primary-foreground group-focus-visible/flip:text-primary-foreground", hover: "bg-primary" }, } as const; /* Size of the square and the button's right padding, so the square sits 4px from the edge (KorDent: 28px in 38, 5px). */ const iconBoxSize = { sm: "size-6", default: "size-7", lg: "size-8" } as const; /* The right padding when there is an arrow: the size's own padding less the 5px the arrow's box keeps for its nudge. */ const arrowPadding = { sm: "pr-[7px]", default: "pr-[11px]", lg: "pr-[19px]", } as const; type Common = { variant?: keyof typeof variantClasses; size?: keyof typeof sizeClasses; /** An arrow after the label: `true` or "nudge" nudges it 5px to the right as the label rolls; "turn" turns it 45° from up-right to right; "slide" sends it out to the right while a copy comes in from the left. */ arrow?: boolean | "nudge" | "turn" | "slide"; /** Pill instead of the shadcn rounded-md corner, as in the template. */ pill?: boolean; /** The whole face rolls: the face of this variant rises to replace the resting one (`variant`). arrow, dot and blur are ignored. */ face?: keyof typeof variantClasses; /** The label leaves to the right while its copy comes in from the left (KorDent), instead of rising. */ direction?: "up" | "right"; /** An icon in a square at the end of the button, whose cover rolls with the label (KorDent). arrow and dot are ignored with it. */ iconBox?: React.ReactNode; /** "letter" writes the label again letter by letter on hover (KorDent's menu links); the label must be plain text. */ by?: "label" | "letter"; /** A small dot after the label, instead of an arrow: "ring" shrinks from 8px to 4px and fills; "grow" grows from 6px to 8px and turns solid. Ignored with an arrow. */ dot?: "ring" | "grow"; /** Blur in px while the label rolls: the leaving copy goes 0 to n, the arriving one n to 0. 0 (default) is none. */ blur?: number; className?: string; children?: React.ReactNode; }; export type FlipButtonProps = | (Common & { href: string } & Omit<HTMLMotionProps<"a">, keyof Common | "href">) | (Common & { href?: undefined } & Omit<HTMLMotionProps<"button">, keyof Common>); const MotionLink = motion.create(Link); export function FlipButton({ variant = "default", size = "default", arrow: arrowProp = false, pill = false, dot: dotProp, blur = 0, face, direction = "up", iconBox, by = "label", className, children, ...props }: FlipButtonProps) { /* An icon box takes the end of the button: no arrow or dot beside it. */ const arrow = iconBox ? false : arrowProp; const dot = iconBox ? undefined : dotProp; const letters = by === "letter" && typeof children === "string"; const iconOnly = Boolean(iconBox) && !children; const dotted = !arrow && dot; const nudge = arrow === true || arrow === "nudge"; const motionProps = { /* by="letter": nothing moves before the first hover, so the letters start in their end state and play only when the hover starts or ends. */ initial: letters ? false : "rest", animate: "rest", whileHover: "hover", whileFocus: "hover", className: cn( "inline-flex shrink-0 cursor-pointer items-center justify-center text-sm font-medium whitespace-nowrap transition-colors select-none", pill ? "rounded-full" : "rounded-md", "outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50", "disabled:pointer-events-none disabled:opacity-50", iconBox && !face && "group/flip", face ? ["overflow-hidden", sizeClasses[size].split(" ")[0]] : [variantClasses[variant], sizeClasses[size], nudge && arrowPadding[size], iconBox && (iconOnly ? "px-1" : "pr-1")], className, ), } as const; /* One of the two copies of direction="right": it moves its own width, so the window clips it; with blur it also sharpens or blurs. */ const side = (first: boolean) => ({ rest: { x: first ? "0%" : "-100%", ...(blur > 0 ? { filter: `blur(${first ? 0 : blur}px)` } : {}) }, hover: { x: first ? "100%" : "0%", ...(blur > 0 ? { filter: `blur(${first ? blur : 0}px)` } : {}) }, }); const sideLabel = ( <span className="relative block h-5 overflow-hidden"> <span className="block leading-5 opacity-0">{children}</span> {[true, false].map((first) => ( <motion.span key={String(first)} aria-hidden className="absolute inset-0 block leading-5 motion-reduce:filter-none!" variants={side(first)} transition={soft}> {children} </motion.span> ))} </span> ); /* by="letter": an invisible copy sizes the label and carries the text; the letters above it are aria-hidden. The keyframes start each letter off its place (below on hover, above on leaving) and bring it home, each 0.075s after the one before. */ const letterLabel = ( <span className="relative block h-5"> <span className="block leading-5 opacity-0">{children}</span> <span aria-hidden className="absolute inset-0 flex leading-5 whitespace-pre"> {Array.from(typeof children === "string" ? children : "").map((character, index) => ( <motion.span key={index} className="inline-block motion-reduce:transform-none!" variants={{ rest: { y: [-10, 0], opacity: [0, 1] }, hover: { y: [10, 0], opacity: [0, 1] } }} transition={{ type: "spring", bounce: 0.2, duration: 0.2, delay: index * 0.075 }} > {character} </motion.span> ))} </span> </span> ); /* The label box is one line tall (20px); the column holds both copies 8px apart, so one flip travels 28px. */ const riseLabel = ( <span className="relative block h-5 overflow-hidden"> <motion.span className="flex flex-col gap-2" variants={{ rest: { y: 0 }, hover: { y: -28 } }} transition={soft} > {blur > 0 ? ( <> <motion.span className="block leading-5 motion-reduce:filter-none!" variants={{ rest: { filter: "blur(0px)" }, hover: { filter: `blur(${blur}px)` } }} transition={soft} > {children} </motion.span> <motion.span aria-hidden className="block leading-5 motion-reduce:filter-none!" variants={{ rest: { filter: `blur(${blur}px)` }, hover: { filter: "blur(0px)" } }} transition={soft} > {children} </motion.span> </> ) : ( <> <span className="block leading-5">{children}</span> <span aria-hidden className="block leading-5"> {children} </span> </> )} </motion.span> </span> ); const label = letters ? letterLabel : direction === "right" ? sideLabel : riseLabel; const iconBoxClass = iconBoxClasses[variant]; const content = ( <> {!iconOnly && label} {arrow === "turn" && ( <span aria-hidden className="ml-2 flex size-4 shrink-0"> <motion.svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" className="size-4" variants={{ rest: { rotate: 0 }, hover: { rotate: 45 } }} transition={turn} > <path d="M4.5 11.5l7-7M5.5 4.5h6v6" /> </motion.svg> </span> )} {arrow === "slide" && ( /* A window one arrow wide holding two arrows 5px apart: at rest the right one shows; on hover the pair moves 21px to the right. */ <span aria-hidden className="ml-2 flex size-4 shrink-0 overflow-hidden"> <motion.span className="flex shrink-0 gap-[5px]" variants={{ rest: { x: -21 }, hover: { x: 0 } }} transition={soft}> {[0, 1].map((copy) => ( <svg key={copy} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" strokeLinejoin="round" className="size-4 shrink-0"> <path d="M3 8h10M9 4l4 4-4 4" /> </svg> ))} </motion.span> </span> )} {dotted === "ring" && ( <span aria-hidden className="ml-2 flex size-2 shrink-0 items-center justify-center"> <motion.span className="relative block rounded-full border border-current" variants={{ rest: { width: 8, height: 8 }, hover: { width: 4, height: 4 } }} transition={soft} > <motion.span className="absolute -inset-px rounded-full bg-current" variants={{ rest: { opacity: 0 }, hover: { opacity: 1 } }} transition={soft} /> </motion.span> </span> )} {dotted === "grow" && ( <span aria-hidden className="ml-2 flex size-2 shrink-0 items-center justify-center"> <motion.span className="block rounded-full bg-current" variants={{ rest: { width: 6, height: 6, opacity: 0.6 }, hover: { width: 8, height: 8, opacity: 1 } }} transition={soft} /> </span> )} {iconBox && ( <span aria-hidden className={cn("relative grid shrink-0 overflow-hidden rounded-md", iconBoxSize[size], !iconOnly && "ml-3")}> {/* Two covers in a strip twice the square wide: at rest the right one shows; on hover the strip moves half of itself, so it leaves to the right and the other comes in from the left. */} <motion.span className="absolute inset-y-0 left-0 flex w-[200%]" variants={{ rest: { x: "-50%" }, hover: { x: "0%" } }} transition={soft}> <span className={cn("w-1/2", iconBoxClass.hover)} /> <span className={cn("w-1/2", iconBoxClass.rest)} /> </motion.span> <span className={cn("relative grid size-full place-items-center transition-colors duration-400 [&>svg]:size-4", iconBoxClass.icon)}>{iconBox}</span> </span> )} {nudge && ( <span aria-hidden className="ml-2 flex h-4 w-[21px] shrink-0"> <motion.span className="flex" variants={{ rest: { x: 0 }, hover: { x: 5 } }} transition={soft}> <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" strokeLinejoin="round" className="size-4"> <path d="M3 8h10M9 4l4 4-4 4" /> </svg> </motion.span> </span> )} </> ); /* The whole face rolls: two faces in a block twice as tall as the button, the block rising by half of itself. */ const faceStyle = (kind: keyof typeof variantClasses) => cn("flex w-full shrink-0 items-center justify-center", sizeClasses[size], faceClasses[kind]); const body = face ? ( <motion.span className="flex w-full flex-col self-start" variants={{ rest: { y: "0%" }, hover: { y: "-50%" } }} transition={soft}> <span className={faceStyle(variant)}>{children}</span> <span aria-hidden className={faceStyle(face)}> {children} </span> </motion.span> ) : ( content ); if (props.href !== undefined) { const { href, ...rest } = props; const external = /^https?:\/\//.test(href); return ( <MotionLink href={href} {...(external ? { target: "_blank", rel: "noopener noreferrer" } : {})} {...rest} {...motionProps} > {body} </MotionLink> ); } const { type = "button", ...rest } = props as HTMLMotionProps<"button">; return ( <motion.button type={type} {...rest} {...motionProps}> {body} </motion.button> ); }
Usage
import { FlipButton } from "@/components/ui/flip-button";
<FlipButton href="/contact">Book a viewing</FlipButton>
<FlipButton variant="outline" pill onClick={save}>Save</FlipButton>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "secondary" | "outline" | "ghost" | "default" | shadcn button styles. |
| size | "sm" | "default" | "lg" | "default" | Height 32 / 36 / 40 px, like the shadcn button. |
| arrow | boolean | "nudge" | "turn" | "slide" | false | An arrow after the label. true or "nudge" nudges it 5 px to the right as the label rolls (Semono); "turn" points it up-right and turns it 45° to point right, on a spring with a little bounce (Compose Digi, Lookis, Catchup); "slide" sends it out to the right while a copy of it comes in from the left (Metuo). |
| dot | "ring" | "grow" | — | A small dot after the label, instead of an arrow (ignored with one). "ring" is an 8 px ring that shrinks to 4 px and fills (Cerette); "grow" is a 6 px dot at 60% that grows to 8 px and turns solid (Kalme). Decoration only: aria-hidden, drawn in the label colour. |
| direction | "up" | "right" | "up" | Which way the label goes: up (the roll), or right: it leaves to the right while its copy comes in from the left (KorDent). face ignores it; it combines with arrow, dot and blur. |
| iconBox | ReactNode | — | An icon in a 28 px square at the end of the button (KorDent). The square holds two covers: the one you see leaves to the right and the other comes in from the left as the label rolls, while the icon stays and takes the other cover's colour. Without children the square is the whole button, so give it an aria-label. arrow and dot are ignored with it. |
| by | "label" | "letter" | "label" | With letter, hover writes the label again letter by letter, each rising from 10 px below and fading in 0.075 s after the one before; leaving brings it back from 10 px above (the menu links of KorDent). The label must be plain text. direction and blur are ignored with it. |
| face | "default" | "secondary" | "outline" | "ghost" | — | The whole face rolls, not only the label: the face of this variant rises to replace the resting one (variant), taking its fill, its line and its label with it (Goeboek). arrow, dot and blur are ignored with it. |
| blur | number | 0 | Blur in px while the label rolls: the label that leaves goes from 0 to this, the copy that arrives from this to 0. Balancee uses 2, Kalme 5. 0 leaves the button exactly as it was. |
| pill | boolean | false | Fully round corners, as in the template. |
| href | string | — | Render a Next.js link instead of a button. http(s) links open in a new tab. |
| …props | button / anchor props | — | Passed to the element (onClick, disabled, aria-*, Motion props). |
- direction, iconBox and by are KorDent's: every one of its buttons is one of these, in eight variants. direction="right": a strip of two copies 10 px apart slides from the right edge to the left in Framer, on spring 500 / 60; here each copy moves its own width on the component's own spring and the window clips them, so the gap is not needed. It works on keyboard focus too, which KorDent's own port does not. iconBox: the square holds a strip of two covers twice its width that moves half of itself, with the label, while the icon stays on top; each variant has its own two covers and two icon colours from the theme's pairs (3:1 or better for the icon on its cover, measured in the four sample themes). The icon is decoration (aria-hidden): a button with only the icon needs an aria-label. by="letter": one aria-hidden span per character over an invisible copy that carries the text, so the label is read once; nothing moves before the first hover; a mouse or the keyboard focus starts it, not a touch. Reduced motion: the letters fade without rising (motion-reduce:transform-none!, which beats the inline transform, so the markup never depends on the preference). direction and blur do not combine with letter, and iconBox ignores arrow and dot, both at the end of the button: the ignored ones are not drawn.
- face is Goeboek's Button/Secondary and filter chips: a block two faces tall holds the resting face over the one that takes its place, and on hover and focus it rises one face (measured 26 px at 100 ms, 43.8 at 250, 48.1 at 450 and 48.8 at 800 for a 48.8 px face, on spring 500 / 60). The component's own bounce-0, 0.4 s spring does it, one spring for the whole button. The distance is one face, so every size works. Each face carries its own fill with no hover fade, and the second is aria-hidden, so the label is read once; both faces keep 4.5:1 over their own fill. arrow, dot and blur are ignored with face: they would roll with it and say the same thing twice. The rise is a transform, so MotionConfig shows the second face at once for reduced motion. The focus ring is on the button, which clips its faces.
- blur is the second template with it (Balancee 2 px, Kalme 5 px), so an option. It runs on the same bounce-0 spring as the roll; in Framer both are a 200 ms linear tween, and the spring stands in, as it does for arrow="turn". With blur 0 nothing extra is drawn. Filter is not a transform or a size key, so <MotionConfig> does not skip it: the blur is switched off for reduced motion in CSS (motion-reduce:filter-none!, which beats the inline style), so the markup never depends on the preference, and the roll itself is skipped by MotionConfig.
- dot is Cerette's ring and Kalme's growing dot, the second template with one, so an option and not a component. The box is a fixed 8 px, so the label never moves. It animates width and height as Framer does, so the ring's line stays 1 px while it shrinks (a scale would thin it to 0.5 px); <MotionConfig> skips size keys under reduced motion, so the dot jumps to its hovered size and the fill still fades. It is drawn in the label's colour, so it passes wherever the label does; a brand colour is yours to add with hover: classes.
- The second copy of the label is aria-hidden, so a screen reader reads the label once.
- The flip also runs on keyboard focus.
- The nudging arrow sits in a box 5 px wider than itself, so the nudge stays inside the button, and the padding on that side is 5 px smaller, so the gap at rest is the same on both sides.
- The turning arrow is Spring Button's, in this button: the label rolls on the bounce-0 spring and the arrow turns on bounce 0.2 (Compose Digi measured 45.6° for 45°, settling in about 0.44 s). It needs no spare room, so the padding is the size's own, and nothing changes colour. It is the third template with this pair (Lookis and Catchup have it too), which is why it is an option and not left to Spring Button plus Flip Button.
- The sliding arrow is Metuo's: two arrows 5 px apart in a window one arrow wide, so one is always in sight; on hover the pair moves 21 px to the right (Metuo: 19 px for a 14 px arrow), the one in the window leaving at the right as the other comes in from the left, on the same bounce-0 spring as the roll. It is Arrow Flip Link's direction="right" inside a button, and like the turn it needs no spare room. The second arrow is aria-hidden with the rest.
- The default variant hovers to 95% of its fill, not shadcn's 90%: at 90% the label measures 4.3:1 in a themed project (the Blocks "soft" sample theme, light); at 95% it keeps 4.7:1 or better in all four sample themes, light and dark.
AI prompt
Paste into v0, Lovable, Bolt or Claude to rebuild this component in your own project.
Create a React + Tailwind CSS + Motion (motion/react) component called FlipButton.
- Look like the shadcn/ui Button: rounded-md (or rounded-full with a "pill" prop), text-sm font-medium, variants
default / secondary / outline / ghost (the default variant hovers to bg-primary/95, not shadcn's /90, so its label keeps
4.5:1 in a coloured theme), sizes sm (h-8 px-3), default (h-9 px-4), lg (h-10 px-6),
focus ring ring-[3px] ring-ring/50.
- The label sits in a box one line tall (h-5) with overflow-hidden, holding a column of two identical labels 8px apart.
- On hover and on keyboard focus the column moves up 28px with a spring (bounce 0, duration 0.4s): the first label
leaves at the top while the copy arrives from below. The copy is aria-hidden.
- If an href prop is given render a Next.js Link (motion.create(Link)); external http(s) links get target _blank and
rel noopener noreferrer.
- An arrow prop adds, after the label, a 16px right arrow in a box 21px wide (so there is 5px of room): on hover and focus it
moves 5px to the right with the same spring while the label rolls. With an arrow the right padding is the size's own
padding less 5px (pr-[11px] for the default size), so the gap at rest is the same on both sides.
- arrow="turn" instead draws a 16px up-right arrow (path "M4.5 11.5l7-7M5.5 4.5h6v6", stroke 1.5, round caps) 8px after the
label, which rotates 0 → 45° on hover and focus with its own spring (bounce 0.2, duration 0.4s) while the label rolls on the
bounce-0 one. No spare room: the padding is the size's own.
- arrow="slide" draws, 8px after the label, a window one arrow wide (size-4, overflow-hidden) holding a row of two right arrows
(path "M3 8h10M9 4l4 4-4 4", stroke 1.75) 5px apart; the row sits at x -21 at rest, so the right arrow shows, and moves to 0 on hover and
focus on the same bounce-0 spring as the label, so that one leaves at the right while the other comes in from the left.
- direction ("up" | "right", default "up"): with right the label box holds an invisible copy (it sizes the box and carries the text) and two aria-hidden absolute copies; the first moves x 0% to 100%, the second -100% to 0%, on the same spring, the box overflow-hidden; blur, if set, goes on the copies as it does for the roll.
- iconBox (ReactNode): at the end of the button, ml-3 and size-6 / size-7 / size-8 by size, a grid overflow-hidden rounded-md holding a strip (absolute, flex, w-[200%]) of two covers (w-1/2 each) that goes from x -50% to 0% with the spring, over which the icon (size-4, aria-hidden) changes colour on hover and focus (group/flip on the button). Covers per variant: default primary-foreground, then foreground; secondary and outline foreground, then background; ghost foreground, then primary; the icon is the matching text colour. The button's right padding is pr-1; with no children the box is the whole button (px-1). arrow and dot are not drawn.
- by ("label" | "letter"): with letter and a plain-text label, an invisible copy carries the text and an aria-hidden row of one inline-block motion.span per character sits over it; the button starts with initial false so nothing plays before the first hover; each letter has keyframes rest y [-10, 0] opacity [0, 1] and hover y [10, 0] opacity [0, 1], on a spring (bounce 0.2, duration 0.2s) delayed index * 0.075s, with motion-reduce:transform-none!.
- face ("default" | "secondary" | "outline" | "ghost"): the button becomes overflow-hidden with only its height class and holds a motion.span column (flex-col, w-full) of two faces, each a flex span with the size's height and padding and that variant's fill and line without hover classes (default: bg-primary text-primary-foreground; secondary: bg-secondary text-secondary-foreground; outline: border bg-background shadow-xs dark:border-input dark:bg-input/30; ghost: transparent): the first is variant, the second face, aria-hidden. The column goes from y 0% to -50% with the same spring on hover and focus. arrow, dot and blur are not drawn.
- blur (px, default 0): when above 0 the two copies of the label are motion.spans that animate filter with the roll's spring: the first from blur(0px) to blur(npx), the second from blur(npx) to blur(0px), both with motion-reduce:filter-none!. With 0 they are plain spans.
- dot="ring" or "grow" draws instead, 8px after the label, a size-2 aria-hidden box that never changes size, with a rounded-full dot in currentColor inside it, on the bounce-0 spring: ring is a 1px border whose width and height go 8 to 4px while a bg-current layer fades 0 to 1; grow is a bg-current dot going 6 to 8px and from opacity 0.6 to 1. Animate width and height, not scale.










