From 22cd6706615f5dbf74442b9ef5131fc2eabee11a Mon Sep 17 00:00:00 2001 From: John Grishin Date: Sat, 9 Jun 2018 09:14:28 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20themeSelector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 1 + src/utils/helpers.js | 18 +++++++++++++----- test/{prop-selector.js => selectors.js} | 0 3 files changed, 14 insertions(+), 5 deletions(-) rename test/{prop-selector.js => selectors.js} (100%) diff --git a/src/index.js b/src/index.js index d27f253..dc53850 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ export { propSelector, propSelector as ps, combineSelectors as cs, + themeSelector as ts, sizeValue, spaceValue, skipPropValue diff --git a/src/utils/helpers.js b/src/utils/helpers.js index b299479..fb1fddb 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -25,14 +25,21 @@ const handlePropStyle = (style, value, ...args) => isFn(style) ? style(value, ...args) : value === true ? style : null -const propSelector = curryN(2, (name, value) => (style, ...args) => ({ - [name]: handlePropStyle(style, value, ...args) +const propSelector = curryN(2, (name, value) => (style, props, mediaKey) => ({ + [name]: handlePropStyle(style, value, props, mediaKey) })) -const combineSelectors = (...selectors) => (style, ...args) => selectors.map( +const themeSelector = (fn) => (style = identity, props, mediaKey) => handlePropStyle( + style, + fn(props.theme), + props, + mediaKey +) + +const combineSelectors = (...selectors) => (style, props, mediaKey) => selectors.map( (selectorOrValue) => isFn(selectorOrValue) - ? selectorOrValue(style, ...args) - : handlePropStyle(style, selectorOrValue, ...args) + ? selectorOrValue(style, props, mediaKey) + : handlePropStyle(style, selectorOrValue, props, mediaKey) ) const wrapIfMedia = (query, style) => wrap( @@ -64,6 +71,7 @@ export { combineSelectors, handlePropStyle, sizeValue, + themeSelector, spaceValue, skipPropValue } diff --git a/test/prop-selector.js b/test/selectors.js similarity index 100% rename from test/prop-selector.js rename to test/selectors.js