Skip to content

Commit 20867a1

Browse files
committed
create input-stepper shape
1 parent 6d5db61 commit 20867a1

9 files changed

Lines changed: 169 additions & 1 deletion

File tree

Lines changed: 15 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
@@ -20,3 +20,4 @@ export * from './togglelightdark-shape';
2020
export * from './gauge/gauge';
2121
export * from './fab-button/fab-button';
2222
export * from './file-tree/file-tree';
23+
export * from './input-stepper';
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 { ShapeProps } from '../shape.model';
6+
import { useGroupShapeProps } from '../mock-components.utils';
7+
8+
const InputStepperShapeSizeRestrictions: ShapeSizeRestrictions = {
9+
minWidth: 100,
10+
minHeight: 100,
11+
maxWidth: -1,
12+
maxHeight: -1,
13+
defaultWidth: 250,
14+
defaultHeight: 150,
15+
};
16+
17+
export const getInputStepperShapeSizeRestrictions = (): ShapeSizeRestrictions =>
18+
InputStepperShapeSizeRestrictions;
19+
20+
const shapeType: ShapeType = 'inputStepper';
21+
22+
export const InputStepperShape = forwardRef<any, ShapeProps>((props, ref) => {
23+
const { x, y, width, height, id, onSelected, ...shapeProps } = props;
24+
const restrictedSize = fitSizeToShapeSizeRestrictions(
25+
InputStepperShapeSizeRestrictions,
26+
width,
27+
height
28+
);
29+
30+
const inputWidth = width - 30; // Reservar espacio para el stepper
31+
const buttonHeight = height / 2;
32+
33+
const commonGroupProps = useGroupShapeProps(
34+
props,
35+
restrictedSize,
36+
shapeType,
37+
ref
38+
);
39+
40+
return (
41+
<Group {...commonGroupProps} {...shapeProps}>
42+
{/* Caja del input */}
43+
<Rect
44+
x={0}
45+
y={0}
46+
width={inputWidth / 2} // Reducir ancho a la mitad
47+
height={height}
48+
fill="white"
49+
stroke="black"
50+
strokeWidth={2}
51+
cornerRadius={0} // Sin bordes redondeados
52+
/>
53+
54+
{/* Texto del input */}
55+
<Text
56+
x={inputWidth / 2 - 10} // Alinear a la derecha
57+
y={height / 2 - 8} // Centrar verticalmente
58+
text={'0'}
59+
fontFamily="Arial"
60+
fontSize={16}
61+
fill="black"
62+
align="right"
63+
/>
64+
65+
{/* Botón de incremento (flecha arriba) */}
66+
<Group>
67+
<Rect
68+
x={0}
69+
y={0}
70+
width={30}
71+
height={buttonHeight}
72+
fill="lightgray"
73+
stroke="black"
74+
strokeWidth={2}
75+
/>
76+
<Text
77+
x={10}
78+
y={buttonHeight / 2 - 8}
79+
text="▲"
80+
fontFamily="Arial"
81+
fontSize={14}
82+
fill="black"
83+
/>
84+
</Group>
85+
86+
{/* Botón de decremento (flecha abajo) */}
87+
<Group>
88+
<Rect
89+
x={0}
90+
y={0}
91+
width={30}
92+
height={buttonHeight}
93+
fill="lightgray"
94+
stroke="black"
95+
strokeWidth={2}
96+
/>
97+
<Text
98+
x={10}
99+
y={buttonHeight / 2 - 8}
100+
text="▼"
101+
fontFamily="Arial"
102+
fontSize={14}
103+
fill="black"
104+
/>
105+
</Group>
106+
</Group>
107+
);
108+
});
109+
110+
export default InputStepperShape;

src/core/model/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export type ShapeType =
8686
| 'textScribbled'
8787
| 'paragraphScribbled'
8888
| 'fabButton'
89-
| 'fileTree';
89+
| 'fileTree'
90+
| 'inputStepper';
9091

9192
export const ShapeDisplayName: Record<ShapeType, string> = {
9293
multiple: 'multiple',
@@ -162,6 +163,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
162163
paragraphScribbled: 'Paragraph Scribbled',
163164
fabButton: 'Fab Button',
164165
fileTree: 'File Tree',
166+
inputStepper: 'Input Stepper',
165167
};
166168

167169
export type EditType = 'input' | 'textarea' | 'imageupload';

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
getGaugeShapeSizeRestrictions,
6767
getFabButtonShapeSizeRestrictions,
6868
getFileTreeShapeSizeRestrictions,
69+
getInputStepperShapeSizeRestrictions,
6970
// other imports
7071
} from '@/common/components/mock-components/front-rich-components';
7172
import {
@@ -175,6 +176,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
175176
paragraphScribbled: getParagraphScribbledShapeRestrictions,
176177
fabButton: getFabButtonShapeSizeRestrictions,
177178
fileTree: getFileTreeShapeSizeRestrictions,
179+
inputStepper: getInputStepperShapeSizeRestrictions,
178180
};
179181

180182
export default shapeSizeMap;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
renderLoadingIndicator,
5151
renderFabButton,
5252
renderFileTree,
53+
renderInputStepper,
5354
} from './simple-rich-components';
5455
import {
5556
renderDiamond,
@@ -235,6 +236,8 @@ export const renderShapeComponent = (
235236
return renderTextScribbled(shape, shapeRenderedProps);
236237
case 'paragraphScribbled':
237238
return renderParagraphScribbled(shape, shapeRenderedProps);
239+
case 'inputStepper':
240+
return renderInputStepper(shape, shapeRenderedProps);
238241
default:
239242
return renderNotFound(shape, shapeRenderedProps);
240243
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export * from './loading-indicator.renderer';
2222
export * from './videoconference.renderer';
2323
export * from './fab-button.renderer';
2424
export * from './file-tree.renderer';
25+
export * from './input-stepper.renderer';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { InputStepperShape } from '@/common/components/mock-components/front-rich-components';
2+
import { ShapeRendererProps } from '../model';
3+
import { ShapeModel } from '@/core/model';
4+
5+
export const renderInputStepper = (
6+
shape: ShapeModel,
7+
shapeRenderedProps: ShapeRendererProps
8+
) => {
9+
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } =
10+
shapeRenderedProps;
11+
12+
return (
13+
<InputStepperShape
14+
id={shape.id}
15+
key={shape.id}
16+
ref={shapeRefs.current[shape.id]}
17+
x={shape.x}
18+
y={shape.y}
19+
name="shape"
20+
width={shape.width}
21+
height={shape.height}
22+
draggable
23+
typeOfTransformer={shape.typeOfTransformer}
24+
onSelected={handleSelected}
25+
onDragEnd={handleDragEnd(shape.id)}
26+
onTransform={handleTransform}
27+
onTransformEnd={handleTransform}
28+
/>
29+
);
30+
};

src/pods/galleries/rich-components-gallery/rich-components-gallery-data/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ export const mockRichComponentsCollection: ItemInfo[] = [
4444
thumbnailSrc: '/rich-components/file-tree.svg',
4545
type: 'fileTree',
4646
},
47+
{
48+
thumbnailSrc: '/rich-components/input-stepper.svg',
49+
type: 'inputStepper',
50+
},
4751
];

0 commit comments

Comments
 (0)