Skip to content

Commit

Permalink
✨ Add themeSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
exah committed Jun 9, 2018
1 parent ee145b1 commit 22cd670
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
propSelector,
propSelector as ps,
combineSelectors as cs,
themeSelector as ts,
sizeValue,
spaceValue,
skipPropValue
Expand Down
18 changes: 13 additions & 5 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -64,6 +71,7 @@ export {
combineSelectors,
handlePropStyle,
sizeValue,
themeSelector,
spaceValue,
skipPropValue
}
File renamed without changes.

0 comments on commit 22cd670

Please sign in to comment.