Skip to content

Commit 06d965f

Browse files
Aarti Nanwani SamtaniAarti Nanwani Samtani
authored andcommitted
Define mouse-cursor-component
1 parent 603be6b commit 06d965f

9 files changed

Lines changed: 119 additions & 1 deletion

File tree

src/common/components/mock-components/front-basic-shapes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './large-arrow-shape';
1010
export * from './image-shape';
1111
export * from './modal-cover-shape';
1212
export * from './cilinder-basic-shape';
13+
export * from './mouse-cursor-basic-shape';
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { ShapeSizeRestrictions, ShapeType, BASE_ICONS_URL } from '@/core/model';
2+
import { forwardRef, useEffect, useState } from 'react';
3+
import { ShapeProps } from '../shape.model';
4+
import { loadSvgWithFill } from '@/common/utils/svg.utils';
5+
import { Group, Image } from 'react-konva';
6+
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
7+
import { returnIconSize } from '../front-components/icon/icon-shape.business';
8+
import { useGroupShapeProps } from '../mock-components.utils';
9+
10+
const MouseCursorSizeRestrictions: ShapeSizeRestrictions = {
11+
minWidth: 25,
12+
minHeight: 25,
13+
maxWidth: -1,
14+
maxHeight: -1,
15+
defaultWidth: 150,
16+
defaultHeight: 150,
17+
};
18+
19+
export const getMouseCursorShapeSizeRestrictions = (): ShapeSizeRestrictions =>
20+
MouseCursorSizeRestrictions;
21+
22+
const shapeType: ShapeType = 'mouseCursor';
23+
24+
export const MouseCursorShape = forwardRef<any, ShapeProps>((props, ref) => {
25+
const {
26+
x,
27+
y,
28+
width,
29+
height,
30+
id,
31+
onSelected,
32+
text,
33+
iconSize,
34+
otherProps,
35+
...shapeProps
36+
} = props;
37+
38+
const [iconWidth, iconHeight] = returnIconSize(iconSize);
39+
const restrictedSize = fitSizeToShapeSizeRestrictions(
40+
MouseCursorSizeRestrictions,
41+
iconWidth,
42+
iconHeight
43+
);
44+
45+
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
46+
const commonGroupProps = useGroupShapeProps(
47+
props,
48+
restrictedSize,
49+
shapeType,
50+
ref
51+
);
52+
53+
const [image, setImage] = useState<HTMLImageElement | null>(null);
54+
//const imgRef = useRef(null);
55+
const fileName = 'cursor.svg';
56+
useEffect(() => {
57+
loadSvgWithFill(`${BASE_ICONS_URL}${fileName}`, '').then(img => {
58+
setImage(img);
59+
});
60+
}, []);
61+
return (
62+
<Group {...commonGroupProps} {...shapeProps}>
63+
{image && (
64+
<Image
65+
image={image}
66+
x={0}
67+
y={0}
68+
width={restrictedWidth}
69+
height={restrictedHeight}
70+
//ref={imageRef}
71+
/>
72+
)}
73+
</Group>
74+
);
75+
});

src/core/model/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export type ShapeType =
8787
| 'textScribbled'
8888
| 'paragraphScribbled'
8989
| 'fabButton'
90-
| 'fileTree';
90+
| 'fileTree'
91+
| 'mouseCursor';
9192

9293
export const ShapeDisplayName: Record<ShapeType, string> = {
9394
multiple: 'multiple',
@@ -164,6 +165,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
164165
paragraphScribbled: 'Paragraph Scribbled',
165166
fabButton: 'Fab Button',
166167
fileTree: 'File Tree',
168+
mouseCursor: 'Mouse Cursor',
167169
};
168170

169171
export type EditType = 'input' | 'textarea' | 'imageupload';

src/pods/canvas/model/shape-size.mapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
getStarShapeSizeRestrictions,
4343
getModalCoverShapeSizeRestrictions,
4444
getCilinderShapeSizeRestrictions,
45+
getMouseCursorShapeSizeRestrictions,
4546
// other imports
4647
} from '@/common/components/mock-components/front-basic-shapes';
4748
import {
@@ -177,6 +178,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
177178
fabButton: getFabButtonShapeSizeRestrictions,
178179
fileTree: getFileTreeShapeSizeRestrictions,
179180
paragraphScribbled: getParagraphScribbledShapeRestrictions,
181+
mouseCursor: getMouseCursorShapeSizeRestrictions,
180182
};
181183

182184
export default shapeSizeMap;

src/pods/canvas/model/transformer.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const generateTypeOfTransformer = (shapeType: ShapeType): string[] => {
8787
'bottom-center',
8888
];
8989
case 'icon':
90+
case 'mouseCursor':
9091
case 'multiple':
9192
return [];
9293
case 'image':

src/pods/canvas/shape-renderer/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
renderLargeArrowShape,
6666
renderCilinder,
6767
renderImage,
68+
renderMouseCursor,
6869
} from './simple-basic-shapes';
6970
import {
7071
renderHeading1,
@@ -238,6 +239,8 @@ export const renderShapeComponent = (
238239
return renderTextScribbled(shape, shapeRenderedProps);
239240
case 'paragraphScribbled':
240241
return renderParagraphScribbled(shape, shapeRenderedProps);
242+
case 'mouseCursor':
243+
return renderMouseCursor(shape, shapeRenderedProps);
241244
default:
242245
return renderNotFound(shape, shapeRenderedProps);
243246
}

src/pods/canvas/shape-renderer/simple-basic-shapes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './large-arrow.renderer';
1010
export * from './modal-cover.rerender';
1111
export * from './cilinder.renderer';
1212
export * from './image.renderer';
13+
export * from './mouse-cursor.renderer';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { MouseCursorShape } from '@/common/components/mock-components/front-basic-shapes';
2+
import { ShapeModel } from '@/core/model';
3+
import { ShapeRendererProps } from '../model';
4+
5+
export const renderMouseCursor = (
6+
shape: ShapeModel,
7+
shapeRenderedProps: ShapeRendererProps
8+
) => {
9+
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } =
10+
shapeRenderedProps;
11+
12+
return (
13+
<MouseCursorShape
14+
id={shape.id}
15+
key={shape.id}
16+
ref={shapeRefs.current[shape.id]}
17+
x={shape.x}
18+
y={shape.y}
19+
name="shape"
20+
width={shape.width}
21+
height={shape.height}
22+
draggable
23+
typeOfTransformer={shape.typeOfTransformer}
24+
onSelected={handleSelected}
25+
onDragEnd={handleDragEnd(shape.id)}
26+
onTransform={handleTransform}
27+
onTransformEnd={handleTransform}
28+
otherProps={shape.otherProps}
29+
iconSize={shape.otherProps?.iconSize}
30+
/>
31+
);
32+
};

src/pods/galleries/basic-shapes-gallery/basic-gallery-data/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export const mockBasicShapesCollection: ItemInfo[] = [
1313
{ thumbnailSrc: '/shapes/triangle.svg', type: 'triangle' },
1414
{ thumbnailSrc: '/shapes/verticalLine.svg', type: 'verticalLine' },
1515
{ thumbnailSrc: '/shapes/cilinder.svg', type: 'cilinder' },
16+
{ thumbnailSrc: '/icons/cursor.svg', type: 'mouseCursor' },
1617
];

0 commit comments

Comments
 (0)