Skip to content

Commit e76da86

Browse files
committed
create getTextFieldWidth business function
1 parent 3358d11 commit e76da86

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './input-stepper';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const getTextFieldWidth = (restrictedWidth: number): number => {
2+
const inputWidth = restrictedWidth * 0.3;
3+
const minInputWidth = 30;
4+
const maxInputWidth = 70;
5+
6+
if (inputWidth < minInputWidth) {
7+
return minInputWidth;
8+
} else if (inputWidth > maxInputWidth) {
9+
return maxInputWidth;
10+
}
11+
12+
return inputWidth;
13+
};

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { forwardRef } from 'react';
22
import { Group, Rect, Text } from 'react-konva';
33
import { ShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
4-
import { useGroupShapeProps } from '../mock-components.utils';
4+
import { useGroupShapeProps } from '../../mock-components.utils';
55
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
66
import { ShapeType } from '@/core/model';
7-
import { ShapeProps } from '../shape.model';
8-
import { useShapeProps } from '../../shapes/use-shape-props.hook';
9-
import { INPUT_SHAPE } from '../front-components/shape.const';
7+
import { ShapeProps } from '../../shape.model';
8+
import { useShapeProps } from '../../../shapes/use-shape-props.hook';
9+
import { INPUT_SHAPE } from '../../front-components/shape.const';
10+
import { getTextFieldWidth } from './input-stepper.business';
1011

1112
// Size restrictions (igual patrón que file-tree)
1213
export const inputStepperShapeRestrictions: ShapeSizeRestrictions = {
@@ -49,17 +50,7 @@ export const InputWithStepper = forwardRef<any, ShapeProps>((props, ref) => {
4950

5051
const { width: restrictedWidth } = restrictedSize;
5152

52-
const getInputWidth = (restrictedWidth: number): number => {
53-
const inputWidth = restrictedWidth * 0.3;
54-
const minInputWidth = 30;
55-
const maxInputWidth = 70;
56-
57-
if (inputWidth < minInputWidth) return minInputWidth;
58-
if (inputWidth > maxInputWidth) return maxInputWidth;
59-
return inputWidth;
60-
};
61-
62-
const a = getInputWidth(restrictedWidth);
53+
const textFieldWidth = getTextFieldWidth(restrictedWidth);
6354

6455
return (
6556
<Group {...commonGroupProps} {...shapeProps}>
@@ -78,9 +69,9 @@ export const InputWithStepper = forwardRef<any, ShapeProps>((props, ref) => {
7869

7970
{/* Texto del input */}
8071
<Text
81-
x={0} // Alinear a la derecha
72+
x={0}
8273
y={height / 2 - 8} // Centrar verticalmente
83-
width={restrictedWidth - a - 8}
74+
width={restrictedWidth - textFieldWidth - 8}
8475
text={text}
8576
fontFamily="Arial"
8677
fontSize={16}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +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';
3+
import { getInputStepperShapeSizeRestrictions } from '@/common/components/mock-components/front-rich-components/input-stepper/input-stepper';
44
import {
55
getButtonShapeSizeRestrictions,
66
getCheckboxShapeSizeRestrictions,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InputWithStepper } from '@/common/components/mock-components/front-rich-components/input-stepper';
1+
import { InputWithStepper } from '@/common/components/mock-components/front-rich-components/input-stepper/input-stepper';
22
import { ShapeRendererProps } from '../model';
33
import { ShapeModel } from '@/core/model';
44

0 commit comments

Comments
 (0)