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

postcss-utilities

v0.8.4

Published

PostCSS plugin to add a collection of mixins, shortcuts, helpers and tools for your CSS

Downloads

28,585

Readme

PostCSS Utility Library Build Status

postcss-utilities is a PostCSS plugin that includes the most commonly used mixins, shortcuts and helpers. It's as easy as specifying @util utility-name in your stylesheet, and postcss-utilities will handle the rest for you.

Motivation

PostCSS has a lot of plugins and some of them use non-standard CSS properties to work as mixins or helpers. This is not a best way for a PostCSS plugin, because developers will not understand what is the source of this property.

"This plugin saves us from many tiny plugins with unknown properties" @ai proposal postcss/issues/645

What is the difference between preprocessor’s mixins libraries?

There are lot of Sass Mixins Libraries (over 65!), but postcss-utilities makes the difference. All mixins and helpers are built with JavaScript and you can add to your workflow with ease, as simple as adding autoprefixer or many others useful PostCSS plugins.

You can forget about copy mixins from project to project and focus on write your project specific mixins and use this plugin for the most generic helpers.

  • You don’t need the extra files in your CSS codebase for mixins.
  • You don’t need mixins for vendor prefixing (use autoprefixer plugin)
  • You can use postcss-utilities with LESS, SASS, vanilla CSS or whatever you choice.

List of current utilities

IMPORTANT: The list of utilities is open for suggestions.

Examples

Input


.cfx {
    @util clearfix;
}

.rounded-top {
    @util border-top-radius(4px);
}

@util no-hover {
    .box {
        background-color: #666;
    }
}

Output


.cfx:after {
    content: '';
    display: block;
    clear: both;
}

.rounded-top {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.no-hover .box {
    background-color: #666;
}

Usage

Quick usage

Using PostCSS CLI you can do the following:

Install postcss-cli and the plugin on your project directory:

npm install postcss-cli postcss-utilities --save-dev

Add a postcss script to your package.json:

"scripts": {
    "postcss": "postcss input.css -u postcss-utilities -o output.css"
}

After this, you can run npm run postcss and transform your input.css into output.css.

Use with styled-jsx

styled-jsx allows you to use full, scoped and component-friendly CSS in your JSX (rendered on the server or the client) and you can add @util rules with postcss-utilities.

npm install --save styled-jsx styled-jsx-plugin-postcss postcss-utilities

Add postcss config in your package.json:

"postcss": {
    "plugins": {
        "postcss-utilities": {}
    }
}

Add styled-jsx/babel to plugins in your babel configuration:

{
  "plugins": [
    "styled-jsx/babel"
  ]
}

Then write @util rules in your code:

export default () => (
  <div>
    <p>only this paragraph will get the style :)</p>

    <style jsx>{`
      p {
        color: red;
        @util center;
      }
    `}</style>
  </div>
)

For tasks runners and others enviroments

postcss([ require('postcss-utilities')({ /* options*/ }) ])

See PostCSS docs for examples of your environment.

Options

noHoverSelector

Type: string Default: .no-hover

To use with no-hover utility

noJsSelector

Type: string Default: .no-js

To use with no-js utility

ie8

Type: boolean Default: false

Set true to use clearfix method IE8 compatible

centerMethod

Type: string Default: transform Values: ['transform'|'flexbox']

To use with center utility

textHideMethod

Type: string Default: indent Values: ['indent'|'font']

To use with text-hide utility

Contributing

The list of utilities is open for suggestions.

Contributors