Skip to content

Instantly share code, notes, and snippets.

@cjohansen
Created May 12, 2016 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjohansen/feeb4ecfd368c488bec006f0c316c12b to your computer and use it in GitHub Desktop.
Save cjohansen/feeb4ecfd368c488bec006f0c316c12b to your computer and use it in GitHub Desktop.
import {createComponent} from 'origo-react';
import {DOM, createFactory} from 'react';
import {findDOMNode} from 'react-dom';
const {div} = DOM;
export const Drawer = createComponent({
componentWillAppear(callback) {
this.componentWillEnter(callback);
},
componentWillEnter(callback) {
const el = findDOMNode(this);
el.style.height = 'auto';
const height = el.offsetHeight;
if (!this.props.data.animate) {
el.style.height = `${height}px`;
return callback();
}
el.style.height = 0;
setTimeout(() => {
el.style.height = `${height}px`;
callback();
}, 0);
},
componentWillLeave(callback) {
const el = findDOMNode(this);
function afterTransition() {
callback();
el.removeEventListener('transitionend', afterTransition);
el.style.height = 'auto';
}
el.addEventListener('transitionend', afterTransition);
el.style.height = 0;
},
render(data, children) {
return div({className: 'leest-sticky'}, children);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment