diff --git a/types/react-onclickoutside/index.d.ts b/types/react-onclickoutside/index.d.ts index 98bef683ad..05c086fac1 100644 --- a/types/react-onclickoutside/index.d.ts +++ b/types/react-onclickoutside/index.d.ts @@ -1,29 +1,38 @@ -// Type definitions for react-onclickoutside v5.7.0 +// Type definitions for react-onclickoutside 5.7 // Project: https://github.com/Pomax/react-onclickoutside // Definitions by: Karol Janyst // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -import * as React from "react"; +import * as React from 'react'; -declare namespace ReactOnClickOutside { - interface OnClickOutsideComponent { - handleClickOutside(e: React.MouseEvent): void +declare namespace OnClickOut { + interface HandleClickOutside { + handleClickOutside: React.MouseEventHandler; } - interface OnClickOutsideProps { - disableOnClickOutside?: boolean | Function - enableOnClickOutside?: Function - eventTypes?: string | Array - outsideClickIgnoreClass?: string - preventDefault?: boolean - stopPropagation?: boolean + interface InjectedOnClickOutProps { + disableOnClickOutside(): void; + enableOnClickOutside(): void; } - interface onClickOutside { - (component: React.ComponentClass | React.StatelessComponent): React.ComponentClass + interface OnClickOutProps { + disableOnClickOutside?: boolean; + eventTypes?: string | string[]; + outsideClickIgnoreClass?: string; + preventDefault?: boolean; + stopPropagation?: boolean; } } -declare const onClickOutside: ReactOnClickOutside.onClickOutside -export = onClickOutside; \ No newline at end of file +type ComponentConstructor

= React.ComponentClass

| React.StatelessComponent

; +interface ClickOutComponentClass

extends React.ComponentClass

{ + new (props?: P, context?: any): React.Component & OnClickOut.HandleClickOutside; +} + +declare function OnClickOut

( + component: ComponentConstructor

> + | ClickOutComponentClass

+): React.ComponentClass

; + +export = OnClickOut; diff --git a/types/react-onclickoutside/react-onclickoutside-tests.tsx b/types/react-onclickoutside/react-onclickoutside-tests.tsx index fc782bb68c..f6ed316683 100644 --- a/types/react-onclickoutside/react-onclickoutside-tests.tsx +++ b/types/react-onclickoutside/react-onclickoutside-tests.tsx @@ -1,21 +1,49 @@ -import * as React from "react" -import { Component, StatelessComponent, MouseEvent } from "react" -import { render } from "react-dom" -import * as onClickOutside from "react-onclickoutside" +import * as React from 'react'; +import { Component, MouseEvent, StatelessComponent } from 'react'; +import { render } from 'react-dom'; +import * as onClickOutside from 'react-onclickoutside'; -interface TestProps {} - -var TestStateless: StatelessComponent = (props: TestProps) => { - return (

Test
) +function TestStateless(props: { handleClickOutside(): void; }) { + return ( +
Test
+ ); } -var TestStatelessWrapped = onClickOutside(TestStateless) +const TestStatelessWrapped = onClickOutside(TestStateless); render( - , + console.log('Stateless HandleClickOutside')} + />, document.getElementById("main") -) \ No newline at end of file +); + +class TestComponent extends React.Component<{ disableOnClickOutside(): void; enableOnClickOutside(): void; }, {}> { + handleClickOutside = () => { + console.log('this.handleClickOutside'); + } + + render() { + this.props.disableOnClickOutside(); + this.props.enableOnClickOutside(); + return ( +
TestComponent
+ ); + } +} + +const WrappedComponent = onClickOutside<{}>(TestComponent); + +render( + , + document.getElementById("main") +); diff --git a/types/react-onclickoutside/tslint.json b/types/react-onclickoutside/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/react-onclickoutside/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}