-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
useMouse.story.tsx
40 lines (37 loc) Β· 936 Bytes
/
useMouse.story.tsx
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
import * as React from 'react';
import {storiesOf} from '@storybook/react';
import {useMouse} from '..';
import ShowDocs from '../util/ShowDocs';
const Demo: React.FC<any> = () => {
const ref = React.useRef(null);
const state = useMouse(ref)
return (
<>
<pre>
{JSON.stringify(state, null, 2)}
</pre>
<br />
<br />
<div
ref={ref}
style={{
position: 'relative',
width: '400px',
height: '400px',
backgroundColor: 'whitesmoke',
}}>
<span style={{
position: 'absolute',
left: `${state.elX}px`,
top: `${state.elY}px`,
pointerEvents: 'none',
transform: 'scale(4)'}}>
π
</span>
</div>
</>
);
};
storiesOf('Sensors|useMouse', module)
.add('Docs', () => <ShowDocs md={require('../../docs/useMouse.md')} />)
.add('Demo', () => <Demo />)