react-resizable 1.8.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +10 -4
- package/.browserslistrc +3 -0
- package/.eslintrc +10 -6
- package/.flowconfig +10 -10
- package/CHANGELOG.md +61 -32
- package/README.md +14 -4
- package/__tests__/Resizable.test.js +245 -0
- package/__tests__/ResizableBox.test.js +99 -0
- package/__tests__/__snapshots__/Resizable.test.js.snap +29 -0
- package/__tests__/__snapshots__/ResizableBox.test.js.snap +23 -0
- package/build/Resizable.js +172 -208
- package/build/Resizable.js.flow +99 -178
- package/build/ResizableBox.js +95 -79
- package/build/ResizableBox.js.flow +58 -33
- package/build/propTypes.js +112 -0
- package/build/propTypes.js.flow +135 -0
- package/build/utils.js +27 -0
- package/build/{cloneElement.js.flow → utils.js.flow} +2 -2
- package/coverage/clover.xml +107 -0
- package/coverage/coverage-final.json +5 -0
- package/coverage/lcov-report/Resizable.js.html +665 -0
- package/coverage/lcov-report/ResizableBox.js.html +374 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/flow-typed/npm/index.html +111 -0
- package/coverage/lcov-report/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
- package/coverage/lcov-report/index.html +156 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/propTypes.js.html +485 -0
- package/coverage/lcov-report/react-resizable/dist/bundle.js.html +95 -0
- package/coverage/lcov-report/react-resizable/dist/index.html +111 -0
- package/coverage/lcov-report/react-resizable/flow-typed/npm/index.html +111 -0
- package/coverage/lcov-report/react-resizable/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
- package/coverage/lcov-report/react-resizable/index.html +111 -0
- package/coverage/lcov-report/react-resizable/index.js.html +101 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/utils.js.html +122 -0
- package/coverage/lcov.info +233 -0
- package/dist/bundle.js +6 -0
- package/flow-typed/npm/jest_v26.x.x.js +1218 -0
- package/package.json +34 -26
- package/setupTests/enzyme.js +4 -0
- package/.github/ISSUE_TEMPLATE.md +0 -23
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -5
- package/build/cloneElement.js +0 -20
package/.babelrc
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"presets": [
|
|
3
|
-
[
|
|
4
|
-
|
|
3
|
+
[
|
|
4
|
+
"@babel/preset-env",
|
|
5
|
+
{
|
|
6
|
+
"loose": true
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"@babel/preset-react",
|
|
10
|
+
"@babel/preset-flow"
|
|
5
11
|
],
|
|
6
12
|
"plugins": [
|
|
7
|
-
"
|
|
8
|
-
"
|
|
13
|
+
"@babel/plugin-proposal-class-properties",
|
|
14
|
+
"@babel/plugin-proposal-object-rest-spread"
|
|
9
15
|
]
|
|
10
16
|
}
|
package/.browserslistrc
ADDED
package/.eslintrc
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
"plugins": [
|
|
5
5
|
"react"
|
|
6
6
|
],
|
|
7
|
-
"extends":
|
|
7
|
+
"extends": [
|
|
8
|
+
"eslint:recommended"
|
|
9
|
+
],
|
|
8
10
|
"rules": {
|
|
9
11
|
"strict": 0,
|
|
10
12
|
"quotes": [0, "single"],
|
|
@@ -20,14 +22,16 @@
|
|
|
20
22
|
"react/jsx-uses-vars": 1,
|
|
21
23
|
"semi": [1, "always"]
|
|
22
24
|
},
|
|
23
|
-
env: {
|
|
25
|
+
"env": {
|
|
24
26
|
"browser": true,
|
|
25
|
-
"node": true
|
|
27
|
+
"node": true,
|
|
28
|
+
"jest": true
|
|
26
29
|
},
|
|
27
30
|
"globals": {
|
|
28
31
|
// For Flow
|
|
29
|
-
"ReactElement",
|
|
30
|
-
"ReactClass",
|
|
31
|
-
"SyntheticEvent"
|
|
32
|
+
"ReactElement": false,
|
|
33
|
+
"ReactClass": false,
|
|
34
|
+
"SyntheticEvent": false,
|
|
35
|
+
"ClientRect": false
|
|
32
36
|
}
|
|
33
37
|
}
|
package/.flowconfig
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
[version]
|
|
2
|
-
^0.
|
|
2
|
+
^0.133.0
|
|
3
3
|
|
|
4
4
|
[ignore]
|
|
5
|
-
.*/node_modules
|
|
6
|
-
.*/node_modules/fbjs/.*
|
|
5
|
+
.*/node_modules/@babel.*
|
|
7
6
|
.*/node_modules/express/.*
|
|
8
7
|
.*/node_modules/serve-index/.*
|
|
9
8
|
<PROJECT_ROOT>/build/.*
|
|
@@ -11,20 +10,21 @@
|
|
|
11
10
|
[include]
|
|
12
11
|
|
|
13
12
|
[libs]
|
|
13
|
+
flow-typed
|
|
14
|
+
|
|
15
|
+
[lints]
|
|
16
|
+
all=warn
|
|
17
|
+
implicit-inexact-object=error
|
|
14
18
|
|
|
15
19
|
[options]
|
|
16
|
-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowFixMe.*
|
|
17
|
-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowBug.*
|
|
18
|
-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowIgnore.*
|
|
19
|
-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowNewLine.*
|
|
20
|
-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowIssue
|
|
21
20
|
suppress_type=$FlowFixMe
|
|
22
21
|
esproposal.class_static_fields=enable
|
|
23
22
|
esproposal.class_instance_fields=enable
|
|
24
23
|
esproposal.decorators=ignore
|
|
25
24
|
esproposal.export_star_as=enable
|
|
26
25
|
experimental.strict_call_arity=true
|
|
27
|
-
module.system.node.
|
|
28
|
-
module.system.node.resolve_dirname=.
|
|
26
|
+
module.system.node.allow_root_relative=true
|
|
29
27
|
module.use_strict=true
|
|
30
28
|
server.max_workers=6
|
|
29
|
+
exact_by_default=true
|
|
30
|
+
sharedmemory.heap_size=3221225472
|
package/CHANGELOG.md
CHANGED
|
@@ -1,99 +1,128 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
### 1.
|
|
3
|
+
### 1.11.1 (Mar 5, 2021)
|
|
4
4
|
|
|
5
|
-
- Added
|
|
6
|
-
|
|
5
|
+
- Added React 17 to peerDependencies.
|
|
6
|
+
|
|
7
|
+
### 1.11.0 (Sep 3, 2020)
|
|
8
|
+
|
|
9
|
+
- ⚠ Important Notice!
|
|
10
|
+
- React-Resizable 2.0.0 was published due to a breaking change in `props` handling. This change ended up actually completely breaking certain workflows, for the dubious benefit of making the code slightly simpler to add to. The breaking change has been reverted, 2.0.0 is now deprecated, and we will continue on the 1.x branch. Future breaking changes to `react-resizable` will upgrade the major version to `3`.
|
|
11
|
+
- ➕ Feature: `<ResizableBox>` now takes a `style` prop which will be applied on the wrapping `<div>`. `width` and `height` in this prop are ignored.
|
|
12
|
+
- 🐛 Bugfix: remove unknown Prop `handle` from div children in Resizable `React.cloneElement`. [#124](https://github.com/STRML/react-resizable/issues/124)
|
|
13
|
+
- 🐛 Bugfix: Fix top and left resizing jerkiness. Thanks @conor-kelleher. [#136](https://github.com/STRML/react-resizable/pull/136)
|
|
14
|
+
- ✏ Chore: Improved test suite. Please contribute tests for your use cases if you have the time, I would really appreciate it! Thanks very much, @Danielecina
|
|
15
|
+
- ✏ Chore: Minor internal refactors and additional tests.
|
|
16
|
+
- ✏ Chore: Additional examples.
|
|
17
|
+
|
|
18
|
+
### 1.10.1 (Nov 25, 2019)
|
|
19
|
+
|
|
20
|
+
> Note: 1.10.0 was a mis-publish.
|
|
21
|
+
|
|
22
|
+
- ➕ Feature: Add `transformScale` prop [#115](https://github.com/STRML/react-resizable/pull/115)
|
|
23
|
+
- 🐛 Bugfix: Resolve `getDerivedStateFromProps` dev warning [#117](https://github.com/STRML/react-resizable/pull/117)
|
|
24
|
+
|
|
25
|
+
### 1.9.0 (Oct 24, 2019)
|
|
26
|
+
|
|
27
|
+
- 🐛 Bugfix: Fix resize with north/south handles when `lockAspectRatio=true` [#106](https://github.com/STRML/react-resizable/pull/106)
|
|
28
|
+
- ✏ Chore: Remove deprecated React 16.9 lifecycle methods (`componentWillReceiveProps`) (https://github.com/STRML/react-resizable/pull/112/commits/541dee69b8e45d91a533855609472b481634edee)
|
|
29
|
+
- ✏ Chore: Upgrade to babel 7
|
|
30
|
+
- ✏ Chore: [Remove unused state inside `<Draggable>`](https://github.com/STRML/react-resizable/pull/112/commits/05693f63d6d221ad652f0f28af024cfb46a5f2df). This has not been needed for quite some time, fixes [some bugs](https://github.com/STRML/react-resizable/issues/99) and improves performance.
|
|
31
|
+
|
|
32
|
+
### 1.8.0 (May 15, 2019)
|
|
33
|
+
|
|
34
|
+
- ➕ Feature: Added support for custom resize handles [#79](https://github.com/STRML/react-resizable/pull/79)
|
|
35
|
+
- ➕ Feature: Added support for resize handles on all corners [#191](https://github.com/STRML/react-resizable/pull/191)
|
|
7
36
|
|
|
8
37
|
### 1.7.5 (Sep 26, 2017)
|
|
9
38
|
|
|
10
|
-
- Support for React 16 (no changes required, updated `peerDependencies`)
|
|
11
|
-
- Minor dep updates.
|
|
39
|
+
- ✏ Chore: Support for React 16 (no changes required, updated `peerDependencies`)
|
|
40
|
+
- ✏ Chore: Minor dep updates.
|
|
12
41
|
|
|
13
42
|
### 1.7.4 (Sep 5, 2017)
|
|
14
43
|
|
|
15
|
-
- Minor Flow & dependency updates.
|
|
44
|
+
- ✏ Chore: Minor Flow & dependency updates.
|
|
16
45
|
|
|
17
46
|
### 1.7.3 (Aug 31, 2017)
|
|
18
47
|
|
|
19
|
-
-
|
|
48
|
+
- 🐛 Bugfix: React deprecation warnings from `import *`
|
|
20
49
|
- https://github.com/facebook/react/issues/10583
|
|
21
50
|
|
|
22
51
|
### 1.7.2 (Aug 21, 2017)
|
|
23
52
|
|
|
24
|
-
- Pkg: Add `react-draggable@3.0.0` to version range.
|
|
53
|
+
- ✏ Chore: Pkg: Add `react-draggable@3.0.0` to version range.
|
|
25
54
|
- This package is compatible with both `@2` and `@3` versions.
|
|
26
55
|
|
|
27
56
|
### 1.7.1 (May 23, 2017)
|
|
28
57
|
|
|
29
|
-
- Bugfix: Some flow types were improperly specified.
|
|
58
|
+
- 🐛 Bugfix: Some flow types were improperly specified.
|
|
30
59
|
|
|
31
60
|
### 1.7.0 (May 1, 2017)
|
|
32
61
|
|
|
33
|
-
- Deprecation: `React.PropTypes` now deprecated in React 15.5, moved to `prop-types` package
|
|
34
|
-
-
|
|
35
|
-
-
|
|
62
|
+
- ⚠ Deprecation: `React.PropTypes` now deprecated in React 15.5, moved to `prop-types` package
|
|
63
|
+
- ✏ Chore: Update devDeps, upgrade to webpack 2
|
|
64
|
+
- ✏ Chore: Remove babel `stage-1` and `transform-flow-comments`, bring in only selected plugins, makes for leaner dev/build.
|
|
36
65
|
|
|
37
66
|
### 1.6.0 (Jan 23, 2017)
|
|
38
67
|
|
|
39
|
-
- Feature: Allow restricting by axis. (#40, thanks @dnissley-al)
|
|
68
|
+
- ➕ Feature: Allow restricting by axis. (#40, thanks @dnissley-al)
|
|
40
69
|
|
|
41
70
|
### 1.5.0 (Jan 23, 2017)
|
|
42
71
|
|
|
43
|
-
- Bugfix: Persist SyntheticEvents when needed (#45, #46)
|
|
44
|
-
- Feature: Add componentWillReceiveProps to `<ResizableBox>` (#44, thanks @JoaoMosmann)
|
|
72
|
+
- 🐛 Bugfix: Persist SyntheticEvents when needed (#45, #46)
|
|
73
|
+
- ➕ Feature: Add componentWillReceiveProps to `<ResizableBox>` (#44, thanks @JoaoMosmann)
|
|
45
74
|
|
|
46
75
|
### 1.4.6 (Dec 30, 2016)
|
|
47
76
|
|
|
48
|
-
- Removed unused ref from `<Resizable>`.
|
|
49
|
-
- Added development lockfile.
|
|
77
|
+
- ✏ Chore: Removed unused ref from `<Resizable>`.
|
|
78
|
+
- ✏ Chore: Added development lockfile.
|
|
50
79
|
|
|
51
80
|
### 1.4.5 (Sep 30, 2016)
|
|
52
81
|
|
|
53
|
-
- Fix bad publish
|
|
82
|
+
- 🐛 Bugfix: Fix bad publish
|
|
54
83
|
|
|
55
84
|
### 1.4.4 (Sep 30, 2016)
|
|
56
85
|
|
|
57
|
-
- Bugfix: Minor flow errors
|
|
86
|
+
- 🐛 Bugfix: Minor flow errors
|
|
58
87
|
|
|
59
88
|
### 1.4.3 (Sep 27, 2016)
|
|
60
89
|
|
|
61
|
-
- Bugfix: Don't pass `onResize` in `<ResizableBox>`.
|
|
62
|
-
- Bugfix: Fix new Flow errors (type parameters no longer optional).
|
|
90
|
+
- 🐛 Bugfix: Don't pass `onResize` in `<ResizableBox>`.
|
|
91
|
+
- 🐛 Bugfix: Fix new Flow errors (type parameters no longer optional).
|
|
63
92
|
|
|
64
93
|
### 1.4.2 (July 1, 2016)
|
|
65
94
|
|
|
66
|
-
- Bugfix: Don't pass unknown props to underlying DOM element. Fixes React 15.2.0 warnings.
|
|
95
|
+
- 🐛 Bugfix: Don't pass unknown props to underlying DOM element. Fixes React 15.2.0 warnings.
|
|
67
96
|
|
|
68
97
|
### 1.4.1 (May 23, 2016)
|
|
69
98
|
|
|
70
|
-
- Bugfix: Resizable handle should have a `key` when injected. Fixes React warnings on custom components.
|
|
99
|
+
- 🐛 Bugfix: Resizable handle should have a `key` when injected. Fixes React warnings on custom components.
|
|
71
100
|
|
|
72
101
|
### 1.4.0 (May 20, 2016)
|
|
73
102
|
|
|
74
|
-
- Update to React-Draggable v2, which changed callback data structure.
|
|
103
|
+
- ✏ Chore: Update to React-Draggable v2, which changed callback data structure.
|
|
75
104
|
|
|
76
105
|
### 1.3.4 (May 17, 2016)
|
|
77
106
|
|
|
78
|
-
- Bugfix: Slack was not being reset on resizeStop. Fixes #34, #36.
|
|
79
|
-
- Added `flow-bin` to devDeps.
|
|
107
|
+
- 🐛 Bugfix: Slack was not being reset on resizeStop. Fixes #34, #36.
|
|
108
|
+
- ✏ Chore: Added `flow-bin` to devDeps.
|
|
80
109
|
|
|
81
110
|
### 1.3.3 (Apr 19, 2016)
|
|
82
111
|
|
|
83
|
-
-
|
|
112
|
+
- ➕ Feature: Add Flow comments.
|
|
84
113
|
|
|
85
114
|
### 1.3.2 (Apr 8, 2016)
|
|
86
115
|
|
|
87
|
-
- Bugfix: Prevent `width` and `height` from leaking to the underlying DOM element and being written.
|
|
116
|
+
- 🐛 Bugfix: Prevent `width` and `height` from leaking to the underlying DOM element and being written.
|
|
88
117
|
|
|
89
118
|
### 1.3.1 (Apr 8, 2016)
|
|
90
119
|
|
|
91
|
-
- Allow React v15 in peerdeps.
|
|
120
|
+
- ✏ Chore: Allow React v15 in peerdeps.
|
|
92
121
|
|
|
93
122
|
### 1.3.0 (Mar 11, 2016)
|
|
94
123
|
|
|
95
|
-
- Switch to ES2015 Loose Mode to fix IE9/10 issues.
|
|
96
|
-
- Flow typing fixes.
|
|
97
|
-
- Styling fixes to the demo page.
|
|
124
|
+
- 🐛 Bugfix: Switch to ES2015 Loose Mode to fix IE9/10 issues.
|
|
125
|
+
- 🐛 Bugfix: Flow typing fixes.
|
|
126
|
+
- 🐛 Bugfix: Styling fixes to the demo page.
|
|
98
127
|
|
|
99
128
|
> Changes before 1.3.0 were not logged. Please see the git commit history.
|
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
### React-Resizable
|
|
2
2
|
|
|
3
|
-
[View the Demo](https://
|
|
3
|
+
[View the Demo](https://react-grid-layout.github.io/react-resizable/examples/1.html)
|
|
4
4
|
|
|
5
5
|
A simple widget that can be resized via one or more handles.
|
|
6
6
|
|
|
7
7
|
You can either use the `<Resizable>` element directly, or use the much simpler `<ResizableBox>` element.
|
|
8
8
|
|
|
9
|
-
See the example and associated code in [TestLayout](/
|
|
9
|
+
See the example and associated code in [TestLayout](/examples/TestLayout.js) and
|
|
10
10
|
[ResizableBox](/lib/ResizableBox.js) for more details.
|
|
11
11
|
|
|
12
12
|
Make sure you use the associated styles in [/css/styles.css](/css/styles.css), as without them, you will have
|
|
13
13
|
problems with handle placement and visibility.
|
|
14
14
|
|
|
15
15
|
You can pass options directly to the underlying `DraggableCore` instance by using the prop `draggableOpts`.
|
|
16
|
-
See the [demo](/
|
|
16
|
+
See the [demo](/examples/TestLayout.js) for more on this.
|
|
17
17
|
|
|
18
18
|
### Installation
|
|
19
19
|
|
|
@@ -43,7 +43,7 @@ render() {
|
|
|
43
43
|
|
|
44
44
|
### Props
|
|
45
45
|
|
|
46
|
-
These props apply to both `<Resizable>` and `<ResizableBox>`.
|
|
46
|
+
These props apply to both `<Resizable>` and `<ResizableBox>`. Unknown props that are not in the list below will be passed to the child component.
|
|
47
47
|
|
|
48
48
|
```js
|
|
49
49
|
{
|
|
@@ -65,3 +65,13 @@ These props apply to both `<Resizable>` and `<ResizableBox>`.
|
|
|
65
65
|
resizeHandles?: ?Array<'s' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'> = ['se']
|
|
66
66
|
};
|
|
67
67
|
```
|
|
68
|
+
|
|
69
|
+
The following props can also be used on `<ResizableBox>`:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
{
|
|
73
|
+
style?: Object
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
If a `width` or `height` is passed to `<ResizableBox>`'s `style` prop, it will be ignored as it is required for internal function.
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import renderer from 'react-test-renderer';
|
|
4
|
+
import {shallow} from 'enzyme';
|
|
5
|
+
import {DraggableCore} from "react-draggable";
|
|
6
|
+
|
|
7
|
+
import Resizable from '../lib/Resizable';
|
|
8
|
+
|
|
9
|
+
describe('render Resizable', () => {
|
|
10
|
+
const props = {
|
|
11
|
+
axis: 'both',
|
|
12
|
+
className: 'test-classname',
|
|
13
|
+
draggableOpts: {},
|
|
14
|
+
handleSize: [20, 20],
|
|
15
|
+
height: 50,
|
|
16
|
+
lockAspectRatio: false,
|
|
17
|
+
maxConstraints: [Infinity, Infinity],
|
|
18
|
+
minConstraints: [20, 20],
|
|
19
|
+
onResize: jest.fn(),
|
|
20
|
+
onResizeStart: jest.fn(),
|
|
21
|
+
onResizeStop: jest.fn(),
|
|
22
|
+
resizeHandles: ['se', 'e'],
|
|
23
|
+
transformScale: 1,
|
|
24
|
+
width: 50,
|
|
25
|
+
};
|
|
26
|
+
const userChildren = <span className={'children'} />;
|
|
27
|
+
const resizableBoxChildren = <div style={{width: '50px', height: '50px'}}>{userChildren}</div>;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
jest.clearAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('snapshot default props', () => {
|
|
34
|
+
const tree = renderer.create(<Resizable {...props}>{resizableBoxChildren}</Resizable>).toJSON();
|
|
35
|
+
expect(tree).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('with correct props', () => {
|
|
39
|
+
const element = shallow(<Resizable {...props}>{resizableBoxChildren}</Resizable>);
|
|
40
|
+
expect(element.find('.test-classname').find('.children'));
|
|
41
|
+
expect(element.find(DraggableCore)).toHaveLength(2);
|
|
42
|
+
const cursorSe = element.find('.react-resizable-handle-se');
|
|
43
|
+
const cursorE = element.find('.react-resizable-handle-e');
|
|
44
|
+
expect(cursorSe).toHaveLength(1);
|
|
45
|
+
expect(cursorE).toHaveLength(1);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('and pass handle props', () => {
|
|
49
|
+
test('as component', () => {
|
|
50
|
+
const customProps = {
|
|
51
|
+
...props,
|
|
52
|
+
resizeHandles: ['se'],
|
|
53
|
+
handle: <span className={'custom-component'} />
|
|
54
|
+
};
|
|
55
|
+
const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
|
|
56
|
+
expect(element.find('.react-resizable-handle-se')).toHaveLength(0);
|
|
57
|
+
expect(element.find('.custom-component')).toHaveLength(1);
|
|
58
|
+
});
|
|
59
|
+
test('as function', () => {
|
|
60
|
+
const customProps = {
|
|
61
|
+
...props,
|
|
62
|
+
resizeHandles: ['se'],
|
|
63
|
+
handle: (h) => <span className={`custom-component-${h}`} />
|
|
64
|
+
};
|
|
65
|
+
const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
|
|
66
|
+
expect(element.find('.custom-component-se')).toHaveLength(1);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('<Resizable> props filtering', () => {
|
|
71
|
+
const allProps = {
|
|
72
|
+
...props,
|
|
73
|
+
draggableOpts: {},
|
|
74
|
+
handle: <div />,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Ensure everything in propTypes is represented here. Otherwise the next two tests are not valid
|
|
78
|
+
test('all intended props are in our allProps object', () => {
|
|
79
|
+
expect(['children', ...Object.keys(allProps)].sort()).toEqual(Object.keys(Resizable.propTypes).sort());
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('none of these props leak down to the child', () => {
|
|
83
|
+
const element = shallow(<Resizable {...allProps}><div className="foo" /></Resizable>);
|
|
84
|
+
expect(Object.keys(element.find('.foo').props())).toEqual(['className', 'children']);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('className is constructed properly', () => {
|
|
88
|
+
const element = shallow(<Resizable {...allProps}><div className="foo" /></Resizable>);
|
|
89
|
+
expect(element.find('.foo').props().className).toEqual(`foo ${allProps.className} react-resizable`);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('onResize callback with modified position', () => {
|
|
94
|
+
const customProps = {
|
|
95
|
+
...props,
|
|
96
|
+
resizeHandles: ['nw', 'sw' ,'ne', 'se', 'n', 's', 'w', 'e'],
|
|
97
|
+
};
|
|
98
|
+
const mockClientRect = {
|
|
99
|
+
left: 0,
|
|
100
|
+
top: 0,
|
|
101
|
+
};
|
|
102
|
+
const node = document.createElement('div');
|
|
103
|
+
// $FlowIgnore need to override to have control over dummy dom element
|
|
104
|
+
node.getBoundingClientRect = () => ({ ...mockClientRect });
|
|
105
|
+
const mockEvent = { };
|
|
106
|
+
const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
|
|
107
|
+
const nwHandle = element.find('DraggableCore').first();
|
|
108
|
+
|
|
109
|
+
test('Gradual resizing without movement between does not modify callback', () => {
|
|
110
|
+
expect(props.onResize).not.toHaveBeenCalled();
|
|
111
|
+
nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
|
|
112
|
+
expect(props.onResize).lastCalledWith(
|
|
113
|
+
mockEvent,
|
|
114
|
+
expect.objectContaining({
|
|
115
|
+
size: {
|
|
116
|
+
height: 40,
|
|
117
|
+
width: 45,
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('Movement between callbacks modifies response values', () => {
|
|
124
|
+
expect(props.onResize).not.toHaveBeenCalled();
|
|
125
|
+
|
|
126
|
+
mockClientRect.top = -10; // Object moves between callbacks
|
|
127
|
+
nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
|
|
128
|
+
expect(props.onResize).lastCalledWith(
|
|
129
|
+
mockEvent,
|
|
130
|
+
expect.objectContaining({
|
|
131
|
+
size: {
|
|
132
|
+
height: 50, // No height change since deltaY is caused by clientRect moving vertically
|
|
133
|
+
width: 45,
|
|
134
|
+
},
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
mockClientRect.left = 20; // Object moves between callbacks
|
|
139
|
+
nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
|
|
140
|
+
expect(props.onResize).lastCalledWith(
|
|
141
|
+
mockEvent,
|
|
142
|
+
expect.objectContaining({
|
|
143
|
+
size: {
|
|
144
|
+
height: 40, // Height decreased as deltaY increases - no further top position change since last
|
|
145
|
+
width: 25, // Width decreased 25 - 5 from deltaX and 20 from changing position
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
props.onResize.mockClear();
|
|
151
|
+
mockClientRect.left -= 10; // Object moves between callbacks
|
|
152
|
+
mockClientRect.top -= 10; // Object moves between callbacks
|
|
153
|
+
nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
|
|
154
|
+
expect(props.onResize).not.toHaveBeenCalled();
|
|
155
|
+
|
|
156
|
+
mockClientRect.left -= 10; // Object moves between callbacks
|
|
157
|
+
mockClientRect.top -= 10; // Object moves between callbacks
|
|
158
|
+
const swHandle = element.find('DraggableCore').at(1);
|
|
159
|
+
swHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
|
|
160
|
+
expect(props.onResize).lastCalledWith(
|
|
161
|
+
mockEvent,
|
|
162
|
+
expect.objectContaining({
|
|
163
|
+
size: {
|
|
164
|
+
height: 60, // Changed since resizing from bottom doesn't cause position change
|
|
165
|
+
width: 50, // No change - movement has caused entire delta
|
|
166
|
+
},
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
mockClientRect.left -= 10; // Object moves between callbacks
|
|
171
|
+
mockClientRect.top -= 10; // Object moves between callbacks
|
|
172
|
+
const neHandle = element.find('DraggableCore').at(2);
|
|
173
|
+
neHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
|
|
174
|
+
expect(props.onResize).lastCalledWith(
|
|
175
|
+
mockEvent,
|
|
176
|
+
expect.objectContaining({
|
|
177
|
+
size: {
|
|
178
|
+
height: 50, // No change - movement has caused entire delta
|
|
179
|
+
width: 60, // Changed since resizing from right doesn't cause position change
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
mockClientRect.left -= 10; // Object moves between callbacks
|
|
185
|
+
mockClientRect.top -= 10; // Object moves between callbacks
|
|
186
|
+
const seHandle = element.find('DraggableCore').at(3);
|
|
187
|
+
seHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
|
|
188
|
+
expect(props.onResize).lastCalledWith(
|
|
189
|
+
mockEvent,
|
|
190
|
+
expect.objectContaining({
|
|
191
|
+
size: {
|
|
192
|
+
height: 60, // Changed since resizing from right doesn't cause position change
|
|
193
|
+
width: 60, // Changed since resizing from right doesn't cause position change
|
|
194
|
+
},
|
|
195
|
+
})
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('use of < 1 transformScale', () => {
|
|
200
|
+
const element = shallow(<Resizable {...customProps} transformScale={0.5}>{resizableBoxChildren}</Resizable>);
|
|
201
|
+
const nwHandle = element.find('DraggableCore').first();
|
|
202
|
+
expect(props.onResize).not.toHaveBeenCalled();
|
|
203
|
+
nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
|
|
204
|
+
expect(props.onResize).lastCalledWith(
|
|
205
|
+
mockEvent,
|
|
206
|
+
expect.objectContaining({
|
|
207
|
+
size: {
|
|
208
|
+
// Should be doubled
|
|
209
|
+
height: 30,
|
|
210
|
+
width: 40,
|
|
211
|
+
},
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
mockClientRect.left = 20; // Object moves between callbacks
|
|
216
|
+
nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
|
|
217
|
+
expect(props.onResize).lastCalledWith(
|
|
218
|
+
mockEvent,
|
|
219
|
+
expect.objectContaining({
|
|
220
|
+
size: {
|
|
221
|
+
height: 30, // Height decreased as deltaY increases - no further top position change since last
|
|
222
|
+
width: 20, // Width decreased 10 from deltaX and 20 from changing position
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('use of > 1 transformScale', () => {
|
|
229
|
+
const element = shallow(<Resizable {...customProps} transformScale={2}>{resizableBoxChildren}</Resizable>);
|
|
230
|
+
const nwHandle = element.find('DraggableCore').first();
|
|
231
|
+
expect(props.onResize).not.toHaveBeenCalled();
|
|
232
|
+
nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
|
|
233
|
+
expect(props.onResize).lastCalledWith(
|
|
234
|
+
mockEvent,
|
|
235
|
+
expect.objectContaining({
|
|
236
|
+
size: {
|
|
237
|
+
// Should be halved
|
|
238
|
+
height: 45,
|
|
239
|
+
width: 47.5,
|
|
240
|
+
},
|
|
241
|
+
})
|
|
242
|
+
);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import renderer from 'react-test-renderer';
|
|
4
|
+
import {shallow} from 'enzyme';
|
|
5
|
+
|
|
6
|
+
import ResizableBox from '../lib/ResizableBox';
|
|
7
|
+
import Resizable from "../lib/Resizable";
|
|
8
|
+
|
|
9
|
+
describe('render ResizableBox', () => {
|
|
10
|
+
const props = {
|
|
11
|
+
axis: 'x',
|
|
12
|
+
draggableOpts: {},
|
|
13
|
+
handle: jest.fn(resizeHandle => <span className={`test-class-${resizeHandle}`} />),
|
|
14
|
+
handleSize: [20, 20],
|
|
15
|
+
height: 50,
|
|
16
|
+
lockAspectRatio: false,
|
|
17
|
+
maxConstraints: [30, 30],
|
|
18
|
+
minConstraints: [10, 10],
|
|
19
|
+
onResize: jest.fn(),
|
|
20
|
+
onResizeStart: jest.fn(),
|
|
21
|
+
onResizeStop: jest.fn(),
|
|
22
|
+
resizeHandles: ['w'],
|
|
23
|
+
transformScale: 1,
|
|
24
|
+
width: 50,
|
|
25
|
+
};
|
|
26
|
+
const children = <span className="children" />;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('snapshot default props', () => {
|
|
33
|
+
const tree = renderer.create(<ResizableBox {...props}>{children}</ResizableBox>).toJSON();
|
|
34
|
+
expect(tree).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('with correct props', () => {
|
|
38
|
+
const element = shallow(<ResizableBox {...props}>{children}</ResizableBox>);
|
|
39
|
+
expect(element.state()).toEqual({
|
|
40
|
+
height: 50,
|
|
41
|
+
propsHeight: 50,
|
|
42
|
+
propsWidth: 50,
|
|
43
|
+
width: 50,
|
|
44
|
+
});
|
|
45
|
+
const resizable = element.find(Resizable);
|
|
46
|
+
const fakeEvent = {persist: jest.fn()};
|
|
47
|
+
const data = {node: children, size: {width: 30, height: 30}, handle: 'w'};
|
|
48
|
+
resizable.simulate('resize', fakeEvent, data);
|
|
49
|
+
expect(element.state()).toEqual({
|
|
50
|
+
height: 30,
|
|
51
|
+
propsHeight: 50,
|
|
52
|
+
propsWidth: 50,
|
|
53
|
+
width: 30,
|
|
54
|
+
});
|
|
55
|
+
expect(element.find('.children')).toHaveLength(1);
|
|
56
|
+
expect(fakeEvent.persist).toHaveBeenCalledTimes(1);
|
|
57
|
+
expect(props.onResize).toHaveBeenCalledWith(fakeEvent, data);
|
|
58
|
+
|
|
59
|
+
resizable.simulate('resizeStart', fakeEvent, data);
|
|
60
|
+
expect(props.onResizeStart).toHaveBeenCalledWith(fakeEvent, data);
|
|
61
|
+
|
|
62
|
+
resizable.simulate('resizeStop', fakeEvent, data);
|
|
63
|
+
expect(props.onResizeStop).toHaveBeenCalledWith(fakeEvent, data);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('<Resizable> props filtering', () => {
|
|
67
|
+
// Ensure everything in propTypes is represented here. Otherwise the next two tests are not valid
|
|
68
|
+
test('all intended props are in our props object', () => {
|
|
69
|
+
expect(['children', 'className', ...Object.keys(props)].sort()).toEqual(Object.keys(Resizable.propTypes).sort());
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('none of these props leak down to the child', () => {
|
|
73
|
+
const element = shallow(<ResizableBox {...props} />);
|
|
74
|
+
expect(Object.keys(element.find('div').props())).toEqual(['style']);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('className is constructed properly', () => {
|
|
78
|
+
const element = shallow(<ResizableBox {...props} className='foo' />);
|
|
79
|
+
expect(element.find('div').props().className).toEqual(`foo`);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('style prop', () => {
|
|
84
|
+
const element = shallow(<ResizableBox {...props} style={{backgroundColor: 'red'}}>{children}</ResizableBox>);
|
|
85
|
+
expect(element.find('div').at(0).prop('style')).toEqual({
|
|
86
|
+
width: '50px',
|
|
87
|
+
height: '50px',
|
|
88
|
+
backgroundColor: 'red'
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('style prop width and height ignored', () => {
|
|
93
|
+
const element = shallow(<ResizableBox {...props} style={{width: 10, height: 10}}>{children}</ResizableBox>);
|
|
94
|
+
expect(element.find('div').at(0).prop('style')).toEqual({
|
|
95
|
+
width: '50px',
|
|
96
|
+
height: '50px',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`render Resizable snapshot default props 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="test-classname react-resizable"
|
|
6
|
+
style={
|
|
7
|
+
Object {
|
|
8
|
+
"height": "50px",
|
|
9
|
+
"width": "50px",
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
>
|
|
13
|
+
<span
|
|
14
|
+
className="children"
|
|
15
|
+
/>
|
|
16
|
+
<span
|
|
17
|
+
className="react-resizable-handle react-resizable-handle-se"
|
|
18
|
+
onMouseDown={[Function]}
|
|
19
|
+
onMouseUp={[Function]}
|
|
20
|
+
onTouchEnd={[Function]}
|
|
21
|
+
/>
|
|
22
|
+
<span
|
|
23
|
+
className="react-resizable-handle react-resizable-handle-e"
|
|
24
|
+
onMouseDown={[Function]}
|
|
25
|
+
onMouseUp={[Function]}
|
|
26
|
+
onTouchEnd={[Function]}
|
|
27
|
+
/>
|
|
28
|
+
</div>
|
|
29
|
+
`;
|