Button
Displays a button or a component that looks like a button.
Usage
Installation
Button.tsx
1import React from "react";
2import { cn } from "@/utils/cn";
3import { ClassNameValue } from "tailwind-merge";
4
5type Variant =
6 | "info"
7 | "success"
8 | "warning"
9 | "error"
10 | "disabled"
11 | "ghost"
12 | "link"
13 | "";
14
15function switchVariant(variant: Variant) {
16 switch (variant) {
17 case "info":
18 return "bg-sky-500 text-sky-100 ease-in-out duration-200 hover:shadow-lg px-6 py-2 flex items-center gap-3";
19 case "success":
20 return "bg-teal-500 text-teal-100 px-6 py-2 flex items-center gap-3 ease-in-out duration-200 hover:shadow-lg ";
21 case "warning":
22 return "bg-amber-500 text-amber-100 px-6 py-2 flex items-center gap-3 ease-in-out duration-200 hover:shadow-lg ";
23 case "error":
24 return "bg-red-500 text-red-100 px-6 py-2 flex items-center gap-3 ease-in-out duration-200 hover:shadow-lg ";
25 case "disabled":
26 return "hover:brightness-90 bg-white border border-zinc-900 text-gray-800 opacity-50 px-6 py-2 flex items-center gap-3 cursor-not-allowed hover:shadow-none ease-in-out duration-200";
27 case "ghost":
28 return "hover:bg-[#ffe4e60d] bg-transparent ghost-text px-6 py-2 flex items-center gap-3 ease-in-out duration-200 hover:shadow-lg";
29 case "link":
30 return "underline-offset-2 underline bg-transparent hover:bg-transparent text-rose-100";
31 default:
32 return "";
33 }
34}
35
36type ButtonProps = {
37 children?: React.ReactNode;
38 variant?:
39 | "info"
40 | "success"
41 | "warning"
42 | "error"
43 | "disabled"
44 | "ghost"
45 | "link"
46 | "";
47 className?: ClassNameValue;
48} & React.ButtonHTMLAttributes<HTMLButtonElement>;
49
50const Button = ({
51 children,
52 variant = "",
53 className,
54 ...props
55}: ButtonProps) => {
56 return (
57 <button
58 className={cn(
59 "flex items-center gap-3 rounded-lg bg-rose-500 px-6 py-2 font-geist font-semibold text-rose-100 shadow-md duration-200 ease-in-out hover:shadow-lg hover:brightness-95",
60 switchVariant(variant),
61 className
62 )}
63 {...props}
64 >
65 {children}
66 </button>
67 );
68};
69
70export default Button;
71
Props
The button component accepts the following props:
Prop | Type | Description |
---|---|---|
children | ReactNode | Content to be displayed inside the button |
variant | info , success , warning , | The style variant of the button, used to apply different styles |
error , disabled , ghost , | ||
link | ||
className | string | Additional classes to be added to the button |
...props | any | Any other props you want to pass to the button |