Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active April 17, 2020 10:53
Show Gist options
  • Save vincentorback/1dbf671de067589bc48869969e929e15 to your computer and use it in GitHub Desktop.
Save vincentorback/1dbf671de067589bc48869969e929e15 to your computer and use it in GitHub Desktop.
List z-index values
const postcss = require('postcss')
module.exports = postcss.plugin('postcss-zindex', (options) => {
return (css) => {
let nodes = []
// TODO: Some options?
// Get all z-index declarations
css.walkDecls('z-index', (decl, i) => {
nodes.push({
selector: decl.parent.selector,
value: parseInt(decl.value)
})
})
// Sort them by weight
nodes.sort((a, b) => {
if (a.value < b.value) {
return 1
}
if (a.value > b.value) {
return -1
}
return 0
})
// Log them
nodes.forEach(node => {
console.log(node.selector + ' ' + node.value)
})
}
})
@vincentorback
Copy link
Author

Example output:

.Head 9999
.Menu 123
.Foo .Foo-item 99
.Bar 1
.Thing -1

@davidpelayo
Copy link

Awesome! I like it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment