mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
afc2ca65cf
* List Dnd Complete feature * fix minor bugs in list dnd * remove double overlay in kanban post refactor * add missing dependencies to useEffects * make provision to add to the last issue of the group * show current child issues to also be disabled if the parent issue is being dragged * fix last issue border * fix code static analysis suggestions * prevent context menu on drag handle
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { MutableRefObject, useRef, useState } from "react";
|
|
import { LucideIcon, X } from "lucide-react";
|
|
import { IIssueLabel } from "@plane/types";
|
|
//ui
|
|
import { CustomMenu, DragHandle } from "@plane/ui";
|
|
//types
|
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
|
//hooks
|
|
//components
|
|
import { LabelName } from "./label-name";
|
|
|
|
//types
|
|
export interface ICustomMenuItem {
|
|
CustomIcon: LucideIcon;
|
|
onClick: (label: IIssueLabel) => void;
|
|
isVisible: boolean;
|
|
text: string;
|
|
key: string;
|
|
}
|
|
|
|
interface ILabelItemBlock {
|
|
label: IIssueLabel;
|
|
isDragging: boolean;
|
|
customMenuItems: ICustomMenuItem[];
|
|
handleLabelDelete: (label: IIssueLabel) => void;
|
|
isLabelGroup?: boolean;
|
|
dragHandleRef: MutableRefObject<HTMLButtonElement | null>;
|
|
}
|
|
|
|
export const LabelItemBlock = (props: ILabelItemBlock) => {
|
|
const { label, isDragging, customMenuItems, handleLabelDelete, isLabelGroup, dragHandleRef } = props;
|
|
// states
|
|
const [isMenuActive, setIsMenuActive] = useState(false);
|
|
// refs
|
|
const actionSectionRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
useOutsideClickDetector(actionSectionRef, () => setIsMenuActive(false));
|
|
|
|
return (
|
|
<div className="group flex items-center">
|
|
<div className="flex items-center">
|
|
<DragHandle isDragging={isDragging} ref={dragHandleRef} />
|
|
<LabelName color={label.color} name={label.name} isGroup={isLabelGroup ?? false} />
|
|
</div>
|
|
|
|
<div
|
|
ref={actionSectionRef}
|
|
className={`absolute right-3 flex items-start gap-3.5 px-4 ${
|
|
isMenuActive || isLabelGroup
|
|
? "opacity-100"
|
|
: "opacity-0 group-hover:pointer-events-auto group-hover:opacity-100"
|
|
} ${isLabelGroup && "-top-0.5"}`}
|
|
>
|
|
<CustomMenu ellipsis>
|
|
{customMenuItems.map(
|
|
({ isVisible, onClick, CustomIcon, text, key }) =>
|
|
isVisible && (
|
|
<CustomMenu.MenuItem key={key} onClick={() => onClick(label)}>
|
|
<span className="flex items-center justify-start gap-2">
|
|
<CustomIcon className="h-4 w-4" />
|
|
<span>{text}</span>
|
|
</span>
|
|
</CustomMenu.MenuItem>
|
|
)
|
|
)}
|
|
</CustomMenu>
|
|
{!isLabelGroup && (
|
|
<div className="py-0.5">
|
|
<button className="flex h-4 w-4 items-center justify-start gap-2" onClick={() => handleLabelDelete(label)}>
|
|
<X className="h-4 w-4 flex-shrink-0 text-custom-sidebar-text-400" />
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|