import Link, { LinkProps } from "next/link"; import React, { forwardRef } from "react"; import { Icon } from "react-feather"; import classNames from "@calcom/lib/classNames"; import { Tooltip } from "./Tooltip"; export type ButtonBaseProps = { /* Primary: Signals most important actions at any given point in the application. Secondary: Gives visual weight to actions that are important Minimal: Used for actions that we want to give very little significane to */ color?: keyof typeof variantClassName; /**Default: H = 36px (default) Large: H = 38px (Onboarding, modals) Icon: Makes the button be an icon button */ size?: "base" | "lg" | "icon"; /**Signals the button is loading */ loading?: boolean; /** Disables the button from being clicked */ disabled?: boolean; /** Action that happens when the button is clicked */ onClick?: (event: React.MouseEvent) => void; /**Left aligned icon*/ StartIcon?: Icon | React.ElementType; /**Right aligned icon */ EndIcon?: Icon; shallow?: boolean; /**Tool tip used when icon size is set to small */ tooltip?: string; combined?: boolean; flex?: boolean; }; export type ButtonProps = ButtonBaseProps & ( | (Omit & LinkProps) | (Omit & { href?: never }) ); const variantClassName = { primary: "border border-transparent text-white bg-brand-500 hover:bg-brand-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brand-500", secondary: "border border-gray-200 text-brand-900 bg-white hover:bg-gray-100", minimal: "text-gray-700 bg-transparent hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:bg-gray-100 focus:ring-brand-900 dark:text-darkgray-900", destructive: "text-gray-700 bg-transparent hover:bg-red-100 hover:text-red-700 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:bg-red-100 focus:ring-red-700", }; const variantDisabledClassName = { primary: "border border-transparent bg-brand-500 bg-opacity-20 text-white", secondary: "border border-gray-200 text-brand-900 bg-white opacity-30", minimal: "text-gray-400 bg-transparent", destructive: "text-red-700 bg-transparent opacity-30", }; export const Button = forwardRef(function Button( props: ButtonProps, forwardedRef ) { const { loading = false, color = "primary", size = "base", StartIcon, EndIcon, shallow, flex, combined = false, // 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 `