components / actions
Avatar Button
A button with a cartoon avatar that peeks over the edge, tilts on hover and squashes on press.
1.8 kB gzip client component
avatar-button-default.tsx
import { AvatarButton } from "@/components/ui/avatar-button";
export default function AvatarButtonDefault() {
return (
<div className="flex flex-wrap items-center justify-center gap-6 pt-4">
<AvatarButton fallback="CD" src="/avatar-cartoon.svg">
Say hi
</AvatarButton>
<AvatarButton blink fallback="CD" size="lg" src="/avatar-cartoon.svg">
Blinking
</AvatarButton>
<AvatarButton fallback="CD" size="sm" src="/avatar-cartoon.svg" variant="outline">
Plain style
</AvatarButton>
</div>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/avatar-button.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { AvatarButton } from "@/components/ui/avatar-button"
<AvatarButton src="/me.svg" fallback="AL" blink>
Say hi
</AvatarButton>API
AvatarButton
Base UI · ButtonA Button with an Avatar inside. The avatar peeks above the edge, tilts on hover and squashes on press. Accepts every Button prop.
| prop | type | default |
|---|---|---|
srcPicture of the character. A transparent SVG or PNG works best. | string | - |
fallbackShown while the picture loads or if it fails (usually initials). | ReactNode | - |
blinkBlinks (a quick squash) every few seconds. Off with reduced motion. | boolean | false |
variantVisual style. | ButtonProps['variant'] | "cartoon" |
sizeHeight and spacing. | "sm" | "md" | "lg" | "icon" | "icon-sm" | "md" |
classNameExtra classes, merged with | string | - |
Keyboard
| key | action |
|---|---|
| EnterSpace | Activates the button. |
Accessibility
- The picture is decorative (
alt=""): the button is named by its text. Without text, add anaria-label. - Tilt, squash and blink only run with
motion-safe. Hover effects only apply to devices that can hover.