-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5960b17
commit 765f879
Showing
9 changed files
with
164 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.
100 changes: 100 additions & 0 deletions
100
src/common/components/front-rich-components/buttonBar.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,100 @@ | ||
import { ShapeSizeRestrictions } from '@/core/model'; | ||
import { forwardRef, useMemo } from 'react'; | ||
import { Group, Rect, Text } from 'react-konva'; | ||
import { ShapeProps } from '../front-components/shape.model'; | ||
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; | ||
|
||
const horizontalMenuShapeSizeRestrictions: ShapeSizeRestrictions = { | ||
minWidth: 75, | ||
minHeight: 25, | ||
maxWidth: -1, | ||
maxHeight: 100, | ||
defaultWidth: 200, | ||
defaultHeight: 50, | ||
}; | ||
|
||
export const getButtonBarShapeSizeRestrictions = (): ShapeSizeRestrictions => | ||
horizontalMenuShapeSizeRestrictions; | ||
|
||
export const ButtonBarShape = forwardRef<any, ShapeProps>( | ||
( | ||
{ x, y, width, height, id, onSelected, text, otherProps, ...shapeProps }, | ||
ref | ||
) => { | ||
const menuElements: string[] = text.split('\n'); | ||
const numberOfItems = menuElements.length; | ||
const minItemWidth = 100; | ||
const itemSpacing = 20; | ||
const totalWidth = Math.max( | ||
minItemWidth * numberOfItems + itemSpacing * (numberOfItems + 1), | ||
width | ||
); | ||
const { width: restrictedWidth, height: restrictedHeight } = | ||
fitSizeToShapeSizeRestrictions( | ||
horizontalMenuShapeSizeRestrictions, | ||
totalWidth, | ||
height | ||
); | ||
const totalMargins = restrictedWidth - itemSpacing * (numberOfItems + 1); | ||
const itemWidth = totalMargins / numberOfItems; | ||
|
||
const textColor = useMemo( | ||
() => otherProps?.textColor ?? 'black', | ||
[otherProps?.textColor] | ||
); | ||
const backgroundColor = useMemo( | ||
() => otherProps?.backgroundColor ?? 'white', | ||
[otherProps?.backgroundColor] | ||
); | ||
const strokeColor = useMemo( | ||
() => otherProps?.stroke ?? 'black', | ||
[otherProps?.stroke] | ||
); | ||
const strokeStyle = useMemo( | ||
() => otherProps?.strokeStyle ?? [], | ||
[otherProps?.strokeStyle] | ||
); | ||
|
||
return ( | ||
<Group | ||
x={x} | ||
y={y} | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
ref={ref} | ||
{...shapeProps} | ||
onClick={() => onSelected(id, 'horizontal-menu')} | ||
> | ||
<Rect | ||
x={0} | ||
y={0} | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
stroke={strokeColor} | ||
strokeWidth={2} | ||
dash={strokeStyle} | ||
fill={backgroundColor} | ||
/> | ||
|
||
{menuElements.map((e: string, index: number) => ( | ||
<Group key={index}> | ||
<Text | ||
x={itemSpacing * (index + 1) + itemWidth * index} | ||
y={restrictedHeight / 2 - 8} | ||
text={e} | ||
fontFamily="Arial" | ||
fontSize={16} | ||
fill={textColor} | ||
width={itemWidth} | ||
align="center" | ||
wrap="none" | ||
ellipsis={true} | ||
/> | ||
</Group> | ||
))} | ||
</Group> | ||
); | ||
} | ||
); | ||
|
||
export default ButtonBarShape; |
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-rich-components/button-bar.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 { ButtonBarShape } from '@/common/components/front-rich-components/buttonBar'; | ||
import { ShapeRendererProps } from '../model'; | ||
import { ShapeModel } from '@/core/model'; | ||
|
||
export const renderButtonBar = ( | ||
shape: ShapeModel, | ||
shapeRenderedProps: ShapeRendererProps | ||
) => { | ||
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } = | ||
shapeRenderedProps; | ||
|
||
return ( | ||
<ButtonBarShape | ||
id={shape.id} | ||
key={shape.id} | ||
x={shape.x} | ||
y={shape.y} | ||
width={shape.width} | ||
height={shape.height} | ||
name="shape" | ||
draggable | ||
typeOfTransformer={shape.typeOfTransformer} | ||
onSelected={handleSelected} | ||
ref={shapeRefs.current[shape.id]} | ||
onDragEnd={handleDragEnd(shape.id)} | ||
onTransform={handleTransform} | ||
onTransformEnd={handleTransform} | ||
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
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