File size: 1,174 Bytes
597ee18 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import anim from '../src';
import React from 'react';
import ReactDOM from 'react-dom';
import { storiesOf } from '@storybook/react';
const style = `
.box {
background:red;
width:100px;
height:100px;
}
.collapse-active {
transition: height .3s ease-out;
}
`;
let show = true;
function toggle() {
const t = document.getElementById('t');
const b = document.getElementById('b');
b.disabled = true;
t.style.display = '';
let height;
anim(t, `collapse`, {
start() {
if (show) {
t.style.height = `${t.offsetHeight}px`;
} else {
height = t.offsetHeight;
t.style.height = 0;
}
},
active() {
t.style.height = `${show ? height : 0}px`;
},
end() {
t.style.display = show ? '' : 'none';
b.disabled = false;
t.style.height = '';
},
});
show = !show;
}
const Demo = () => (
<div>
<style dangerouslySetInnerHTML={{ __html: style }}></style>
<div className="box" id="t"></div>
<button onClick={toggle} id="b">
toggle
</button>
</div>
);
Demo.story = 'collapse';
storiesOf(Demo.story, module).add('demo', () => <Demo />);
export default Demo;
|