-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmouse-cursor-shape.tsx
More file actions
86 lines (72 loc) · 2.17 KB
/
mouse-cursor-shape.tsx
File metadata and controls
86 lines (72 loc) · 2.17 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { forwardRef, useEffect, useState, useRef } from 'react';
import { Group, Image } from 'react-konva';
import { ShapeSizeRestrictions, ShapeType, BASE_ICONS_URL } from '@/core/model';
import { ShapeProps } from '../../shape.model';
import { BASIC_SHAPE } from '../shape.const';
import { useShapeProps } from '../../../shapes/use-shape-props.hook';
import { useGroupShapeProps } from '../../mock-components.utils';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { returnIconSize } from './icon-shape.business';
import { loadSvgWithFill } from '@/common/utils/svg.utils';
const MouseCursorSizeRestrictions: ShapeSizeRestrictions = {
minWidth: 25,
minHeight: 25,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 150,
defaultHeight: 150,
};
export const getMouseCursorShapeSizeRestrictions = (): ShapeSizeRestrictions =>
MouseCursorSizeRestrictions;
const shapeType: ShapeType = 'mousecursor';
export const MouseCursorShape = forwardRef<any, ShapeProps>((props, ref) => {
const {
x,
y,
width,
height,
id,
onSelected,
text,
iconSize,
otherProps,
...shapeProps
} = props;
const [iconWidth, iconHeight] = returnIconSize(iconSize);
const restrictedSize = fitSizeToShapeSizeRestrictions(
MouseCursorSizeRestrictions,
iconWidth,
iconHeight
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
const { stroke } = useShapeProps(otherProps, BASIC_SHAPE);
const commonGroupProps = useGroupShapeProps(
props,
restrictedSize,
shapeType,
ref
);
const [image, setImage] = useState<HTMLImageElement | null>(null);
const imageRef = useRef(null);
const fileName = 'cursor.svg';
useEffect(() => {
loadSvgWithFill(`${BASE_ICONS_URL}${fileName}`, `${stroke}`).then(img => {
setImage(img);
});
}, [stroke]);
return (
<Group {...commonGroupProps} {...shapeProps}>
{image && (
<Image
image={image}
x={0}
y={0}
width={restrictedWidth}
height={restrictedHeight}
ref={imageRef}
/>
)}
</Group>
);
});
export default MouseCursorShape;