mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
0d036e6bf5
* refactor: dropdown button components * chore: dropdowns accessibility improvement * chore: update module dropdown * chore: update option content * chore: hide icon from the peek overview --------- Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so>
102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
// helpers
|
|
import { cn } from "helpers/common.helper";
|
|
// types
|
|
import { TButtonVariants } from "./types";
|
|
// constants
|
|
import { BACKGROUND_BUTTON_VARIANTS, BORDER_BUTTON_VARIANTS } from "./constants";
|
|
import { Tooltip } from "@plane/ui";
|
|
|
|
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)
|
|
? BackgroundButton
|
|
: TransparentButton;
|
|
|
|
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;
|
|
|
|
return (
|
|
<Tooltip tooltipHeading={tooltipHeading} tooltipContent={tooltipContent} disabled={!showTooltip}>
|
|
<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;
|
|
|
|
return (
|
|
<Tooltip tooltipHeading={tooltipHeading} tooltipContent={tooltipContent} disabled={!showTooltip}>
|
|
<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;
|
|
|
|
return (
|
|
<Tooltip tooltipHeading={tooltipHeading} tooltipContent={tooltipContent} disabled={!showTooltip}>
|
|
<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>
|
|
);
|
|
};
|