@@ -19,6 +19,25 @@ interface Props {
19
19
className ?: string ;
20
20
}
21
21
22
+ const extensionsToIcons = new Map ( [
23
+ [ 'ts' , 'i-ph-file-ts-duotone' ] ,
24
+
25
+ [ 'cjs' , 'i-ph-file-js-duotone' ] ,
26
+ [ 'mjs' , 'i-ph-file-js-duotone' ] ,
27
+ [ 'js' , 'i-ph-file-js-duotone' ] ,
28
+
29
+ [ 'html' , 'i-ph-file-html-duotone' ] ,
30
+
31
+ [ 'css' , 'i-ph-file-css-duotone' ] ,
32
+
33
+ [ 'md' , 'i-ph-file-md-duotone' ] ,
34
+
35
+ [ 'gif' , 'i-ph-file-image-duotone' ] ,
36
+ [ 'jpg' , 'i-ph-file-image-duotone' ] ,
37
+ [ 'jpeg' , 'i-ph-file-image-duotone' ] ,
38
+ [ 'png' , 'i-ph-file-image-duotone' ] ,
39
+ ] ) ;
40
+
22
41
export function FileTree ( {
23
42
files,
24
43
onFileSelect,
@@ -183,7 +202,8 @@ interface FileProps {
183
202
}
184
203
185
204
function File ( { file : { depth, name } , onClick, selected } : FileProps ) {
186
- const fileIcon = name ? getFileTreeIcon ( name ) : '' ;
205
+ const extension = getFileExtension ( name ) ;
206
+ const fileIcon = extensionsToIcons . get ( extension ) || 'i-ph-file-duotone' ;
187
207
return (
188
208
< NodeButton
189
209
className = { classNames ( 'group transition-theme' , {
@@ -360,47 +380,12 @@ function compareString(a: string, b: string) {
360
380
return 0 ;
361
381
}
362
382
363
- function getFileTreeIcon ( fileName : string ) {
364
- const extension = fileName . split ( '.' ) . at ( - 1 ) ;
383
+ function getFileExtension ( filename : string ) {
384
+ const parts = filename . split ( '.' ) ;
365
385
366
- if ( ! extension ) {
367
- console . error ( 'Cannot infer file type' ) ;
368
- return '' ;
369
- }
386
+ parts . shift ( ) ;
370
387
371
- switch ( extension ) {
372
- case 'ts' : {
373
- return 'i-ph-file-ts-duotone' ;
374
- }
375
- case 'cjs' :
376
- case 'mjs' :
377
- case 'js' : {
378
- return 'i-ph-file-js-duotone' ;
379
- }
380
- case 'html' : {
381
- return 'i-ph-file-html-duotone' ;
382
- }
383
- case 'css' : {
384
- return 'i-ph-file-css-duotone' ;
385
- }
386
- // case 'scss':
387
- // case 'sass': {
388
- // return 'i-languages-sass?mask';
389
- // }
390
- case 'md' : {
391
- return 'i-ph-file-md-duotone' ;
392
- }
393
- // case 'json': {
394
- // return 'i-languages-json?mask';
395
- // }
396
- case 'gif' :
397
- case 'jpg' :
398
- case 'jpeg' :
399
- case 'png' : {
400
- return 'i-ph-file-image-duotone' ;
401
- }
402
- default : {
403
- return 'i-ph-file-duotone' ;
404
- }
405
- }
388
+ const extension = parts . at ( - 1 ) || '' ;
389
+
390
+ return extension ;
406
391
}
0 commit comments