-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
implement file type icons #2550
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { IoLogoHtml5, IoLogoCss3, IoLogoJavascript } from 'react-icons/io'; | ||
import { TbFileTypeXml, TbTxt, TbCsv } from 'react-icons/tb'; | ||
import { VscJson } from 'react-icons/vsc'; | ||
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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In javascript, same code can be assigned to multiple cases like this:
So I think switch overall is the best way. |
||
case '.html': | ||
return ( | ||
<span> | ||
<IoLogoHtml5 /> | ||
</span> | ||
); | ||
case '.css': | ||
return ( | ||
<span> | ||
<IoLogoCss3 /> | ||
</span> | ||
); | ||
case '.js': | ||
return ( | ||
<span> | ||
<IoLogoJavascript /> | ||
</span> | ||
); | ||
case '.json': | ||
return ( | ||
<span> | ||
<VscJson /> | ||
</span> | ||
); | ||
case '.xml': | ||
return ( | ||
<span> | ||
<TbFileTypeXml /> | ||
</span> | ||
); | ||
case '.txt': | ||
return ( | ||
<span> | ||
<TbTxt /> | ||
</span> | ||
); | ||
case '.csv': | ||
return ( | ||
<span> | ||
<TbCsv /> | ||
</span> | ||
); | ||
default: | ||
return <FileIcon focusable="false" aria-hidden="true" />; | ||
} | ||
} | ||
|
||
FileTypeIcon.propTypes = { | ||
fileExtension: PropTypes.string.isRequired | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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!