UNPKG

5.74 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 snap?: {
60 x?: number[];
61 y?: number[];
62 };
63 snapGap?: number;
64 bounds?: 'parent' | 'window' | HTMLElement;
65 boundsByDirection?: boolean;
66 size?: Size;
67 minWidth?: string | number;
68 minHeight?: string | number;
69 maxWidth?: string | number;
70 maxHeight?: string | number;
71 lockAspectRatio?: boolean | number;
72 lockAspectRatioExtraWidth?: number;
73 lockAspectRatioExtraHeight?: number;
74 enable?: Enable | false;
75 handleStyles?: HandleStyles;
76 handleClasses?: HandleClassName;
77 handleWrapperStyle?: React.CSSProperties;
78 handleWrapperClass?: string;
79 handleComponent?: HandleComponent;
80 children?: React.ReactNode;
81 onResizeStart?: ResizeStartCallback;
82 onResize?: ResizeCallback;
83 onResizeStop?: ResizeCallback;
84 defaultSize?: Size;
85 scale?: number;
86 resizeRatio?: number | [number, number];
87}
88interface State {
89 isResizing: boolean;
90 direction: Direction;
91 original: {
92 x: number;
93 y: number;
94 width: number;
95 height: number;
96 };
97 width: number | string;
98 height: number | string;
99 backgroundStyle: React.CSSProperties;
100 flexBasis?: string | number;
101}
102declare global {
103 interface Window {
104 MouseEvent: typeof MouseEvent;
105 TouchEvent: typeof TouchEvent;
106 }
107}
108export declare class Resizable extends React.PureComponent<ResizableProps, State> {
109 flexDir?: 'row' | 'column';
110 get parentNode(): HTMLElement | null;
111 get window(): Window | null;
112 get propsSize(): Size;
113 get size(): NumberSize;
114 get sizeStyle(): {
115 width: string;
116 height: string;
117 };
118 static defaultProps: {
119 as: string;
120 onResizeStart: () => void;
121 onResize: () => void;
122 onResizeStop: () => void;
123 enable: {
124 top: boolean;
125 right: boolean;
126 bottom: boolean;
127 left: boolean;
128 topRight: boolean;
129 bottomRight: boolean;
130 bottomLeft: boolean;
131 topLeft: boolean;
132 };
133 style: {};
134 grid: number[];
135 lockAspectRatio: boolean;
136 lockAspectRatioExtraWidth: number;
137 lockAspectRatioExtraHeight: number;
138 scale: number;
139 resizeRatio: number;
140 snapGap: number;
141 };
142 ratio: number;
143 resizable: HTMLElement | null;
144 parentLeft: number;
145 parentTop: number;
146 resizableLeft: number;
147 resizableRight: number;
148 resizableTop: number;
149 resizableBottom: number;
150 targetLeft: number;
151 targetTop: number;
152 constructor(props: ResizableProps);
153 getParentSize(): {
154 width: number;
155 height: number;
156 };
157 bindEvents(): void;
158 unbindEvents(): void;
159 componentDidMount(): void;
160 appendBase: () => HTMLDivElement | null;
161 removeBase: (base: HTMLElement) => void;
162 componentWillUnmount(): void;
163 createSizeForCssProperty(newSize: number | string, kind: 'width' | 'height'): number | string;
164 calculateNewMaxFromBoundary(maxWidth?: number, maxHeight?: number): {
165 maxWidth: number | undefined;
166 maxHeight: number | undefined;
167 };
168 calculateNewSizeFromDirection(clientX: number, clientY: number): {
169 newWidth: number;
170 newHeight: number;
171 };
172 calculateNewSizeFromAspectRatio(newWidth: number, newHeight: number, max: {
173 width?: number;
174 height?: number;
175 }, min: {
176 width?: number;
177 height?: number;
178 }): {
179 newWidth: number;
180 newHeight: number;
181 };
182 setBoundingClientRect(): void;
183 onResizeStart(event: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, direction: Direction): void;
184 onMouseMove(event: MouseEvent | TouchEvent): void;
185 onMouseUp(event: MouseEvent | TouchEvent): void;
186 updateSize(size: Size): void;
187 renderResizer(): JSX.Element | null;
188 render(): JSX.Element;
189}
190export {};