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

v4.1.0

Published

PostCSS plugin inherit rules from other selectors

Downloads

6,856

Readme

PostCSS Inherit

Build Status Code Climate Issue Count codecov Dependency Status Inline docs npm version


Inherit plugin for PostCSS. Allows you to inherit all the rules associated with a given selector. Modeled after rework-inherit.

API

var postcss = require('postcss');
var inherit = require('postcss-inherit')

postcss([ inherit ])
  .process(css, { from: 'src/app.css', to: 'app.css' })
  .then(function (result) {
    fs.writeFileSync('app.css', result.css);
    if ( result.map ) fs.writeFileSync('app.css.map', result.map);
  });

Inherit(options{})

Option parameters:

  • propertyRegExp - Regular expression to match the "inherit" at-rule. By default, it is /^(inherit|extend)s?:?$/i, so it matches "inherit", "inherits", "extend", and "extends". For example, if you only want to allow the extend keyword, set the regular expression to /^extend$/.

Examples

Regular inherit

.gray {
  color: gray;
}

.text {
  @inherit: .gray;
}

yields:

.gray,
.text {
  color: gray;
}

Multiple inherit

Inherit multiple selectors at the same time.

.gray {
  color: gray;
}

.black {
  color: black;
}

.button {
  @inherit: .gray, .black;
}

yields:

.gray,
.button {
  color: gray;
}

.black,
.button {
  color: black;
}

Placeholders

Any selector that includes a % is considered a placeholder. Placeholders will not be output in the final CSS.

%gray {
  color: gray;
}

.text {
  @inherit: %gray;
}

yields:

.text {
  color: gray;
}

Partial selectors

If you inherit a selector, all rules that include that selector will be included as well.

div button span {
  color: red;
}

div button {
  color: green;
}

button span {
  color: pink;
}

.button {
  @inherit: button;
}

.link {
  @inherit: div button;
}

yields:

div button span,
div .button span,
.link span {
  color: red;
}

div button,
div .button,
.link {
  color: green;
}

button span,
.button span {
  color: pink;
}

Chained inheritance

.button {
  background-color: gray;
}

.button-large {
  @inherit: .button;
  padding: 10px;
}

.button-large-red {
  @inherit: .button-large;
  color: red;
}

yields:

.button,
.button-large,
.button-large-red {
  background-color: gray;
}

.button-large,
.button-large-red {
  padding: 10px;
}

.button-large-red {
  color: red;
}

Media Queries

Inheriting from inside a media query will create a copy of the declarations. It will act like a "mixin". Thus, with %placeholders, you won't have to use mixins at all. Each type of media query will need its own declaration, so there will be some inevitable repetition.

.gray {
  color: gray
}

@media (min-width: 320px) {
  .button {
    @inherit: .gray;
  }
}

@media (min-width: 320px) {
  .link {
    @inherit: .gray;
  }
}

yields:

.gray {
  color: gray;
}

@media (min-width: 320px) {
  .button,
  .link {
    color: gray;
  }
}

Limitations

  • When in a media query, you can only inherit rules from root, or rules contained in a media query with the same parameters.