Raised Button
gaia/raised-buttonFreeComponent
A beautiful 3D raised button with customizable colors and dynamic text contrast.
Install it
npx shadcn@latest add https://ui.heygaia.io/r/raised-button.jsonSource
1"use client";23import { cva, type VariantProps } from "class-variance-authority";4import * as React from "react";56import { cn } from "@/lib/utils";7import {8 getContrastColor,9 getLuminance,10 parseColor,11} from "@/lib/utils/colorUtils";1213const buttonVariants = cva(14 "inline-flex items-center justify-center dark:bg-zinc-500 dark:text-white whitespace-nowrap text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 relative bg-primary text-primary-foreground hover:bg-primary/90 border border-primary/50 shadow-md before:absolute before:inset-0 before:border-t before:border-white/40 before:bg-gradient-to-b before:from-white/20 before:to-transparent cursor-pointer transition-transform duration-200 active:scale-[0.96] subpixel-antialiased gap-2",15 {16 variants: {17 variant: {18 default: "",19 },20 size: {21 default: "h-10 px-4 py-2 rounded-xl before:rounded-xl",22 sm: "h-9 rounded-lg px-3 before:rounded-xl",23 lg: "h-11 rounded-lg px-8 before:rounded-lg",24 icon: "h-10 w-10",25 },26 },27 defaultVariants: {28 variant: "default",29 size: "default",30 },31 },32);3334export interface ButtonProps35 extends React.ButtonHTMLAttributes<HTMLButtonElement>,36 VariantProps<typeof buttonVariants> {37 color?: string;38}3940const RaisedButton = React.forwardRef<HTMLButtonElement, ButtonProps>(41 ({ className, variant, size, color, style = {}, ...props }, ref) => {42 const Comp = "button";4344 const dynamicStyles = React.useMemo(() => {45 if (!color) return {};4647 try {48 const rgb = parseColor(color);49 if (!rgb) return {};5051 const luminance = getLuminance(rgb);52 const textColor = getContrastColor(luminance);53 const borderOpacity = 0.5;54 const hoverOpacity = 0.9;55 const whiteBorderOpacity = 0.6;56 const whiteGradientOpacity = 0.3;57 const shadowOpacity = 0.2;58 const shadowSpread = "0px";59 const shadowBlur = "5px";6061 return {62 backgroundColor: color,63 color: textColor,64 borderColor: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${borderOpacity})`,65 "--hover-bg": `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${hoverOpacity})`,66 "--border": `rgba(255, 255, 255, ${whiteBorderOpacity})`,67 "--gradient": `rgba(255, 255, 255, ${whiteGradientOpacity})`,68 "--shadow-color": `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${shadowOpacity})`,69 boxShadow: `0 4px ${shadowBlur} ${shadowSpread} var(--shadow-color)`,70// … truncated
What it pulls in
npm packages
Files it writes
More from gaia
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Area Chartarea-chart | gaia | Components | Free | 1 dep | |
| Author Tooltipauthor-tooltip | gaia | Components | Free | no deps | |
| Bar Chartbar-chart | gaia | Components | Free | 1 dep | |
| Composercomposer | gaia | Components | Free | no deps | |
| Email Compose Cardemail-compose-card | gaia | Components | Free | no deps | |
| Gauge Chartgauge-chart | gaia | Components | Free | 1 dep | |
| GitHub Stars Buttongithub-stars-button | gaia | Components | Free | 1 dep | |
| Holo Cardholo-card | gaia | Components | Free | 1 dep · 2 files |
