import { cn } from "@formbricks/lib/cn"; import { LucideIcon } from "lucide-react"; import Link, { LinkProps } from "next/link"; import React, { AnchorHTMLAttributes, ButtonHTMLAttributes, forwardRef } from "react"; type SVGComponent = React.FunctionComponent> | LucideIcon; export type ButtonBaseProps = { variant?: "highlight" | "primary" | "secondary" | "minimal" | "warn" | "alert" | "darkCTA"; size?: "base" | "sm" | "lg" | "fab" | "icon"; loading?: boolean; disabled?: boolean; onClick?: (event: React.MouseEvent) => void; StartIcon?: SVGComponent | React.ComponentType>; startIconClassName?: string; EndIcon?: SVGComponent | React.ComponentType>; endIconClassName?: string; shallow?: boolean; }; type ButtonBasePropsWithTarget = ButtonBaseProps & { target?: string }; export type ButtonProps = ButtonBasePropsWithTarget & ( | (Omit, "href" | "onClick" | "target"> & LinkProps) | (Omit, "onClick" | "target"> & { href?: never }) ); export const Button: React.ForwardRefExoticComponent< React.PropsWithoutRef & React.RefAttributes > = forwardRef(function Button( props: ButtonProps, forwardedRef ) { const { loading = false, variant = "primary", size = "base", StartIcon, startIconClassName, endIconClassName, EndIcon, shallow, // attributes propagated from `HTMLAnchorProps` or `HTMLButtonProps` ...passThroughProps } = props; // Buttons are **always** disabled if we're in a `loading` state const disabled = props.disabled || loading; // If pass an `href`-attr is passed it's ``, otherwise it's a `