Skip to content

feat: add file extension based icons #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion packages/react/src/core/FileTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
}

function File({ file: { depth, name }, onClick, selected }: FileProps) {
const fileIcon = name ? getFileTreeIcon(name) : '';
return (
<NodeButton
className={classNames('group transition-theme', {
Expand All @@ -192,7 +193,7 @@
selected,
})}
depth={depth}
iconClasses={classNames('i-ph-file-duotone', {
iconClasses={classNames(fileIcon, {
'text-tk-elements-fileTree-file-iconColor group-hover:text-tk-elements-fileTree-file-iconColorHover': !selected,
'text-tk-elements-fileTree-file-iconColorSelected': selected,
})}
Expand Down Expand Up @@ -358,3 +359,48 @@

return 0;
}

function getFileTreeIcon(fileName: string) {
const extension = fileName.split('.').at(-1);

if (!extension) {
console.error('Cannot infer file type');
return '';
}

switch (extension) {
case 'ts': {
return 'i-ph-file-ts-duotone';
}
case 'cjs':
case 'mjs':
case 'js': {
return 'i-ph-file-js-duotone';
}
case 'html': {
return 'i-ph-file-html-duotone';
}
case 'css': {
return 'i-ph-file-css-duotone';
}
// case 'scss':

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 18)

Expected a block comment instead of consecutive line comments

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 18)

Expected line before comment

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 20)

Expected a block comment instead of consecutive line comments

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 20)

Expected line before comment

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 22)

Expected a block comment instead of consecutive line comments

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 22)

Expected line before comment

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (macos-latest, 20)

Expected a block comment instead of consecutive line comments

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (macos-latest, 20)

Expected line before comment

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (windows-latest, 20.13.1)

Expected a block comment instead of consecutive line comments

Check failure on line 386 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (windows-latest, 20.13.1)

Expected line before comment
// case 'sass': {
// return 'i-languages-sass?mask';
// }
case 'md': {
return 'i-ph-file-md-duotone';
}
// case 'json': {

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 18)

Expected a block comment instead of consecutive line comments

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 18)

Expected line before comment

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 20)

Expected a block comment instead of consecutive line comments

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 20)

Expected line before comment

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 22)

Expected a block comment instead of consecutive line comments

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 22)

Expected line before comment

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (macos-latest, 20)

Expected a block comment instead of consecutive line comments

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (macos-latest, 20)

Expected line before comment

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (windows-latest, 20.13.1)

Expected a block comment instead of consecutive line comments

Check failure on line 393 in packages/react/src/core/FileTree.tsx

View workflow job for this annotation

GitHub Actions / Test (windows-latest, 20.13.1)

Expected line before comment
// return 'i-languages-json?mask';
// }
case 'gif':
case 'jpg':
case 'jpeg':
case 'png': {
return 'i-ph-file-image-duotone';
}
default: {
return 'i-ph-file-duotone';
}
}
}
Loading