Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/allotment.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,34 @@
width: 100%;
}

.splitView.vertical.gap
> .splitViewContainer
> .splitViewView:not(:first-child) {
padding-top: var(--gap-size);
}

.splitView.vertical.gap
> .splitViewContainer
> .splitViewView:not(:last-child) {
padding-bottom: var(--gap-size);
}

.splitView.horizontal > .splitViewContainer > .splitViewView {
height: 100%;
}

.splitView.horizontal.gap
> .splitViewContainer
> .splitViewView:not(:first-child) {
padding-left: var(--gap-size);
}

.splitView.horizontal.gap
> .splitViewContainer
> .splitViewView:not(:last-child) {
padding-right: var(--gap-size);
}

.splitView.separatorBorder
> .splitViewContainer
> .splitViewView:not(:first-child)::before {
Expand Down
10 changes: 10 additions & 0 deletions src/allotment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export type AllotmentProps = {
children: React.ReactNode;
/** Initial size of each element */
defaultSizes?: number[];
/** The gaps (gutters) between panes */
gap?: number;
/** Resize each view proportionally when resizing container */
proportionalLayout?: boolean;
/**
Expand All @@ -122,6 +124,7 @@ const Allotment = forwardRef<AllotmentHandle, AllotmentProps>(
{
children,
className,
gap,
maxSize = Infinity,
minSize = 30,
proportionalLayout = true,
Expand Down Expand Up @@ -454,6 +457,12 @@ const Allotment = forwardRef<AllotmentHandle, AllotmentProps>(
}
}, []);

useEffect(() => {
if (gap) {
document.documentElement.style.setProperty("--gap-size", gap + "px");
}
}, [gap]);
Comment on lines +460 to +464

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If gap changed from say 5 to 0, this wouldn't change the --gap-size back to 0. Maybe prefer a nullish check? Also I think for effects that modify style, useLayoutEffect is preferred because it runs before paint.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on both points. I've not progressed this PR because it doesn't play nice with the 'real' dimensions of the panes. If you ask for a minSize of 10 then it won't account for the gap size. Which is a long-winded way of saying I need to go in and change the guts of how allotment works. Which I want to do but don't have the time right now.

The gap === 0 point is a really good one though. Just the sort of thing a code review would catch 😁

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really cool to implement this feature. I need a gap between panels in my designs. Do you have any plans to implement it?


return (
<div
ref={containerRef}
Expand All @@ -463,6 +472,7 @@ const Allotment = forwardRef<AllotmentHandle, AllotmentProps>(
styles.splitView,
vertical ? styles.vertical : styles.horizontal,
styles.separatorBorder,
{ [styles.gap]: gap !== undefined },
className
)}
>
Expand Down
13 changes: 13 additions & 0 deletions stories/basic.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,16 @@ export const PreferredSize: Story = (args) => {
);
};
PreferredSize.args = {};

export const Gap: Story = (args) => (
<div className={styles.container}>
<Allotment {...args}>
<Content />
<Content />
</Allotment>
</div>
);
Gap.args = {
gap: 10,
vertical: true,
};