file-tree-doc.js 1.3 KB

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