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 11:42:11 +07:00
|
|
|
|
2026-10-06 19:29:13 +07:00
|
|
|
type ButtonVariant = "primary" | "secondary" | "ghost"
|
|
|
|
|
type ButtonSize = "sm" | "md" | "lg"
|
2026-10-06 11:42:11 +07:00
|
|
|
|
2026-10-06 19:29:13 +07:00
|
|
|
interface ButtonProps extends ComponentPropsWithoutRef<"button"> {
|
2026-10-06 11:42:11 +07:00
|
|
|
variant?: ButtonVariant
|
|
|
|
|
size?: ButtonSize
|
|
|
|
|
href?: string
|
2026-10-06 14:14:01 +07:00
|
|
|
download?: boolean
|
2026-10-06 11:42:11 +07:00
|
|
|
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",
|
2026-10-06 11:42:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sizeClasses: Record<ButtonSize, string> = {
|
2026-10-06 19:29:13 +07:00
|
|
|
sm: "btn-sm",
|
|
|
|
|
md: "",
|
|
|
|
|
lg: "btn-lg",
|
2026-10-06 11:42:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-10-06 11:42:11 +07:00
|
|
|
|
|
|
|
|
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>)}
|
|
|
|
|
>
|
2026-10-06 11:42:11 +07:00
|
|
|
{children}
|
2026-10-06 19:29:13 +07:00
|
|
|
</motion.button>
|
2026-10-06 11:42:11 +07:00
|
|
|
)
|
|
|
|
|
}
|
2026-10-06 19:29:13 +07:00
|
|
|
)
|
2026-10-06 11:42:11 +07:00
|
|
|
|
2026-10-06 19:29:13 +07:00
|
|
|
Button.displayName = "Button"
|