From a8873e3407dcbd91e699d3360a318467f67290ef Mon Sep 17 00:00:00 2001 From: Rafly Maulana Date: Sat, 19 Nov 2022 21:43:29 +0700 Subject: [PATCH] Add context menu when clicking on card --- client/src/components/Card/Card.jsx | 51 +++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/client/src/components/Card/Card.jsx b/client/src/components/Card/Card.jsx index 4efb17ad..762ab902 100755 --- a/client/src/components/Card/Card.jsx +++ b/client/src/components/Card/Card.jsx @@ -1,10 +1,11 @@ -import React, { useCallback, useRef } from 'react'; +import React, { useCallback, useRef, useState } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Button, Icon } from 'semantic-ui-react'; import { Link } from 'react-router-dom'; import { Draggable } from 'react-beautiful-dnd'; +import { ControlledMenu, MenuItem, useMenuState } from '@szhsin/react-menu'; import { startTimer, stopTimer } from '../../utils/timer'; import Paths from '../../constants/Paths'; import Tasks from './Tasks'; @@ -17,6 +18,8 @@ import Timer from '../Timer'; import styles from './Card.module.scss'; +import '@szhsin/react-menu/dist/index.css'; + const Card = React.memo( ({ id, @@ -52,11 +55,22 @@ const Card = React.memo( }) => { const nameEdit = useRef(null); - const handleClick = useCallback(() => { - if (document.activeElement) { - document.activeElement.blur(); - } - }, []); + const [menuProps, toggleMenu] = useMenuState(); + const [anchorPoint, setAnchorPoint] = useState({ x: 0, y: 0 }); + + const handleClick = useCallback( + (e) => { + if (menuProps.state === 'open') { + e.preventDefault(); + e.stopPropagation(); + } + + if (document.activeElement) { + document.activeElement.blur(); + } + }, + [menuProps.state], + ); const handleToggleTimerClick = useCallback( (event) => { @@ -85,7 +99,15 @@ const Card = React.memo( const contentNode = ( <> {coverUrl && } -
+ +
{ + e.preventDefault(); + setAnchorPoint({ x: e.clientX, y: e.clientY }); + toggleMenu(true); + }} + > {labels.length > 0 && ( {labels.map((label) => ( @@ -98,8 +120,11 @@ const Card = React.memo( ))} )} +
{name}
+ {tasks.length > 0 && } + {(dueDate || timer || notificationsTotal > 0) && ( {notificationsTotal > 0 && ( @@ -131,6 +156,7 @@ const Card = React.memo( )} )} + {users.length > 0 && ( {users.map((user) => ( @@ -143,6 +169,16 @@ const Card = React.memo( ))} )} + + toggleMenu(false)} + > + Delete Card +
); @@ -163,6 +199,7 @@ const Card = React.memo( > {contentNode} + {canEdit && (