Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created May 10, 2020 22:27
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 kyleshevlin/9b2326a76305b9ae55b3d8702c336c07 to your computer and use it in GitHub Desktop.
Save kyleshevlin/9b2326a76305b9ae55b3d8702c336c07 to your computer and use it in GitHub Desktop.
One of my favorite features of EmotionJS
// One of my favorite things about using Emotion for CSS-in-JS is the
// ability to put nested CSS selectors write into my components.
// Ignoring my use of `bs()` from my ShevyJS library (it just mathematically
// calculates spacing based on my vertical rhythm config), this is such
// a simple way to tell this div to space these links out if they're both
// present. I love it.
function MyComponent() {
return (
// ... lots of other code
// Right here, neighboring links need some space!
<div css={{ 'a + a': { marginLeft: bs(0.5) } }}>
{justEnoughDevUrl && (
<LinkButton href={justEnoughDevUrl}>
View on JustEnoughDev
</LinkButton>
)}
{eggheadUrl && (
<LinkButton href={eggheadUrl + EGGHEAD_AFFILIATE_QUERY_PARAM}>
View on egghead.io
</LinkButton>
)}
</div>
// ... more code here
)
}
// :chefs_kiss: it just works perfectly. Such a nice API!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment