Skip to content

Commit ef18b4d

Browse files
authored
Merge branch 'dev' into fix/#740-table-issue-when-no-chars-in-column
2 parents be67560 + a054a1e commit ef18b4d

File tree

14 files changed

+174
-2
lines changed

14 files changed

+174
-2
lines changed

public/widgets/chip.svg

Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { forwardRef } from 'react';
2+
import { Group, Rect, Text } from 'react-konva';
3+
import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
4+
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
5+
import { useShapeProps } from '../../shapes/use-shape-props.hook';
6+
import { CHIP_SHAPE } from '../front-components/shape.const';
7+
import { ShapeProps } from '../shape.model';
8+
import { useGroupShapeProps } from '../mock-components.utils';
9+
10+
const ChipShapeSizeRestrictions: ShapeSizeRestrictions = {
11+
minWidth: 40,
12+
minHeight: 28,
13+
maxWidth: -1,
14+
maxHeight: 28,
15+
defaultWidth: 56,
16+
defaultHeight: 28,
17+
};
18+
19+
export const getChipShapeSizeRestrictions = (): ShapeSizeRestrictions =>
20+
ChipShapeSizeRestrictions;
21+
22+
const shapeType: ShapeType = 'chip';
23+
24+
export const ChipShape = forwardRef<any, ShapeProps>((props, ref) => {
25+
const {
26+
x,
27+
y,
28+
width,
29+
height,
30+
id,
31+
text,
32+
onSelected,
33+
otherProps,
34+
...shapeProps
35+
} = props;
36+
const restrictedSize = fitSizeToShapeSizeRestrictions(
37+
ChipShapeSizeRestrictions,
38+
width,
39+
height
40+
);
41+
42+
const { width: restrictedWidth, height: restrictedHeigth } = restrictedSize;
43+
const { stroke, strokeStyle, fill, textColor } = useShapeProps(
44+
otherProps,
45+
CHIP_SHAPE
46+
);
47+
48+
const commonGroupProps = useGroupShapeProps(
49+
props,
50+
restrictedSize,
51+
shapeType,
52+
ref
53+
);
54+
55+
return (
56+
<Group {...commonGroupProps} {...shapeProps}>
57+
<Rect
58+
x={0}
59+
y={0}
60+
width={restrictedWidth + CHIP_SHAPE.DEFAULT_STROKE_WIDTH * 2}
61+
height={restrictedHeigth}
62+
fill={fill}
63+
stroke={stroke}
64+
dash={strokeStyle}
65+
strokeWidth={CHIP_SHAPE.DEFAULT_STROKE_WIDTH}
66+
cornerRadius={CHIP_SHAPE.DEFAULT_CORNER_RADIUS}
67+
/>
68+
69+
<Text
70+
x={CHIP_SHAPE.DEFAULT_PADDING}
71+
y={CHIP_SHAPE.DEFAULT_PADDING - CHIP_SHAPE.DEFAULT_STROKE_WIDTH * 2}
72+
width={
73+
restrictedWidth -
74+
CHIP_SHAPE.DEFAULT_PADDING * 2 -
75+
CHIP_SHAPE.DEFAULT_STROKE_WIDTH
76+
}
77+
text={text}
78+
fontFamily={CHIP_SHAPE.DEFAULT_FONT_FAMILY}
79+
fontSize={CHIP_SHAPE.DEFAULT_FONT_SIZE}
80+
fill={textColor}
81+
verticalAlign="middle"
82+
align="center"
83+
ellipsis={true}
84+
wrap="none"
85+
/>
86+
</Group>
87+
);
88+
});

src/common/components/mock-components/front-components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './horizontalscrollbar-shape';
1515
export * from './label-shape';
1616
export * from './tooltip-shape';
1717
export * from './slider-shape';
18+
export * from './chip-shape';

src/common/components/mock-components/front-components/shape.const.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const DEFAULT_FONT_STYLE = 'normal';
1717
const DEFAULT_TEXT_DECORATION = 'none';
1818
const DEFAULT_TEXT_ALIGNMENT = 'left';
1919
const DEFAULT_DISABLED = false;
20+
const DEFAULT_CORNER_RADIUS_CHIP = 1000;
21+
const DEFAULT_FONT_SIZE_CHIP = 14;
2022

2123
export interface DefaultStyleShape {
2224
DEFAULT_CORNER_RADIUS: number;
@@ -135,3 +137,23 @@ export const LINK_SHAPE: DefaultStyleShape = {
135137
...BASIC_SHAPE,
136138
DEFAULT_FILL_TEXT: '#0000FF',
137139
};
140+
141+
export const CHIP_SHAPE: DefaultStyleShape = {
142+
DEFAULT_CORNER_RADIUS: DEFAULT_CORNER_RADIUS_CHIP,
143+
DEFAULT_STROKE_COLOR,
144+
DEFAULT_STROKE_WIDTH,
145+
DEFAULT_FILL_BACKGROUND,
146+
DEFAULT_FONT_FAMILY,
147+
DEFAULT_FONT_SIZE: DEFAULT_FONT_SIZE_CHIP,
148+
DEFAULT_FILL_TEXT,
149+
DEFAULT_PADDING,
150+
DEFAULT_LINE_HEIGHT,
151+
DEFAULT_TEXT_WIDTH,
152+
DEFAULT_TEXT_HEIGHT,
153+
DEFAULT_STROKE_STYLE,
154+
DEFAULT_FONT_VARIANT,
155+
DEFAULT_FONT_STYLE,
156+
DEFAULT_TEXT_DECORATION,
157+
DEFAULT_TEXT_ALIGNMENT,
158+
DEFAULT_DISABLED,
159+
};

src/core/model/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type ShapeType =
6969
| 'buttonBar'
7070
| 'tooltip'
7171
| 'slider'
72+
| 'chip'
7273
| 'link'
7374
| 'cilinder'
7475
| 'richtext'
@@ -136,6 +137,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
136137
buttonBar: 'Button Bar',
137138
tooltip: 'Tooltip',
138139
slider: 'Slider',
140+
chip: 'Chip',
139141
richtext: 'Rich Text',
140142
cilinder: 'Cilinder',
141143
'loading-indicator': 'Loading',

src/pods/canvas/model/inline-editable.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const inlineEditableShapes = new Set<ShapeType>([
3232
'buttonBar',
3333
'tabsBar',
3434
'tooltip',
35+
'chip',
3536
'timepickerinput',
3637
'datepickerinput',
3738
'browser',
@@ -74,6 +75,7 @@ const shapeTypesWithDefaultText = new Set<ShapeType>([
7475
'buttonBar',
7576
'tabsBar',
7677
'link',
78+
'chip',
7779
'timepickerinput',
7880
'datepickerinput',
7981
'browser',
@@ -114,6 +116,7 @@ const defaultTextValueMap: Partial<Record<ShapeType, string>> = {
114116
buttonBar: 'Button 1, Button 2, Button 3',
115117
tabsBar: 'Tab 1, Tab 2, Tab 3',
116118
link: 'Link',
119+
chip: 'Chip',
117120
timepickerinput: 'hh:mm',
118121
datepickerinput: new Date().toLocaleDateString(),
119122
browser: 'https://example.com',

src/pods/canvas/model/shape-other-props.utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ export const generateDefaultOtherProps = (
253253
return {
254254
activeElement: 0,
255255
};
256+
case 'chip':
257+
return {
258+
stroke: '#939393',
259+
backgroundColor: '#D3D3D3',
260+
textColor: '#000000',
261+
strokeStyle: [],
262+
};
256263
default:
257264
return undefined;
258265
}

src/pods/canvas/model/shape-size.mapper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
getToggleSwitchShapeSizeRestrictions,
2020
getTooltipShapeSizeRestrictions,
2121
getVerticalScrollBarShapeSizeRestrictions,
22+
getChipShapeSizeRestrictions,
2223
} from '@/common/components/mock-components/front-components';
2324
import {
2425
getBrowserWindowShapeSizeRestrictions,
@@ -63,6 +64,7 @@ import {
6364
getVideoPlayerShapeSizeRestrictions,
6465
getVideoconferenceShapeSizeRestrictions,
6566
getGaugeShapeSizeRestrictions,
67+
6668
// other imports
6769
} from '@/common/components/mock-components/front-rich-components';
6870
import {
@@ -153,6 +155,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
153155
videoconference: getVideoconferenceShapeSizeRestrictions,
154156
gauge: getGaugeShapeSizeRestrictions,
155157
imagePlaceholder: getImagePlaceholderShapeSizeRestrictions,
158+
chip: getChipShapeSizeRestrictions,
156159
};
157160

158161
export default shapeSizeMap;

src/pods/canvas/model/transformer.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const generateTypeOfTransformer = (shapeType: ShapeType): string[] => {
6767
case 'loading-indicator':
6868
case 'buttonBar':
6969
case 'slider':
70+
case 'chip':
7071
return ['middle-left', 'middle-right'];
7172
case 'verticalLine':
7273
case 'verticalScrollBar':

src/pods/canvas/shape-renderer/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
renderVerticalScrollBar,
2020
renderTooltip,
2121
renderSlider,
22+
renderChip,
2223
} from './simple-component';
2324
import {
2425
renderBrowserWindow,
@@ -203,6 +204,8 @@ export const renderShapeComponent = (
203204
return renderGauge(shape, shapeRenderedProps);
204205
case 'imagePlaceholder':
205206
return renderImagePlaceHolder(shape, shapeRenderedProps);
207+
case 'chip':
208+
return renderChip(shape, shapeRenderedProps);
206209
default:
207210
return renderNotFound(shape, shapeRenderedProps);
208211
}

0 commit comments

Comments
 (0)