Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update button styles

Tim Wilsonfdc8cc0147e8
diff --git a/packages/ui/src/button.tsx b/packages/ui/src/button.tsx
index d5bb357610..e88f0a7c17 100644
--- a/packages/ui/src/button.tsx
+++ b/packages/ui/src/button.tsx
@@ -1,18 +1,40 @@
import { cn } from "@dub/utils";
+import { VariantProps, cva } from "class-variance-authority";
import { ReactNode, forwardRef } from "react";
import { LoadingSpinner } from "./icons";
import { Tooltip } from "./tooltip";
+const buttonVariants = cva(
+ "group flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all",
+ {
+ variants: {
+ variant: {
+ primary:
+ "border-black bg-black text-white hover:bg-gray-800 hover:ring-4 hover:ring-gray-200",
+ secondary: cn(
+ "border-gray-200 bg-white text-gray-900 hover:bg-gray-50 focus-visible:border-gray-500",
+ "data-[state=open]:border-gray-500 data-[state=open]:ring-4 data-[state=open]:ring-gray-200",
+ ),
+ outline:
+ "border-transparent text-gray-500 duration-75 hover:bg-gray-100",
+ success:
+ "border-blue-500 bg-blue-500 text-white hover:bg-blue-600 hover:ring-4 hover:ring-blue-100",
+ danger:
+ "border-red-500 bg-red-500 text-white hover:bg-red-600 hover:ring-4 hover:ring-red-100",
+ "danger-outline":
+ "border-transparent bg-white text-red-500 hover:bg-red-600 hover:text-white",
+ },
+ },
+ defaultVariants: {
+ variant: "primary",
+ },
+ },
+);
+
export interface ButtonProps
- extends React.ButtonHTMLAttributes<HTMLButtonElement> {
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
+ VariantProps<typeof buttonVariants> {
text?: string;
- variant?:
- | "primary"
- | "secondary"
- | "outline"
- | "success"
- | "danger"
- | "danger-outline";
loading?: boolean;
icon?: ReactNode;
shortcut?: string;
@@ -41,7 +63,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
"flex h-10 w-full cursor-not-allowed items-center justify-center space-x-2 rounded-md border border-gray-200 bg-gray-100 px-4 text-sm text-gray-400 transition-all focus:outline-none",
{
"border-transparent bg-transparent":
- variant.endsWith("outline"),
+ variant?.endsWith("outline"),
},
className,
)}
@@ -53,7 +75,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
className={cn(
"hidden rounded bg-gray-200 px-2 py-0.5 text-xs font-light text-gray-400 md:inline-block",
{
- "bg-gray-100": variant.endsWith("outline"),
+ "bg-gray-100": variant?.endsWith("outline"),
},
)}
>
@@ -70,23 +92,9 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
// if onClick is passed, it's a "button" type, otherwise it's being used in a form, hence "submit"
type={props.onClick ? "button" : "submit"}
className={cn(
- "group flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all",
- props.disabled || loading
- ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"
- : {
- "border-black bg-black text-white hover:bg-gray-800 hover:ring-4 hover:ring-gray-200":
- variant === "primary",
- "border-gray-200 bg-white text-gray-600 hover:bg-gray-100":
- variant === "secondary",
- "border-transparent text-gray-500 duration-75 hover:bg-gray-100":
- variant === "outline",
- "border-blue-500 bg-blue-500 text-white hover:bg-blue-600 hover:ring-4 hover:ring-blue-100":
- variant === "success",
- "border-red-500 bg-red-500 text-white hover:bg-red-600 hover:ring-4 hover:ring-red-100":
- variant === "danger",
- "border-transparent bg-white text-red-500 hover:bg-red-600 hover:text-white":
- variant === "danger-outline",
- },
+ buttonVariants({ variant }),
+ (props.disabled || loading) &&
+ "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400",
className,
)}
disabled={props.disabled || loading}