2023-10-12 04:38:31 -04:00
|
|
|
import { useRef } from 'react'
|
2020-11-26 09:22:30 -05:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
|
|
|
import Icon from '../../../../shared/components/icon'
|
|
|
|
|
2021-11-09 06:01:08 -05:00
|
|
|
import { useFileTreeMainContext } from '../../contexts/file-tree-main'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
function FileTreeItemMenu({ id }) {
|
|
|
|
const { t } = useTranslation()
|
2021-11-09 06:01:08 -05:00
|
|
|
const { contextMenuCoords, setContextMenuCoords } = useFileTreeMainContext()
|
2023-10-12 04:38:31 -04:00
|
|
|
const menuButtonRef = useRef()
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2023-10-12 04:38:31 -04:00
|
|
|
function handleClick(event) {
|
|
|
|
event.stopPropagation()
|
2021-11-09 06:01:08 -05:00
|
|
|
if (!contextMenuCoords) {
|
2023-10-12 04:38:31 -04:00
|
|
|
const target = menuButtonRef.current.getBoundingClientRect()
|
2021-11-09 06:01:08 -05:00
|
|
|
setContextMenuCoords({
|
|
|
|
top: target.top + target.height / 2,
|
|
|
|
left: target.right,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
setContextMenuCoords(null)
|
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-11-09 06:01:08 -05:00
|
|
|
<div className="menu-button btn-group">
|
2023-10-12 04:38:31 -04:00
|
|
|
<button
|
|
|
|
className="entity-menu-toggle btn btn-sm"
|
2021-11-09 06:01:08 -05:00
|
|
|
id={`menu-button-${id}`}
|
2023-10-12 04:38:31 -04:00
|
|
|
onClick={handleClick}
|
2021-11-09 06:01:08 -05:00
|
|
|
ref={menuButtonRef}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
|
|
|
<Icon type="ellipsis-v" accessibilityLabel={t('menu')} />
|
2023-10-12 04:38:31 -04:00
|
|
|
</button>
|
2021-11-09 06:01:08 -05:00
|
|
|
</div>
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeItemMenu.propTypes = {
|
2021-04-27 03:52:58 -04:00
|
|
|
id: PropTypes.string.isRequired,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default FileTreeItemMenu
|