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/#473 create a gray semitransparent rectangle component #517

Merged
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
3 changes: 3 additions & 0 deletions public/shapes/modalCover.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
Expand Up @@ -8,3 +8,4 @@ export * from './circle-basic-shape';
export * from './star-shape';
export * from './large-arrow-shape';
export * from './image-shape';
export * from './modal-cover-shape';
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes';
import { ShapeSizeRestrictions } from '@/core/model';
import { Group, Rect } from 'react-konva';
import { useGroupShapeProps } from '../mock-components.utils';
import { forwardRef } from 'react';
import { ShapeProps } from '../shape.model';

const modalCoverShapeSizeRestrictions: ShapeSizeRestrictions = {
minWidth: 50,
minHeight: 50,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 200,
defaultHeight: 200,
};

export const getModalCoverShapeSizeRestrictions = (): ShapeSizeRestrictions =>
modalCoverShapeSizeRestrictions;

const shapeType = 'modalCover';

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

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

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

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

return (
<Group {...commonGroupProps} {...shapeProps}>
<Rect
x={0}
y={0}
width={restrictedWidth}
height={restrictedHeight}
fill={'gray'}
strokeWidth={2}
dash={[1]}
opacity={0.7}
listening={true}
/>
</Group>
);
});
2 changes: 2 additions & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type ShapeType =
| 'verticalScrollBar'
| 'horizontalScrollBar'
| 'modal'
| 'modalCover'
| 'tabsBar'
| 'appBar'
| 'appBar'
Expand Down Expand Up @@ -118,6 +119,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
calendar: 'Calendar',
verticalScrollBar: 'Vertical Scroll Bar',
modal: 'Modal',
modalCover: 'Modal Cover',
tabsBar: 'Tabs Bar',
appBar: 'AppBar',
buttonBar: 'Button Bar',
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 @@ -38,6 +38,7 @@ import {
getPostItShapeSizeRestrictions,
getRectangleShapeSizeRestrictions,
getStarShapeSizeRestrictions,
getModalCoverShapeSizeRestrictions,
// other imports
} from '@/common/components/mock-components/front-basic-shapes';
import {
Expand Down Expand Up @@ -128,6 +129,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
calendar: getCalendarShapeSizeRestrictions,
verticalScrollBar: getVerticalScrollBarShapeSizeRestrictions,
modal: getModalShapeSizeRestrictions,
modalCover: getModalCoverShapeSizeRestrictions,
tabsBar: getTabsBarShapeSizeRestrictions,
appBar: getAppBarShapeSizeRestrictions,
buttonBar: getButtonBarShapeSizeRestrictions,
Expand Down
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 @@ -49,6 +49,7 @@ import {
renderHorizontalLine,
renderVerticalLine,
renderCircle,
renderModalCover,
renderStar,
renderPostit,
renderLargeArrowShape,
Expand Down Expand Up @@ -166,6 +167,8 @@ export const renderShapeComponent = (
return renderVerticalScrollBar(shape, shapeRenderedProps);
case 'modal':
return renderModal(shape, shapeRenderedProps);
case 'modalCover':
return renderModalCover(shape, shapeRenderedProps);
case 'tabsBar':
return renderTabsBar(shape, shapeRenderedProps);
case 'appBar':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './vertical-line.renderer';
export * from './circle.renderer';
export * from './star.renderer';
export * from './large-arrow.renderer';
export * from './modal-cover.rerender';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ModalCoverShape } from '@/common/components/mock-components/front-basic-shapes';
import { ShapeRendererProps } from '../model';
import { ShapeModel } from '@/core/model';

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

return (
<ModalCoverShape
id={shape.id}
key={shape.id}
ref={shapeRefs.current[shape.id]}
x={shape.x}
y={shape.y}
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 @@ -6,6 +6,7 @@ export const mockBasicShapesCollection: ItemInfo[] = [
{ thumbnailSrc: '/shapes/horizontalLine.svg', type: 'horizontalLine' },
{ thumbnailSrc: '/shapes/image.svg', type: 'image' },
{ thumbnailSrc: '/shapes/largeArrow.svg', type: 'largeArrow' },
{ thumbnailSrc: '/shapes/modalCover.svg', type: 'modalCover' },
{ thumbnailSrc: '/shapes/postit.svg', type: 'postit' },
{ thumbnailSrc: '/shapes/rectangle.svg', type: 'rectangle' },
{ thumbnailSrc: '/shapes/star.svg', type: 'star' },
Expand Down