From 87e6758d43ffcb303536b866f3401363a074f41b Mon Sep 17 00:00:00 2001 From: abirkholz Date: Fri, 7 Apr 2017 00:19:55 -0500 Subject: [PATCH] Add type for react-grid-layout --- types/react-grid-layout/index.d.ts | 110 ++++++++++++++++++ .../react-grid-layout-tests.tsx | 61 ++++++++++ types/react-grid-layout/tsconfig.json | 24 ++++ types/react-grid-layout/tslint.json | 1 + 4 files changed, 196 insertions(+) create mode 100644 types/react-grid-layout/index.d.ts create mode 100644 types/react-grid-layout/react-grid-layout-tests.tsx create mode 100644 types/react-grid-layout/tsconfig.json create mode 100644 types/react-grid-layout/tslint.json diff --git a/types/react-grid-layout/index.d.ts b/types/react-grid-layout/index.d.ts new file mode 100644 index 0000000000..5ece607aa5 --- /dev/null +++ b/types/react-grid-layout/index.d.ts @@ -0,0 +1,110 @@ +// Type definitions for react-grid-layout 0.14 +// Project: https://github.com/STRML/react-grid-layout +// Definitions by: Andrew Birkholz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as React from "react"; + +export as namespace ReactGridLayout; +export = ReactGridLayout; + +declare class ReactGridLayout extends React.Component { + constructor(props: any, context: any); + + componentDidMount(): void; + componentWillReceiveProps(nextProps: any): void; + containerHeight(): any; + onDrag(i: number, x: number, y: number, _ref2: any): void; + onDragStart(i: number, x: number, y: number, _ref: any): void; + onDragStop(i: number, x: number, y: number, _ref3: any): void; + onLayoutMaybeChanged(newLayout: any[], oldLayout: any[]): void; + onResize(i: number, w: number, h: number, _ref5: any): void; + onResizeStart(i: number, w: number, h: number, _ref4: any): void; + onResizeStop(i: number, w: number, h: number, _ref6: any): void; + placeholder(): any; + processGridItem(child: any): any; + render(): JSX.Element | null; + + static WidthProvider(ComposedComponent: any, ...args: any[]): any; + static displayName: string; +} + +declare namespace ReactGridLayout { + interface CoreProps { + autoSize?: boolean; + className?: string; + isDraggable?: boolean; + isResizable?: boolean; + layout?: any[]; + margin?: number[]; + maxRows?: number; + rowHeight?: number; + useCSSTransforms?: boolean; + verticalCompact?: boolean; + width?: number; + + onDrag?(layout: any, oldItem: any, newItem: any, placeholder: any, e: MouseEvent, element: HTMLElement): any; + onDragStart?(layout: any, oldItem: any, newItem: any, placeholder: any, e: MouseEvent, element: HTMLElement): any; + onDragStop?(layout: any, oldItem: any, newItem: any, placeholder: any, e: MouseEvent, element: HTMLElement): any; + onResize?(layout: any, oldItem: any, newItem: any, placeholder: any, e: MouseEvent, element: HTMLElement): any; + onResizeStart?(layout: any, oldItem: any, newItem: any, placeholder: any, e: MouseEvent, element: HTMLElement): any; + onResizeStop?(layout: any, oldItem: any, newItem: any, placeholder: any, e: MouseEvent, element: HTMLElement): any; + } + + interface DefaultProps extends CoreProps { + cols?: number; + onLayoutChange?(layout: any): any; + } + + interface ResponsiveProps extends CoreProps { + breakpoints: {lg: number, md: number, sm: number, xs: number, xxs: number}; + cols: {lg: number, md: number, sm: number, xs: number, xxs: number}; + layouts?: {}; + + onBreakpointChange?(newBreakpoint: string, newCols: number): any; + onLayoutChange?(currentLayout: any, allLayouts: any): any; + onWidthChange?(containerWidth: number, margin: [number, number], cols: number, containerPadding: [number, number]): any; + } + + class Responsive extends React.Component { + constructor(...args: any[]); + + componentWillReceiveProps(nextProps: any): void; + generateInitialState(): any; + onWidthChange(nextProps: any): void; + render(): JSX.Element | null; + } + + namespace Responsive { + namespace utils { + function findOrGenerateResponsiveLayout(layouts: {}, breakpoints: {}, breakpoint: number, lastBreakpoint: number, cols: {}, verticalCompact: boolean): any; + function getBreakpointFromWidth(breakpoints: {}, width: number): any; + function getColsFromBreakpoint(breakpoint: number, cols: {}): any; + function sortBreakpoints(breakpoints: {}): any; + } + } + + namespace utils { + function autoBindHandlers(el: any, fns: any): any; + function bottom(layout: any): any; + function childrenEqual(a: any, b: any): any; + function cloneLayout(layout: any): any; + function cloneLayoutItem(layoutItem: any): any; + function collides(l1: any, l2: any): any; + function compact(layout: any, verticalCompact: any): any; + function compactItem(compareWith: any, l: any, verticalCompact: any): any; + function correctBounds(layout: any, bounds: any): any; + function getAllCollisions(layout: any, layoutItem: any): any; + function getFirstCollision(layout: any, layoutItem: any): any; + function getLayoutItem(layout: any, id: any): any; + function getStatics(layout: any): any; + function moveElement(layout: any, l: any, x: any, y: any, isUserAction: any): any; + function moveElementAwayFromCollision(layout: any, collidesWith: any, itemToMove: any, isUserAction: any): any; + function perc(num: any): any; + function setTopLeft(_ref2: any): any; + function setTransform(_ref: any): any; + function sortLayoutItemsByRowCol(layout: any): any; + function synchronizeLayoutWithChildren(initialLayout: any, children: any, cols: any, verticalCompact: any): any; + function validateLayout(layout: any, contextName: any): void; + } +} diff --git a/types/react-grid-layout/react-grid-layout-tests.tsx b/types/react-grid-layout/react-grid-layout-tests.tsx new file mode 100644 index 0000000000..90c716e7f6 --- /dev/null +++ b/types/react-grid-layout/react-grid-layout-tests.tsx @@ -0,0 +1,61 @@ +import * as React from 'react'; +import * as ReactGridLayout from 'react-grid-layout'; + +const ReactGridLayoutResponsive = ReactGridLayout.Responsive; +const ReactGridLayoutResponsiveWidth = ReactGridLayout.WidthProvider(ReactGridLayout.Responsive); + +class DefaultGridTest extends React.Component { + render() { + const layout = [ + {i: 'a', x: 0, y: 0, w: 1, h: 2, static: true}, + {i: 'b', x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4}, + {i: 'c', x: 4, y: 0, w: 1, h: 2} + ]; + + return ( + +
a
+
b
+
c
+
+ ); + } +} + +class ResponsiveGridTest extends React.Component { + render() { + return ( + +
a
+
b
+
c
+
+ ); + } +} + +class ResponsiveGridWidthProviderTest extends React.Component { + render() { + return ( + +
a
+
b
+
c
+
+ ); + } +} diff --git a/types/react-grid-layout/tsconfig.json b/types/react-grid-layout/tsconfig.json new file mode 100644 index 0000000000..89ece1c775 --- /dev/null +++ b/types/react-grid-layout/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-grid-layout-tests.tsx" + ] +} \ No newline at end of file diff --git a/types/react-grid-layout/tslint.json b/types/react-grid-layout/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/types/react-grid-layout/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }