From 81d82b4c08c2a25c46ae4840737468604c83650c Mon Sep 17 00:00:00 2001 From: Brent Jackson Date: Mon, 28 Aug 2017 17:11:06 -0400 Subject: [PATCH 1/5] Add css prop support --- src/component.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/component.js b/src/component.js index e3f3a1ef..c0691e87 100644 --- a/src/component.js +++ b/src/component.js @@ -4,7 +4,10 @@ const cxs = require('./index') module.exports = C => (...args) => { const Comp = (props, context) => { - const stylePropKeys = Object.keys(Comp.propTypes || {}) + const stylePropKeys = [ + ...Object.keys(Comp.propTypes || {}), + 'css' + ] const styleProps = Object.assign({ theme: context.theme }, props) const next = {} @@ -16,7 +19,8 @@ module.exports = C => (...args) => { next.className, ...args.map(a => typeof a === 'function' ? a(styleProps) : a) .filter(s => s !== null) - .map(s => cxs(s)) + .map(s => cxs(s)), + cxs(props.css || {}) ].join(' ').trim() return h(C, next) From cdfee6516deca434472733cf56bf603601d2ad1a Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Wed, 6 Sep 2017 12:03:19 +0200 Subject: [PATCH 2/5] Remove unused dependencies --- package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/package.json b/package.json index c25e9243..e757e06c 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,6 @@ "keywords": [], "author": "Brent Jackson", "license": "MIT", - "dependencies": { - "objss": "^1.0.3", - "tag-hoc": "^1.0.0-0" - }, "devDependencies": { "ava": "^0.21.0", "babel-cli": "^6.24.1", From b66691c664596bee553737e11099374f58836795 Mon Sep 17 00:00:00 2001 From: Aaron Boyd Date: Wed, 20 Sep 2017 15:14:58 -0700 Subject: [PATCH 3/5] add cxs.prefix to config class prefix --- src/index.js | 4 +++- test/cxs.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c91b30b8..bf4c483e 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ const parse = (obj, child = '', media) => } const _key = key + val + child + media if (cache[_key]) return cache[_key] - const className = 'x' + (rules.length).toString(36) + const className = module.exports.prefix + (rules.length).toString(36) insert(mx(rx(className + noAnd(child), key, val), media)) cache[_key] = className return className @@ -35,6 +35,8 @@ module.exports.reset = () => { while (rules.length) rules.pop() } +module.exports.prefix = 'x'; + if (typeof document !== 'undefined') { const sheet = document.head.appendChild( document.createElement('style') diff --git a/test/cxs.js b/test/cxs.js index f3149e7d..92ed2c89 100644 --- a/test/cxs.js +++ b/test/cxs.js @@ -1,8 +1,11 @@ import test from 'ava' import cxs from '../src' +const originalPrefix = cxs.prefix; + test.afterEach.always(() => { cxs.reset() + cxs.prefix = originalPrefix; }) test('exports a function', t => { @@ -119,3 +122,13 @@ test('media rules stay in order', t => { t.regex(css, /^\.x0/) t.regex(css, /@media/) }) + +test("cxs.prefix defaults to 'x'", t => { + t.is(cxs.prefix, 'x' ) +}) + +test('uses custom prefix', t => { + cxs.prefix = '_cxs'; + cxs({ color: 'tomato' }) + t.is(cxs.css(), '._cxs0{color:tomato}') +}) From bbda440162a7cc0ad480341c779bf90da3de5692 Mon Sep 17 00:00:00 2001 From: Aaron Boyd Date: Mon, 30 Oct 2017 10:18:47 -0700 Subject: [PATCH 4/5] remove trailing semicolons --- src/index.js | 2 +- test/cxs.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index bf4c483e..d209d257 100644 --- a/src/index.js +++ b/src/index.js @@ -35,7 +35,7 @@ module.exports.reset = () => { while (rules.length) rules.pop() } -module.exports.prefix = 'x'; +module.exports.prefix = 'x' if (typeof document !== 'undefined') { const sheet = document.head.appendChild( diff --git a/test/cxs.js b/test/cxs.js index 92ed2c89..f814196c 100644 --- a/test/cxs.js +++ b/test/cxs.js @@ -1,11 +1,11 @@ import test from 'ava' import cxs from '../src' -const originalPrefix = cxs.prefix; +const originalPrefix = cxs.prefix test.afterEach.always(() => { cxs.reset() - cxs.prefix = originalPrefix; + cxs.prefix = originalPrefix }) test('exports a function', t => { @@ -128,7 +128,7 @@ test("cxs.prefix defaults to 'x'", t => { }) test('uses custom prefix', t => { - cxs.prefix = '_cxs'; + cxs.prefix = '_cxs' cxs({ color: 'tomato' }) t.is(cxs.css(), '._cxs0{color:tomato}') }) From cacb3416839d01cb6878970b8aaad3ba09fe63bf Mon Sep 17 00:00:00 2001 From: Aaron Boyd Date: Mon, 30 Oct 2017 10:30:51 -0700 Subject: [PATCH 5/5] change cxs.prefix to a function, like monolithic --- src/index.js | 5 +++-- test/cxs.js | 10 ++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index d209d257..1d20873a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ let cache = {} +let prefix = 'x' const rules = [] let insert = rule => rules.push(rule) const hyph = s => s.replace(/[A-Z]|^ms/g, '-$&').toLowerCase() @@ -17,7 +18,7 @@ const parse = (obj, child = '', media) => } const _key = key + val + child + media if (cache[_key]) return cache[_key] - const className = module.exports.prefix + (rules.length).toString(36) + const className = prefix + (rules.length).toString(36) insert(mx(rx(className + noAnd(child), key, val), media)) cache[_key] = className return className @@ -35,7 +36,7 @@ module.exports.reset = () => { while (rules.length) rules.pop() } -module.exports.prefix = 'x' +module.exports.prefix = val => prefix = val if (typeof document !== 'undefined') { const sheet = document.head.appendChild( diff --git a/test/cxs.js b/test/cxs.js index f814196c..0c0d4816 100644 --- a/test/cxs.js +++ b/test/cxs.js @@ -1,11 +1,9 @@ import test from 'ava' import cxs from '../src' -const originalPrefix = cxs.prefix - test.afterEach.always(() => { cxs.reset() - cxs.prefix = originalPrefix + cxs.prefix('x') }) test('exports a function', t => { @@ -123,12 +121,12 @@ test('media rules stay in order', t => { t.regex(css, /@media/) }) -test("cxs.prefix defaults to 'x'", t => { - t.is(cxs.prefix, 'x' ) +test('cxs.prefix is a function', t => { + t.is(typeof cxs.prefix, 'function' ) }) test('uses custom prefix', t => { - cxs.prefix = '_cxs' + cxs.prefix('_cxs') cxs({ color: 'tomato' }) t.is(cxs.css(), '._cxs0{color:tomato}') })