-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathparagraph-scribbled-shape.tsx
More file actions
69 lines (60 loc) · 2.09 KB
/
Copy pathparagraph-scribbled-shape.tsx
File metadata and controls
69 lines (60 loc) · 2.09 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
import { forwardRef, useMemo } from 'react';
import { Group, Path, Rect } from 'react-konva';
import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
import { ShapeProps } from '../../shape.model';
import { useShapeProps } from '../../../shapes/use-shape-props.hook';
import { BASIC_SHAPE } from '../../front-components/shape.const';
import { useGroupShapeProps } from '../../mock-components.utils';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes';
import { MIN_LINE_HEIGHT } from './paragraph-scribbled.const';
import { calculateParagraphPaths } from './paragraph-scribbled.business';
const paragraphScribbledShapeRestrictions: ShapeSizeRestrictions = {
minWidth: BASIC_SHAPE.DEFAULT_MIN_WIDTH,
minHeight: MIN_LINE_HEIGHT,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 300,
defaultHeight: 150,
};
export const getParagraphScribbledShapeRestrictions =
(): ShapeSizeRestrictions => paragraphScribbledShapeRestrictions;
const shapeType: ShapeType = 'paragraphScribbled';
export const ParagraphScribbled = forwardRef<any, ShapeProps>((props, ref) => {
const { width, height, id, otherProps, ...shapeProps } = props;
const { stroke } = useShapeProps(otherProps, BASIC_SHAPE);
const commonGroupProps = useGroupShapeProps(
props,
{ width, height },
shapeType,
ref
);
const restrictedSize = fitSizeToShapeSizeRestrictions(
paragraphScribbledShapeRestrictions,
width,
height
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
const paths = useMemo(() => {
return calculateParagraphPaths(restrictedWidth, restrictedHeight, id);
}, [restrictedWidth, restrictedHeight, id]);
return (
<Group {...commonGroupProps} {...shapeProps}>
{paths.map((path, idx) => (
<Path
key={idx}
data={path}
stroke={stroke}
strokeWidth={3}
lineCap="round"
lineJoin="round"
/>
))}
<Rect
width={restrictedSize.width}
height={restrictedSize.height}
stroke={stroke}
strokeWidth={0}
/>
</Group>
);
});