Skip to content

Commit ef791fc

Browse files
authored
Add flowtype (#188)
* feat: Add flow skeleton * fix: add copy flow
1 parent 6a2d528 commit ef791fc

File tree

3 files changed

+325
-9
lines changed

3 files changed

+325
-9
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
"@types/storybook__addon-actions": "3.0.3",
4646
"@types/storybook__react": "3.0.7",
4747
"babel-core": "6.26.3",
48-
"cypress": "3.0.1",
4948
"concurrently": "3.5.1",
49+
"cpx": "^1.5.0",
50+
"cpy-cli": "^2.0.0",
51+
"cypress": "3.0.1",
5052
"gh-pages": "1.2.0",
5153
"light-ts-loader": "1.1.2",
5254
"npm-run-all": "4.1.3",
@@ -67,8 +69,9 @@
6769
"scripts": {
6870
"build:prod:main": "rollup -c config/prod.js",
6971
"build:prod:es5": "rollup -c config/prod.es5.js",
70-
"build": "npm-run-all --serial build:prod:*",
72+
"build": "npm-run-all --serial build:prod:* copy:flow",
7173
"start": "npm run storybook",
74+
"copy:flow": "cpy src/react-sortable-pane.es5.js.flow lib && cpy src/react-sortable-pane.es5.js.flow lib --rename react-sortable-pane.js.flow",
7275
"test": "concurrently 'npm run storybook' 'npm run cypress:test' -k -s first",
7376
"storybook": "start-storybook -p 6096",
7477
"cypress:test": "wait-on http-get://localhost:6096 && npm run cypress:run",
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* @flow */
2+
3+
import * as React from 'react';
4+
5+
export type Size = string | number;
6+
export type PaneDirection = 'horizontal' | 'vertical';
7+
export type PaneResizeDirection = 'x' | 'y' | 'xy';
8+
export type PaneMode = 'add' | 'remove';
9+
export type PaneKey = string | number | null;
10+
export type PaneSize = { width: number; height: number };
11+
12+
export type SortablePaneProps = {
13+
direction?: 'horizontal' | 'vertical',
14+
margin?: number,
15+
style?: { [key: string]: number | string },
16+
onResize?: (e: MouseEvent | TouchEvent, key: PaneKey, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void,
17+
onResizeStop?: (e: MouseEvent | TouchEvent, key: PaneKey, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void,
18+
onResizeStart?: (e: SyntheticMouseEvent<HTMLElement> | SyntheticTouchEvent<HTMLElement>, key: PaneKey, dir: PaneResizeDirection) => void,
19+
onDragStart?: (e: SyntheticMouseEvent<HTMLElement> | SyntheticTouchEvent<HTMLElement>, key: PaneKey, elementRef: HTMLElement) => void,
20+
onDragStop?: (e: MouseEvent | TouchEvent, key: PaneKey, elementRef: HTMLElement) => void,
21+
onOrderChange?: (order: string[]) => void,
22+
className?: string,
23+
disableEffect?: boolean,
24+
isSortable?: boolean,
25+
dragHandleClassName?: string,
26+
defaultOrder?: string[],
27+
order?: string[],
28+
children: Pane[],
29+
};
30+
31+
class SortablePane extends React.Component<SortablePaneProps> {
32+
static defaultProps = {
33+
direction: 'horizontal',
34+
style: {},
35+
children: [],
36+
margin: 0,
37+
onClick: () => {},
38+
onTouchStart: () => {},
39+
onResizeStart: () => {},
40+
onResize: () => {},
41+
onResizeStop: () => {},
42+
onDragStart: () => {},
43+
onDragStop: () => {},
44+
onOrderChange: () => {},
45+
className: '',
46+
disableEffect: false,
47+
isSortable: true,
48+
};
49+
}
50+
51+
export type IsPaneResizable = {
52+
x?: boolean,
53+
y?: boolean,
54+
xy?: boolean,
55+
};
56+
57+
export type PaneProps = {
58+
defaultSize?: {
59+
width?: Size,
60+
height?: Size,
61+
};
62+
size?: {
63+
width?: Size,
64+
height?: Size,
65+
};
66+
minWidth?: Size,
67+
maxWidth?: Size,
68+
minHeight?: Size,
69+
maxHeight?: Size,
70+
style?: { [key: string]: number | string },
71+
className?: string,
72+
children?: string | React$Node,
73+
resizable?: IsPaneResizable,
74+
grid?: [number, number],
75+
onSizeChange?: () => void,
76+
};
77+
78+
79+
class Pane extends React.Component<PaneProps> {
80+
static defaultProps: {
81+
minWidth: 0,
82+
minHeight: 0,
83+
style: {},
84+
className: '',
85+
grid: [1, 1],
86+
resizable: {
87+
x: true,
88+
y: true,
89+
xy: true,
90+
},
91+
}
92+
}
93+
94+
95+
export { Pane, SortablePane };

0 commit comments

Comments
 (0)