@@ -183,6 +183,7 @@ interface FileProps {
183
183
}
184
184
185
185
function File ( { file : { depth, name } , onClick, selected } : FileProps ) {
186
+ const fileIcon = name ? getFileTreeIcon ( name ) : '' ;
186
187
return (
187
188
< NodeButton
188
189
className = { classNames ( 'group transition-theme' , {
@@ -192,7 +193,7 @@ function File({ file: { depth, name }, onClick, selected }: FileProps) {
192
193
selected ,
193
194
} ) }
194
195
depth = { depth }
195
- iconClasses = { classNames ( 'i-ph-file-duotone' , {
196
+ iconClasses = { classNames ( fileIcon , {
196
197
'text-tk-elements-fileTree-file-iconColor group-hover:text-tk-elements-fileTree-file-iconColorHover' : ! selected ,
197
198
'text-tk-elements-fileTree-file-iconColorSelected' : selected ,
198
199
} ) }
@@ -358,3 +359,48 @@ function compareString(a: string, b: string) {
358
359
359
360
return 0 ;
360
361
}
362
+
363
+ function getFileTreeIcon ( fileName : string ) {
364
+ const extension = fileName . split ( '.' ) . at ( - 1 ) ;
365
+
366
+ if ( ! extension ) {
367
+ console . error ( 'Cannot infer file type' ) ;
368
+ return '' ;
369
+ }
370
+
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
+ }
406
+ }
0 commit comments