Dot Morph Button
Dot Morph Button is a React and Tailwind CSS text component from SmoothUI, licensed MIT. Copy it and paste it into your project.
SmoothUI
MIT
text
What it is
Dot Morph Button is a React and Tailwind CSS text component from SmoothUI, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
Needs
npm i motion
Licence
This component comes from SmoothUI and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Dot Morph Button
"use client";
import SmoothButton from "@/components/smoothui/smooth-button";
import { motion, useReducedMotion } from "motion/react";
import { useEffect, useState } from "react";
export interface DotMorphButtonProps {
className?: string;
label: string;
onClick?: () => void;
}
export function DotMorphButton({
label,
className = "",
onClick,
}: DotMorphButtonProps) {
const [isHovered, setIsHovered] = useState(false);
const shouldReduceMotion = useReducedMotion();
const [isHoverDevice, setIsHoverDevice] = useState(false);
useEffect(() => {
const mediaQuery = window.matchMedia("(hover: hover) and (pointer: fine)");
setIsHoverDevice(mediaQuery.matches);
const handleChange = (e: MediaQueryListEvent) => {
setIsHoverDevice(e.matches);
};
mediaQuery.addEventListener("change", handleChange);
return () => mediaQuery.removeEventListener("change", handleChange);
}, []);
return (
<SmoothButton
className={`flex items-center gap-3 rounded-full border bg-background ${className}`}
onClick={onClick}
onMouseEnter={() => {
if (isHoverDevice) {
setIsHovered(true);
}
}}
onMouseLeave={() => setIsHovered(false)}
type="button"
>
<motion.span
animate={
shouldReduceMotion || !isHoverDevice || !isHovered
? {
borderRadius: 999,
height: 16,
width: 16,
}
: {
borderRadius: 999,
height: 28,
width: 12,
}
}
className="flex items-center justify-center"
initial={false}
style={{
background: "var(--color-brand)",
display: "inline-block",
}}
transition={
shouldReduceMotion
? { duration: 0 }
: {
damping: 22,
duration: 0.25,
stiffness: 600,
type: "spring" as const,
}
}
/>
<span className="select-none font-medium text-2xl text-foreground">
{label}
</span>
</SmoothButton>
);
}
export default DotMorphButton;