Skip to content

Commit

Permalink
removing ReactDOM dependency and using regular element refs to get pa…
Browse files Browse the repository at this point in the history
…ne nodes (#292)
  • Loading branch information
wuweiweiwu authored Jul 9, 2018
1 parent d43d64c commit a7aefa5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "React split-pane component",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"source": "src/index.js",
"types": "index.d.ts",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import resolve from 'rollup-plugin-node-resolve';
import pkg from './package.json';

export default {
input: 'src/index.js',
input: pkg.source,
output: [
{
file: pkg.main,
Expand Down
8 changes: 7 additions & 1 deletion src/Pane.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Pane extends React.PureComponent {
split,
style: styleProps,
size,
eleRef,
} = this.props;

const classes = ['Pane', split, className];
Expand All @@ -38,7 +39,11 @@ class Pane extends React.PureComponent {
}

return (
<div className={classes.join(' ')} style={prefixer.prefix(style)}>
<div
ref={eleRef}
className={classes.join(' ')}
style={prefixer.prefix(style)}
>
{children}
</div>
);
Expand All @@ -52,6 +57,7 @@ Pane.propTypes = {
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
split: PropTypes.oneOf(['vertical', 'horizontal']),
style: stylePropType,
eleRef: PropTypes.func,
};

Pane.defaultProps = {
Expand Down
18 changes: 7 additions & 11 deletions src/SplitPane.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import Prefixer from 'inline-style-prefixer';
import stylePropType from 'react-style-proptype';
import { polyfill } from 'react-lifecycles-compat';
Expand Down Expand Up @@ -134,8 +133,8 @@ class SplitPane extends React.Component {
const ref = isPrimaryFirst ? this.pane1 : this.pane2;
const ref2 = isPrimaryFirst ? this.pane2 : this.pane1;
if (ref) {
const node = ReactDOM.findDOMNode(ref);
const node2 = ReactDOM.findDOMNode(ref2);
const node = ref;
const node2 = ref2;

if (node.getBoundingClientRect) {
const width = node.getBoundingClientRect().width;
Expand Down Expand Up @@ -164,11 +163,11 @@ class SplitPane extends React.Component {

let newMaxSize = maxSize;
if (maxSize !== undefined && maxSize <= 0) {
const splPane = this.splitPane;
const splitPane = this.splitPane;
if (split === 'vertical') {
newMaxSize = splPane.getBoundingClientRect().width + maxSize;
newMaxSize = splitPane.getBoundingClientRect().width + maxSize;
} else {
newMaxSize = splPane.getBoundingClientRect().height + maxSize;
newMaxSize = splitPane.getBoundingClientRect().height + maxSize;
}
}

Expand Down Expand Up @@ -318,7 +317,7 @@ class SplitPane extends React.Component {
<Pane
className={pane1Classes}
key="pane1"
ref={node => {
eleRef={node => {
this.pane1 = node;
}}
size={pane1Size}
Expand All @@ -335,17 +334,14 @@ class SplitPane extends React.Component {
onTouchStart={this.onTouchStart}
onTouchEnd={this.onMouseUp}
key="resizer"
ref={node => {
this.resizer = node;
}}
resizerClassName={resizerClassNamesIncludingDefault}
split={split}
style={resizerStyle || {}}
/>
<Pane
className={pane2Classes}
key="pane2"
ref={node => {
eleRef={node => {
this.pane2 = node;
}}
size={pane2Size}
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"react-router-dom": "^4.3.1",
"react-router-hash-link": "^1.2.0",
"react-scripts": "^2.0.0-next.66cc7a90",
"react-split-pane": "latest",
"react-split-pane": "link:..",
"resolve": "1.6.0",
"style-loader": "0.19.0",
"sw-precache-webpack-plugin": "0.11.4",
Expand Down
14 changes: 7 additions & 7 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7720,6 +7720,10 @@ [email protected]:
version "5.0.0-next.66cc7a90"
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-5.0.0-next.66cc7a90.tgz#68379b131ebe74112a12197504bfe7fa53119b3b"

react-lifecycles-compat@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"

react-router-dom@^4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-4.3.1.tgz#4c2619fc24c4fa87c9fd18f4fb4a43fe63fbd5c6"
Expand Down Expand Up @@ -7804,13 +7808,9 @@ react-scripts@^2.0.0-next.66cc7a90:
optionalDependencies:
fsevents "1.2.0"

react-split-pane@latest:
version "0.1.77"
resolved "https://registry.yarnpkg.com/react-split-pane/-/react-split-pane-0.1.77.tgz#f0c8cd18d076bbac900248dcf6dbcec02d5340db"
dependencies:
inline-style-prefixer "^3.0.6"
prop-types "^15.5.10"
react-style-proptype "^3.0.0"
"react-split-pane@link:..":
version "0.0.0"
uid ""

react-style-proptype@^3.0.0:
version "3.2.1"
Expand Down

0 comments on commit a7aefa5

Please sign in to comment.