create space between panes inside a container #1488
-
This seems a fairly simple task and maybe I'm overthinking it but I can't achieve the result I want. In pure css you can use the adjacent selector to give margins to all the elements but the first one
This helps when you have a bunch of elements inside a container and you want to create some space between them. However when using evergreen I would like to not use additional css sheets if possible and so I was wondering if there is a way to achieve the same result with the css-in-js style of evergreen, right now I have:
and I would like to add some space between my panes, of course I can do:
but obviously this is not DRY, what if I have like 10 panes? Other solution is create a wrapper component just to apply that style but that seems very unpractical. So is there a way to achieve the same result that the adjacent selector produce? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @GhostOrder28! While we don't have something out of the box that can do this, you could do this by pulling in import { Pane, PaneProps } from "evergreen-ui";
import React from "react";
import { css } from "glamor";
interface SpaceProps {
props: Pick<
PaneProps,
| "margin"
| "marginBottom"
| "marginLeft"
| "marginRight"
| "marginTop"
| "marginX"
| "marginY"
>;
children: React.ReactNode;
}
const Space: React.FC<SpaceProps> = (props) => {
const { props: paneProps, children } = props;
const className = css({
"& > *": paneProps
}).toString();
return <Pane className={className}>{children}</Pane>;
};
// ...
<Space props={{ marginTop: 10 }}>
<Pane />
<Pane />
<Pane />
</Space> You could also leverage import { Pane, PaneProps } from "evergreen-ui";
import React from "react";
interface SpaceProps
extends Pick<
PaneProps,
| "margin"
| "marginBottom"
| "marginLeft"
| "marginRight"
| "marginTop"
| "marginX"
| "marginY"
> {
children: React.ReactNode;
}
const Space: React.FC<SpaceProps> = (props) => {
const { children, ...paneProps } = props;
return (
<React.Fragment>
{React.Children.map(children, (child) => {
if (React.isValidElement(child) && child.type === Pane) {
return React.cloneElement(child, paneProps);
}
return child;
})}
</React.Fragment>
);
};
// ...
<Space marginTop={10}>
<Pane />
<Pane />
<Pane />
</Space> |
Beta Was this translation helpful? Give feedback.
Hey @GhostOrder28! While we don't have something out of the box that can do this, you could do this by pulling in
glamor
and making a utility component for spacing with something like this: