Skip to content

Commit

Permalink
adding onReveal event hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rnosov committed Oct 20, 2016
1 parent d83518c commit 9f09414
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Wrap the jsx that you want to be revealed in your **render** method:
### Properties

- `effect` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** This prop expects a string containing CSS animation effect. You can use any animate.css animations or use any other CSS based animations. If you're using animate.css don't forget to add *animated* base class. **Required**.
- `onReveal` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)** Function called once the element is revealed. **Optional**.

### Children

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-reveal",
"version": "0.1.0",
"version": "0.1.1",
"author": "Roman Nosov <rnosov@gmail.com>",
"description": "Easily add reveal animation to any React component",
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion src/Reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const
effect: PropTypes.string.isRequired,
className: PropTypes.string,
style: PropTypes.object,
onReveal: PropTypes.func,
children: PropTypes.node.isRequired,
},
defaultProps = {
Expand All @@ -35,6 +36,8 @@ class Reveal extends Component {
if (window.pageYOffset + window.innerHeight*0.85 > getAbsoluteOffsetTop(this.refs.el)) {
this.setState({ isHidden: false });
this.componentWillUnmount();
if (typeof this.props.onReveal === 'function')
this.props.onReveal();
}
};

Expand All @@ -54,7 +57,7 @@ class Reveal extends Component {
}

render() {
const { effect, style, className, ...props } = this.props;
const { effect, style, className, onReveal, ...props } = this.props;
let animation = '', s = {};
if (this.props.effect) {
if (this.state.isHidden)
Expand Down

0 comments on commit 9f09414

Please sign in to comment.