React interactive (#39068)

* Added type definitions for react-interactive

* fix lint errors

* change to address suggestions

* fix name conflict

* add new line to end of files
This commit is contained in:
Daniel Santoro 2019-10-16 14:30:26 -04:00 committed by Andrew Branch
parent 5f756cbfc8
commit a70a4e352f
4 changed files with 134 additions and 0 deletions

82
types/react-interactive/index.d.ts vendored Normal file
View File

@ -0,0 +1,82 @@
// Type definitions for react-interactive 0.9
// Project: https://github.com/rafrex/react-interactive
// Definitions by: Daniel Santoro <https://github.com/DanudeSandstorm>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { ReactNode, ReactElement, Component, SyntheticEvent, CSSProperties } from 'react';
export {};
export type IState = 'normal' | 'hover' | 'hoverActive' | 'touchActive' | 'keyActive';
export type Focus = false | 'tab' | 'mouse' | 'touch';
export type ClickType = "mouseClick" | "tapClick" | "keyClick";
export type State = {focus: Focus, iState: IState};
type ActiveProps = {
active?: CSSProperties;
} | {
hoverActive?: CSSProperties;
touchActive?: CSSProperties;
keyActive?: CSSProperties;
};
type FocusProps = {
focus?: CSSProperties;
} | {
focusFromTab?: CSSProperties;
focusFromMouse?: CSSProperties;
focusFromTouch?: CSSProperties;
};
export type InteractiveProps = FocusProps & ActiveProps & {
// as: string | Component | ReactElement;
as: any;
hover?: CSSProperties;
style?: CSSProperties;
className?: string;
onStateChange?: (arg0: {prevState: State, nextState: State, event: SyntheticEvent}) => void;
setStateCallback?: (arg0: {prevState: State, nextState: State}) => void;
onClick?: (event: SyntheticEvent, clickType: ClickType) => void;
onTapTwo?: (event: Event) => void;
onTapThree?: (event: Event) => void;
onTapFour?: (event: Event) => void;
tapTimeCutoff?: number;
onLongPress?: (event: Event) => void;
touchActiveTapOnly?: boolean;
extraTouchNoTap?: boolean;
nonContainedChild?: boolean;
initialState?: State;
forceState?: State;
styleProperty?: object;
refDOMNode?: (node: any) => any; // Not sure about this type
focusToggleOff?: boolean;
mutableProps?: boolean;
interactiveChild?: boolean;
wrapperStyle?: CSSProperties;
wrapperClassName?: string;
};
export default class Interactive extends Component<InteractiveProps> {}

View File

@ -0,0 +1,21 @@
import * as React from "react";
import Interactive, { State } from 'react-interactive';
class InteractiveDiv extends React.Component {
private handleInteractiveStateChange(arg0: {prevState: State, nextState: State, event: React.SyntheticEvent}): void {}
private handleClick(e: React.SyntheticEvent): void {}
render() {
return (<Interactive
as="div"
hover={{ color: 'green' }}
active={{ color: 'blue' }}
focus={{ outline: '2px solid green' }}
onStateChange={this.handleInteractiveStateChange}
onClick={this.handleClick}
style={{ fontSize: '16px', padding: '3px', color: 'black' }}
>This is an interactive and focusable div</Interactive>);
}
}
export default InteractiveDiv;

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "preserve"
},
"files": [
"index.d.ts",
"react-interactive-tests.tsx"
]
}

View File

@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"interface-over-type-literal": false
}
}