Socket
Socket
Sign inDemoInstall

@drawbotics/file-icons

Package Overview
Dependencies
9
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @drawbotics/file-icons

Small icon library for file type icons


Version published
Weekly downloads
199
decreased by-19.43%
Maintainers
2
Install size
101 kB
Created
Weekly downloads
 

Readme

Source

File Icons

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.

Usage

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';
Pure 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.

React

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:

PropTypeDescriptionPossible values
fileStringFile extension without the dot.doc
sizeStringTo toggle between the 3 sizesmedium, large
filenameStringIf you don't want to extract the extension yourself you can pass the filename directlymy-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.

Supported file types

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.

CategoryPossible values
Archiveszip, rar, tar, dmg, jar
3D Files3ds, dwg, obj, dae, skp, fbx
Text Documentsdoc, rtf, txt, odt, tex,
Vector graphicsai, svg
PDFpdf
Dataxml, csv, xls
Imagesjpg, gif, png, jpeg, tif, psd, raw
Videowebm, mkv, avi, mov, m4v, mpeg, mp4
Audiomp3, 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.

Develop

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

License

MIT. See LICENSE for details.

FAQs

Last updated on 14 Feb 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc