-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathpropTypes.js
More file actions
161 lines (153 loc) · 4.54 KB
/
propTypes.js
File metadata and controls
161 lines (153 loc) · 4.54 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// @flow
/* global Element */
import PropTypes from 'prop-types';
import {DraggableCore} from "react-draggable";
import type {Element as ReactElement, ElementConfig} from 'react';
export type ReactRef<T: HTMLElement> = {
current: T | null
};
export type Axis = 'both' | 'x' | 'y' | 'none';
export type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';
export type ResizableState = void;
export type ResizableBoxState = {
width: number, height: number,
propsWidth: number, propsHeight: number
};
export type DragCallbackData = {
node: HTMLElement,
x: number, y: number,
deltaX: number, deltaY: number,
lastX: number, lastY: number
};
export type ResizeCallbackData = {
node: HTMLElement,
size: {width: number, height: number},
handle: ResizeHandleAxis
};
// <Resizable>
export type DefaultProps = {
axis: Axis,
handleSize: [number, number],
lockAspectRatio: boolean,
minConstraints: [number, number],
maxConstraints: [number, number],
resizeHandles: ResizeHandleAxis[],
transformScale: number,
};
export type Props = {
...DefaultProps,
children: ReactElement<any>,
className?: ?string,
draggableOpts?: ?ElementConfig<typeof DraggableCore>,
height: number,
handle?: ReactElement<any> | (resizeHandleAxis: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>,
onResizeStop?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
onResizeStart?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
onResize?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
width: number,
};
export const resizableProps: Object = {
/*
* Restricts resizing to a particular axis (default: 'both')
* 'both' - allows resizing by width or height
* 'x' - only allows the width to be changed
* 'y' - only allows the height to be changed
* 'none' - disables resizing altogether
* */
axis: PropTypes.oneOf(['both', 'x', 'y', 'none']),
className: PropTypes.string,
/*
* Require that one and only one child be present.
* */
children: PropTypes.element.isRequired,
/*
* These will be passed wholesale to react-draggable's DraggableCore
* */
draggableOpts: PropTypes.shape({
allowAnyClick: PropTypes.bool,
cancel: PropTypes.string,
children: PropTypes.node,
disabled: PropTypes.bool,
enableUserSelectHack: PropTypes.bool,
// #251: Check for Element to support SSR environments where DOM globals don't exist
offsetParent: typeof Element !== 'undefined' ? PropTypes.instanceOf(Element) : PropTypes.any,
grid: PropTypes.arrayOf(PropTypes.number),
handle: PropTypes.string,
nodeRef: PropTypes.object,
onStart: PropTypes.func,
onDrag: PropTypes.func,
onStop: PropTypes.func,
onMouseDown: PropTypes.func,
scale: PropTypes.number,
}),
/*
* Initial height
* */
height: (...args) => {
const [props] = args;
// Required if resizing height or both
if (props.axis === 'both' || props.axis === 'y') {
return PropTypes.number.isRequired(...args);
}
return PropTypes.number(...args);
},
/*
* Customize cursor resize handle
* */
handle: PropTypes.oneOfType([
PropTypes.node,
PropTypes.func
]),
/*
* If you change this, be sure to update your css
* */
handleSize: PropTypes.arrayOf(PropTypes.number),
lockAspectRatio: PropTypes.bool,
/*
* Max X & Y measure
* */
maxConstraints: PropTypes.arrayOf(PropTypes.number),
/*
* Min X & Y measure
* */
minConstraints: PropTypes.arrayOf(PropTypes.number),
/*
* Called on stop resize event
* */
onResizeStop: PropTypes.func,
/*
* Called on start resize event
* */
onResizeStart: PropTypes.func,
/*
* Called on resize event
* */
onResize: PropTypes.func,
/*
* Defines which resize handles should be rendered (default: 'se')
* 's' - South handle (bottom-center)
* 'w' - West handle (left-center)
* 'e' - East handle (right-center)
* 'n' - North handle (top-center)
* 'sw' - Southwest handle (bottom-left)
* 'nw' - Northwest handle (top-left)
* 'se' - Southeast handle (bottom-right)
* 'ne' - Northeast handle (top-center)
* */
resizeHandles: PropTypes.arrayOf(PropTypes.oneOf(['s', 'w', 'e', 'n', 'sw', 'nw', 'se', 'ne'])),
/*
* If `transform: scale(n)` is set on the parent, this should be set to `n`.
* */
transformScale: PropTypes.number,
/*
* Initial width
*/
width: (...args) => {
const [props] = args;
// Required if resizing width or both
if (props.axis === 'both' || props.axis === 'x') {
return PropTypes.number.isRequired(...args);
}
return PropTypes.number(...args);
},
};