file-tree-icon.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { useTranslation } from 'react-i18next'
  2. import iconTypeFromName, {
  3. newEditorIconTypeFromName,
  4. } from '../util/icon-type-from-name'
  5. import classnames from 'classnames'
  6. import MaterialIcon from '@/shared/components/material-icon'
  7. import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
  8. function FileTreeIcon({
  9. isLinkedFile,
  10. name,
  11. }: {
  12. name: string
  13. isLinkedFile?: boolean
  14. }) {
  15. const { t } = useTranslation()
  16. const className = classnames('file-tree-icon', {
  17. 'linked-file-icon': isLinkedFile,
  18. })
  19. const newEditor = useIsNewEditorEnabled()
  20. if (newEditor) {
  21. return (
  22. <>
  23. <MaterialIcon
  24. unfilled
  25. type={newEditorIconTypeFromName(name)}
  26. className={className}
  27. />
  28. {isLinkedFile && (
  29. <MaterialIcon
  30. type="open_in_new"
  31. modifier="rotate-180"
  32. className="linked-file-highlight"
  33. accessibilityLabel={t('linked_file')}
  34. />
  35. )}
  36. </>
  37. )
  38. }
  39. return (
  40. <>
  41. &nbsp;
  42. <MaterialIcon type={iconTypeFromName(name)} className={className} />
  43. {isLinkedFile && (
  44. <MaterialIcon
  45. type="open_in_new"
  46. modifier="rotate-180"
  47. className="linked-file-highlight"
  48. accessibilityLabel={t('linked_file')}
  49. />
  50. )}
  51. </>
  52. )
  53. }
  54. export default FileTreeIcon