|
| 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