overleaf/services/web/frontend/js/features/file-tree/components/file-tree-toolbar.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

101 lines
2.4 KiB
JavaScript

import { useTranslation } from 'react-i18next'
import Icon from '../../../shared/components/icon'
import TooltipButton from '../../../shared/components/tooltip-button'
import { useFileTreeMainContext } from '../contexts/file-tree-main'
import { useFileTreeActionable } from '../contexts/file-tree-actionable'
function FileTreeToolbar() {
const { hasWritePermissions } = useFileTreeMainContext()
if (!hasWritePermissions) return null
return (
<div className="toolbar toolbar-filetree">
<FileTreeToolbarLeft />
<FileTreeToolbarRight />
</div>
)
}
function FileTreeToolbarLeft() {
const { t } = useTranslation()
const {
canCreate,
startCreatingFolder,
startCreatingDocOrFile,
startUploadingDocOrFile,
} = useFileTreeActionable()
if (!canCreate) return null
return (
<div className="toolbar-left">
<TooltipButton
id="new_file"
description={t('new_file')}
onClick={startCreatingDocOrFile}
>
<Icon type="file" modifier="fw" accessibilityLabel={t('new_file')} />
</TooltipButton>
<TooltipButton
id="new_folder"
description={t('new_folder')}
onClick={startCreatingFolder}
>
<Icon
type="folder"
modifier="fw"
accessibilityLabel={t('new_folder')}
/>
</TooltipButton>
<TooltipButton
id="upload"
description={t('upload')}
onClick={startUploadingDocOrFile}
>
<Icon type="upload" modifier="fw" accessibilityLabel={t('upload')} />
</TooltipButton>
</div>
)
}
function FileTreeToolbarRight() {
const { t } = useTranslation()
const {
canRename,
canDelete,
startRenaming,
startDeleting,
} = useFileTreeActionable()
if (!canRename && !canDelete) {
return null
}
return (
<div className="toolbar-right">
{canRename ? (
<TooltipButton
id="rename"
description={t('rename')}
onClick={startRenaming}
>
<Icon type="pencil" modifier="fw" accessibilityLabel={t('rename')} />
</TooltipButton>
) : null}
{canDelete ? (
<TooltipButton
id="delete"
description={t('delete')}
onClick={startDeleting}
>
<Icon type="trash-o" modifier="fw" accessibilityLabel={t('delete')} />
</TooltipButton>
) : null}
</div>
)
}
export default FileTreeToolbar