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/#731 low wireframes create thick rectangle placeholder #750

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
4 changes: 2 additions & 2 deletions e2e/rectangle-shape.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ test('has rectangle component', async ({ page }) => {
await page.goto('');
await page.getByText('Basic Shapes').click();

await expect(page.getByAltText('Rectangle')).toBeVisible();
await expect(page.getByAltText(/^Rectangle$/)).toBeVisible();
});

test('can add rectangle component to canvas', async ({ page }) => {
await page.goto('');
await page.getByText('Basic Shapes').click();
const component = page.getByAltText('Rectangle');
const component = page.getByAltText(/^Rectangle$/);

const position = await getLocatorPosition(component);
await dragAndDrop(page, position, {
Expand Down
3 changes: 3 additions & 0 deletions public/low-wireframes/rectangleLow.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 @@ -2,4 +2,5 @@ export * from './ellipse-low-shape';
export * from './horizontal-line-low-shape';
export * from './image-placeholder-shape';
export * from './vertical-line-low-shape';
export * from './rectangle-low-shape';
export * from './circle-low-shape';
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
import { forwardRef } from 'react';
import { ShapeProps } from '../shape.model';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes';
import { Group, Rect } from 'react-konva';
import { useGroupShapeProps } from '../mock-components.utils';
import { useShapeProps } from '../../shapes/use-shape-props.hook';
import { BASIC_SHAPE } from '../front-components/shape.const';

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

export const getRectangleLowShapeRestrictions = (): ShapeSizeRestrictions =>
rectangleLowShapeRestriction;

const shapeType: ShapeType = 'rectangleLow';

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

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

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

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

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

return (
<Group {...commonGroupProps} {...shapeProps}>
<Rect
width={restrictedWidth}
height={restrictedHeight}
stroke={stroke}
dash={strokeStyle}
strokeWidth={6}
fill="white"
/>
</Group>
);
});
2 changes: 2 additions & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type ShapeType =
| 'horizontalLineLow'
| 'verticalLineLow'
| 'ellipseLow'
| 'rectangleLow'
| 'circleLow';

export const ShapeDisplayName: Record<ShapeType, string> = {
Expand Down Expand Up @@ -151,6 +152,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
horizontalLineLow: 'Horizontal Divider',
verticalLineLow: 'Vertical Divider',
ellipseLow: 'Ellipse',
rectangleLow: 'Rectangle Placeholder',
circleLow: 'Circle',
};

Expand Down
1 change: 1 addition & 0 deletions src/pods/canvas/model/shape-other-props.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const generateDefaultOtherProps = (
};
case 'horizontalLine':
case 'horizontalLineLow':
case 'rectangleLow':
case 'circleLow':
case 'verticalLineLow':
case 'ellipseLow':
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 @@ -82,6 +82,7 @@ import {
getHorizontalLineLowShapeRestrictions,
getImagePlaceholderShapeSizeRestrictions,
getVerticalLineLowShapeRestrictions,
getRectangleLowShapeRestrictions,
getEllipseLowShapeRestrictions,
getCircleLowShapeSizeRestrictions,
} from '@/common/components/mock-components/front-low-wireframes-components';
Expand Down Expand Up @@ -164,6 +165,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
horizontalLineLow: getHorizontalLineLowShapeRestrictions,
verticalLineLow: getVerticalLineLowShapeRestrictions,
ellipseLow: getEllipseLowShapeRestrictions,
rectangleLow: getRectangleLowShapeRestrictions,
circleLow: getCircleLowShapeSizeRestrictions,
};

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 @@ -79,6 +79,7 @@ import {
renderImagePlaceHolder,
renderVerticalLowLine,
renderEllipseLow,
renderRectangleLow,
} from './simple-low-wireframes-components';

export const renderShapeComponent = (
Expand Down Expand Up @@ -218,6 +219,8 @@ export const renderShapeComponent = (
return renderVerticalLowLine(shape, shapeRenderedProps);
case 'ellipseLow':
return renderEllipseLow(shape, shapeRenderedProps);
case 'rectangleLow':
return renderRectangleLow(shape, shapeRenderedProps);
case 'circleLow':
return renderCircleLow(shape, shapeRenderedProps);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from './ellipse-low.renderer';
export * from './image-placeholder.renderer';
export * from './low-horizontal-line.renderer';
export * from './low-vertical-line.renderer';
export * from './rectangle-low.renderer';
export * from './circle-low.renderer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ShapeModel } from '@/core/model';
import { ShapeRendererProps } from '../model';
import { RectangleLowShape } from '@/common/components/mock-components/front-low-wireframes-components';

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

return (
<RectangleLowShape
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 @@ -17,6 +17,10 @@ export const mockLowWireframeCollection: ItemInfo[] = [
thumbnailSrc: '/low-wireframes/ellipseLow.svg',
type: 'ellipseLow',
},
{
thumbnailSrc: '/low-wireframes/rectangleLow.svg',
type: 'rectangleLow',
},
{
thumbnailSrc: '/low-wireframes/circleLow.svg',
type: 'circleLow',
Expand Down