npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dibs-vg

v1.86.0

Published

1stdibs's in-house vector graphics.

Downloads

41

Readme

dibs-vg

1stdibs's in-house vector graphics. See the full list of SVGs in action HERE.

Description

Dibs VG are broken up into individual SVG files so you can require them to be inlined in your HTML, or required directly in your client side JS for easy use. Instructions on how to do the latter follow.

We also provide some basic styling and wrapper modules for React and Backbone.

Contributing :

Please view the guide on contributing here.

Using inline SVG files :

With REACT / JSX :

Require Precompiled react component (recommended):

This is our recommended method because you don't have to do any setup to start requiring SVG files. This is particularly important if you plan on running your modules in a node environment (ie. unit tests). Pre-compiled react components are available in any environment that supports JSX.

React components are compiled and placed in dist/react, and for users who don't code in React we build template strings into the dist/templateString directory.

Each pre-compiled React component supports a className prop so that you can specify styling.

const svgComponent = require('dibs-vg/dist/react/account-filled.js');
const stringSvg = require('dibs-vg/dist/templateString/account-filled.es.js');

Require these files directly in your modules and use just like you would any React component or string for inserting into pages. Pre-compiled React components accept a className prop so you can apply custom styling.

loading with Webpack (not recommended):

You don't have to use pre-compiled modules. If you want to grab the raw SVG files and manipulate them go ahead, or if you want to use webpack to load the SVG files, use the method(s) below.

If you are using Webpack, and want to render your SVG with React we recommend svg-react-loader which will allow you to require your SVG files direclty in your JS as React components.

Configuration for svg-react-loader looks like this (see gotcha below, via their documentation) :

module.exports = {
    loaders: [
        { test: /\.svg$/, loader: 'babel!svg-react' }
    ],
    resolve: {
        alias: {
            react-dom: __dirname + '/node_modules/react'
        }
    }
}

One gotcha I ran into while implementing is that svg-react-loader requires that you also use babel loader, so this line :

{ test: /\.svg$/, loader: 'babel!svg-react' }

will not work if you already have babel configured as a loader in your config. To solve, add ".svg" to the list of extensions to match against, and remove it from that line to end up with something like :

module.exports = {
    loaders: [
        { test: /\.(js|jsx|svg)$/, loader: 'babel' },
        { test: /\.svg$/, loader: 'svg-react' }
    ],
    resolve: {
        alias: {
            react-dom: __dirname + '/node_modules/react'
        }
    }
}

Now that that's out of the way, require your icon and let it rip :

const Icon = require('dibs-vg/src/bell.svg');
// ...
<Icon className={myKlass} />;

Use it with the icon wraper React component :

const IconWrapper = require('dibs-vg/js/SvgComponent');
const Icon = require('dibs-vg/src/bell.svg');
// ...
<IconWrapper className="icon-spin" size={25} title={'Weeee! Weeeeeeeee!'}>
    <Icon />
</IconWrapper>;

In Backbone :

Require the precompiled string version directly :

require the string and pass it into the template or append it to the dom using jquery

const stringSvg = require('dibs-vg/dist/templateString/account-filled.es.js');

With webpack:

If you are using Webpack and want to render your SVG with Backbone we recommend using the html loader which returns the SVG file as a string, or the webpack compile templates loader which will transform the SVG file to an underscore template.

var SvgWrapper = require('dibs-vg/js/SvgWrapper.es.js');
const icon = require('!html!dibs-vg/src/bell.svg');

$('.place').append(
    new SvgWrapper({
        icon: icon,
        className: 'some-thing',
        size: '25',
        title: 'Flerg! I did it!',
    }).render().el
);

Versioning :

New icons added to the set will be considered a minor version bump. Changes to existing icons will be a major version.

Customize it, style it, resize it :

Inline SVGs are great, not only because they're more performant, but they're also easier for developers to manipulate. Of course you can scale them infinitely in either direction just by changing some CSS, but having different paths inside of your SVG files also allows you to apply colors or other transformations to individual parts of the SVG. Check out this example :

Gotchas :

  • A SVG will not be compiled into the dist folder properly if the opening <svg> tag contains the xml:space="preserve" attribute.
  • The SVGs automatically have styling that adds height: 100% and width: 100%. In non-IE11 browsers, setting just one of those to an explicit value (e.g. height: 25px) on the containing element correctly sizes the svg container. However, IE11 adds whitespace in the dimension that was not explicitly set. To fix this, make sure to add sizes to both dimension (e.g. height: 25px; width: 25px;).