-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-under-basic-shapes #150 line shape created
- Loading branch information
Showing
11 changed files
with
143 additions
and
19 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './rectangle-basic-shape'; | ||
export * from './diamond-shape'; | ||
export * from './line-basic-shape'; |
51 changes: 51 additions & 0 deletions
51
src/common/components/front-basic-sapes/line-basic-shape.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { forwardRef } from 'react'; | ||
import { Group, Line, Rect } from 'react-konva'; | ||
import { ShapeSizeRestrictions } from '@/core/model'; | ||
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; | ||
import { ShapeProps } from '../front-components/shape.model'; | ||
|
||
const lineShapeRestrictions: ShapeSizeRestrictions = { | ||
minWidth: 50, | ||
minHeight: 10, | ||
maxWidth: -1, | ||
maxHeight: 10, | ||
defaultWidth: 200, | ||
defaultHeight: 10, | ||
}; | ||
|
||
export const getlineShapeRestrictions = (): ShapeSizeRestrictions => | ||
lineShapeRestrictions; | ||
|
||
export const LineShape = forwardRef<any, ShapeProps>( | ||
({ x, y, width, height, id, onSelected, text, ...shapeProps }, ref) => { | ||
const { width: restrictedWidth, height: restrictedHeight } = | ||
fitSizeToShapeSizeRestrictions(lineShapeRestrictions, width, height); | ||
|
||
return ( | ||
<Group | ||
x={x} | ||
y={y} | ||
ref={ref} | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
{...shapeProps} | ||
onClick={() => onSelected(id, 'line')} | ||
> | ||
{/* Transparent rectangle for applying margin */} | ||
<Rect | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
fill="transparent" | ||
/> | ||
|
||
<Line | ||
x={0} | ||
y={restrictedHeight / 2} | ||
points={[0, 0, restrictedWidth, 0]} | ||
stroke="black" | ||
strokeWidth={2} | ||
/> | ||
</Group> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './rectangle.rerender'; | ||
export * from './diamond.renderer'; | ||
export * from './line.renderer'; |
30 changes: 30 additions & 0 deletions
30
src/pods/canvas/shape-renderer/simple-basic-shapes/line.renderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { LineShape } from '@/common/components/front-basic-sapes'; | ||
import { ShapeRendererProps } from '../model'; | ||
import { ShapeModel } from '@/core/model'; | ||
|
||
export const renderLine = ( | ||
shape: ShapeModel, | ||
shapeRenderedProps: ShapeRendererProps | ||
) => { | ||
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } = | ||
shapeRenderedProps; | ||
|
||
return ( | ||
<LineShape | ||
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 | ||
hasLateralTransformer={shape.hasLateralTransformer} | ||
onSelected={handleSelected} | ||
onDragEnd={handleDragEnd(shape.id)} | ||
onTransform={handleTransform} | ||
onTransformEnd={handleTransform} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters