|
| 1 | +import { ShapeSizeRestrictions } from '@/core/model'; |
| 2 | +import { forwardRef } from 'react'; |
| 3 | +import { ShapeProps } from '../shape.model'; |
| 4 | +import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; |
| 5 | +import { Group, Rect, Ellipse, Line } from 'react-konva'; |
| 6 | +import { BASIC_SHAPE } from '../front-components/shape.const'; |
| 7 | +import { useShapeProps } from '../../shapes/use-shape-props.hook'; |
| 8 | +import { useGroupShapeProps } from '../mock-components.utils'; |
| 9 | + |
| 10 | +const cilinderShapeRestrictions: ShapeSizeRestrictions = { |
| 11 | + minWidth: 10, |
| 12 | + minHeight: 10, |
| 13 | + maxWidth: -1, |
| 14 | + maxHeight: -1, |
| 15 | + defaultWidth: 160, |
| 16 | + defaultHeight: 110, |
| 17 | +}; |
| 18 | + |
| 19 | +export const getCilinderShapeSizeRestrictions = (): ShapeSizeRestrictions => |
| 20 | + cilinderShapeRestrictions; |
| 21 | + |
| 22 | +const shapeType = 'cilinder'; |
| 23 | + |
| 24 | +export const CilinderShape = forwardRef<any, ShapeProps>((props, ref) => { |
| 25 | + const { |
| 26 | + x, |
| 27 | + y, |
| 28 | + width, |
| 29 | + height, |
| 30 | + id, |
| 31 | + onSelected, |
| 32 | + text, |
| 33 | + otherProps, |
| 34 | + ...shapeProps |
| 35 | + } = props; |
| 36 | + |
| 37 | + const restrictedSize = fitSizeToShapeSizeRestrictions( |
| 38 | + cilinderShapeRestrictions, |
| 39 | + width, |
| 40 | + height |
| 41 | + ); |
| 42 | + |
| 43 | + const { width: restrictedWidth, height: restrictedHeight } = restrictedSize; |
| 44 | + |
| 45 | + const { strokeStyle } = useShapeProps(otherProps, BASIC_SHAPE); |
| 46 | + |
| 47 | + const commonGroupProps = useGroupShapeProps( |
| 48 | + props, |
| 49 | + restrictedSize, |
| 50 | + shapeType, |
| 51 | + ref |
| 52 | + ); |
| 53 | + |
| 54 | + return ( |
| 55 | + <Group {...commonGroupProps} {...shapeProps}> |
| 56 | + <Ellipse |
| 57 | + x={restrictedWidth / 2} |
| 58 | + y={restrictedHeight} |
| 59 | + radiusX={restrictedWidth / 2} |
| 60 | + radiusY={restrictedWidth / 8} |
| 61 | + fill="#B0B0B0" |
| 62 | + stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR} |
| 63 | + strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} |
| 64 | + /> |
| 65 | + <Rect |
| 66 | + x={0} |
| 67 | + y={0} |
| 68 | + width={restrictedWidth} |
| 69 | + height={restrictedHeight} |
| 70 | + strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} |
| 71 | + fill="#B0B0B0" |
| 72 | + dash={strokeStyle} |
| 73 | + /> |
| 74 | + <Line |
| 75 | + points={[0, 0, 0, restrictedHeight]} |
| 76 | + stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR} |
| 77 | + strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} |
| 78 | + /> |
| 79 | + <Line |
| 80 | + points={[restrictedWidth, 0, restrictedWidth, restrictedHeight]} |
| 81 | + stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR} |
| 82 | + strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} |
| 83 | + /> |
| 84 | + <Ellipse |
| 85 | + x={restrictedWidth / 2} |
| 86 | + y={0} |
| 87 | + radiusX={restrictedWidth / 2} |
| 88 | + radiusY={restrictedWidth / 8} |
| 89 | + fill="#CFCFCF" |
| 90 | + stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR} |
| 91 | + strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} |
| 92 | + /> |
| 93 | + </Group> |
| 94 | + ); |
| 95 | +}); |
0 commit comments