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

v5.0.0

Published

A better way to manage z-indexes

Downloads

453

Readme

PostCSS Stack

A better way to manage z-indexes

NPM Version Build Status Dependency Status

Define the stack of components and PostCSS Stack will resolve the z-indexes for you instead of playing a game of z-index: 99999.

/* input */
.modal {
  z-index: stack('modal');
}

.tool-tip {
  z-index: stack('tool-tip');
}

.element-beneath {
  z-index: stack('beneath');
}
/* output */
.modal {
  z-index: 2;
}

.tool-tip {
  z-index: 1;
}

.element-beneath {
  z-index: -1;
}

Install

# npm
npm install --save-dev postcss postcss-stack

# or yarn
yarn add --dev postcss postcss-stack

Usage

Add it to your PostCSS work-flow, whatever way you choose to.

// Using a postcss.config.js
const stack = require('postcss-stack');

module.exports = {
  plugins: [
    stack({
      list: [
        { 'beneath': -1 },
        'application',
        'tool-tip',
        'modal'
      ]
    })
  ]
};

Then call the stack function with relevant item name in your css.

/* input */
.application {
  z-index: stack('application');
}
/* output */
.application {
  z-index: 0;
}

See tests for more examples.

Options

option | type | default | description :--- |:--- |:--- |:--- list | array or function | [] | Array of items in the stack or function returning array of items increment | number | 1 | The increment value

list

The list of items that defines the stack. An item can either be explicitly defined by a name key and z-index value or by a name string that will have it's z-index auto-generated.

stack({
  list: [
    { 'explicit': -10 }, // stack('explicit') => z-index: -10
    'auto', // stack('auto') => z-index: 0
    'generated', // stack('generated') => z-index: 1
  ]
});

By default it's ordered by the order of the array, but you can use Array.prototype.reverse() to better visualize how the stack is set.

stack({
  list: [
    { 'beneath': -1 }, // z-index: -1
    'application', // z-index: 0
    'tool-tip',  // z-index: 1
    'modal'  // z-index: 2
  ]
});

// Reversed
stack({
  list: [
    'modal' // z-index: 2
    'tool-tip', // z-index: 1
    'application', // z-index: 0
    { 'beneath': -1 }, // z-index: -1
  ].reverse();
});

increment

Allows a increment value to be set. For example if increment: 100, the output of our example would be:

.modal {
  z-index: 200;
}

.tool-tip {
  z-index: 100;
}

.element-beneath {
  z-index: -1;
}

Stacking Context

Remember that stacking context is relative to the parent, so if you have a parent element that is z-index: 2 and a child of z-index: 1, the child will not be below the parent but instead relative to any other stacking context of that parent.

For more information on stacking context, MDN has a good overview.

License