-
Notifications
You must be signed in to change notification settings - Fork 30
/
DragHandle.js
57 lines (51 loc) · 1.24 KB
/
DragHandle.js
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
import { forwardRef } from 'react';
import PropTypes from 'prop-types'
import styled from 'styled-components'
import draggable from '../draggable'
const StyledCircle = styled('circle')`
stroke-width: 2;
&:hover {
cursor: move;
}
`
const RADIUS = screen.width > 900 ? 4 : 10
const DragHandle = forwardRef(function DragHandle(
{
fill,
radius,
scale,
x,
y,
dragging = false,
invisibleWhenDragging = false,
testid,
...props
},
ref
) {
const transform = `translate(${x}, ${y}) scale(${1 / scale})`
const styleProps = {
fill: dragging && invisibleWhenDragging ? 'transparent' : fill,
stroke: dragging && invisibleWhenDragging ? 'transparent' : 'currentColor',
strokeWidth: 1
}
return (
<g ref={ref} transform={transform} data-testid={testid} {...props} >
<StyledCircle r={radius} {...styleProps} />
<StyledCircle r={2 * radius} fill='transparent' stroke='transparent' />
</g>
)
})
DragHandle.propTypes = {
fill: PropTypes.string,
radius: PropTypes.number,
scale: PropTypes.number,
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired
}
DragHandle.defaultProps = {
fill: 'currentColor',
radius: RADIUS,
scale: 1
}
export default draggable(DragHandle)