file-tree-doc.js 1.6 KB

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