2024-01-31 10:06:55 +00:00
|
|
|
// helpers
|
2024-03-06 13:09:14 +00:00
|
|
|
import { Tooltip } from "@plane/ui";
|
2024-01-31 10:06:55 +00:00
|
|
|
import { cn } from "helpers/common.helper";
|
|
|
|
// types
|
2024-03-06 13:09:14 +00:00
|
|
|
import { BACKGROUND_BUTTON_VARIANTS, BORDER_BUTTON_VARIANTS } from "./constants";
|
2024-01-31 10:06:55 +00:00
|
|
|
import { TButtonVariants } from "./types";
|
2024-03-12 15:09:36 +00:00
|
|
|
import { usePlatformOS } from "hooks/use-platform-os";
|
2024-01-31 10:06:55 +00:00
|
|
|
|
|
|
|
export type DropdownButtonProps = {
|
|
|
|
children: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
isActive: boolean;
|
|
|
|
tooltipContent: string | React.ReactNode;
|
|
|
|
tooltipHeading: string;
|
|
|
|
showTooltip: boolean;
|
|
|
|
variant: TButtonVariants;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ButtonProps = {
|
|
|
|
children: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
isActive: boolean;
|
|
|
|
tooltipContent: string | React.ReactNode;
|
|
|
|
tooltipHeading: string;
|
|
|
|
showTooltip: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DropdownButton: React.FC<DropdownButtonProps> = (props) => {
|
|
|
|
const { children, className, isActive, tooltipContent, tooltipHeading, showTooltip, variant } = props;
|
|
|
|
const ButtonToRender: React.FC<ButtonProps> = BORDER_BUTTON_VARIANTS.includes(variant)
|
|
|
|
? BorderButton
|
|
|
|
: BACKGROUND_BUTTON_VARIANTS.includes(variant)
|
2024-03-06 13:09:14 +00:00
|
|
|
? BackgroundButton
|
|
|
|
: TransparentButton;
|
2024-01-31 10:06:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ButtonToRender
|
|
|
|
className={className}
|
|
|
|
isActive={isActive}
|
|
|
|
tooltipContent={tooltipContent}
|
|
|
|
tooltipHeading={tooltipHeading}
|
|
|
|
showTooltip={showTooltip}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</ButtonToRender>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const BorderButton: React.FC<ButtonProps> = (props) => {
|
|
|
|
const { children, className, isActive, tooltipContent, tooltipHeading, showTooltip } = props;
|
2024-03-12 15:09:36 +00:00
|
|
|
const { isMobile } = usePlatformOS();
|
2024-01-31 10:06:55 +00:00
|
|
|
|
|
|
|
return (
|
2024-03-12 15:09:36 +00:00
|
|
|
<Tooltip tooltipHeading={tooltipHeading} tooltipContent={tooltipContent} disabled={!showTooltip} isMobile={isMobile}>
|
2024-01-31 10:06:55 +00:00
|
|
|
<div
|
|
|
|
className={cn(
|
|
|
|
"h-full flex items-center gap-1.5 border-[0.5px] border-custom-border-300 hover:bg-custom-background-80 rounded text-xs px-2 py-0.5",
|
|
|
|
{ "bg-custom-background-80": isActive },
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const BackgroundButton: React.FC<ButtonProps> = (props) => {
|
|
|
|
const { children, className, tooltipContent, tooltipHeading, showTooltip } = props;
|
2024-03-12 15:09:36 +00:00
|
|
|
const { isMobile } = usePlatformOS();
|
2024-01-31 10:06:55 +00:00
|
|
|
return (
|
2024-03-12 15:09:36 +00:00
|
|
|
<Tooltip tooltipHeading={tooltipHeading} tooltipContent={tooltipContent} disabled={!showTooltip} isMobile={isMobile}>
|
2024-01-31 10:06:55 +00:00
|
|
|
<div
|
|
|
|
className={cn(
|
|
|
|
"h-full flex items-center gap-1.5 rounded text-xs px-2 py-0.5 bg-custom-background-80",
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const TransparentButton: React.FC<ButtonProps> = (props) => {
|
|
|
|
const { children, className, isActive, tooltipContent, tooltipHeading, showTooltip } = props;
|
2024-03-12 15:09:36 +00:00
|
|
|
const { isMobile } = usePlatformOS();
|
2024-01-31 10:06:55 +00:00
|
|
|
return (
|
2024-03-12 15:09:36 +00:00
|
|
|
<Tooltip tooltipHeading={tooltipHeading} tooltipContent={tooltipContent} disabled={!showTooltip} isMobile={isMobile}>
|
2024-01-31 10:06:55 +00:00
|
|
|
<div
|
|
|
|
className={cn(
|
|
|
|
"h-full flex items-center gap-1.5 rounded text-xs px-2 py-0.5 hover:bg-custom-background-80",
|
|
|
|
{ "bg-custom-background-80": isActive },
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|