Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/#598-create a cilinder basic shape #679

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions public/shapes/cilinder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { ShapeSizeRestrictions } from '@/core/model';
import { forwardRef } from 'react';
import { ShapeProps } from '../shape.model';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { Group, Rect, Ellipse, Line } from 'react-konva';
import { BASIC_SHAPE } from '../front-components/shape.const';
import { useShapeProps } from '../../shapes/use-shape-props.hook';
import { useGroupShapeProps } from '../mock-components.utils';

const cilinderShapeRestrictions: ShapeSizeRestrictions = {
minWidth: 10,
minHeight: 10,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 160,
defaultHeight: 110,
};

export const getCilinderShapeSizeRestrictions = (): ShapeSizeRestrictions =>
cilinderShapeRestrictions;

const shapeType = 'cilinder';

export const CilinderShape = forwardRef<any, ShapeProps>((props, ref) => {
const {
x,
y,
width,
height,
id,
onSelected,
text,
otherProps,
...shapeProps
} = props;

const restrictedSize = fitSizeToShapeSizeRestrictions(
cilinderShapeRestrictions,
width,
height
);

const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { strokeStyle } = useShapeProps(otherProps, BASIC_SHAPE);

const commonGroupProps = useGroupShapeProps(
props,
restrictedSize,
shapeType,
ref
);

return (
<Group {...commonGroupProps} {...shapeProps}>
<Ellipse
x={restrictedWidth / 2}
y={restrictedHeight}
radiusX={restrictedWidth / 2}
radiusY={restrictedWidth / 8}
fill="#B0B0B0"
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
<Rect
x={0}
y={0}
width={restrictedWidth}
height={restrictedHeight}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
fill="#B0B0B0"
dash={strokeStyle}
/>
<Line
points={[0, 0, 0, restrictedHeight]}
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
<Line
points={[restrictedWidth, 0, restrictedWidth, restrictedHeight]}
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
<Ellipse
x={restrictedWidth / 2}
y={0}
radiusX={restrictedWidth / 2}
radiusY={restrictedWidth / 8}
fill="#CFCFCF"
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
</Group>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './star-shape';
export * from './large-arrow-shape';
export * from './image-shape';
export * from './modal-cover-shape';
export * from './cilinder-basic-shape';
2 changes: 2 additions & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type ShapeType =
| 'tooltip'
| 'slider'
| 'link'
| 'cilinder'
| 'richtext';

export const ShapeDisplayName: Record<ShapeType, string> = {
Expand Down Expand Up @@ -129,6 +130,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
tooltip: 'Tooltip',
slider: 'Slider',
richtext: 'Rich Text',
cilinder: 'Cilinder',
};

export type EditType = 'input' | 'textarea' | 'imageupload';
Expand Down
2 changes: 2 additions & 0 deletions src/pods/canvas/model/shape-size.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getRectangleShapeSizeRestrictions,
getStarShapeSizeRestrictions,
getModalCoverShapeSizeRestrictions,
getCilinderShapeSizeRestrictions,
// other imports
} from '@/common/components/mock-components/front-basic-shapes';
import {
Expand Down Expand Up @@ -140,6 +141,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
tooltip: getTooltipShapeSizeRestrictions,
slider: getSliderShapeSizeRestrictions,
audioPlayer: getAudioPlayerShapeSizeRestrictions,
cilinder: getCilinderShapeSizeRestrictions,
};

export default shapeSizeMap;
3 changes: 3 additions & 0 deletions src/pods/canvas/shape-renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
renderStar,
renderPostit,
renderLargeArrowShape,
renderCilinder,
} from './simple-basic-shapes';
import {
renderHeading1,
Expand Down Expand Up @@ -185,6 +186,8 @@ export const renderShapeComponent = (
return renderTooltip(shape, shapeRenderedProps);
case 'slider':
return renderSlider(shape, shapeRenderedProps);
case 'cilinder':
return renderCilinder(shape, shapeRenderedProps);
default:
return renderNotFound(shape, shapeRenderedProps);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CilinderShape } from '@/common/components/mock-components/front-basic-shapes';
import { ShapeRendererProps } from '../model';
import { ShapeModel } from '@/core/model';

export const renderCilinder = (
shape: ShapeModel,
shapeRenderedProps: ShapeRendererProps
) => {
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } =
shapeRenderedProps;

return (
<CilinderShape
id={shape.id}
key={shape.id}
ref={shapeRefs.current[shape.id]}
x={shape.x}
y={shape.y}
name="shape"
width={shape.width}
height={shape.height}
draggable
typeOfTransformer={shape.typeOfTransformer}
onSelected={handleSelected}
onDragEnd={handleDragEnd(shape.id)}
onTransform={handleTransform}
onTransformEnd={handleTransform}
otherProps={shape.otherProps}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './circle.renderer';
export * from './star.renderer';
export * from './large-arrow.renderer';
export * from './modal-cover.rerender';
export * from './cilinder.renderer';
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const mockBasicShapesCollection: ItemInfo[] = [
{ thumbnailSrc: '/shapes/star.svg', type: 'star' },
{ thumbnailSrc: '/shapes/triangle.svg', type: 'triangle' },
{ thumbnailSrc: '/shapes/verticalLine.svg', type: 'verticalLine' },
{ thumbnailSrc: '/shapes/cilinder.svg', type: 'cilinder' },
];