overleaf/services/web/frontend/js/features/file-tree/components/file-tree-item/file-tree-item-menu.js
Alf Eaton 7c97f8ab6e Switch to new JSX runtime (#4225)
* Use new JSX runtime and update Babel Node target
* Update .eslintrc
* Remove React imports

GitOrigin-RevId: 559de0267f8f2934c56a860ea8701bb522aa861a
2021-06-24 02:06:59 +00:00

81 lines
2 KiB
JavaScript

import { useState } from 'react'
import { findDOMNode } from 'react-dom'
import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next'
import withoutPropagation from '../../../../infrastructure/without-propagation'
import { Dropdown, Overlay } from 'react-bootstrap'
import Icon from '../../../../shared/components/icon'
import FileTreeItemMenuItems from './file-tree-item-menu-items'
function FileTreeItemMenu({ id }) {
const { t } = useTranslation()
const [dropdownOpen, setDropdownOpen] = useState(false)
const [dropdownTarget, setDropdownTarget] = useState()
function handleToggle(wantOpen) {
setDropdownOpen(wantOpen)
}
function handleClick() {
handleToggle(false)
}
const toggleRef = component => {
if (component) {
// eslint-disable-next-line react/no-find-dom-node
setDropdownTarget(findDOMNode(component))
}
}
return (
<Dropdown
onClick={withoutPropagation(handleClick)}
pullRight
open={dropdownOpen}
id={`dropdown-${id}`}
onToggle={handleToggle}
>
<Dropdown.Toggle
noCaret
className="dropdown-toggle-no-background entity-menu-toggle"
onClick={withoutPropagation()}
ref={toggleRef}
>
<Icon type="ellipsis-v" accessibilityLabel={t('menu')} />
</Dropdown.Toggle>
<Overlay
bsRole="menu"
show={dropdownOpen}
target={dropdownTarget}
container={document.body}
>
<Menu dropdownId={`dropdown-${id}`} />
</Overlay>
</Dropdown>
)
}
FileTreeItemMenu.propTypes = {
id: PropTypes.string.isRequired,
}
function Menu({ dropdownId, style, className }) {
return (
<div className={`dropdown open ${className}`} style={style}>
<ul className="dropdown-menu" role="menu" aria-labelledby={dropdownId}>
<FileTreeItemMenuItems />
</ul>
</div>
)
}
Menu.propTypes = {
dropdownId: PropTypes.string.isRequired,
style: PropTypes.object,
className: PropTypes.string,
}
export default FileTreeItemMenu