File size: 1,172 Bytes
1e92f2d |
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 |
import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useIntersection } from '../src';
import ShowDocs from './util/ShowDocs';
const Spacer = () => (
<div
style={{
width: '200px',
height: '300px',
backgroundColor: 'whitesmoke',
}}
/>
);
const Demo = () => {
const intersectionRef = React.useRef(null);
const intersection = useIntersection(intersectionRef, {
root: null,
rootMargin: '0px',
threshold: 1,
});
return (
<div
style={{
width: '400px',
height: '400px',
backgroundColor: 'whitesmoke',
overflow: 'scroll',
}}>
Scroll me
<Spacer />
<div
ref={intersectionRef}
style={{
width: '100px',
height: '100px',
padding: '20px',
backgroundColor: 'palegreen',
}}>
{intersection && intersection.intersectionRatio < 1 ? 'Obscured' : 'Fully in view'}
</div>
<Spacer />
</div>
);
};
storiesOf('Sensors/useIntersection', module)
.add('Docs', () => <ShowDocs md={require('../docs/useIntersection.md')} />)
.add('Demo', () => <Demo />);
|