mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-06 09:19:08 +00:00
Merge pull request #17716 from DeividasBakanas/feature/react-swipe
react-swipe types added.
This commit is contained in:
34
types/react-swipe/index.d.ts
vendored
Normal file
34
types/react-swipe/index.d.ts
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// Type definitions for react-swipe 5.0
|
||||
// Project: https://github.com/voronianski/react-swipe
|
||||
// Definitions by: Deividas Bakanas <https://github.com/DeividasBakanas>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="swipe" />
|
||||
|
||||
import * as React from "react";
|
||||
|
||||
declare class ReactSwipe extends React.Component<ReactSwipe.Props, {}> {
|
||||
prev(): void;
|
||||
next(): void;
|
||||
getPos(): number;
|
||||
getNumSlides(): number;
|
||||
slide(index: number, duration: number): void;
|
||||
}
|
||||
|
||||
declare namespace ReactSwipe {
|
||||
interface Style {
|
||||
container: React.CSSProperties;
|
||||
wrapper: React.CSSProperties;
|
||||
child: React.CSSProperties;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
id?: string;
|
||||
swipeOptions?: SwipeOptions;
|
||||
style?: Style;
|
||||
className?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export = ReactSwipe;
|
||||
75
types/react-swipe/react-swipe-tests.tsx
Normal file
75
types/react-swipe/react-swipe-tests.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import * as React from "react";
|
||||
import * as ReactSwipe from "react-swipe";
|
||||
|
||||
class ReactSwipeTest extends React.PureComponent {
|
||||
private swipeComponent: ReactSwipe | null = null;
|
||||
|
||||
private onPrev: React.MouseEventHandler<HTMLButtonElement> = () => {
|
||||
if (this.swipeComponent != null) {
|
||||
this.swipeComponent.prev();
|
||||
}
|
||||
}
|
||||
|
||||
private onNext: React.MouseEventHandler<HTMLButtonElement> = () => {
|
||||
if (this.swipeComponent != null) {
|
||||
this.swipeComponent.next();
|
||||
}
|
||||
}
|
||||
|
||||
private onSlideToStart: React.MouseEventHandler<HTMLButtonElement> = () => {
|
||||
if (this.swipeComponent != null) {
|
||||
const lastSlide = this.swipeComponent.getNumSlides() - 1;
|
||||
this.swipeComponent.slide(lastSlide, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private onGetCurrentPosition: React.MouseEventHandler<HTMLButtonElement> = () => {
|
||||
let currentPosition: number;
|
||||
|
||||
if (this.swipeComponent != null) {
|
||||
currentPosition = this.swipeComponent.getPos();
|
||||
} else {
|
||||
currentPosition = 0;
|
||||
}
|
||||
|
||||
alert(currentPosition);
|
||||
}
|
||||
|
||||
render() {
|
||||
const swipeOptions: SwipeOptions = {
|
||||
auto: 12,
|
||||
disableScroll: true,
|
||||
stopPropagation: true
|
||||
};
|
||||
|
||||
const style: ReactSwipe.Style = {
|
||||
child: {
|
||||
backgroundColor: "yellow"
|
||||
},
|
||||
container: {
|
||||
backgroundColor: "green"
|
||||
},
|
||||
wrapper: {
|
||||
backgroundColor: "red"
|
||||
}
|
||||
};
|
||||
|
||||
return <div>
|
||||
<ReactSwipe
|
||||
className="carousel"
|
||||
id="test-carousel"
|
||||
swipeOptions={swipeOptions}
|
||||
style={style}
|
||||
ref={(swipeComponent) => { this.swipeComponent = swipeComponent; }}
|
||||
>
|
||||
<div>PANE 1</div>
|
||||
<div>PANE 2</div>
|
||||
<div>PANE 3</div>
|
||||
</ReactSwipe>
|
||||
<button onClick={this.onPrev}>Prev</button>
|
||||
<button onClick={this.onNext}>Next</button>
|
||||
<button onClick={this.onSlideToStart}>Slide to end</button>
|
||||
<button onClick={this.onGetCurrentPosition}>Get current position</button>
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
25
types/react-swipe/tsconfig.json
Normal file
25
types/react-swipe/tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"jsx": "react",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [
|
||||
],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-swipe-tests.tsx"
|
||||
]
|
||||
}
|
||||
1
types/react-swipe/tslint.json
Normal file
1
types/react-swipe/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user