Skip to content

Instantly share code, notes, and snippets.

@hnordt
Last active July 5, 2019 04:45
Show Gist options
  • Save hnordt/752b550f7e9afb371ad4a460d50a5826 to your computer and use it in GitHub Desktop.
Save hnordt/752b550f7e9afb371ad4a460d50a5826 to your computer and use it in GitHub Desktop.
function Spacer({ size }) {
return (
<span
className={css({
display: "block",
width: `var(--spacing-${size})`,
height: `var(--spacing-${size})`
})}
aria-hidden
/>
);
}
function InBetweenSpacing({ size, children }) {
return Children.toArray(children).map((child, index, children) => (
<Fragment key={index}>
{child.type === Fragment ? (
<InBetweenSpacing size={size}>{child.props.children}</InBetweenSpacing>
) : (
child
)}
{children[index + 1] && <Spacer size={size} />}
</Fragment>
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment