file-tree-doc.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import PropTypes from 'prop-types'
  2. import { useTranslation } from 'react-i18next'
  3. import Icon from '../../../shared/components/icon'
  4. import iconTypeFromName from '../util/icon-type-from-name'
  5. import { useSelectableEntity } from '../contexts/file-tree-selectable'
  6. import FileTreeItemInner from './file-tree-item/file-tree-item-inner'
  7. function FileTreeDoc({ name, id, isLinkedFile }) {
  8. const { t } = useTranslation()
  9. const { isSelected, props: selectableEntityProps } = useSelectableEntity(id)
  10. const icons = (
  11. <>
  12. <Icon
  13. type={iconTypeFromName(name)}
  14. modifier="fw"
  15. classes={{ icon: 'spaced' }}
  16. >
  17. {isLinkedFile ? (
  18. <Icon
  19. type="external-link-square"
  20. modifier="rotate-180"
  21. classes={{ icon: 'linked-file-highlight' }}
  22. accessibilityLabel={t('linked_file')}
  23. />
  24. ) : null}
  25. </Icon>
  26. </>
  27. )
  28. return (
  29. <li
  30. role="treeitem"
  31. {...selectableEntityProps}
  32. aria-label={name}
  33. tabIndex="0"
  34. >
  35. <FileTreeItemInner
  36. id={id}
  37. name={name}
  38. isSelected={isSelected}
  39. icons={icons}
  40. />
  41. </li>
  42. )
  43. }
  44. FileTreeDoc.propTypes = {
  45. name: PropTypes.string.isRequired,
  46. id: PropTypes.string.isRequired,
  47. isLinkedFile: PropTypes.bool,
  48. }
  49. export default FileTreeDoc