Skip to content

Commit 98acab5

Browse files
author
zuqiang.you
committedJul 28, 2022
✨ feat: 更新组件和依赖
1 parent 489216b commit 98acab5

File tree

5 files changed

+71
-83
lines changed

5 files changed

+71
-83
lines changed
 

‎package.json

+7-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dist",
1010
"index.d.ts"
1111
],
12-
"version": "1.0.2",
12+
"version": "1.0.3",
1313
"repository": {
1414
"type": "git",
1515
"url": "https://github.com/yozojo/react-split-pane-next"
@@ -28,7 +28,7 @@
2828
"es6"
2929
],
3030
"scripts": {
31-
"start": "parcel website/index.html",
31+
"start": "parcel build/index.html",
3232
"prebuild": "yarn run clean",
3333
"build": "rollup -c",
3434
"build:watch": "rollup -c --watch",
@@ -41,17 +41,17 @@
4141
"deploy": "gh-pages -d build"
4242
},
4343
"dependencies": {
44-
"inline-style-prefixer": "^4.0.0",
45-
"prop-types": "^15.7.2",
46-
"styled-components": "^2.4.0"
44+
"inline-style-prefixer": "^6.0.1",
45+
"prop-types": "^15.8.1",
46+
"styled-components": "^5.3.5",
47+
"react": "^17.0.2",
48+
"react-dom": "^17.0.2"
4749
},
4850
"devDependencies": {
4951
"@babel/core": "^7.7.2",
5052
"@babel/plugin-transform-modules-commonjs": "^7.7.0",
5153
"@babel/preset-env": "^7.7.1",
5254
"@babel/preset-react": "^7.7.0",
53-
"@emotion/core": "^10.0.22",
54-
"@emotion/styled": "^10.0.23",
5555
"@storybook/addons": "^5.3.17",
5656
"@storybook/react": "^5.3.17",
5757
"@storybook/theming": "^5.3.17",
@@ -80,18 +80,11 @@
8080
"parcel-bundler": "^1.12.4",
8181
"prettier": "2.0.5",
8282
"pretty-quick": "^2.0.1",
83-
"react": ">=15",
84-
"react-dom": "^16.0.0-0",
85-
"react-router-dom": "^5.1.2",
8683
"rimraf": "^3.0.0",
8784
"rollup": "^2.3.4",
8885
"rollup-plugin-babel": "^4.3.3",
8986
"rollup-plugin-commonjs": "^10.1.0",
9087
"rollup-plugin-node-resolve": "^5.2.0",
9188
"standard-version": "^7.0.0"
92-
},
93-
"peerDependencies": {
94-
"react": "^16.0.0-0",
95-
"react-dom": "^16.0.0-0"
9689
}
9790
}

‎rollup.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ export default {
2424
exports: 'named',
2525
},
2626
],
27-
external: [
28-
...Object.keys(pkg.dependencies),
29-
...Object.keys(pkg.peerDependencies),
30-
],
27+
external: [...Object.keys(pkg.dependencies)],
3128
plugins: [
3229
babel({
3330
exclude: 'node_modules/**',

‎src/Pane.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
33

44
import prefixAll from 'inline-style-prefixer/static';
5-
6-
import { getUnit, convertSizeToCssValue } from './SplitPane';
5+
import { getUnit, convertSizeToCssValue } from './utils';
76

87
function PaneStyle({
98
split,

‎src/SplitPane.js

+4-63
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from 'styled-components';
44

55
import Resizer from './Resizer';
66
import Pane from './Pane';
7+
import { getUnit, convertToUnit, convert } from './utils';
78

89
const DEFAULT_PANE_SIZE = '1';
910
const DEFAULT_PANE_MIN_SIZE = '0';
@@ -29,69 +30,9 @@ const RowStyle = styled.div`
2930
user-select: text;
3031
`;
3132

32-
function convert(str, size) {
33-
const tokens = str.match(/([0-9]+)([px|%]*)/);
34-
const value = tokens[1];
35-
const unit = tokens[2];
36-
return toPx(value, unit, size);
37-
}
38-
39-
function toPx(value, unit = 'px', size) {
40-
switch (unit) {
41-
case '%': {
42-
return +((size * value) / 100).toFixed(2);
43-
}
44-
default: {
45-
return +value;
46-
}
47-
}
48-
}
49-
5033
function removeNullChildren(children) {
5134
return React.Children.toArray(children).filter((c) => c);
5235
}
53-
54-
export function getUnit(size) {
55-
if (size.endsWith('px')) {
56-
return 'px';
57-
}
58-
59-
if (size.endsWith('%')) {
60-
return '%';
61-
}
62-
63-
return 'ratio';
64-
}
65-
66-
export function convertSizeToCssValue(value, resizersSize) {
67-
if (getUnit(value) !== '%') {
68-
return value;
69-
}
70-
71-
if (!resizersSize) {
72-
return value;
73-
}
74-
75-
const idx = value.search('%');
76-
const percent = value.slice(0, idx) / 100;
77-
if (percent === 0) {
78-
return value;
79-
}
80-
81-
return `calc(${value} - ${resizersSize}px*${percent})`;
82-
}
83-
84-
function convertToUnit(size, unit, containerSize) {
85-
switch (unit) {
86-
case '%':
87-
return `${((size / containerSize) * 100).toFixed(2)}%`;
88-
case 'px':
89-
return `${size.toFixed(2)}px`;
90-
case 'ratio':
91-
return (size * 100).toFixed(0);
92-
}
93-
}
94-
9536
class SplitPane extends Component {
9637
constructor(props) {
9738
super(props);
@@ -101,7 +42,7 @@ class SplitPane extends Component {
10142
};
10243
}
10344

104-
componentWillReceiveProps(nextProps) {
45+
UNSAFE_componentWillReceiveProps(nextProps) {
10546
this.setState({ sizes: this.getPanePropSize(nextProps) });
10647
}
10748

@@ -132,7 +73,7 @@ class SplitPane extends Component {
13273
};
13374

13475
onDown = (resizerIndex, clientX, clientY) => {
135-
const { allowResize, onResizeStart, split } = this.props;
76+
const { allowResize, onResizeStart } = this.props;
13677

13778
if (!allowResize) {
13879
return;
@@ -361,7 +302,7 @@ class SplitPane extends Component {
361302
}
362303

363304
render() {
364-
const { children, className, split } = this.props;
305+
const { className, split } = this.props;
365306
const notNullChildren = removeNullChildren(this.props.children);
366307
const sizes = this.getSizes();
367308
const resizersSize = this.getResizersSize(notNullChildren);

‎src/utils.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
export function getUnit(size) {
2+
if (size.endsWith('px')) {
3+
return 'px';
4+
}
5+
6+
if (size.endsWith('%')) {
7+
return '%';
8+
}
9+
10+
return 'ratio';
11+
}
12+
13+
export function convertSizeToCssValue(value, resizersSize) {
14+
if (getUnit(value) !== '%') {
15+
return value;
16+
}
17+
18+
if (!resizersSize) {
19+
return value;
20+
}
21+
22+
const idx = value.search('%');
23+
const percent = value.slice(0, idx) / 100;
24+
if (percent === 0) {
25+
return value;
26+
}
27+
28+
return `calc(${value} - ${resizersSize}px*${percent})`;
29+
}
30+
31+
export function convertToUnit(size, unit, containerSize) {
32+
switch (unit) {
33+
case '%':
34+
return `${((size / containerSize) * 100).toFixed(2)}%`;
35+
case 'px':
36+
return `${size.toFixed(2)}px`;
37+
case 'ratio':
38+
return (size * 100).toFixed(0);
39+
}
40+
}
41+
42+
export function toPx(value, unit = 'px', size) {
43+
switch (unit) {
44+
case '%': {
45+
return +((size * value) / 100).toFixed(2);
46+
}
47+
default: {
48+
return +value;
49+
}
50+
}
51+
}
52+
53+
export function convert(str, size) {
54+
const tokens = str.match(/([0-9]+)([px|%]*)/);
55+
const value = tokens[1];
56+
const unit = tokens[2];
57+
return toPx(value, unit, size);
58+
}

0 commit comments

Comments
 (0)
Please sign in to comment.