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'
|
2024-09-25 09:46:02 -04:00
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
|
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2024-09-25 09:46:02 -04:00
|
|
|
function FileTreeItemMenu({ id, name }) {
|
2020-11-26 09:22:30 -05:00
|
|
|
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
|
|
|
|
2024-09-25 09:46:02 -04:00
|
|
|
const isMenuOpen = Boolean(contextMenuCoords)
|
|
|
|
|
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}
|
2024-09-25 09:46:02 -04:00
|
|
|
aria-haspopup="true"
|
|
|
|
aria-expanded={isMenuOpen}
|
|
|
|
aria-label={t('open_action_menu', { name })}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
2024-09-25 09:46:02 -04:00
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<Icon type="ellipsis-v" accessibilityLabel={t('menu')} />}
|
|
|
|
bs5={<MaterialIcon type="more_vert" 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,
|
2024-09-25 09:46:02 -04:00
|
|
|
name: PropTypes.string.isRequired,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default FileTreeItemMenu
|