-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathuseMouseHovered.story.tsx
46 lines (43 loc) Β· 1.23 KB
/
useMouseHovered.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
41
42
43
44
45
46
import { boolean, withKnobs } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useMouseHovered } from '../src';
import ShowDocs from './util/ShowDocs';
const Demo = ({ whenHovered, bound }: any) => {
const ref = React.useRef(null);
const state = useMouseHovered(ref, { whenHovered, bound });
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/useMouseHovered', module)
.addDecorator(withKnobs)
.add('Docs', () => <ShowDocs md={require('../docs/useMouse.md')} />)
.add('Demo', () => {
const bound = boolean('bound', false);
const whenHovered = boolean('whenHovered', false);
return <Demo whenHovered={whenHovered} bound={bound} />;
});