Files
cv/src/components/ui/Button.tsx
T

74 lines
1.6 KiB
TypeScript
Raw Normal View History

2026-10-06 19:29:13 +07:00
import { motion } from "motion/react"
import { forwardRef } from "react"
import type { ComponentPropsWithoutRef } from "react"
2026-10-06 19:29:13 +07:00
type ButtonVariant = "primary" | "secondary" | "ghost"
type ButtonSize = "sm" | "md" | "lg"
2026-10-06 19:29:13 +07:00
interface ButtonProps extends ComponentPropsWithoutRef<"button"> {
variant?: ButtonVariant
size?: ButtonSize
href?: string
download?: boolean
children: React.ReactNode
}
const variantClasses: Record<ButtonVariant, string> = {
2026-10-06 19:29:13 +07:00
primary: "btn btn-primary",
secondary: "btn btn-secondary",
ghost: "btn btn-ghost",
}
const sizeClasses: Record<ButtonSize, string> = {
2026-10-06 19:29:13 +07:00
sm: "btn-sm",
md: "",
lg: "btn-lg",
}
export const Button = forwardRef<
HTMLButtonElement | HTMLAnchorElement,
ButtonProps
2026-10-06 19:29:13 +07:00
>(
(
{
variant = "primary",
size = "md",
href,
className = "",
children,
...props
},
ref
) => {
const classes = `${variantClasses[variant]} ${sizeClasses[size]} ${className}`.trim()
if (href) {
return (
<motion.a
href={href}
className={classes}
ref={ref as React.Ref<HTMLAnchorElement>}
whileTap={{ scale: 0.95 }}
{...(props as Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof ButtonProps>)}
>
{children}
</motion.a>
)
}
return (
2026-10-06 19:29:13 +07:00
<motion.button
className={classes}
ref={ref as React.Ref<HTMLButtonElement>}
whileTap={{ scale: 0.95 }}
{...(props as Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof ButtonProps>)}
>
{children}
2026-10-06 19:29:13 +07:00
</motion.button>
)
}
2026-10-06 19:29:13 +07:00
)
2026-10-06 19:29:13 +07:00
Button.displayName = "Button"