-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsmalltext-shape.tsx
More file actions
85 lines (76 loc) · 2.16 KB
/
Copy pathsmalltext-shape.tsx
File metadata and controls
85 lines (76 loc) · 2.16 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
import { forwardRef } from 'react';
import { Group, Text } from 'react-konva';
import { ShapeProps } from '../shape.model';
import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { useShapeProps } from '../../shapes/use-shape-props.hook';
import { BASIC_SHAPE } from '../front-components/shape.const';
import { useGroupShapeProps } from '../mock-components.utils';
import { useResizeOnFontSizeChange } from './front-text-hooks/resize-fontsize-change.hook';
const smalltextSizeRestrictions: ShapeSizeRestrictions = {
minWidth: BASIC_SHAPE.DEFAULT_MIN_WIDTH,
minHeight: 20,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 375,
defaultHeight: 25,
};
export const getSmalltextSizeRestrictions = (): ShapeSizeRestrictions =>
smalltextSizeRestrictions;
const shapeType: ShapeType = 'smalltext';
export const SmalltextShape = forwardRef<any, ShapeProps>((props, ref) => {
const {
x,
y,
width,
height,
id,
onSelected,
text,
otherProps,
...shapeProps
} = props;
const restrictedSize = fitSizeToShapeSizeRestrictions(
smalltextSizeRestrictions,
width,
height
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
const {
textColor,
fontVariant,
fontStyle,
textDecoration,
fontSize,
textAlignment,
} = useShapeProps(otherProps, BASIC_SHAPE);
const commonGroupProps = useGroupShapeProps(
props,
restrictedSize,
shapeType,
ref
);
useResizeOnFontSizeChange(id, { x, y }, text, fontSize, fontVariant);
return (
<Group {...commonGroupProps} {...shapeProps}>
<Text
x={0}
y={0}
width={restrictedWidth}
height={restrictedHeight}
text={text}
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align={textAlignment}
verticalAlign="middle"
ellipsis={true}
wrap="none"
fontVariant={fontVariant}
fontStyle={fontStyle}
textDecoration={textDecoration}
/>
</Group>
);
});
export default SmalltextShape;