|
| 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; |
0 commit comments