-
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.
Browse files
Browse the repository at this point in the history
Feature/#218 creating app bar
- Loading branch information
Showing
16 changed files
with
310 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { forwardRef, useMemo } from 'react'; | ||
import { Group, Rect, Text } from 'react-konva'; | ||
import { ShapeProps } from '../front-components/shape.model'; | ||
import { ShapeSizeRestrictions } from '@/core/model'; | ||
import { BASIC_SHAPE } from '../front-components/shape.const'; | ||
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; | ||
|
||
const AppBarShapeSizeRestrictions: ShapeSizeRestrictions = { | ||
minWidth: 155, | ||
minHeight: 38, | ||
maxWidth: -1, | ||
maxHeight: -1, | ||
defaultWidth: 250, | ||
defaultHeight: BASIC_SHAPE.DEFAULT_TEXT_HEIGHT, | ||
}; | ||
|
||
export const getAppBarShapeSizeRestrictions = (): ShapeSizeRestrictions => | ||
AppBarShapeSizeRestrictions; | ||
|
||
export const AppBarShape = forwardRef<any, ShapeProps>( | ||
( | ||
{ | ||
x, | ||
y, | ||
width, | ||
height, | ||
title, | ||
id, | ||
text, | ||
otherProps, | ||
onSelected, | ||
...shapeProps | ||
}, | ||
ref | ||
) => { | ||
const { width: restrictedWidth, height: restrictedHeight } = | ||
fitSizeToShapeSizeRestrictions( | ||
AppBarShapeSizeRestrictions, | ||
width, | ||
height | ||
); | ||
|
||
const iconWidth = 30; | ||
const iconPadding = 10; | ||
|
||
const textColor = useMemo( | ||
() => otherProps?.textColor ?? '#ffffff', | ||
[otherProps?.textColor] | ||
); | ||
|
||
const fill = useMemo( | ||
() => otherProps?.backgroundColor ?? 'lightgrey', | ||
[otherProps?.backgroundColor] | ||
); | ||
|
||
const stroke = useMemo( | ||
() => otherProps?.stroke ?? BASIC_SHAPE.DEFAULT_STROKE_COLOR, | ||
[otherProps?.stroke] | ||
); | ||
|
||
const strokeStyle = useMemo( | ||
() => otherProps?.strokeStyle ?? BASIC_SHAPE.DEFAULT_STROKE_STYLE, | ||
[otherProps?.strokeStyle] | ||
); | ||
|
||
const padding = 10; | ||
const textStartX = iconPadding + iconWidth + padding; | ||
const textWidth = restrictedWidth - textStartX - padding; | ||
|
||
const barHeight = 3; // Height bar | ||
const barSpacing = 2; // Space between bars | ||
const totalIconHeight = 3 * barHeight + 2 * barSpacing; // Total height including spacing | ||
|
||
return ( | ||
<Group | ||
x={x} | ||
y={y} | ||
ref={ref} | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
{...shapeProps} | ||
onClick={() => onSelected(id, 'appBar')} | ||
> | ||
{/* AppBar background */} | ||
<Rect | ||
x={0} | ||
y={0} | ||
width={width} | ||
height={height} | ||
fill={fill} | ||
stroke={stroke} | ||
dash={strokeStyle} | ||
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH} | ||
/> | ||
|
||
{/* Menu Icon */} | ||
<Rect | ||
x={iconPadding} | ||
y={(height - totalIconHeight) / 2} | ||
width={iconWidth} | ||
height={barHeight} | ||
fill="lightgrey" | ||
/> | ||
<Rect | ||
x={iconPadding} | ||
y={(height - totalIconHeight) / 2 + barHeight + barSpacing} | ||
width={iconWidth} | ||
height={barHeight} | ||
fill="lightgrey" | ||
/> | ||
<Rect | ||
x={iconPadding} | ||
y={(height - totalIconHeight) / 2 + 2 * (barHeight + barSpacing)} | ||
width={iconWidth} | ||
height={barHeight} | ||
fill="lightgrey" | ||
/> | ||
|
||
{/* AppBar title */} | ||
<Text | ||
x={textStartX} | ||
y={restrictedHeight / 2 - 7} | ||
width={textWidth} | ||
text={text} | ||
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY} | ||
fontSize={BASIC_SHAPE.DEFAULT_FONT_SIZE} | ||
fill={textColor} | ||
align="center" | ||
ellipsis={true} | ||
wrap="none" | ||
/> | ||
</Group> | ||
); | ||
} | ||
); | ||
|
||
export default AppBarShape; |
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/appBar.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 { AppBarShape } from '@/common/components/front-rich-components/appBar'; | ||
import { ShapeRendererProps } from '../model'; | ||
import { ShapeModel } from '@/core/model'; | ||
|
||
export const renderAppBar = ( | ||
shape: ShapeModel, | ||
shapeRenderedProps: ShapeRendererProps | ||
) => { | ||
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } = | ||
shapeRenderedProps; | ||
|
||
return ( | ||
<AppBarShape | ||
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} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.