fileIcon.tsx 789 B

123456789101112131415161718192021222324252627282930
  1. import {IconFile} from 'sentry/icons';
  2. import {fileExtensionToPlatform, getFileExtension} from 'sentry/utils/fileExtension';
  3. import theme from 'sentry/utils/theme';
  4. type Props = {
  5. fileName: string;
  6. className?: string;
  7. size?: string;
  8. };
  9. const FileIcon = ({fileName, size: providedSize = 'sm', className}: Props) => {
  10. const fileExtension = getFileExtension(fileName);
  11. const iconName = fileExtension ? fileExtensionToPlatform(fileExtension) : null;
  12. const size = theme.iconSizes[providedSize] ?? providedSize;
  13. if (!iconName) {
  14. return <IconFile size={size} className={className} />;
  15. }
  16. return (
  17. <img
  18. src={require(`platformicons/svg/${iconName}.svg`)}
  19. width={size}
  20. height={size}
  21. className={className}
  22. />
  23. );
  24. };
  25. export default FileIcon;