Skip to content

Commit d1bcb17

Browse files
committed
fix component
1 parent 20867a1 commit d1bcb17

File tree

2 files changed

+73
-38
lines changed

2 files changed

+73
-38
lines changed

src/common/components/mock-components/front-rich-components/input-stepper.tsx

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
44
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
55
import { ShapeProps } from '../shape.model';
66
import { useGroupShapeProps } from '../mock-components.utils';
7+
import { useShapeProps } from '@/common/components/shapes/use-shape-props.hook';
8+
import { INPUT_SHAPE } from '../front-components/shape.const';
79

810
const InputStepperShapeSizeRestrictions: ShapeSizeRestrictions = {
9-
minWidth: 100,
10-
minHeight: 100,
11-
maxWidth: -1,
12-
maxHeight: -1,
13-
defaultWidth: 250,
14-
defaultHeight: 150,
11+
minWidth: 60,
12+
minHeight: 35,
13+
maxWidth: 500,
14+
maxHeight: 35,
15+
defaultWidth: 100,
16+
defaultHeight: 35,
1517
};
1618

1719
export const getInputStepperShapeSizeRestrictions = (): ShapeSizeRestrictions =>
@@ -20,15 +22,29 @@ export const getInputStepperShapeSizeRestrictions = (): ShapeSizeRestrictions =>
2022
const shapeType: ShapeType = 'inputStepper';
2123

2224
export const InputStepperShape = forwardRef<any, ShapeProps>((props, ref) => {
23-
const { x, y, width, height, id, onSelected, ...shapeProps } = props;
25+
const { x, y, width, height, id, onSelected, otherProps, ...shapeProps } =
26+
props;
27+
2428
const restrictedSize = fitSizeToShapeSizeRestrictions(
2529
InputStepperShapeSizeRestrictions,
2630
width,
2731
height
2832
);
2933

30-
const inputWidth = width - 30; // Reservar espacio para el stepper
31-
const buttonHeight = height / 2;
34+
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
35+
36+
const handleButtonWidth = (restrictedWidth: number): number => {
37+
const buttonWidth = restrictedWidth * 0.3;
38+
const minButtonWidth = 30;
39+
const maxButtonWidth = 70;
40+
41+
if (buttonWidth < minButtonWidth) return minButtonWidth;
42+
if (buttonWidth > maxButtonWidth) return maxButtonWidth;
43+
return buttonWidth;
44+
};
45+
46+
const buttonWidth = handleButtonWidth(restrictedWidth);
47+
const buttonHeight = restrictedHeight / 2;
3248

3349
const commonGroupProps = useGroupShapeProps(
3450
props,
@@ -37,70 +53,80 @@ export const InputStepperShape = forwardRef<any, ShapeProps>((props, ref) => {
3753
ref
3854
);
3955

56+
const { stroke, strokeStyle, fill, textColor } = useShapeProps(
57+
otherProps,
58+
INPUT_SHAPE
59+
);
60+
4061
return (
4162
<Group {...commonGroupProps} {...shapeProps}>
4263
{/* Caja del input */}
4364
<Rect
4465
x={0}
4566
y={0}
46-
width={inputWidth / 2} // Reducir ancho a la mitad
47-
height={height}
48-
fill="white"
49-
stroke="black"
67+
width={restrictedWidth - buttonWidth}
68+
height={restrictedHeight}
69+
fill={fill}
70+
stroke={stroke}
5071
strokeWidth={2}
51-
cornerRadius={0} // Sin bordes redondeados
72+
dash={strokeStyle}
5273
/>
5374

5475
{/* Texto del input */}
5576
<Text
56-
x={inputWidth / 2 - 10} // Alinear a la derecha
57-
y={height / 2 - 8} // Centrar verticalmente
77+
width={restrictedWidth - buttonWidth - 8}
78+
x={0} // Alinear a la derecha dependiendo de la cantidad de dígitos
79+
y={restrictedHeight / 2 - 6} // Centrar verticalmente
5880
text={'0'}
59-
fontFamily="Arial"
60-
fontSize={16}
61-
fill="black"
81+
fontFamily={INPUT_SHAPE.DEFAULT_FONT_FAMILY}
82+
fontSize={INPUT_SHAPE.DEFAULT_FONT_SIZE + 2}
83+
fill={textColor}
6284
align="right"
6385
/>
6486

6587
{/* Botón de incremento (flecha arriba) */}
66-
<Group>
88+
<Group x={restrictedWidth - buttonWidth} y={buttonHeight}>
6789
<Rect
6890
x={0}
69-
y={0}
70-
width={30}
91+
y={-17}
92+
width={buttonWidth}
7193
height={buttonHeight}
72-
fill="lightgray"
73-
stroke="black"
94+
fill={fill}
95+
stroke={stroke}
7496
strokeWidth={2}
97+
dash={strokeStyle}
7598
/>
7699
<Text
77-
x={10}
78-
y={buttonHeight / 2 - 8}
100+
x={buttonWidth / 2 - 7}
101+
y={buttonHeight / 2 - 25}
79102
text="▲"
80-
fontFamily="Arial"
81-
fontSize={14}
82-
fill="black"
103+
fontFamily={INPUT_SHAPE.DEFAULT_FONT_FAMILY}
104+
fontSize={INPUT_SHAPE.DEFAULT_FONT_SIZE}
105+
fill={textColor}
106+
align="center"
83107
/>
84108
</Group>
85109

86110
{/* Botón de decremento (flecha abajo) */}
87-
<Group>
111+
<Group x={restrictedWidth - buttonWidth} y={buttonHeight}>
88112
<Rect
89113
x={0}
90114
y={0}
91-
width={30}
115+
width={buttonWidth}
92116
height={buttonHeight}
93-
fill="lightgray"
94-
stroke="black"
117+
fill={fill}
118+
stroke={stroke}
95119
strokeWidth={2}
120+
dash={strokeStyle}
96121
/>
97122
<Text
98-
x={10}
99-
y={buttonHeight / 2 - 8}
123+
x={buttonWidth / 2 - 6}
124+
y={buttonHeight / 2 - 6}
100125
text="▼"
101-
fontFamily="Arial"
102-
fontSize={14}
103-
fill="black"
126+
fontFamily={INPUT_SHAPE.DEFAULT_FONT_FAMILY}
127+
fontSize={INPUT_SHAPE.DEFAULT_FONT_SIZE}
128+
fill={textColor}
129+
align="center"
104130
/>
105131
</Group>
106132
</Group>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ export const generateDefaultOtherProps = (
287287
textColor: '#000000',
288288
strokeStyle: [],
289289
};
290+
case 'inputStepper':
291+
return {
292+
stroke: INPUT_SHAPE.DEFAULT_STROKE_COLOR,
293+
backgroundColor: INPUT_SHAPE.DEFAULT_FILL_BACKGROUND,
294+
textColor: INPUT_SHAPE.DEFAULT_FILL_TEXT,
295+
borderRadius: `${INPUT_SHAPE.DEFAULT_CORNER_RADIUS}`,
296+
disabled: INPUT_SHAPE.DEFAULT_DISABLED,
297+
strokeStyle: [],
298+
};
290299
default:
291300
return undefined;
292301
}

0 commit comments

Comments
 (0)