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
|
|
|
|
2022-03-01 04:14:41 -05:00
|
|
|
function FileTreeDoc({ name, id, isFile, isLinkedFile }) {
|
|
|
|
const { isSelected, props: selectableEntityProps } = useSelectableEntity(
|
|
|
|
id,
|
|
|
|
isFile
|
|
|
|
)
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
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,
|
2022-03-01 04:14:41 -05:00
|
|
|
isFile: PropTypes.bool,
|
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()
|
|
|
|
|
2022-05-11 07:27:09 -04:00
|
|
|
const className = classnames('spaced', 'file-tree-icon', {
|
|
|
|
'linked-file-icon': isLinkedFile,
|
|
|
|
})
|
2022-01-19 06:56:57 -05:00
|
|
|
|
|
|
|
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
|