-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
implement file type icons #2550
Conversation
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. |
@@ -256,6 +256,7 @@ class FileNode extends React.Component { | |||
const isRoot = this.props.name === 'root'; | |||
|
|||
const { t } = this.props; | |||
const { extension } = parseFileName(this.props.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome that we already had a function for this!
import FileIcon from '../../../images/file.svg'; | ||
|
||
export default function FileTypeIcon({ fileExtension }) { | ||
switch (fileExtension) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great starting point!
As this evolves we'll figure out what makes sense code-wise. switch
definitely works. A dictionary object could work. That is, const icons = { html: IoLogoHtml5, /// etc. }
. If we want to use the same icon for more than one extension then if else
statements might make sense. Like if (/jsx?/i.test(fileExtension)) { return <IoLogoJavascript /> }
to match .js
and .jsx
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to use the same icon for more than one extension then if else statements might make sense. Like if (/jsx?/i.test(fileExtension)) { return } to match .js and .jsx.
In javascript, same code can be assigned to multiple cases like this:
switch (choice) {
case "1":
case "2":
console.log("test1");
break;
case "3":
console.log("test2");
}
So I think switch overall is the best way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this! I think this looks pretty good for now so I'm finally going to merge this in—any added changes can be made in future PRs! One minor additional change I made is adding the focusable' and
aria-hiddenproperties to
FileTypeIcon` for accessibility purposes.
Fixes #2542 (needs discussion about icon design)
Changes:
Added File Type Icons.
I have created a new React Component and passed the file extension as a prop. The component returns suitable icon according to the prop. I have not put much thought into choosing the icons (I have used react-icons) as the icon choice can be reviewed and discussed later. For the file types I could not find the icons for, I have set the default case to the old generic FileIcon.
I have verified that this pull request:
npm run lint
)npm run test
)develop
branch.Fixes #123