Created
December 4, 2018 05:50
-
-
Save siddharthkp/73a910f91212a10b21d53cb3a0b280d6 to your computer and use it in GitHub Desktop.
temp
This file contains hidden or 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
import { spacing } from '@auth0/cosmos-tokens' | |
const directions = ['top', 'bottom', 'left', 'right'] | |
/* this helper gets all the props of the component */ | |
const margin = ({ margin = {} }) => { | |
let styles = '' | |
directions.map(direction => { | |
if (typeof margin[direction] !== 'undefined') { | |
let rawValue = margin[direction] | |
let value | |
/* | |
if the value is a string, it's either a token (xsmall) | |
or has units (8em) | |
if it's a number, we assume it's pixels | |
*/ | |
if (typeof rawValue === 'string') { | |
if (spacing[rawValue]) value = spacing[rawValue] | |
else value = rawValue | |
} else { | |
value = rawValue + 'px' | |
} | |
// syntax: margin-top: margin.top | |
styles += `margin-${direction}: ${value};` | |
} | |
}) | |
return styles | |
} | |
export default margin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment