Skip to content

Commit

Permalink
Implement onRest and remove onTransitionEnd (#8)
Browse files Browse the repository at this point in the history
* Implement onRest and remove onTransitionEnd

* Update storybook

* Update CHANGELOG.md
  • Loading branch information
torleifhalseth committed Apr 7, 2017
1 parent a6d1dac commit 39ad093
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Changelog

# 3.0.0
> Apr 7, 2017
* :tada: **Feature** added `onRest` callback. The callback is triggered when your transition on `height` (specified in `className`) is done.
* :boom: **Breaking** Remove `onTransitionEnd` callback. Please use `onRest` instead.

# 2.1.0
> Apr 7, 2017
* :tada: **Feature** added `onTransitionEnd` callback that gets called after the expand/collapse animation has finished
* :tada: **Feature** added `onTransitionEnd` callback that gets called after the expand/collapse animation has finished

# 2.0.2
> Apr 5, 2017
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ One or multiple children with static, variable or dynamic height.
</Collapse>
```

#### `onTransitionEnd`: PropTypes.func

A function that is called each time the expand or collapse animation has finished
#### `onRest`: PropTypes.func
Callback function for when your transition on `height` (specified in `className`) is finished. It can be used to trigger any function after transition is done.

#### `className`: PropType.string

Expand Down
12 changes: 6 additions & 6 deletions src/components/Collapse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import util from '../util';

class Collapse extends Component {
componentDidMount() {
if (this.props.isOpen && this.content) {
if (this.content && this.props.isOpen) {
this.setContentStyleProperty('height', 'auto');
}
}
Expand Down Expand Up @@ -45,13 +45,13 @@ class Collapse extends Component {
overflow: 'hidden',
}}
className={this.props.className}
onTransitionEnd={() => {
onTransitionEnd={(e) => {
if (this.props.isOpen) {
this.setContentStyleProperty('height', 'auto');
this.setContentStyleProperty('overflow', 'visible');
}
if (this.props.onTransitionEnd) {
this.props.onTransitionEnd();
if (this.props.onRest && e.target === this.content && e.propertyName === 'height') {
this.props.onRest();
}
}}
>
Expand All @@ -65,14 +65,14 @@ Collapse.defaultProps = {
isOpen: false,
className: null,
children: null,
onTransitionEnd: null,
onRest: null,
};

Collapse.propTypes = {
children: PropTypes.node,
isOpen: PropTypes.bool,
className: PropTypes.string,
onTransitionEnd: PropTypes.func,
onRest: PropTypes.func,
};

export default Collapse;
2 changes: 1 addition & 1 deletion src/stories/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class App extends Component {
<Collapse
isOpen={this.state.index === index}
className="react-css-collapse-transition"
onTransitionEnd={action(`${element.name} is now ${this.state.index === index ? 'open' : 'closed'}`)}
onRest={action(`${element.name} is now ${this.state.index === index ? 'open' : 'closed'}`)}
>
<div style={{ background: 'lightpink', padding: '20px' }}>
{element.text}
Expand Down

0 comments on commit 39ad093

Please sign in to comment.