Git Product home page Git Product logo

file-icons's Introduction

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:

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.

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.

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 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.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.