Created
August 12, 2017 22:04
-
-
Save jxnblk/8759924538ae3aaf6f3f081ae4e4b636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rules = [] | |
let insert = rule => rules.push(rule) | |
const cxs = (css, opts = {}) => { | |
const { | |
child = '', | |
media | |
} = opts | |
const className = opts.className || '_' + rules.length | |
const rule = '.' + className + child + '{' + css + '}' | |
if (!media) { | |
insert(rule) | |
} else { | |
const mediaRule = media + '{' + rule + '}' | |
insert(mediaRule) | |
} | |
return { | |
toString: () => className, | |
push: (style, opts) => cxs(style, Object.assign(opts, { className })) | |
} | |
} | |
if (typeof document !== 'undefined') { | |
const sheet = document.head.appendChild( | |
document.createElement('style') | |
).sheet | |
insert = rule => { | |
rules.push(rule) | |
sheet.insertRule(rule, sheet.cssRules.length) | |
} | |
} | |
module.exports.css = () => rules.join('') | |
module.exports = cxs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment