UNPKG

5.8 kBTypeScriptView Raw
1import * as React from 'react';
2import { Direction } from './resizer';
3export declare type ResizeDirection = Direction;
4export interface Enable {
5 top?: boolean;
6 right?: boolean;
7 bottom?: boolean;
8 left?: boolean;
9 topRight?: boolean;
10 bottomRight?: boolean;
11 bottomLeft?: boolean;
12 topLeft?: boolean;
13}
14export interface HandleStyles {
15 top?: React.CSSProperties;
16 right?: React.CSSProperties;
17 bottom?: React.CSSProperties;
18 left?: React.CSSProperties;
19 topRight?: React.CSSProperties;
20 bottomRight?: React.CSSProperties;
21 bottomLeft?: React.CSSProperties;
22 topLeft?: React.CSSProperties;
23}
24export interface HandleClassName {
25 top?: string;
26 right?: string;
27 bottom?: string;
28 left?: string;
29 topRight?: string;
30 bottomRight?: string;
31 bottomLeft?: string;
32 topLeft?: string;
33}
34export interface Size {
35 width?: string | number;
36 height?: string | number;
37}
38export interface NumberSize {
39 width: number;
40 height: number;
41}
42export interface HandleComponent {
43 top?: React.ReactElement<any>;
44 right?: React.ReactElement<any>;
45 bottom?: React.ReactElement<any>;
46 left?: React.ReactElement<any>;
47 topRight?: React.ReactElement<any>;
48 bottomRight?: React.ReactElement<any>;
49 bottomLeft?: React.ReactElement<any>;
50 topLeft?: React.ReactElement<any>;
51}
52export declare type ResizeCallback = (event: MouseEvent | TouchEvent, direction: Direction, elementRef: HTMLElement, delta: NumberSize) => void;
53export declare type ResizeStartCallback = (e: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, dir: Direction, elementRef: HTMLElement) => void | boolean;
54export interface ResizableProps {
55 as?: string | React.ComponentType<any>;
56 style?: React.CSSProperties;
57 className?: string;
58 grid?: [number, number];
59 gridGap?: [number, number];
60 snap?: {
61 x?: number[];
62 y?: number[];
63 };
64 snapGap?: number;
65 bounds?: 'parent' | 'window' | HTMLElement;
66 boundsByDirection?: boolean;
67 size?: Size;
68 minWidth?: string | number;
69 minHeight?: string | number;
70 maxWidth?: string | number;
71 maxHeight?: string | number;
72 lockAspectRatio?: boolean | number;
73 lockAspectRatioExtraWidth?: number;
74 lockAspectRatioExtraHeight?: number;
75 enable?: Enable | false;
76 handleStyles?: HandleStyles;
77 handleClasses?: HandleClassName;
78 handleWrapperStyle?: React.CSSProperties;
79 handleWrapperClass?: string;
80 handleComponent?: HandleComponent;
81 children?: React.ReactNode;
82 onResizeStart?: ResizeStartCallback;
83 onResize?: ResizeCallback;
84 onResizeStop?: ResizeCallback;
85 defaultSize?: Size;
86 scale?: number;
87 resizeRatio?: number | [number, number];
88}
89interface State {
90 isResizing: boolean;
91 direction: Direction;
92 original: {
93 x: number;
94 y: number;
95 width: number;
96 height: number;
97 };
98 width: number | string;
99 height: number | string;
100 backgroundStyle: React.CSSProperties;
101 flexBasis?: string | number;
102}
103declare global {
104 interface Window {
105 MouseEvent: typeof MouseEvent;
106 TouchEvent: typeof TouchEvent;
107 }
108}
109export declare class Resizable extends React.PureComponent<ResizableProps, State> {
110 flexDir?: 'row' | 'column';
111 get parentNode(): HTMLElement | null;
112 get window(): Window | null;
113 get propsSize(): Size;
114 get size(): NumberSize;
115 get sizeStyle(): {
116 width: string;
117 height: string;
118 };
119 static defaultProps: {
120 as: string;
121 onResizeStart: () => void;
122 onResize: () => void;
123 onResizeStop: () => void;
124 enable: {
125 top: boolean;
126 right: boolean;
127 bottom: boolean;
128 left: boolean;
129 topRight: boolean;
130 bottomRight: boolean;
131 bottomLeft: boolean;
132 topLeft: boolean;
133 };
134 style: {};
135 grid: number[];
136 gridGap: number[];
137 lockAspectRatio: boolean;
138 lockAspectRatioExtraWidth: number;
139 lockAspectRatioExtraHeight: number;
140 scale: number;
141 resizeRatio: number;
142 snapGap: number;
143 };
144 ratio: number;
145 resizable: HTMLElement | null;
146 parentLeft: number;
147 parentTop: number;
148 resizableLeft: number;
149 resizableRight: number;
150 resizableTop: number;
151 resizableBottom: number;
152 targetLeft: number;
153 targetTop: number;
154 constructor(props: ResizableProps);
155 getParentSize(): {
156 width: number;
157 height: number;
158 };
159 bindEvents(): void;
160 unbindEvents(): void;
161 componentDidMount(): void;
162 appendBase: () => HTMLDivElement | null;
163 removeBase: (base: HTMLElement) => void;
164 componentWillUnmount(): void;
165 createSizeForCssProperty(newSize: number | string, kind: 'width' | 'height'): number | string;
166 calculateNewMaxFromBoundary(maxWidth?: number, maxHeight?: number): {
167 maxWidth: number | undefined;
168 maxHeight: number | undefined;
169 };
170 calculateNewSizeFromDirection(clientX: number, clientY: number): {
171 newWidth: number;
172 newHeight: number;
173 };
174 calculateNewSizeFromAspectRatio(newWidth: number, newHeight: number, max: {
175 width?: number;
176 height?: number;
177 }, min: {
178 width?: number;
179 height?: number;
180 }): {
181 newWidth: number;
182 newHeight: number;
183 };
184 setBoundingClientRect(): void;
185 onResizeStart(event: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, direction: Direction): void;
186 onMouseMove(event: MouseEvent | TouchEvent): void;
187 onMouseUp(event: MouseEvent | TouchEvent): void;
188 updateSize(size: Size): void;
189 renderResizer(): JSX.Element | null;
190 render(): JSX.Element;
191}
192export {};