Skip to content

feature/#213 Create a badge component to be placed under Rich Components #374

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

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: 4 additions & 0 deletions public/widgets/chip.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
@@ -0,0 +1,88 @@
import { forwardRef } from 'react';
import { Group, Rect, Text } from 'react-konva';
import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { useShapeProps } from '../../shapes/use-shape-props.hook';
import { CHIP_SHAPE } from '../front-components/shape.const';
import { ShapeProps } from '../shape.model';
import { useGroupShapeProps } from '../mock-components.utils';

const ChipShapeSizeRestrictions: ShapeSizeRestrictions = {
minWidth: 40,
minHeight: 28,
maxWidth: -1,
maxHeight: 28,
defaultWidth: 56,
defaultHeight: 28,
};

export const getChipShapeSizeRestrictions = (): ShapeSizeRestrictions =>
ChipShapeSizeRestrictions;

const shapeType: ShapeType = 'chip';

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

const { width: restrictedWidth, height: restrictedHeigth } = restrictedSize;
const { stroke, strokeStyle, fill, textColor } = useShapeProps(
otherProps,
CHIP_SHAPE
);

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

return (
<Group {...commonGroupProps} {...shapeProps}>
<Rect
x={0}
y={0}
width={restrictedWidth + CHIP_SHAPE.DEFAULT_STROKE_WIDTH * 2}
height={restrictedHeigth}
fill={fill}
stroke={stroke}
dash={strokeStyle}
strokeWidth={CHIP_SHAPE.DEFAULT_STROKE_WIDTH}
cornerRadius={CHIP_SHAPE.DEFAULT_CORNER_RADIUS}
/>

<Text
x={CHIP_SHAPE.DEFAULT_PADDING}
y={CHIP_SHAPE.DEFAULT_PADDING - CHIP_SHAPE.DEFAULT_STROKE_WIDTH * 2}
width={
restrictedWidth -
CHIP_SHAPE.DEFAULT_PADDING * 2 -
CHIP_SHAPE.DEFAULT_STROKE_WIDTH
}
text={text}
fontFamily={CHIP_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={CHIP_SHAPE.DEFAULT_FONT_SIZE}
fill={textColor}
verticalAlign="middle"
align="center"
ellipsis={true}
wrap="none"
/>
</Group>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './horizontalscrollbar-shape';
export * from './label-shape';
export * from './tooltip-shape';
export * from './slider-shape';
export * from './chip-shape';
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const DEFAULT_FONT_STYLE = 'normal';
const DEFAULT_TEXT_DECORATION = 'none';
const DEFAULT_TEXT_ALIGNMENT = 'left';
const DEFAULT_DISABLED = false;
const DEFAULT_CORNER_RADIUS_CHIP = 1000;
const DEFAULT_FONT_SIZE_CHIP = 14;

export interface DefaultStyleShape {
DEFAULT_CORNER_RADIUS: number;
Expand Down Expand Up @@ -135,3 +137,23 @@ export const LINK_SHAPE: DefaultStyleShape = {
...BASIC_SHAPE,
DEFAULT_FILL_TEXT: '#0000FF',
};

export const CHIP_SHAPE: DefaultStyleShape = {
DEFAULT_CORNER_RADIUS: DEFAULT_CORNER_RADIUS_CHIP,
DEFAULT_STROKE_COLOR,
DEFAULT_STROKE_WIDTH,
DEFAULT_FILL_BACKGROUND,
DEFAULT_FONT_FAMILY,
DEFAULT_FONT_SIZE: DEFAULT_FONT_SIZE_CHIP,
DEFAULT_FILL_TEXT,
DEFAULT_PADDING,
DEFAULT_LINE_HEIGHT,
DEFAULT_TEXT_WIDTH,
DEFAULT_TEXT_HEIGHT,
DEFAULT_STROKE_STYLE,
DEFAULT_FONT_VARIANT,
DEFAULT_FONT_STYLE,
DEFAULT_TEXT_DECORATION,
DEFAULT_TEXT_ALIGNMENT,
DEFAULT_DISABLED,
};
2 changes: 2 additions & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type ShapeType =
| 'buttonBar'
| 'tooltip'
| 'slider'
| 'chip'
| 'link'
| 'cilinder'
| 'richtext'
Expand Down Expand Up @@ -136,6 +137,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
buttonBar: 'Button Bar',
tooltip: 'Tooltip',
slider: 'Slider',
chip: 'Chip',
richtext: 'Rich Text',
cilinder: 'Cilinder',
'loading-indicator': 'Loading',
Expand Down
3 changes: 3 additions & 0 deletions src/pods/canvas/model/inline-editable.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const inlineEditableShapes = new Set<ShapeType>([
'buttonBar',
'tabsBar',
'tooltip',
'chip',
'timepickerinput',
'datepickerinput',
'browser',
Expand Down Expand Up @@ -74,6 +75,7 @@ const shapeTypesWithDefaultText = new Set<ShapeType>([
'buttonBar',
'tabsBar',
'link',
'chip',
'timepickerinput',
'datepickerinput',
'browser',
Expand Down Expand Up @@ -114,6 +116,7 @@ const defaultTextValueMap: Partial<Record<ShapeType, string>> = {
buttonBar: 'Button 1, Button 2, Button 3',
tabsBar: 'Tab 1, Tab 2, Tab 3',
link: 'Link',
chip: 'Chip',
timepickerinput: 'hh:mm',
datepickerinput: new Date().toLocaleDateString(),
browser: 'https://example.com',
Expand Down
7 changes: 7 additions & 0 deletions src/pods/canvas/model/shape-other-props.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ export const generateDefaultOtherProps = (
return {
activeElement: 0,
};
case 'chip':
return {
stroke: '#939393',
backgroundColor: '#D3D3D3',
textColor: '#000000',
strokeStyle: [],
};
default:
return undefined;
}
Expand Down
3 changes: 3 additions & 0 deletions src/pods/canvas/model/shape-size.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getToggleSwitchShapeSizeRestrictions,
getTooltipShapeSizeRestrictions,
getVerticalScrollBarShapeSizeRestrictions,
getChipShapeSizeRestrictions,
} from '@/common/components/mock-components/front-components';
import {
getBrowserWindowShapeSizeRestrictions,
Expand Down Expand Up @@ -63,6 +64,7 @@ import {
getVideoPlayerShapeSizeRestrictions,
getVideoconferenceShapeSizeRestrictions,
getGaugeShapeSizeRestrictions,

// other imports
} from '@/common/components/mock-components/front-rich-components';
import {
Expand Down Expand Up @@ -153,6 +155,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
videoconference: getVideoconferenceShapeSizeRestrictions,
gauge: getGaugeShapeSizeRestrictions,
imagePlaceholder: getImagePlaceholderShapeSizeRestrictions,
chip: getChipShapeSizeRestrictions,
};

export default shapeSizeMap;
1 change: 1 addition & 0 deletions src/pods/canvas/model/transformer.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const generateTypeOfTransformer = (shapeType: ShapeType): string[] => {
case 'loading-indicator':
case 'buttonBar':
case 'slider':
case 'chip':
return ['middle-left', 'middle-right'];
case 'verticalLine':
case 'verticalScrollBar':
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 @@ -19,6 +19,7 @@ import {
renderVerticalScrollBar,
renderTooltip,
renderSlider,
renderChip,
} from './simple-component';
import {
renderBrowserWindow,
Expand Down Expand Up @@ -203,6 +204,8 @@ export const renderShapeComponent = (
return renderGauge(shape, shapeRenderedProps);
case 'imagePlaceholder':
return renderImagePlaceHolder(shape, shapeRenderedProps);
case 'chip':
return renderChip(shape, shapeRenderedProps);
default:
return renderNotFound(shape, shapeRenderedProps);
}
Expand Down
33 changes: 33 additions & 0 deletions src/pods/canvas/shape-renderer/simple-component/chip.renderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ChipShape } from '@/common/components/mock-components/front-components';
import { ShapeRendererProps } from '../model';
import { ShapeModel } from '@/core/model';

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

return (
<ChipShape
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}
/>
);
};
1 change: 1 addition & 0 deletions src/pods/canvas/shape-renderer/simple-component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './verticalscrollbar.renderer';
export * from './horizontalscrollbar.renderer';
export * from './tooltip.renderer';
export * from './slider.renderer';
export * from './chip.renderer';
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const mockWidgetCollection: ItemInfo[] = [
{ thumbnailSrc: '/widgets/listbox.svg', type: 'listbox' },
{ thumbnailSrc: '/widgets/progressbar.svg', type: 'progressbar' },
{ thumbnailSrc: '/widgets/radiobutton.svg', type: 'radiobutton' },
{ thumbnailSrc: '/widgets/chip.svg', type: 'chip' },
{ thumbnailSrc: '/widgets/slider.svg', type: 'slider' },
{ thumbnailSrc: '/widgets/textarea.svg', type: 'textarea' },
{ thumbnailSrc: '/widgets/timepicker.svg', type: 'timepickerinput' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ export const mockRichComponentsCollection: ItemInfo[] = [
thumbnailSrc: '/rich-components/horizontal-menu.svg',
type: 'horizontal-menu',
},
{
thumbnailSrc: '/rich-components/vertical-menu.svg',
type: 'vertical-menu',
},
{ thumbnailSrc: '/rich-components/modal.svg', type: 'modal' },
{ thumbnailSrc: '/rich-components/line-chart.svg', type: 'linechart' },
{
thumbnailSrc: '/rich-components/loading-indicator.svg',
type: 'loading-indicator',
},
{ thumbnailSrc: '/rich-components/map.svg', type: 'map' },
{ thumbnailSrc: '/rich-components/modal.svg', type: 'modal' },
{
thumbnailSrc: '/rich-components/gauge.svg',
type: 'gauge',
Expand All @@ -27,7 +31,6 @@ export const mockRichComponentsCollection: ItemInfo[] = [
{ thumbnailSrc: '/rich-components/table.svg', type: 'table' },
{ thumbnailSrc: '/rich-components/tabsbar.svg', type: 'tabsBar' },
{ thumbnailSrc: '/widgets/togglelightdark.svg', type: 'toggleLightDark' },
{ thumbnailSrc: '/rich-components/vertical-menu.svg', type: 'vertical-menu' },
{ thumbnailSrc: '/rich-components/videoPlayer.svg', type: 'videoPlayer' },
{
thumbnailSrc: '/rich-components/videoconference.svg',
Expand Down