mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
cursor: cursor helper
This commit is contained in:
parent
cfe3b5ec8c
commit
3771e5d338
4 changed files with 61 additions and 7 deletions
32
src/components/Cursor.jsx
Normal file
32
src/components/Cursor.jsx
Normal file
|
@ -0,0 +1,32 @@
|
|||
import React from 'react';
|
||||
import { Icon } from '$components/panels/Icon';
|
||||
import { MODES } from '$constants/modes';
|
||||
|
||||
type Props = {
|
||||
mode: String,
|
||||
}
|
||||
|
||||
export class Cursor extends React.PureComponent<Props, void> {
|
||||
componentDidMount() {
|
||||
window.addEventListener('mousemove', this.moveCursor);
|
||||
}
|
||||
|
||||
moveCursor = e => {
|
||||
if (!e.clientX || !e.clientY) return;
|
||||
|
||||
const { clientX, clientY } = e;
|
||||
|
||||
this.cursor.style.transform = `translate3d(${clientX}px, ${clientY}px, 0)`;
|
||||
};
|
||||
|
||||
render() {
|
||||
const { mode } = this.props;
|
||||
|
||||
return (
|
||||
<div className="cursor-tooltip" ref={el => { this.cursor = el; }}>
|
||||
{ mode === MODES.ROUTER && <Icon icon="icon-router" />}
|
||||
{ mode === MODES.POLY && <Icon icon="icon-poly" />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue