-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.tsx
More file actions
85 lines (80 loc) · 1.7 KB
/
Button.tsx
File metadata and controls
85 lines (80 loc) · 1.7 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
"use client";
import {
buttonColors,
buttonShape,
buttonShapes,
buttonSize,
buttonVariant,
} from "@/config/button";
import { Color } from "@/config/colors";
import { FontWeights, fontWeights } from "@/config/typography";
import { HTMLMotionProps, motion } from "framer-motion";
import { forwardRef } from "react";
import { twMerge } from "tailwind-merge";
export type ButtonProps = HTMLMotionProps<"button"> & {
children: React.ReactNode;
color?: Color;
variant?: buttonVariant;
size?: buttonSize;
shape?: buttonShape;
weight?: FontWeights;
};
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
(
{
size = "medium",
color = "red",
shape = "pill",
variant = "filled",
weight = "bold",
children,
className,
disabled,
...props
},
ref,
) => {
const animation = {
initial: {
scale: 1,
opacity: 1,
},
clicked: {
scale: [0.9, 1],
transition: {
duration: 0.2,
stiffness: 10,
type: "spring",
},
},
hover: {
scale: 1.05,
transition: {
duration: 0.2,
type: "ease-in-out",
},
},
};
return (
<motion.button
{...props}
ref={ref}
className={twMerge(
buttonColors(variant, color),
buttonShapes(shape, size),
fontWeights(weight),
"h-fit w-fit",
className,
)}
disabled={disabled}
variants={animation}
initial="initial"
whileTap="clicked"
whileHover="hover"
>
{children}
</motion.button>
);
},
);
Button.displayName = "Button";