-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathinput-stepper.tsx
More file actions
127 lines (114 loc) · 3.27 KB
/
input-stepper.tsx
File metadata and controls
127 lines (114 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { forwardRef } from 'react';
import { Group, Rect, Text } from 'react-konva';
import { ShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { useGroupShapeProps } from '../mock-components.utils';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { ShapeType } from '@/core/model';
import { ShapeProps } from '../shape.model';
import { useShapeProps } from '../../shapes/use-shape-props.hook';
import { INPUT_SHAPE } from '../front-components/shape.const';
// Size restrictions (igual patrón que file-tree)
export const inputStepperShapeRestrictions: ShapeSizeRestrictions = {
minWidth: 80,
minHeight: 24,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 120,
defaultHeight: 32,
};
export const getInputStepperShapeSizeRestrictions = (): ShapeSizeRestrictions =>
inputStepperShapeRestrictions;
export const InputWithStepper = forwardRef<any, ShapeProps>((props, ref) => {
const { x, y, width, height, text, onSelect, otherProps, id, ...shapeProps } =
props;
const inputWidth = width - 30; // Reservar espacio para el stepper
const buttonHeight = height / 2;
const restrictedSize = fitSizeToShapeSizeRestrictions(
inputStepperShapeRestrictions,
width,
height
);
const shapeType: ShapeType = 'input-stepper';
const commonGroupProps = useGroupShapeProps(
props,
restrictedSize,
shapeType,
ref
);
const { stroke, textColor, strokeStyle, fill, strokeWidth } = useShapeProps(
otherProps,
INPUT_SHAPE
);
const { width: restrictedWidth } = restrictedSize;
return (
<Group {...commonGroupProps} {...shapeProps}>
{/* Caja del input */}
<Rect
x={0}
y={0}
width={restrictedWidth}
height={height}
fill={fill}
stroke={stroke}
strokeWidth={strokeWidth}
dash={strokeStyle}
cornerRadius={0} // Sin bordes redondeados
/>
{/* Texto del input */}
<Text
x={0} // Alinear a la derecha
y={height / 2 - 8} // Centrar verticalmente
width={restrictedWidth}
text={text}
fontFamily="Arial"
fontSize={16}
fill={textColor}
align="center"
wrap="none"
/>
{/* Botón de incremento (flecha arriba) */}
<Group x={inputWidth} y={0}>
<Rect
x={0}
y={0}
width={30}
height={buttonHeight}
fill="lightgrey"
stroke={stroke}
strokeWidth={strokeWidth}
dash={strokeStyle}
/>
<Text
x={10}
y={buttonHeight / 2 - 8}
text="▲"
fontFamily="Arial"
fontSize={14}
fill={textColor}
/>
</Group>
{/* Botón de decremento (flecha abajo) */}
<Group x={inputWidth} y={buttonHeight}>
<Rect
x={0}
y={0}
width={30}
height={buttonHeight}
fill="lightgrey"
stroke={stroke}
strokeWidth={strokeWidth}
dash={strokeStyle}
/>
<Text
x={10}
y={buttonHeight / 2 - 8}
text="▼"
fontFamily="Arial"
fontSize={14}
fill={textColor}
/>
</Group>
</Group>
);
});
export default InputWithStepper;