forked from bokuweb/re-resizable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresizer.js
107 lines (101 loc) · 2.15 KB
/
resizer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* @flow */
import * as React from 'react';
const styles = {
base: {
position: 'absolute',
userSelect: 'none',
MsUserSelect: 'none',
},
top: {
width: '100%',
height: '10px',
top: '-5px',
left: '0px',
cursor: 'row-resize',
},
right: {
width: '10px',
height: '100%',
top: '0px',
right: '-5px',
cursor: 'col-resize',
},
bottom: {
width: '100%',
height: '10px',
bottom: '-5px',
left: '0px',
cursor: 'row-resize',
},
left: {
width: '10px',
height: '100%',
top: '0px',
left: '-5px',
cursor: 'col-resize',
},
topRight: {
width: '20px',
height: '20px',
position: 'absolute',
right: '-10px',
top: '-10px',
cursor: 'ne-resize',
},
bottomRight: {
width: '20px',
height: '20px',
position: 'absolute',
right: '-10px',
bottom: '-10px',
cursor: 'se-resize',
},
bottomLeft: {
width: '20px',
height: '20px',
position: 'absolute',
left: '-10px',
bottom: '-10px',
cursor: 'sw-resize',
},
topLeft: {
width: '20px',
height: '20px',
position: 'absolute',
left: '-10px',
top: '-10px',
cursor: 'nw-resize',
},
};
export type Direction = 'top' | 'right' | 'bottom' | 'left' | 'topRight' | 'bottomRight' | 'bottomLeft' | 'topLeft';
export type OnStartCallback = (
e: SyntheticMouseEvent<HTMLDivElement> | SyntheticTouchEvent<HTMLDivElement>,
dir: Direction,
) => void;
export type Props = {
direction: Direction,
className?: string,
replaceStyles?: { [key: string]: string | number },
onResizeStart: OnStartCallback,
children: ?React.ChildrenArray<*>,
};
export default (props: Props): React.Element<'div'> => {
return (
<div
className={props.className}
style={{
...styles.base,
...styles[props.direction],
...(props.replaceStyles || {}),
}}
onMouseDown={(e: SyntheticMouseEvent<HTMLDivElement>) => {
props.onResizeStart(e, props.direction);
}}
onTouchStart={(e: SyntheticTouchEvent<HTMLDivElement>) => {
props.onResizeStart(e, props.direction);
}}
>
{props.children}
</div>
);
};