icons.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. export const getIconByContentType = (type?: Maybe<string>) => {
  3. if (!type) return 'mobile-file'
  4. const contentType = type.replace(/^(.+?\/.+?)(\b|\s).+?$/, '$1')
  5. const icons: Record<string, string> = {
  6. // #image
  7. 'image/jpeg': 'mobile-photos',
  8. 'image/jpg': 'mobile-photos',
  9. 'image/png': 'mobile-photos',
  10. 'image/svg': 'mobile-photos',
  11. 'image/gif': 'mobile-photos',
  12. // # documents
  13. 'application/pdf': 'mobile-library',
  14. 'application/msword': 'mobile-template', // .doc, .dot
  15. 'application/vnd.ms-word': 'mobile-template',
  16. 'application/vnd.oasis.opendocument.text': 'mobile-template',
  17. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
  18. 'mobile-template', // .docx
  19. 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
  20. 'mobile-template', // .dotx
  21. 'application/vnd.ms-excel': 'mobile-file', // .xls
  22. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
  23. 'mobile-file', // .xlsx
  24. 'application/vnd.oasis.opendocument.spreadsheet': 'mobile-file',
  25. 'application/vnd.ms-powerpoint': 'mobile-file', // .ppt
  26. 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
  27. 'mobile-file', // .pptx
  28. 'application/vnd.oasis.opendocument.presentation': 'mobile-file',
  29. 'text/plain': 'mobile-template',
  30. 'text/html': 'mobile-template',
  31. 'application/json': 'mobile-template',
  32. 'message/rfc822': 'mobile-mail-out',
  33. 'text/rtf': 'mobile-template',
  34. 'text/calendar': 'mobile-calendar',
  35. // # archives
  36. 'application/gzip': 'mobile-attachment',
  37. 'application/zip': 'mobile-attachment',
  38. }
  39. return icons[contentType] || 'mobile-file'
  40. }