@@ -3,25 +3,14 @@ import React from 'react';
33import { useTheme } from '../../contexts/themeContext/ThemeContext' ;
44
55import { Audio } from '../../icons/Audio' ;
6- import { CSV } from '../../icons/CSV ' ;
6+ import { Code } from '../../icons/Code ' ;
77import { DOC } from '../../icons/DOC' ;
8- import { DOCX } from '../../icons/DOCX' ;
9- import { GenericFile } from '../../icons/GenericFile' ;
10- import { HTML } from '../../icons/HTML' ;
11- import { MD } from '../../icons/MD' ;
12- import { ODT } from '../../icons/ODT' ;
8+ import { OtherFileIcon } from '../../icons/OtherFileIcon' ;
139import { PDF } from '../../icons/PDF' ;
14- import { PPT } from '../../icons/PPT' ;
15- import { PPTX } from '../../icons/PPTX' ;
16- import { RAR } from '../../icons/RAR' ;
17- import { RTF } from '../../icons/RTF' ;
18- import { SEVEN_Z } from '../../icons/SEVEN_Z' ;
19- import { TAR } from '../../icons/TAR' ;
20- import { TXT } from '../../icons/TXT' ;
10+ import { Presentation } from '../../icons/Presentation' ;
11+ import { SpreadSheet } from '../../icons/SpreadSheet' ;
2112import type { IconProps } from '../../icons/utils/base' ;
2213import { Video } from '../../icons/Video' ;
23- import { XLS } from '../../icons/XLS' ;
24- import { XLSX } from '../../icons/XLSX' ;
2514import { ZIP } from '../../icons/ZIP' ;
2615
2716// https://www.iana.org/assignments/media-types/media-types.xhtml#audio
@@ -203,9 +192,7 @@ const docMimeTypes = [
203192 'application/vnd.oasis.opendocument.text-flat-xml' ,
204193 // .uot
205194 // NOTE: firefox doesn't know mimetype so maybe ignore
206- ] ;
207195
208- const docXMimeTypes = [
209196 // Microsoft Word
210197 // .docx
211198 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ,
@@ -215,6 +202,14 @@ const docXMimeTypes = [
215202 'application/vnd.ms-word.document.macroEnabled.12' ,
216203 // .dotm (no test)
217204 'application/vnd.ms-word.template.macroEnabled.12' ,
205+
206+ // LibreOffice/OpenOffice Writer
207+ // .odt
208+ 'application/vnd.oasis.opendocument.text' ,
209+ // .ott
210+ 'application/vnd.oasis.opendocument.text-template' ,
211+ // .fodt
212+ 'application/vnd.oasis.opendocument.text-flat-xml' ,
218213] ;
219214
220215const excelMimeTypes = [
@@ -229,9 +224,7 @@ const excelMimeTypes = [
229224 'application/vnd.oasis.opendocument.spreadsheet-template' ,
230225 // .fods
231226 'application/vnd.oasis.opendocument.spreadsheet-flat-xml' ,
232- ] ;
233227
234- const excelXMimeTypes = [
235228 // .xlsx
236229 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ,
237230 // .xltx (no test)
@@ -246,16 +239,6 @@ const excelXMimeTypes = [
246239 'application/vnd.ms-excel.addin.macroEnabled.12' ,
247240] ;
248241
249- const odtMimeTypes = [
250- // LibreOffice/OpenOffice Writer
251- // .odt
252- 'application/vnd.oasis.opendocument.text' ,
253- // .ott
254- 'application/vnd.oasis.opendocument.text-template' ,
255- // .fodt
256- 'application/vnd.oasis.opendocument.text-flat-xml' ,
257- ] ;
258-
259242const powerpointMimeTypes = [
260243 // Microsoft Word
261244 // .ppt .pot .pps .ppa (no test for .ppa)
@@ -270,9 +253,7 @@ const powerpointMimeTypes = [
270253 'application/vnd.oasis.opendocument.presentation-flat-xml' ,
271254 // .uop
272255 // NOTE: firefox doesn't know mimetype so maybe ignore
273- ] ;
274256
275- const powerpointXMimeTypes = [
276257 // .pptx
277258 'application/vnd.openxmlformats-officedocument.presentationml.presentation' ,
278259 // .potx (no test)
@@ -289,7 +270,12 @@ const powerpointXMimeTypes = [
289270 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' ,
290271] ;
291272
292- const tarFileTypes = [
273+ const zipFileTypes = [
274+ // .gzip
275+ 'application/gzip' ,
276+ // .zip
277+ 'application/zip' ,
278+
293279 // .ar
294280 'application/x-archive' ,
295281 // .tar
@@ -314,13 +300,6 @@ const tarFileTypes = [
314300 'application/x-webarchive' ,
315301] ;
316302
317- const zipFileTypes = [
318- // .gzip
319- 'application/gzip' ,
320- // .zip
321- 'application/zip' ,
322- ] ;
323-
324303const videoFileTypes = [
325304 'video/3g2' ,
326305 'video/3gp' ,
@@ -361,15 +340,17 @@ const videoFileTypes = [
361340 'video/x-flv' ,
362341] ;
363342
343+ const codeFileTypes = [
344+ 'text/html' ,
345+ 'text/css' ,
346+ 'text/javascript' ,
347+ 'text/xml' ,
348+ 'text/csv' ,
349+ 'text/plain' ,
350+ ] ;
351+
364352const mimeTypeToIconMap : Record < string , React . ComponentType < IconProps > > = {
365353 'application/pdf' : PDF , // .pdf
366- 'application/rtf' : RTF , // .rtf
367- 'application/vnd.rar' : RAR , // .rar
368- 'application/x-7z-compressed' : SEVEN_Z , // .z7
369- 'text/csv' : CSV , // .csv
370- 'text/html' : HTML , // .html .htm
371- 'text/markdown' : MD , // .md
372- 'text/plain' : TXT , // .txt
373354} ;
374355
375356for ( const type of audioFileTypes ) {
@@ -380,32 +361,12 @@ for (const type of docMimeTypes) {
380361 mimeTypeToIconMap [ type ] = DOC ;
381362}
382363
383- for ( const type of docXMimeTypes ) {
384- mimeTypeToIconMap [ type ] = DOCX ;
385- }
386-
387364for ( const type of excelMimeTypes ) {
388- mimeTypeToIconMap [ type ] = XLS ;
389- }
390-
391- for ( const type of excelXMimeTypes ) {
392- mimeTypeToIconMap [ type ] = XLSX ;
393- }
394-
395- for ( const type of odtMimeTypes ) {
396- mimeTypeToIconMap [ type ] = ODT ;
365+ mimeTypeToIconMap [ type ] = SpreadSheet ;
397366}
398367
399368for ( const type of powerpointMimeTypes ) {
400- mimeTypeToIconMap [ type ] = PPT ;
401- }
402-
403- for ( const type of powerpointXMimeTypes ) {
404- mimeTypeToIconMap [ type ] = PPTX ;
405- }
406-
407- for ( const type of tarFileTypes ) {
408- mimeTypeToIconMap [ type ] = TAR ;
369+ mimeTypeToIconMap [ type ] = Presentation ;
409370}
410371
411372for ( const type of zipFileTypes ) {
@@ -416,25 +377,48 @@ for (const type of videoFileTypes) {
416377 mimeTypeToIconMap [ type ] = Video ;
417378}
418379
380+ for ( const type of codeFileTypes ) {
381+ mimeTypeToIconMap [ type ] = Code ;
382+ }
383+
419384function mimeTypeToIcon ( mimeType ?: string ) : React . ComponentType < IconProps > {
420385 if ( ! mimeType ) {
421- return GenericFile ;
386+ return OtherFileIcon ;
422387 }
423388
424389 const Icon = mimeTypeToIconMap [ mimeType ] ;
425390 if ( Icon ) {
426391 return Icon ;
427392 }
428393
429- return GenericFile ;
394+ return OtherFileIcon ;
430395}
431396
432397export type FileIconProps = {
433398 mimeType ?: string ;
434- size ?: number ;
399+ size ?: 'sm' | 'md' | 'lg' ;
400+ } ;
401+
402+ const sizeToNumber = ( size ?: 'sm' | 'md' | 'lg' ) => {
403+ if ( size === 'sm' ) {
404+ return {
405+ height : 24 ,
406+ width : 19 ,
407+ } ;
408+ }
409+ if ( size === 'md' ) {
410+ return {
411+ height : 40 ,
412+ width : 32 ,
413+ } ;
414+ }
415+ return {
416+ height : 48 ,
417+ width : 40 ,
418+ } ;
435419} ;
436420
437- export const FileIcon = ( { mimeType, size } : FileIconProps ) => {
421+ export const FileIcon = ( { mimeType, size = 'md' } : FileIconProps ) => {
438422 const {
439423 theme : {
440424 messageSimple : {
@@ -445,7 +429,7 @@ export const FileIcon = ({ mimeType, size }: FileIconProps) => {
445429
446430 const Icon = mimeTypeToIcon ( mimeType ) ;
447431
448- return < Icon { ...( size ? { height : size , width : size } : { } ) } { ...icon } /> ;
432+ return < Icon { ...( size ? sizeToNumber ( size ) : { } ) } { ...icon } /> ;
449433} ;
450434
451435FileIcon . displayName = 'FileIcon{messageSimple{file{icon}}}' ;
0 commit comments