Comparing version 1.0.0-0 to 1.0.0-1
72
index.js
@@ -26,3 +26,4 @@ /** | ||
const get = require('lodash.get') | ||
import get from 'lodash.get' | ||
const createMediaQuery = n => `@media screen and (min-width:${n})` | ||
@@ -35,7 +36,11 @@ const defaultBreakpoints = [ 40, 52, 64 ].map(n => n + 'em') | ||
const getValue = (props, keys) => keys.reduce((a, key) => { | ||
return get(a, key, a) | ||
}, props) | ||
const getValue = (props, keys) => { | ||
let value = null | ||
for (let i = 0; i < keys.length; i++) { | ||
value = get(props, keys[i], value) | ||
} | ||
return value | ||
} | ||
const style = ({ | ||
export const style = ({ | ||
breakpoints = defaultBreakpoints, | ||
@@ -48,7 +53,5 @@ scale, | ||
const mediaQueries = breakpoints.map(createMediaQuery) | ||
const aliases = alias.split('|') | ||
const func = props => { | ||
// const value = get(props, prop, get(props, alias)) | ||
const value = getValue(props, [ prop, ...aliases ]) | ||
const value = getValue(props, [ prop, alias ]) | ||
scale = get(props.theme, scale) || scale | ||
@@ -62,8 +65,6 @@ const createStyle = n => is(n) && ({ | ||
const styles = [ | ||
createStyle(value[0]) | ||
] | ||
let styles = createStyle(value[0]) | ||
for (let i = 1; i < value.slice(0, breakpoints.length + 1).length; i++) { | ||
styles.push({ | ||
styles = merge(styles, { | ||
[mediaQueries[i - 1]]: createStyle(value[i]) | ||
@@ -75,2 +76,8 @@ }) | ||
} | ||
func.props = [ | ||
prop, | ||
alias, | ||
] | ||
return func | ||
@@ -80,5 +87,40 @@ } | ||
// space transforms | ||
// const compose | ||
module.exports = style | ||
module.exports.style = style | ||
export const merge = (a, b) => { | ||
if (!b) return a | ||
const result = {} | ||
for (const key in a) { | ||
result[key] = a[key] | ||
} | ||
for (const key in b) { | ||
if (typeof b[key] !== 'object' || !a[key]) { | ||
result[key] = b[key] | ||
} else { | ||
result[key] = merge(a[key], b[key]) | ||
} | ||
} | ||
return result | ||
} | ||
export const compose = (...funcs) => { | ||
const dict = {} | ||
funcs.forEach(func => { | ||
func.props.forEach(prop => { | ||
dict[prop] = func | ||
}) | ||
}) | ||
const composed = props => { | ||
let style = {} | ||
for (const key in props) { | ||
if (!dict[key]) continue | ||
style = merge(style, dict[key](props)) | ||
} | ||
return style | ||
} | ||
return composed | ||
} | ||
export const mapProps = (func, mapper) => props => | ||
func(merge(mapper(props), props)) | ||
export default style |
{ | ||
"name": "@2s/core", | ||
"version": "1.0.0-0", | ||
"version": "1.0.0-1", | ||
"description": "", | ||
"type": "module", | ||
"main": "index.js", | ||
"module": "index.js", | ||
"author": "Brent Jackson <jxnblk@gmail.com>", | ||
@@ -7,0 +9,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2656
104
Yes