mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
9daa8f5d98
[web] rename all the JSX files to .jsx/.tsx GitOrigin-RevId: 82056ae47e017523722cf258dcc83c8a925a28f7
70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
import PropTypes from 'prop-types'
|
|
|
|
import { useSelectableEntity } from '../contexts/file-tree-selectable'
|
|
|
|
import FileTreeItemInner from './file-tree-item/file-tree-item-inner'
|
|
import { useTranslation } from 'react-i18next'
|
|
import Icon from '../../../shared/components/icon'
|
|
import iconTypeFromName from '../util/icon-type-from-name'
|
|
import classnames from 'classnames'
|
|
|
|
function FileTreeDoc({ name, id, isFile, isLinkedFile }) {
|
|
const { isSelected, props: selectableEntityProps } = useSelectableEntity(
|
|
id,
|
|
isFile
|
|
)
|
|
|
|
return (
|
|
<li
|
|
// eslint-disable-next-line jsx-a11y/role-has-required-aria-props
|
|
role="treeitem"
|
|
// aria-selected is provided in selectableEntityProps
|
|
{...selectableEntityProps}
|
|
aria-label={name}
|
|
tabIndex="0"
|
|
>
|
|
<FileTreeItemInner
|
|
id={id}
|
|
name={name}
|
|
isSelected={isSelected}
|
|
icons={<FileTreeIcon isLinkedFile={isLinkedFile} name={name} />}
|
|
/>
|
|
</li>
|
|
)
|
|
}
|
|
|
|
FileTreeDoc.propTypes = {
|
|
name: PropTypes.string.isRequired,
|
|
id: PropTypes.string.isRequired,
|
|
isFile: PropTypes.bool,
|
|
isLinkedFile: PropTypes.bool,
|
|
}
|
|
|
|
export const FileTreeIcon = ({ isLinkedFile, name }) => {
|
|
const { t } = useTranslation()
|
|
|
|
const className = classnames('spaced', 'file-tree-icon', {
|
|
'linked-file-icon': isLinkedFile,
|
|
})
|
|
|
|
return (
|
|
<>
|
|
|
|
<Icon type={iconTypeFromName(name)} fw className={className} />
|
|
{isLinkedFile && (
|
|
<Icon
|
|
type="external-link-square"
|
|
modifier="rotate-180"
|
|
className="linked-file-highlight"
|
|
accessibilityLabel={t('linked_file')}
|
|
/>
|
|
)}
|
|
</>
|
|
)
|
|
}
|
|
FileTreeIcon.propTypes = {
|
|
name: PropTypes.string.isRequired,
|
|
isLinkedFile: PropTypes.bool,
|
|
}
|
|
|
|
export default FileTreeDoc
|