Skip to content

Instantly share code, notes, and snippets.

@jepser
Last active May 28, 2019 21:25
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 jepser/6bfd5205a46fc541607845e250cc3da5 to your computer and use it in GitHub Desktop.
Save jepser/6bfd5205a46fc541607845e250cc3da5 to your computer and use it in GitHub Desktop.
const Spacer = ({
top, left, bottom, right, children, sm, md, lg, xl,
}) => {
return (
<Root
top={ top }
left={ left }
bottom={ bottom }
right={ right }
sm={sm}
md={md}
lg={lg}
xl={xl}
>
{children}
</Root>
);
};
// styled-components.js
const baseStyles = ({ top, left, right, bottom }) => css`
margin-top: ${top ? unitizedPx(top) : null};
margin-right: ${right ? unitizedPx(right) : null};
margin-bottom: ${bottom ? unitizedPx(bottom) : null};
margin-left: ${left ? unitizedPx(left) : null};
`;
export const Root = styled.div`
${({ top, left, right, bottom, sm, md, lg, xl }) => `
${baseStyles({ top, left, right, bottom })}
${sm && baseStyles(sm)}
${md && baseStyles(md)}
${lg && baseStyles(lg)}
${xl && baseStyles(xl)}
`}
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment