File size: 3,062 Bytes
5c0175e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
/**
* Buttons per §4 of the YouTube design system.
* - 40px height, 20px radius (pill), 16px horizontal padding, Roboto 14px/500
* - Every variant defines hover, active/pressed and disabled states
* - No shadows at rest; shadows are reserved for modals/dropdowns (§6)
*/
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium transition-colors duration-100 disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-[#3ea6ff] focus-visible:ring-offset-2 focus-visible:ring-offset-[#0f0f0f] aria-invalid:border-[#e1002d]",
{
variants: {
variant: {
// Primary CTA — #065FD4 → #3EA6FF hover → #0540AA pressed
default:
"bg-[#065fd4] text-white hover:bg-[#3ea6ff] active:bg-[#0540aa] disabled:bg-white/5 disabled:text-[#606060]",
// Secondary — translucent white on dark surfaces
secondary:
"bg-white/[0.08] text-[#f1f1f1] hover:bg-white/[0.12] active:bg-white/[0.16] disabled:bg-white/[0.02] disabled:text-[#aaaaaa]",
// Ghost / outlined — 1px hairline border, blue label
outline:
"border border-white/20 bg-transparent text-[#3ea6ff] hover:bg-[#065fd4]/[0.08] active:bg-[#065fd4]/[0.12] disabled:border-white/10 disabled:text-[#aaaaaa]",
// Destructive — Error #E1002D → #FF0033 hover → #C30027 pressed
destructive:
"bg-[#e1002d] text-white hover:bg-[#ff0033] active:bg-[#c30027] disabled:bg-white/5 disabled:text-[#606060]",
ghost:
"bg-transparent text-[#eeeeee] hover:bg-white/[0.08] active:bg-white/[0.12] disabled:text-[#606060]",
link: "bg-transparent text-[#3ea6ff] underline-offset-4 hover:underline hover:text-[#065fd4] active:text-[#0540aa] disabled:text-[#606060]",
},
size: {
// 40px pill is the system default
default: "h-10 px-4 rounded-[20px] text-sm",
sm: "h-8 px-3 rounded-[16px] text-[13.3px] gap-1.5",
lg: "h-12 px-6 rounded-[24px] text-sm",
// Icon button — circular, transparent, hover wash (§4 Icon Button)
icon: "size-10 rounded-full p-0",
"icon-sm": "size-8 rounded-full p-0",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Button({
className,
variant,
size,
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot : "button"
return (
<Comp
data-slot="button"
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Button, buttonVariants }
|