-
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
…-component Feature/#431 create a link component
- Loading branch information
Showing
12 changed files
with
130 additions
and
1 deletion.
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
74 changes: 74 additions & 0 deletions
74
src/common/components/mock-components/front-text-components/link-text-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,74 @@ | ||
import { forwardRef } from 'react'; | ||
import { Group, Text } from 'react-konva'; | ||
import { ShapeProps } from '../shape.model'; | ||
import { ShapeSizeRestrictions, ShapeType } from '@/core/model'; | ||
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; | ||
import { BASIC_SHAPE } from '../front-components/shape.const'; | ||
import { useShapeProps } from '../../shapes/use-shape-props.hook'; | ||
import { useGroupShapeProps } from '../mock-components.utils'; | ||
|
||
const linkSizeRestrictions: ShapeSizeRestrictions = { | ||
minWidth: 40, | ||
minHeight: 20, | ||
maxWidth: -1, | ||
maxHeight: -1, | ||
defaultWidth: 150, | ||
defaultHeight: 25, | ||
}; | ||
|
||
export const getLinkSizeRestrictions = (): ShapeSizeRestrictions => | ||
linkSizeRestrictions; | ||
|
||
const shapeType: ShapeType = 'link'; | ||
|
||
export const LinkShape = forwardRef<any, ShapeProps>((props, ref) => { | ||
const { | ||
x, | ||
y, | ||
width, | ||
height, | ||
id, | ||
onSelected, | ||
text, | ||
otherProps, | ||
...shapeProps | ||
} = props; | ||
const restrictedSize = fitSizeToShapeSizeRestrictions( | ||
linkSizeRestrictions, | ||
width, | ||
height | ||
); | ||
|
||
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize; | ||
|
||
const { textColor, textDecoration } = useShapeProps(otherProps, BASIC_SHAPE); | ||
|
||
const commonGroupProps = useGroupShapeProps( | ||
props, | ||
restrictedSize, | ||
shapeType, | ||
ref | ||
); | ||
|
||
return ( | ||
<Group {...commonGroupProps} {...shapeProps}> | ||
<Text | ||
x={0} | ||
y={0} | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
text={text} | ||
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY} | ||
fontSize={20} | ||
fill={textColor} | ||
align="center" | ||
verticalAlign="middle" | ||
ellipsis={true} | ||
wrap="none" | ||
textDecoration={textDecoration} | ||
/> | ||
</Group> | ||
); | ||
}); | ||
|
||
export default LinkShape; |
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
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
33 changes: 33 additions & 0 deletions
33
src/pods/canvas/shape-renderer/simple-text-components/link.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,33 @@ | ||
import { LinkShape } from '@/common/components/mock-components/front-text-components'; | ||
import { ShapeRendererProps } from '../model'; | ||
import { ShapeModel } from '@/core/model'; | ||
|
||
export const renderLink = ( | ||
shape: ShapeModel, | ||
shapeRenderedProps: ShapeRendererProps | ||
) => { | ||
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } = | ||
shapeRenderedProps; | ||
|
||
return ( | ||
<LinkShape | ||
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 | ||
onSelected={handleSelected} | ||
onDragEnd={handleDragEnd(shape.id)} | ||
onTransform={handleTransform} | ||
onTransformEnd={handleTransform} | ||
editType={shape.editType} | ||
isEditable={shape.allowsInlineEdition} | ||
text={shape.text} | ||
otherProps={shape.otherProps} | ||
/> | ||
); | ||
}; |
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