Skip to content

Commit 1b8fcb9

Browse files
committed
fix type of transformer
1 parent 25a09d1 commit 1b8fcb9

3 files changed

Lines changed: 82 additions & 80 deletions

File tree

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import { useState, forwardRef } from 'react';
1+
import { forwardRef } from 'react';
22
import { Group, Rect, Text } from 'react-konva';
3-
import { ShapeConfig } from 'konva/lib/Shape';
43
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-
}
4+
import { useGroupShapeProps } from '../mock-components.utils';
5+
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
6+
import { ShapeType } from '@/core/model';
7+
import { ShapeProps } from '../shape.model';
148

159
// Size restrictions (igual patrón que file-tree)
1610
export const inputStepperShapeRestrictions: ShapeSizeRestrictions = {
@@ -25,90 +19,96 @@ export const inputStepperShapeRestrictions: ShapeSizeRestrictions = {
2519
export const getInputStepperShapeSizeRestrictions = (): ShapeSizeRestrictions =>
2620
inputStepperShapeRestrictions;
2721

28-
export const InputWithStepper = forwardRef<any, InputWithStepperProps>(
29-
({ x, y, width, height, initialValue = 0, id, ...shapeProps }, ref) => {
30-
const [value, setValue] = useState(initialValue);
22+
export const InputWithStepper = forwardRef<any, ShapeProps>((props, ref) => {
23+
const { x, y, width, height, text, onSelect, otherProps, id, ...shapeProps } =
24+
props;
25+
26+
const inputWidth = width - 30; // Reservar espacio para el stepper
27+
const buttonHeight = height / 2;
28+
29+
const restrictedSize = fitSizeToShapeSizeRestrictions(
30+
inputStepperShapeRestrictions,
31+
width,
32+
height
33+
);
3134

32-
const handleIncrement = () => {
33-
setValue(value + 1);
34-
};
35+
const shapeType: ShapeType = 'input-stepper';
3536

36-
const handleDecrement = () => {
37-
setValue(value - 1);
38-
};
37+
const commonGroupProps = useGroupShapeProps(
38+
props,
39+
restrictedSize,
40+
shapeType,
41+
ref
42+
);
3943

40-
const inputWidth = width - 30; // Reservar espacio para el stepper
41-
const buttonHeight = height / 2;
44+
return (
45+
<Group {...commonGroupProps} {...shapeProps}>
46+
{/* Caja del input */}
47+
<Rect
48+
x={0}
49+
y={0}
50+
width={inputWidth / 2} // Reducir ancho a la mitad
51+
height={height}
52+
fill="white"
53+
stroke="black"
54+
strokeWidth={2}
55+
cornerRadius={0} // Sin bordes redondeados
56+
/>
4257

43-
return (
44-
<Group x={x} y={y} ref={ref} {...shapeProps}>
45-
{/* Caja del input */}
58+
{/* Texto del input */}
59+
<Text
60+
x={inputWidth / 2 - 10} // Alinear a la derecha
61+
y={height / 2 - 8} // Centrar verticalmente
62+
text={'0'}
63+
fontFamily="Arial"
64+
fontSize={16}
65+
fill="black"
66+
align="right"
67+
/>
68+
69+
{/* Botón de incremento (flecha arriba) */}
70+
<Group x={inputWidth / 2} y={0}>
4671
<Rect
4772
x={0}
4873
y={0}
49-
width={inputWidth / 2} // Reducir ancho a la mitad
50-
height={height}
51-
fill="white"
74+
width={30}
75+
height={buttonHeight}
76+
fill="lightgray"
5277
stroke="black"
5378
strokeWidth={2}
54-
cornerRadius={0} // Sin bordes redondeados
5579
/>
56-
57-
{/* Texto del input */}
5880
<Text
59-
x={inputWidth / 2 - 10} // Alinear a la derecha
60-
y={height / 2 - 8} // Centrar verticalmente
61-
text={value.toString()}
81+
x={10}
82+
y={buttonHeight / 2 - 8}
83+
text="▲"
6284
fontFamily="Arial"
63-
fontSize={16}
85+
fontSize={14}
6486
fill="black"
65-
align="right"
6687
/>
88+
</Group>
6789

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>
90+
{/* Botón de decremento (flecha abajo) */}
91+
<Group x={inputWidth / 2} y={buttonHeight}>
92+
<Rect
93+
x={0}
94+
y={0}
95+
width={30}
96+
height={buttonHeight}
97+
fill="lightgray"
98+
stroke="black"
99+
strokeWidth={2}
100+
/>
101+
<Text
102+
x={10}
103+
y={buttonHeight / 2 - 8}
104+
text="▼"
105+
fontFamily="Arial"
106+
fontSize={14}
107+
fill="black"
108+
/>
109109
</Group>
110-
);
111-
}
112-
);
110+
</Group>
111+
);
112+
});
113113

114114
export default InputWithStepper;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const generateTypeOfTransformer = (shapeType: ShapeType): string[] => {
7171
case 'buttonBar':
7272
case 'slider':
7373
case 'chip':
74+
case 'input-stepper':
7475
return ['middle-left', 'middle-right'];
7576
case 'verticalLine':
7677
case 'verticalScrollBar':

src/pods/canvas/shape-renderer/simple-rich-components/input-stepper.renderer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const renderInputStepper = (
2424
onTransform={handleTransform}
2525
onTransformEnd={handleTransform}
2626
initialValue={0}
27+
typeOfTransformer={shape.typeOfTransformer}
2728
/>
2829
);
2930
};

0 commit comments

Comments
 (0)