Openstatus www.openstatus.dev
at main 45 lines 1.0 kB view raw
1import { cn } from "../lib/utils"; 2import { Button } from "./button"; 3import type { ButtonProps } from "./button"; 4import { 5 Tooltip, 6 TooltipContent, 7 TooltipProvider, 8 TooltipTrigger, 9} from "./tooltip"; 10 11interface ButtonWithDisableTooltipProps extends ButtonProps { 12 tooltip: string; 13} 14 15export const ButtonWithDisableTooltip = ({ 16 tooltip, 17 disabled, 18 className, 19 ...props 20}: ButtonWithDisableTooltipProps) => { 21 const ButtonComponent = ( 22 <Button 23 {...props} 24 disabled={disabled} 25 className={cn(className, disabled && "pointer-events-none")} 26 /> 27 ); 28 29 if (disabled) { 30 // If the button is disabled, we wrap it in a tooltip since 31 // we don't want to show the tooltip if the button is enabled. 32 return ( 33 <TooltipProvider> 34 <Tooltip> 35 <TooltipTrigger asChild> 36 <span>{ButtonComponent}</span> 37 </TooltipTrigger> 38 <TooltipContent>{tooltip}</TooltipContent> 39 </Tooltip> 40 </TooltipProvider> 41 ); 42 } 43 44 return ButtonComponent; 45};