Add substituteHoverableAtRules, previously accidentally ignored

This commit is contained in:
Adam Wathan 2017-08-28 08:23:22 -04:00
parent 7bd480a40f
commit 4b99d9e5a4

View File

@ -0,0 +1,27 @@
import _ from 'lodash'
import postcss from 'postcss'
import cloneNodes from '../util/cloneNodes'
export default function(options) {
return function(css) {
css.walkAtRules('hoverable', atRule => {
atRule.walkRules(rule => {
// Might be wise to error if the rule has multiple selectors,
// or weird compound selectors like .bg-blue>p>h1
rule.selectors = [
rule.selector,
`.\\@${rule.selector.slice(1)}:hover`,
`.\\@${rule.selector.slice(1)}:focus`
]
})
const nodes = atRule.nodes
const rules = cloneNodes(nodes)
atRule.parent.insertBefore(atRule, nodes)
atRule.remove()
})
}
}