mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import * as React from 'react';
|
|
import { Component, MouseEvent, StatelessComponent } from 'react';
|
|
import { render } from 'react-dom';
|
|
import onClickOutside from 'react-onclickoutside';
|
|
|
|
interface TestStatelessProps {
|
|
disableOnClickOutside(): void;
|
|
enableOnClickOutside(): void;
|
|
nonClickOutsideProp: string;
|
|
}
|
|
|
|
function TestStateless(props: TestStatelessProps) {
|
|
return (
|
|
<div onKeyUp={props.enableOnClickOutside} onKeyDown={props.disableOnClickOutside}>
|
|
{props.nonClickOutsideProp}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const TestConfigObject = onClickOutside(TestStateless, {
|
|
handleClickOutside: () => console.log('Stateless HandleClickOutside'),
|
|
excludeScrollbar: true
|
|
});
|
|
|
|
render(
|
|
<TestConfigObject nonClickOutsideProp="Test" />,
|
|
document.getElementById("main")
|
|
);
|
|
|
|
const TestStatelessWrapped = onClickOutside(TestStateless);
|
|
|
|
render(
|
|
<TestStatelessWrapped
|
|
nonClickOutsideProp="Test"
|
|
eventTypes="click"
|
|
disableOnClickOutside
|
|
preventDefault
|
|
stopPropagation
|
|
outsideClickIgnoreClass="ignore"
|
|
handleClickOutside={() => console.log('Stateless HandleClickOutside')}
|
|
excludeScrollbar
|
|
/>,
|
|
document.getElementById("main")
|
|
);
|
|
|
|
class TestComponent extends React.Component<{ disableOnClickOutside(): void; enableOnClickOutside(): void; }> {
|
|
handleClickOutside = () => {
|
|
console.log('this.handleClickOutside');
|
|
}
|
|
|
|
logProps = () => {
|
|
console.log(this.props);
|
|
}
|
|
|
|
render() {
|
|
this.props.disableOnClickOutside();
|
|
this.props.enableOnClickOutside();
|
|
return (
|
|
<div onClick={this.props.disableOnClickOutside}>TestComponent</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
const WrappedComponent = onClickOutside(TestComponent);
|
|
const wrappedComponentRef: React.RefObject<InstanceType<typeof WrappedComponent>> = React.createRef();
|
|
|
|
render(
|
|
<WrappedComponent
|
|
ref={wrappedComponentRef}
|
|
eventTypes="whatever"
|
|
preventDefault
|
|
stopPropagation
|
|
/>,
|
|
document.getElementById("main")
|
|
);
|
|
|
|
if (wrappedComponentRef.current) {
|
|
wrappedComponentRef.current.getInstance().logProps();
|
|
}
|