-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move TS defs to own folder and add tests
- Loading branch information
1 parent
ff67f9c
commit a31c5bb
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
declare module 'react-draggable' { | ||
import * as React from 'react'; | ||
|
||
export interface DraggableBounds { | ||
left: number | ||
right: number | ||
top: number | ||
bottom: number | ||
} | ||
|
||
export interface DraggableProps extends DraggableCoreProps { | ||
axis: 'both' | 'x' | 'y' | 'none', | ||
bounds: DraggableBounds | string | false , | ||
defaultClassName: string, | ||
defaultClassNameDragging: string, | ||
defaultClassNameDragged: string, | ||
defaultPosition: ControlPosition, | ||
position: ControlPosition | ||
} | ||
|
||
export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void | false; | ||
|
||
export interface DraggableData { | ||
node: HTMLElement, | ||
x: number, y: number, | ||
deltaX: number, deltaY: number, | ||
lastX: number, lastY: number | ||
} | ||
|
||
export type ControlPosition = {x: number, y: number}; | ||
|
||
export interface DraggableCoreProps { | ||
allowAnyClick: boolean, | ||
cancel: string, | ||
disabled: boolean, | ||
enableUserSelectHack: boolean, | ||
offsetParent: HTMLElement, | ||
grid: [number, number], | ||
handle: string, | ||
onStart: DraggableEventHandler, | ||
onDrag: DraggableEventHandler, | ||
onStop: DraggableEventHandler, | ||
onMouseDown: (e: MouseEvent) => void | ||
} | ||
|
||
export default class Draggable extends React.Component<Partial<DraggableProps>, {}> { | ||
static defaultProps : DraggableProps; | ||
} | ||
|
||
export class DraggableCore extends React.Component<Partial<DraggableCoreProps>, {}> { | ||
static defaultProps : DraggableCoreProps; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import Draggable, {DraggableCore} from 'react-draggable'; | ||
|
||
const root = document.getElementById('root') | ||
|
||
function handleStart() {} | ||
function handleDrag() {} | ||
function handleStop() {} | ||
function handleMouseDown() {} | ||
|
||
ReactDOM.render( | ||
<Draggable | ||
axis="y" | ||
handle=".handle" | ||
cancel=".cancel" | ||
grid={[10, 10]} | ||
onStart={handleStart} | ||
onDrag={handleDrag} | ||
onStop={handleStop} | ||
offsetParent={document.body} | ||
allowAnyClick={true} | ||
onMouseDown={handleMouseDown} | ||
disabled={true} | ||
enableUserSelectHack={false} | ||
bounds={false} | ||
defaultClassName={'draggable'} | ||
defaultClassNameDragging={'dragging'} | ||
defaultClassNameDragged={'dragged'} | ||
defaultPosition={{x: 0, y: 0}} | ||
position={{x: 50, y: 50}}> | ||
<div className="foo bar"> | ||
<div className="handle"/> | ||
<div className="cancel"/> | ||
</div> | ||
</Draggable>, | ||
root | ||
); | ||
|
||
ReactDOM.render( | ||
<DraggableCore | ||
handle=".handle" | ||
cancel=".cancel" | ||
allowAnyClick={true} | ||
disabled={true} | ||
onMouseDown={handleMouseDown} | ||
grid={[10, 10]} | ||
onStart={handleStart} | ||
onDrag={handleDrag} | ||
onStop={handleStop} | ||
offsetParent={document.body} | ||
enableUserSelectHack={false}> | ||
<div className="foo bar"> | ||
<div className="handle"/> | ||
<div className="cancel"/> | ||
</div> | ||
</DraggableCore>, | ||
root | ||
); | ||
|
||
|
||
ReactDOM.render(<Draggable><div/></Draggable>, root); | ||
|
||
ReactDOM.render(<DraggableCore><div/></DraggableCore>, root); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"jsx": "preserve", | ||
"strict": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"test.tsx" | ||
] | ||
} |