file-tree-icon.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { useTranslation } from 'react-i18next'
  2. import Icon from '../../../shared/components/icon'
  3. import iconTypeFromName, {
  4. newEditorIconTypeFromName,
  5. } from '../util/icon-type-from-name'
  6. import classnames from 'classnames'
  7. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  8. import MaterialIcon from '@/shared/components/material-icon'
  9. import { useFeatureFlag } from '@/shared/context/split-test-context'
  10. function FileTreeIcon({
  11. isLinkedFile,
  12. name,
  13. }: {
  14. name: string
  15. isLinkedFile?: boolean
  16. }) {
  17. const { t } = useTranslation()
  18. const className = classnames('file-tree-icon', {
  19. 'linked-file-icon': isLinkedFile,
  20. })
  21. const newEditor = useFeatureFlag('editor-redesign')
  22. if (newEditor) {
  23. return (
  24. <>
  25. <MaterialIcon
  26. unfilled
  27. type={newEditorIconTypeFromName(name)}
  28. className={className}
  29. />
  30. {isLinkedFile && (
  31. <MaterialIcon
  32. type="open_in_new"
  33. modifier="rotate-180"
  34. className="linked-file-highlight"
  35. accessibilityLabel={t('linked_file')}
  36. />
  37. )}
  38. </>
  39. )
  40. }
  41. return (
  42. <>
  43. &nbsp;
  44. <BootstrapVersionSwitcher
  45. bs3={
  46. <>
  47. <Icon type={iconTypeFromName(name)} fw className={className} />
  48. {isLinkedFile && (
  49. <Icon
  50. type="external-link-square"
  51. modifier="rotate-180"
  52. className="linked-file-highlight"
  53. accessibilityLabel={t('linked_file')}
  54. />
  55. )}
  56. </>
  57. }
  58. bs5={
  59. <>
  60. <MaterialIcon type={iconTypeFromName(name)} className={className} />
  61. {isLinkedFile && (
  62. <MaterialIcon
  63. type="open_in_new"
  64. modifier="rotate-180"
  65. className="linked-file-highlight"
  66. accessibilityLabel={t('linked_file')}
  67. />
  68. )}
  69. </>
  70. }
  71. />
  72. </>
  73. )
  74. }
  75. export default FileTreeIcon