Skip to content

Commit f9cf86e

Browse files
authored
Merge branch 'dev' into feature/#692add-a-placeholder-property-to-input-mock-shape
2 parents 4113bc5 + 85789b0 commit f9cf86e

File tree

12 files changed

+136
-0
lines changed

12 files changed

+136
-0
lines changed

public/icons/moonalt.svg

Lines changed: 3 additions & 0 deletions
Loading

public/widgets/togglelightdark.svg

Lines changed: 8 additions & 0 deletions
Loading

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './buttonBar/buttonBar';
1515
export * from './tabsbar';
1616
export * from './audio-player';
1717
export * from './videoconference';
18+
export * from './togglelightdark-shape';
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
2+
import { forwardRef } from 'react';
3+
import { ShapeProps } from '../shape.model';
4+
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
5+
import { Circle, Group, Rect, Image } from 'react-konva';
6+
import { useShapeProps } from '../../shapes/use-shape-props.hook';
7+
import { BASIC_SHAPE } from '../front-components/shape.const';
8+
import { useGroupShapeProps } from '../mock-components.utils';
9+
import sunIconUrl from '/icons/sun.svg';
10+
import moonIconUrl from '/icons/moonalt.svg';
11+
12+
const iconSize = 20;
13+
14+
const toggleLightDarkShapeRestrictions: ShapeSizeRestrictions = {
15+
minWidth: 50,
16+
minHeight: 25,
17+
maxWidth: 50,
18+
maxHeight: 25,
19+
defaultWidth: 50,
20+
defaultHeight: 25,
21+
};
22+
23+
const shapeType: ShapeType = 'toggleLightDark';
24+
25+
export const getToggleLightDarkShapeSizeRestrictions =
26+
(): ShapeSizeRestrictions => toggleLightDarkShapeRestrictions;
27+
28+
export const ToggleLightDark = forwardRef<any, ShapeProps>((props, ref) => {
29+
const { x, y, width, height, id, onSelected, otherProps, ...shapeProps } =
30+
props;
31+
const restrictedSize = fitSizeToShapeSizeRestrictions(
32+
toggleLightDarkShapeRestrictions,
33+
width,
34+
height
35+
);
36+
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
37+
38+
const { isOn } = useShapeProps(otherProps, BASIC_SHAPE);
39+
40+
const circleX = isOn
41+
? restrictedHeight / 2
42+
: restrictedWidth - restrictedHeight / 2;
43+
44+
const commonGroupProps = useGroupShapeProps(
45+
props,
46+
restrictedSize,
47+
shapeType,
48+
ref
49+
);
50+
51+
const toggleIcon = new window.Image();
52+
toggleIcon.src = isOn ? sunIconUrl : moonIconUrl;
53+
54+
return (
55+
<Group {...commonGroupProps} {...shapeProps}>
56+
<Rect
57+
x={0}
58+
y={0}
59+
width={restrictedWidth}
60+
height={restrictedHeight}
61+
cornerRadius={50}
62+
stroke="black"
63+
strokeWidth={2}
64+
fill={isOn ? 'white' : 'gray'}
65+
/>
66+
<Circle
67+
x={circleX}
68+
y={restrictedHeight / 2}
69+
radius={restrictedHeight / 2}
70+
stroke="black"
71+
strokeWidth={2}
72+
fill={isOn ? 'white' : 'gray'}
73+
/>
74+
<Image
75+
image={toggleIcon}
76+
x={circleX - iconSize / 2}
77+
y={restrictedHeight / 2 - iconSize / 2}
78+
width={iconSize}
79+
height={iconSize}
80+
/>
81+
</Group>
82+
);
83+
});

src/core/model/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type ShapeType =
1515
| 'checkbox'
1616
| 'textarea'
1717
| 'toggleswitch'
18+
| 'toggleLightDark'
1819
| 'progressbar'
1920
| 'listbox'
2021
| 'datepickerinput'
@@ -81,6 +82,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
8182
checkbox: 'Checkbox',
8283
textarea: 'Textarea',
8384
toggleswitch: 'Toggle Switch',
85+
toggleLightDark: 'Toggle Light/Dark',
8486
progressbar: 'Progress Bar',
8587
listbox: 'List Box',
8688
datepickerinput: 'Date Picker Input',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export const generateDefaultOtherProps = (
195195
textColor: '#000000',
196196
};
197197
case 'toggleswitch':
198+
case 'toggleLightDark':
198199
return {
199200
checked: true,
200201
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
getPieChartShapeSizeRestrictions,
5858
getTableSizeRestrictions,
5959
getTabsBarShapeSizeRestrictions,
60+
getToggleLightDarkShapeSizeRestrictions,
6061
getVerticalMenuShapeSizeRestrictions,
6162
getVideoPlayerShapeSizeRestrictions,
6263
getVideoconferenceShapeSizeRestrictions,
@@ -90,6 +91,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
9091
combobox: getComboBoxShapeSizeRestrictions,
9192
input: getInputShapeSizeRestrictions,
9293
toggleswitch: getToggleSwitchShapeSizeRestrictions,
94+
toggleLightDark: getToggleLightDarkShapeSizeRestrictions,
9395
textarea: getTextAreaSizeRestrictions,
9496
datepickerinput: getDatepickerInputShapeSizeRestrictions,
9597
button: getButtonShapeSizeRestrictions,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const generateTypeOfTransformer = (shapeType: ShapeType): string[] => {
5050
case 'listbox':
5151
case 'checkbox':
5252
case 'toggleswitch':
53+
case 'toggleLightDark':
5354
case 'progressbar':
5455
case 'timepickerinput':
5556
case 'radiobutton':

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
renderModal,
4242
renderButtonBar,
4343
renderTabsBar,
44+
renderToggleLightDark,
4445
renderVideoconference,
4546
} from './simple-rich-components';
4647
import {
@@ -87,6 +88,8 @@ export const renderShapeComponent = (
8788
return renderTextArea(shape, shapeRenderedProps);
8889
case 'toggleswitch':
8990
return renderToggleSwitch(shape, shapeRenderedProps);
91+
case 'toggleLightDark':
92+
return renderToggleLightDark(shape, shapeRenderedProps);
9093
case 'progressbar':
9194
return renderProgressbar(shape, shapeRenderedProps);
9295
case 'listbox':

src/pods/canvas/shape-renderer/simple-rich-components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from './line-chart.renderer';
99
export * from './vertical-menu.renderer';
1010
export * from './calendar.renderer';
1111
export * from './table.renderer';
12+
export * from './togglelightdark.renderer';
1213
export * from './modal.renderer';
1314
export * from './appBar.renderer';
1415
export * from './button-bar.renderer';

0 commit comments

Comments
 (0)