Skip to content

Commit af2ffe1

Browse files
authored
Merge branch 'dev' into feature/fix-input-stepper-align-right-number
2 parents 59de555 + 43fdba9 commit af2ffe1

13 files changed

Lines changed: 278 additions & 64 deletions

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

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-other-props.utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ export const generateDefaultOtherProps = (
266266
iconSize: 'M',
267267
stroke: BASIC_SHAPE.DEFAULT_STROKE_COLOR,
268268
};
269+
case 'mouseCursor':
270+
return {
271+
stroke: BASIC_SHAPE.DEFAULT_STROKE_COLOR,
272+
iconSize: 'M',
273+
};
269274
case 'image':
270275
return {
271276
imageSrc: '',

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';

0 commit comments

Comments
 (0)