Created
May 4, 2020 01:54
-
-
Save roginfarrer/6a35ecc87feb08af852f1c7f91bd58eb to your computer and use it in GitHub Desktop.
Support styled-system object breakpoints
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 breakpoints = { | |
all: '_', | |
bp320: '320px', | |
bp480: '480px' | |
} | |
export const transformAliasProps = props => { | |
let result = {}; | |
for (let prop in props) { | |
if (typeof props[prop] === "object" && !Array.isArray(props[prop])) { | |
let propOrQuery = prop; | |
if (breakpoints[prop]) { | |
propOrQuery = `@media screen and (min-width: ${breakpoints[prop]})` | |
} | |
result = { ...result, [propOrQuery]: transformAliasProps(props[prop]) }; | |
} else { | |
result = { ...result, ...transformAlias(prop, props[prop]) }; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment