Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@drawbotics/file-icons
Advanced tools
npm install @drawbotics/file-icons
A simple library to display icons depending on the file type. The library can be used both by importing the stylesheet (useful if you have a simple project without React dependencies), and also exports a React component.
DISCLAIMER
In order to have a single div usage, and given the complexity of the icon look, a lot of CSS features that may not be compatible with older browsers is used. Namely linear-gradient
, border-image
and clip-path
. Nonetheless, all the styles are prefixed.
There are two ways to use the icons: with a simple div
or with a React component. Either way, you should include the stylesheet to have the icons style:
@import '~@drawbotics/file-icons/dist/style.css';
You can use file-icons
just by importing the css styling and using a div
as a base element. Add the class file-icon
to your div and set the file type as a data attribute data-file
:
<div className="file-icon" data-file="docx" />
Note: The file extension needs to be in lower case.
You can also pass different class names for different sizes:
<div className="file-icon file-icon--medium" data-file="3ds" />
<div className="file-icon file-icon--large" data-file="rar" />
Example icons with default, medium and large sizing.
You can import the component anywhere in your code through:
import { FileIcon } from '@drawbotics/file-icons';
If you use CSSinJS then don't forget to include the stylesheet if you haven't already
import '@drawbotics/file-icons/dist/style.css';
And use it like such:
<FileIcon file="pdf" />
Here are the different options you can pass:
Prop | Type | Description | Possible values |
---|---|---|---|
file | String | File extension without the dot | .doc |
size | String | To toggle between the 3 sizes | medium , large |
filename | String | If you don't want to extract the extension yourself you can pass the filename directly | my-document.pdf |
When using the React component you don't need to worry if the extension/filename is lowercase, the component takes care of that.
Any file extension that does not match the ones included with the library will fallback to the default grey color. Each category has its own color. The supported extension is a subset of the provided value, meaning that docx
is supported since we look for doc
.
Category | Possible values |
---|---|
Archives | zip , rar , tar , dmg , jar |
3D Files | 3ds , dwg , obj , dae , skp , fbx |
Text Documents | doc , rtf , txt , odt , tex , |
Vector graphics | ai , svg |
pdf | |
Data | xml , csv , xls |
Images | jpg , gif , png , jpeg , tif , psd , raw |
Video | webm , mkv , avi , mov , m4v , mpeg , mp4 |
Audio | mp3 , m4a , ogg , acc , flac |
If you want to add support for an extension, or support a new category of files don't hesitate to submit a PR. More extensions and categories will be added through time.
npm install
To run examples
npm run build:watch # for build step
npm run example # to serve examples
To build for production
npm run build
MIT. See LICENSE for details.
FAQs
Small icon library for file type icons
The npm package @drawbotics/file-icons receives a total of 97 weekly downloads. As such, @drawbotics/file-icons popularity was classified as not popular.
We found that @drawbotics/file-icons demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.