Skip to content

Instantly share code, notes, and snippets.

@siddharthkp
Created December 4, 2018 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siddharthkp/73a910f91212a10b21d53cb3a0b280d6 to your computer and use it in GitHub Desktop.
Save siddharthkp/73a910f91212a10b21d53cb3a0b280d6 to your computer and use it in GitHub Desktop.
temp
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