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

atomic-style

v0.3.2

Published

Atomic classSets and dedupe

Downloads

8

Readme

AtomicStyle

This lib provides atomic classSets and dedupes atomic classes, it is an Atomizer friendly replacement for the classNames module.

The atomic style class sets helps to remove duplication when there are many components repeating the same style over and over but it should not be overused the Atomic prefered way it to have reusable components with explicit atomic classes, the dedupe feature provided by this lib is very usefull for that.

Install

npm install --save atomic-style

How To Use?

Create some classSets to group atomic styles that are duplicated on your app.

// config/styles/btn.json
// the AtomicStyle is a simple object where the keys is the style name,
// and the values can be eather a string, object or array.
{
    // you can use an Array
    'btn': [
        'H(30px) Lh(30px)',
        'Bgc(#ccc)',
        'C(#000)',
        ... // more styles
    ],

    // you can use an String
    'btn-blue': "Bgc(blue) C(#fff)",

    // or you can use an object
    'btn-lg': {
        'H(50px)': true,
        'Lh(50px)': true
    }
}

Create a config file that load your classes.

// config/atomize.js
'use strict';

// atomize-style return a singlethon object where all your styles will be merged
var atomize = require('atomic-style');

atomize.set([
    require('./styles/btn.json'),
    require('./styles/foobar.json'),
    ... // all other styles
]);

module.exports = atomize;

Now you can use your config/atomize to get classSets and dedupe stuff.

// components/SomeComponent.jsx
var atomize = require('../config/atomize');

module.exports = React.createClass({
    displayName: 'SomeComponent',

    ...

    render: function () {
        // #dedupe can be used to merge classes
        var divClasses = atomize.dedupe('W(500px)', this.props.divClassName, {
            'W(100%)': this.props.isFullScreen
        });

        var customBtnClasses = atomize.get('btn btn-lg', {
            'C(#fff) Bgc(pink)': this.props.hasPinkBtn
        });

        return (
            <div className={divClasses}>
                <button className={atomize.get('btn')}>some button</button>
                <button className={atomize.get('btn btn-blue')}>Blue Button</button>
                <button className={customBtnClasses}>Large Custom Button</button>
            </div>
        )
    }
});

The atomize.get and atomize.dedupe both guaranty no duplication of same style, for more details and examples check the tests.

Code licensed under the MIT license. See LICENSE file for terms.