From bf8738e0b13e277a5337dd9f5671aaf047158247 Mon Sep 17 00:00:00 2001 From: davvidbaker Date: Wed, 27 Jun 2018 14:18:11 -0600 Subject: [PATCH 1/5] use src files in storybook, not lib --- stories/index.stories.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stories/index.stories.js b/stories/index.stories.js index a1fd46df..4d29b270 100644 --- a/stories/index.stories.js +++ b/stories/index.stories.js @@ -4,8 +4,8 @@ import { storiesOf } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import { linkTo } from '@storybook/addon-links'; -import SplitPane from '../lib/SplitPane'; -import Pane from "../lib/Pane"; +import SplitPane from '../src/SplitPane'; +import Pane from "../src/Pane"; import { Button, Welcome } from '@storybook/react/demo'; From a007bdca010ff61cc1e603d57209775c85c0c8d2 Mon Sep 17 00:00:00 2001 From: davvidbaker Date: Wed, 27 Jun 2018 14:24:34 -0600 Subject: [PATCH 2/5] don't break when a child is null --- src/SplitPane.js | 19 ++++++++++++------- stories/index.stories.js | 8 ++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/SplitPane.js b/src/SplitPane.js index ccbf014b..a50e1488 100755 --- a/src/SplitPane.js +++ b/src/SplitPane.js @@ -47,6 +47,10 @@ function toPx(value, unit = 'px', size) { } } +function removeNullChildren(children) { + return React.Children.toArray(children).filter(c => c); +} + export function getUnit(size) { if(size.endsWith('px')) { return 'px'; @@ -187,7 +191,7 @@ class SplitPane extends Component { const minSizes = this.getPanePropMinMaxSize(props, 'minSize'); const maxSizes = this.getPanePropMinMaxSize(props, 'maxSize'); - const resizersSize = this.getResizersSize(); + const resizersSize = this.getResizersSize(removeNullChildren(this.props.children)); const splitPaneSizePx = split === 'vertical' ? splitPaneDimensions.width - resizersSize : splitPaneDimensions.height - resizersSize; @@ -207,7 +211,7 @@ class SplitPane extends Component { } getPanePropSize(props) { - return React.Children.map(props.children, child => { + return removeNullChildren(props.children).map(child => { const value = child.props['size'] || child.props['initialSize']; if (value === undefined) { return DEFAULT_PANE_SIZE; @@ -218,7 +222,7 @@ class SplitPane extends Component { } getPanePropMinMaxSize(props, key) { - return React.Children.map(props.children, child => { + return removeNullChildren(props.children).map(child => { const value = child.props[key]; if (value === undefined) { return key === 'maxSize' ? DEFAULT_PANE_MAX_SIZE : DEFAULT_PANE_MIN_SIZE; @@ -338,16 +342,17 @@ class SplitPane extends Component { this.paneElements[idx] = el; } - getResizersSize() { - return (React.Children.count(this.props.children) - 1) * this.props.resizerSize; + getResizersSize(children) { + return (children.length - 1) * this.props.resizerSize; } render() { const { children, className, split } = this.props; + const notNullChildren = removeNullChildren(this.props.children) const sizes = this.getSizes(); - const resizersSize = this.getResizersSize(); + const resizersSize = this.getResizersSize(notNullChildren); - const elements = children.reduce((acc, child, idx) => { + const elements = notNullChildren.reduce((acc, child, idx) => { let pane; const resizerIndex = idx - 1; const isPane = child.type === Pane; diff --git a/stories/index.stories.js b/stories/index.stories.js index 4d29b270..f01abe92 100644 --- a/stories/index.stories.js +++ b/stories/index.stories.js @@ -37,4 +37,12 @@ storiesOf('Horizontal', module) This is a Pane This is a Pane + ) + .add('with a null child', () => + + {false &&
This is a div
} +
This is a div
+
This is a div
+
); + \ No newline at end of file From eef835aa6c430e5635c685ccef541243c2d25f24 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 23 Jul 2018 09:52:37 -0600 Subject: [PATCH 3/5] Remove changes to storybook --- stories/index.stories.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/stories/index.stories.js b/stories/index.stories.js index f01abe92..fd0ded23 100644 --- a/stories/index.stories.js +++ b/stories/index.stories.js @@ -4,8 +4,8 @@ import { storiesOf } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import { linkTo } from '@storybook/addon-links'; -import SplitPane from '../src/SplitPane'; -import Pane from "../src/Pane"; +import SplitPane from '../lib/SplitPane'; +import Pane from "../lib/Pane"; import { Button, Welcome } from '@storybook/react/demo'; @@ -37,12 +37,5 @@ storiesOf('Horizontal', module) This is a Pane This is a Pane - ) - .add('with a null child', () => - - {false &&
This is a div
} -
This is a div
-
This is a div
-
); - \ No newline at end of file + From 641bba693d3b6b364e73e791ccf89ccfd652f413 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 23 Jul 2018 09:53:04 -0600 Subject: [PATCH 4/5] Remove changes to storybook From 93d07cd8a7457bb76a77bb8fe7b245c5150a6751 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 23 Jul 2018 09:53:28 -0600 Subject: [PATCH 5/5] Remove changes to storybook --- stories/index.stories.js | 1 - 1 file changed, 1 deletion(-) diff --git a/stories/index.stories.js b/stories/index.stories.js index fd0ded23..a1fd46df 100644 --- a/stories/index.stories.js +++ b/stories/index.stories.js @@ -38,4 +38,3 @@ storiesOf('Horizontal', module) This is a Pane ); -