Skip to content

Commit

Permalink
doc: add table to show props and proptypes of listener
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdeji authored and ooade committed Oct 1, 2020
1 parent b5551f5 commit a99498d
Showing 1 changed file with 8 additions and 87 deletions.
95 changes: 8 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,93 +44,14 @@ const App = () => {
};
```
### Specify React listener element type
```jsx
import ClickAwayListener from 'react-click-away-listener';
const App = () => {
const handleClickAway = () => {
console.log('Hey, you can close the Popup now');
};
return (
<div id="app">
<ClickAwayListener onClickAway={handleClickAway} as="button">
<div> Some Popup, Nav or anything </div>
</ClickAwayListener>
<div id="rest-of-the-app">Don't name a div like that :(</div>
</div>
);
};
```
### Pass props to the listener
```jsx
import ClickAwayListener from 'react-click-away-listener';

const App = () => {
const handleClickAway = () => {
console.log('Hey, you can close the Popup now');
};

return (
<div id="app">
<ClickAwayListener
onClickAway={handleClickAway}
style={{ padding: '10px', margin: '10px' }}
id="click_away_listener"
>
<div> Some Popup, Nav or anything </div>
</ClickAwayListener>
<div id="rest-of-the-app">Don't name a div like that :(</div>
</div>
);
};
```
### Pass mouse event type to listener
```jsx
import ClickAwayListener from 'react-click-away-listener';
const App = () => {
const handleClickAway = () => {
console.log('Hey, you can close the Popup now');
};
return (
<div id="app">
<ClickAwayListener onClickAway={handleClickAway} mouseEvent="mousedown">
<div> Some Popup, Nav or anything </div>
</ClickAwayListener>
<div id="rest-of-the-app">Don't name a div like that :(</div>
</div>
);
};
```
### Pass touch event type to listener
```jsx
import ClickAwayListener from 'react-click-away-listener';

const App = () => {
const handleClickAway = () => {
console.log('Hey, you can close the Popup now');
};

return (
<div id="app">
<ClickAwayListener onClickAway={handleClickAway} touchEvent="touchend">
<div> Some Popup, Nav or anything </div>
</ClickAwayListener>
<div id="rest-of-the-app">Don't name a div like that :(</div>
</div>
);
};
```
## Props and propsType
| Props | PropsTypes | Description |
| ----------- | ----------------------------- | --------------------------------------------- |
| onClickAway | (event) => void | fires when listener is clicked away |
| as | React.ElementType | element type to render as listener e.g button |
| mouseEvent | 'click' 'mousedown' 'mouseup' | mouse event that fires onClickAway |
| touchEvent | 'touchstart' 'touchend' | touch event that fires onClickAway |
## Examples
Expand Down

0 comments on commit a99498d

Please sign in to comment.