Skip to content

Commit 25a09d1

Browse files
committed
input stepper
1 parent 6d5db61 commit 25a09d1

9 files changed

Lines changed: 177 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
@@ -2,6 +2,7 @@ export * from './accordion';
22
export * from './breadcrumb/breadcrumb';
33
export * from './pie-chart';
44
export * from './horizontal-menu/horizontal-menu';
5+
export * from './input-stepper';
56
export * from './map-chart';
67
export * from './video-player';
78
export * from './bar-chart';
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { useState, forwardRef } from 'react';
2+
import { Group, Rect, Text } from 'react-konva';
3+
import { ShapeConfig } from 'konva/lib/Shape';
4+
import { ShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
5+
6+
interface InputWithStepperProps extends ShapeConfig {
7+
id: string;
8+
x: number;
9+
y: number;
10+
width: number;
11+
height: number;
12+
initialValue?: number;
13+
}
14+
15+
// Size restrictions (igual patrón que file-tree)
16+
export const inputStepperShapeRestrictions: ShapeSizeRestrictions = {
17+
minWidth: 80,
18+
minHeight: 24,
19+
maxWidth: -1,
20+
maxHeight: -1,
21+
defaultWidth: 120,
22+
defaultHeight: 32,
23+
};
24+
25+
export const getInputStepperShapeSizeRestrictions = (): ShapeSizeRestrictions =>
26+
inputStepperShapeRestrictions;
27+
28+
export const InputWithStepper = forwardRef<any, InputWithStepperProps>(
29+
({ x, y, width, height, initialValue = 0, id, ...shapeProps }, ref) => {
30+
const [value, setValue] = useState(initialValue);
31+
32+
const handleIncrement = () => {
33+
setValue(value + 1);
34+
};
35+
36+
const handleDecrement = () => {
37+
setValue(value - 1);
38+
};
39+
40+
const inputWidth = width - 30; // Reservar espacio para el stepper
41+
const buttonHeight = height / 2;
42+
43+
return (
44+
<Group x={x} y={y} ref={ref} {...shapeProps}>
45+
{/* Caja del input */}
46+
<Rect
47+
x={0}
48+
y={0}
49+
width={inputWidth / 2} // Reducir ancho a la mitad
50+
height={height}
51+
fill="white"
52+
stroke="black"
53+
strokeWidth={2}
54+
cornerRadius={0} // Sin bordes redondeados
55+
/>
56+
57+
{/* Texto del input */}
58+
<Text
59+
x={inputWidth / 2 - 10} // Alinear a la derecha
60+
y={height / 2 - 8} // Centrar verticalmente
61+
text={value.toString()}
62+
fontFamily="Arial"
63+
fontSize={16}
64+
fill="black"
65+
align="right"
66+
/>
67+
68+
{/* Botón de incremento (flecha arriba) */}
69+
<Group x={inputWidth / 2} y={0} onClick={handleIncrement}>
70+
<Rect
71+
x={0}
72+
y={0}
73+
width={30}
74+
height={buttonHeight}
75+
fill="lightgray"
76+
stroke="black"
77+
strokeWidth={2}
78+
/>
79+
<Text
80+
x={10}
81+
y={buttonHeight / 2 - 8}
82+
text="▲"
83+
fontFamily="Arial"
84+
fontSize={14}
85+
fill="black"
86+
/>
87+
</Group>
88+
89+
{/* Botón de decremento (flecha abajo) */}
90+
<Group x={inputWidth / 2} y={buttonHeight} onClick={handleDecrement}>
91+
<Rect
92+
x={0}
93+
y={0}
94+
width={30}
95+
height={buttonHeight}
96+
fill="lightgray"
97+
stroke="black"
98+
strokeWidth={2}
99+
/>
100+
<Text
101+
x={10}
102+
y={buttonHeight / 2 - 8}
103+
text="▼"
104+
fontFamily="Arial"
105+
fontSize={14}
106+
fill="black"
107+
/>
108+
</Group>
109+
</Group>
110+
);
111+
}
112+
);
113+
114+
export default InputWithStepper;

src/core/model/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type ShapeType =
3838
| 'accordion'
3939
| 'pie'
4040
| 'horizontal-menu'
41+
| 'input-stepper'
4142
| 'breadcrumb'
4243
| 'map'
4344
| 'circle'
@@ -130,6 +131,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
130131
link: 'Link',
131132
triangle: 'Triangle',
132133
'horizontal-menu': 'Horizontal Menu',
134+
'input-stepper': 'Input Stepper',
133135
largeArrow: 'Large Arrow',
134136
icon: 'Icon',
135137
bar: 'Bar Chart',
@@ -238,3 +240,8 @@ export interface ShapeModel {
238240
text?: string;
239241
otherProps?: OtherProps;
240242
}
243+
244+
export interface inputStepper {
245+
id: string;
246+
min: number;
247+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// src/common/shape-utils/shapeSizeMap.ts
22
import { ShapeType, ShapeSizeRestrictions } from '@/core/model';
3+
import { getInputStepperShapeSizeRestrictions } from '@/common/components/mock-components/front-rich-components/input-stepper';
34
import {
45
getButtonShapeSizeRestrictions,
56
getCheckboxShapeSizeRestrictions,
@@ -128,6 +129,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
128129
postit: getPostItShapeSizeRestrictions,
129130
pie: getPieChartShapeSizeRestrictions,
130131
'horizontal-menu': getHorizontalMenuShapeSizeRestrictions,
132+
'input-stepper': getInputStepperShapeSizeRestrictions,
131133
'vertical-menu': getVerticalMenuShapeSizeRestrictions,
132134
breadcrumb: getBreadcrumbShapeSizeRestrictions,
133135
map: getMapChartShapeSizeRestrictions,
@@ -172,9 +174,9 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
172174
rectangleLow: getRectangleLowShapeRestrictions,
173175
circleLow: getCircleLowShapeSizeRestrictions,
174176
textScribbled: getTextScribbledShapeRestrictions,
175-
paragraphScribbled: getParagraphScribbledShapeRestrictions,
176177
fabButton: getFabButtonShapeSizeRestrictions,
177178
fileTree: getFileTreeShapeSizeRestrictions,
179+
paragraphScribbled: getParagraphScribbledShapeRestrictions,
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
@@ -29,6 +29,7 @@ import {
2929
} from './simple-container';
3030
import {
3131
renderVideoPlayer,
32+
renderInputStepper,
3233
renderAccordion,
3334
renderHorizontalMenu,
3435
renderPieChart,
@@ -153,6 +154,8 @@ export const renderShapeComponent = (
153154
return renderTriangle(shape, shapeRenderedProps);
154155
case 'horizontal-menu':
155156
return renderHorizontalMenu(shape, shapeRenderedProps);
157+
case 'input-stepper':
158+
return renderInputStepper(shape, shapeRenderedProps);
156159
case 'vertical-menu':
157160
return renderVerticalMenuShape(shape, shapeRenderedProps);
158161
case 'breadcrumb':

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './breadcrumb.renderer';
66
export * from './button-bar.renderer';
77
export * from './calendar.renderer';
88
export * from './horizontal-menu.renderer';
9+
export * from './input-stepper.renderer';
910
export * from './line-chart.renderer';
1011
export * from './map-chart.renderer';
1112
export * from './table.renderer';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { InputWithStepper } from '@/common/components/mock-components/front-rich-components/input-stepper';
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+
<InputWithStepper
14+
id={shape.id}
15+
key={shape.id}
16+
ref={shapeRefs.current[shape.id]}
17+
x={shape.x}
18+
y={shape.y}
19+
width={shape.width}
20+
height={shape.height}
21+
draggable
22+
onSelected={handleSelected}
23+
onDragEnd={handleDragEnd(shape.id)}
24+
onTransform={handleTransform}
25+
onTransformEnd={handleTransform}
26+
initialValue={0}
27+
/>
28+
);
29+
};

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: 'input-stepper',
50+
},
4751
];

0 commit comments

Comments
 (0)