jira/apps/web/core/components/dropdowns/buttons.tsx
vickytechkey e67f0cf15d
Some checks failed
Deploy Plane Project Tracker / Deploy to cisystem (push) Failing after 5m16s
fix(web,ui): fix hydration error from nested button descendants and MobX strict-mode warnings
- Replace nested <Button> with styled <div> in DropdownButton (BorderButton, BackgroundButton, TransparentButton) across all issue dropdowns
- Support 'div' variant and element in AppSidebarItem, DragHandle, and CustomMenu triggers/items to avoid invalid HTML button nesting
- Fix MobX strict-mode observable mutations in IssueRootStore autorun and BaseWorkspaceRootStore fetchWorkspaces with runInAction
- Defer WorkItemFilterStore filter registration via queueMicrotask to eliminate cross-component render updates on WorkItemFiltersToggle
- Remove redundant e.preventDefault() in Kanban card actions to prevent blocking native/synthetic event propagation
2026-11-06 17:24:20 +05:30

140 lines
3.7 KiB
TypeScript

/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/
import React from "react";
// helpers
import { getButtonStyling } from "@plane/propel/button";
import { Tooltip } from "@makeplane/propel/components/tooltip";
import { cn } from "@plane/utils";
// types
import { usePlatformOS } from "@/hooks/use-platform-os";
import { BACKGROUND_BUTTON_VARIANTS, BORDER_BUTTON_VARIANTS } from "./constants";
import type { TButtonVariants } from "./types";
export type DropdownButtonProps = {
children: React.ReactNode;
className?: string;
isActive: boolean;
tooltipContent?: string;
tooltipHeading: string;
showTooltip: boolean;
variant: TButtonVariants;
renderToolTipByDefault?: boolean;
};
type ButtonProps = {
children: React.ReactNode;
className?: string;
isActive: boolean;
tooltipContent?: string;
tooltipHeading: string;
showTooltip: boolean;
renderToolTipByDefault?: boolean;
};
export function DropdownButton(props: DropdownButtonProps) {
const {
children,
className,
isActive,
tooltipContent,
renderToolTipByDefault = true,
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}
renderToolTipByDefault={renderToolTipByDefault}
>
{children}
</ButtonToRender>
);
}
function BorderButton(props: ButtonProps) {
const { children, className, isActive, tooltipContent, tooltipHeading, showTooltip } = props;
const { isMobile } = usePlatformOS();
return (
<Tooltip
label={tooltipContent ? `${tooltipHeading}: ${tooltipContent}` : tooltipHeading}
layout="stacked"
disabled={!showTooltip || isMobile}
>
<div
className={cn(
getButtonStyling("ghost", "sm"),
"flex h-full w-full items-center justify-start gap-1.5 border-[0.5px] border-strong",
{
"bg-layer-transparent-active": isActive,
},
className
)}
>
{children}
</div>
</Tooltip>
);
}
function BackgroundButton(props: ButtonProps) {
const { children, className, tooltipContent, tooltipHeading, showTooltip } = props;
const { isMobile } = usePlatformOS();
return (
<Tooltip
label={tooltipContent ? `${tooltipHeading}: ${tooltipContent}` : tooltipHeading}
layout="stacked"
disabled={!showTooltip || isMobile}
>
<div
className={cn(
getButtonStyling("ghost", "sm"),
"flex h-full w-full items-center justify-between gap-1.5 bg-layer-3 hover:bg-layer-1-hover",
className
)}
>
{children}
</div>
</Tooltip>
);
}
function TransparentButton(props: ButtonProps) {
const { children, className, isActive, tooltipContent, tooltipHeading, showTooltip } = props;
const { isMobile } = usePlatformOS();
return (
<Tooltip
label={tooltipContent ? `${tooltipHeading}: ${tooltipContent}` : tooltipHeading}
layout="stacked"
disabled={!showTooltip || isMobile}
>
<div
className={cn(
getButtonStyling("ghost", "sm"),
"flex h-full w-full items-center justify-between gap-1.5",
{
"bg-layer-transparent-active": isActive,
},
className
)}
>
{children}
</div>
</Tooltip>
);
}