2020-11-26 09:22:30 -05:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import { useSelectableEntity } from '../contexts/file-tree-selectable'
|
|
|
|
|
|
|
|
import FileTreeItemInner from './file-tree-item/file-tree-item-inner'
|
2022-01-19 06:56:57 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import iconTypeFromName from '../util/icon-type-from-name'
|
|
|
|
import classnames from 'classnames'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
function FileTreeDoc({ name, id, isLinkedFile }) {
|
|
|
|
const { isSelected, props: selectableEntityProps } = useSelectableEntity(id)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li
|
|
|
|
role="treeitem"
|
|
|
|
{...selectableEntityProps}
|
|
|
|
aria-label={name}
|
|
|
|
tabIndex="0"
|
|
|
|
>
|
|
|
|
<FileTreeItemInner
|
|
|
|
id={id}
|
|
|
|
name={name}
|
|
|
|
isSelected={isSelected}
|
2022-01-19 06:56:57 -05:00
|
|
|
icons={<FileTreeIcon isLinkedFile={isLinkedFile} name={name} />}
|
2020-11-26 09:22:30 -05:00
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeDoc.propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
id: PropTypes.string.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
isLinkedFile: PropTypes.bool,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
2022-01-19 06:56:57 -05:00
|
|
|
export const FileTreeIcon = ({ isLinkedFile, name }) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const className = classnames('spaced', { '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,
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
export default FileTreeDoc
|