mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 04:01:52 +00:00
Add react-canvas-draw definitions (#41515)
This commit is contained in:
committed by
Armando Aguirre
parent
a7b2cbb88a
commit
bd90367295
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
// Type definitions for react-canvas-draw 1.1
|
||||
// Project: https://embiem.github.io/react-canvas-draw/
|
||||
// Definitions by: Kamil Socha <https://github.com/ksocha>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
export interface CanvasDrawProps {
|
||||
onChange?: ((canvas: CanvasDraw) => void) | null;
|
||||
loadTimeOffset?: number;
|
||||
lazyRadius?: number;
|
||||
brushRadius?: number;
|
||||
brushColor?: string;
|
||||
catenaryColor?: string;
|
||||
gridColor?: string;
|
||||
backgroundColor?: string;
|
||||
hideGrid?: boolean;
|
||||
canvasWidth?: number | string;
|
||||
canvasHeight?: number | string;
|
||||
disabled?: boolean;
|
||||
imgSrc?: string;
|
||||
saveData?: string;
|
||||
immediateLoading?: boolean;
|
||||
hideInterface?: boolean;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
}
|
||||
|
||||
export default class CanvasDraw extends React.Component<CanvasDrawProps> {
|
||||
/**
|
||||
* Returns the drawing's save-data as a stringified object.
|
||||
*/
|
||||
getSaveData(): string;
|
||||
|
||||
/**
|
||||
* Loads a previously saved drawing using the saveData string, as well as an optional boolean
|
||||
* flag to load it immediately, instead of live-drawing it.
|
||||
*/
|
||||
loadSaveData(saveData: string, immediate?: boolean): void;
|
||||
|
||||
/**
|
||||
* Clears the canvas completely.
|
||||
*/
|
||||
clear(): void;
|
||||
|
||||
/**
|
||||
* Removes the latest change to the drawing. This includes everything drawn since the last MouseDown event.
|
||||
*/
|
||||
undo(): void;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import CanvasDraw from 'react-canvas-draw';
|
||||
import * as React from 'react';
|
||||
|
||||
const AllOptions: JSX.Element = (
|
||||
<CanvasDraw
|
||||
onChange={canvas => canvas.getSaveData()}
|
||||
loadTimeOffset={7}
|
||||
lazyRadius={4}
|
||||
brushRadius={1}
|
||||
brushColor="brushColor"
|
||||
catenaryColor="catenaryColor"
|
||||
gridColor="gridColor"
|
||||
backgroundColor="backgroundColor"
|
||||
hideGrid
|
||||
canvasWidth="100%"
|
||||
canvasHeight={12}
|
||||
disabled
|
||||
imgSrc="imgSrc"
|
||||
saveData="saveData"
|
||||
immediateLoading
|
||||
hideInterface
|
||||
className="className"
|
||||
style={{ border: '1px solid #000' }}
|
||||
/>
|
||||
);
|
||||
|
||||
const NoOptions: JSX.Element = <CanvasDraw />;
|
||||
|
||||
function RefTest() {
|
||||
const ref = React.useRef<CanvasDraw>(null);
|
||||
|
||||
if (ref.current) {
|
||||
ref.current.clear();
|
||||
ref.current.undo();
|
||||
ref.current.loadSaveData('data');
|
||||
ref.current.loadSaveData('data', true);
|
||||
const saveData: string = ref.current.getSaveData();
|
||||
}
|
||||
|
||||
return <CanvasDraw ref={ref} />;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"jsx": "react",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-canvas-draw-tests.tsx"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user