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

superbem

v0.1.5

Published

Superbem is a very simple Sass tool for writing BEM-ish CSS with ease.

Downloads

50

Readme

Superbem

Superbem is a very simple Sass tool for writing BEM-ish CSS with ease.

The problem

There's a couple of tricks in Sass that community uses to simplify writing styles in the BEM fashion. Maybe you've been using & to avoid repeating yourself?

.my-block {
    &__my-element {
        // ...
    }

    &--my-modifier {
        // ...
    }
}

It compiles to:

.my-block__my-element {
    // ...
}

.my-block--my-modifier {
    // ...
}

It's fine, at least until you'd like your block's modifier to affect it's element:

.my-block {
    &--my-modifier {
        &__element {
            // ...
        }
    }
}

Above effects in:

.my-block--my-modifier__my-element {}

Not cool. In this case, to modify "my-block", you'd not only have to add a modifier class to itself, but also to all of it's elements you want to change in some way.

There's a simple trick we use to overcome this issue - assigning the block's root class to a variable and using like so:

.my-block {
    $block: &;

    &--my-modifier {
        #{$block}__element {
            // ...
        }
    }
}

Now on the output we have:

.my-block--my-modifier .my-block__my-element {
    // ...
}

Above method does the job, however this syntax is pretty imperative. Superbem gives you another, easy and declarative way.

The solution

To achieve the same result, Superbem brings a syntax like this:

@include block(my-block) {
    @include modifier(my-modifier) {
        @include element(my-element) {
            // ...
        }
    }
}

The blocks and the elements make scopes, when modifiers only live inside the scope of the classes they modify. Everywhere in the hierarchy you can access the current scope through the $this variable. Let's look:

@include block(my-block) {
    // $this called in here is "my-block"

    @include modifier(my-modifier) {
        // $this called in here is "my-block"

        @include element(my-element) {
            // $this called in here is "my-block__my-element"

            @include modifier(my-modifier) {
                // $this called in here is "my-block__my-element"
            }
        }
    }
}

Moreover, your modifiers inherit all of the features of the original blocks and elements. It means no more class="my-block my-block--my-modifier". With Superbem class="my-block--my-modifier" is just enough.

Using

At first install Superbem with NPM:

npm install superbem --save

Then import it in your Sass file:

@import 'path/to/node_modules/superbem/superbem';

That's it!

Extras

In addition Superbem comes with three mixins supporting styling with CSS combinators:

@include block(my-block) {
    @include element(my-element) {
        // ...
    }

    @include element(my-second-element) {
        @include is-after(my-element) {
            // ...
        }

        @include is-preceded-by(my-element) {
            // ...
        }

        @include is-inside(my-element) {
            // ...
        }
    }
}

Which output is:

.my-block__my-element {
    // ...
}

.my-block__my-element + .my-block__my-second-element {
    // ...
}

.my-block__my-element ~ .my-block__my-second-element {
    // ...
}

.my-block__my-element > .my-block__my-second-element {
    // ...
}

License

MIT