From 689ae550d54a6c3e356237f8de935f3b03bf574e Mon Sep 17 00:00:00 2001 From: Fran Lopez Date: Wed, 31 Jul 2024 17:18:28 +0200 Subject: [PATCH 1/3] refactor all shape front components --- .../front-components/button-shape.tsx | 26 +++++++---- .../front-components/checkbox-shape.tsx | 46 ++++++++----------- .../front-components/combobox-shape.tsx | 20 ++++---- .../datepickerinput-shape.tsx | 34 +++++++++----- .../front-components/input-shape.tsx | 2 +- .../front-components/progressbar-shape.tsx | 42 ++++++++++------- .../front-components/textarea-shape.tsx | 27 +++++++---- .../timepickerinput-shape.tsx | 42 ++++++++++------- .../front-components/toggleswitch-shape.tsx | 40 ++++++++++------ .../front-containers/browserwindow-shape.tsx | 2 + 10 files changed, 167 insertions(+), 114 deletions(-) diff --git a/src/common/components/front-components/button-shape.tsx b/src/common/components/front-components/button-shape.tsx index 00d58dff..9afb71e2 100644 --- a/src/common/components/front-components/button-shape.tsx +++ b/src/common/components/front-components/button-shape.tsx @@ -1,34 +1,41 @@ -import { forwardRef } from 'react'; -import { Group, Rect, Text } from 'react-konva'; import { ShapeSizeRestrictions } from '@/core/model'; +import { forwardRef } from 'react'; import { ShapeProps } from './shape.model'; +import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; +import { Group, Rect, Text } from 'react-konva'; -export const getButtonShapeSizeRestrictions = (): ShapeSizeRestrictions => ({ - minWidth: 150, +const buttonShapeRestrictions: ShapeSizeRestrictions = { + minWidth: 60, minHeight: 50, maxWidth: -1, maxHeight: 50, defaultWidth: 150, defaultHeight: 50, -}); +}; + +export const getButtonShapeSizeRestrictions = (): ShapeSizeRestrictions => + buttonShapeRestrictions; export const ButtonShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions(buttonShapeRestrictions, width, height); + return ( onSelected(id, 'button')} > ( x={0} y={20} width={width} + height={height - 20} text="Click Me!" fontFamily="Comic Sans MS, cursive" fontSize={15} diff --git a/src/common/components/front-components/checkbox-shape.tsx b/src/common/components/front-components/checkbox-shape.tsx index cb9b852a..66e4e730 100644 --- a/src/common/components/front-components/checkbox-shape.tsx +++ b/src/common/components/front-components/checkbox-shape.tsx @@ -1,16 +1,20 @@ +import { ShapeSizeRestrictions } from '@/core/model'; import { forwardRef } from 'react'; -import { Group, Rect, Line, Text } from 'react-konva'; import { ShapeProps } from './shape.model'; -import { ShapeSizeRestrictions } from '@/core/model'; +import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; +import { Group, Rect, Line, Text } from 'react-konva'; -export const getCheckboxShapeSizeRestrictions = (): ShapeSizeRestrictions => ({ - minWidth: 150, +const checkBoxShapeRestrictions: ShapeSizeRestrictions = { + minWidth: 100, minHeight: 30, maxWidth: -1, maxHeight: 50, - defaultWidth: 220, + defaultWidth: 200, defaultHeight: 50, -}); +}; + +export const getCheckboxShapeSizeRestrictions = (): ShapeSizeRestrictions => + checkBoxShapeRestrictions; const marginTick = 5; const boxTickWidth = 50; @@ -18,42 +22,29 @@ const tickWidth = boxTickWidth - marginTick; export const CheckBoxShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { - const handleClick = () => { - onSelected(id, 'checkbox'); - }; + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions(checkBoxShapeRestrictions, width, height); return ( onSelected(id, 'checkbox')} > - {/* Caja del checkbox */} - - {/* Marca de verificación (checked) */} - - {/* - ---------- - | * - | * * - | * - ----------- - */} - ( lineCap="round" lineJoin="round" /> - - {/* Texto */} ( fontFamily="Comic Sans MS, cursive" fontSize={20} fill="black" + align="left" verticalAlign="middle" + ellipsis={true} + wrap="none" /> ); diff --git a/src/common/components/front-components/combobox-shape.tsx b/src/common/components/front-components/combobox-shape.tsx index bbcea518..e567724d 100644 --- a/src/common/components/front-components/combobox-shape.tsx +++ b/src/common/components/front-components/combobox-shape.tsx @@ -1,26 +1,33 @@ import { ShapeSizeRestrictions } from '@/core/model'; import { forwardRef } from 'react'; -import { Path, Group, Text } from 'react-konva'; import { ShapeProps } from './shape.model'; +import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; +import { Path, Group, Text } from 'react-konva'; -export const getComboBoxShapeSizeRestrictions = (): ShapeSizeRestrictions => ({ +const comboBoxShapeRestrictions: ShapeSizeRestrictions = { minWidth: 100, minHeight: 50, maxWidth: -1, maxHeight: 50, defaultWidth: 220, defaultHeight: 50, -}); +}; + +export const getComboBoxShapeSizeRestrictions = (): ShapeSizeRestrictions => + comboBoxShapeRestrictions; export const ComboBoxShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions(comboBoxShapeRestrictions, width, height); + return ( onSelected(id, 'combobox')} > @@ -37,15 +44,12 @@ export const ComboBoxShape = forwardRef( } L${width - 20},${(height + 10) / 2}`} fill="black" /> - {/* Combo arrow vertical line separator */} - - {/* Text */} ({ - minWidth: 80, - minHeight: 50, - maxWidth: -1, - maxHeight: 50, - defaultWidth: 220, - defaultHeight: 50, - }); + (): ShapeSizeRestrictions => datepickerInputShapeRestrictions; export const DatepickerInputShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions( + datepickerInputShapeRestrictions, + width, + height + ); + const margin = 10; const separatorPadding = 15; // Extra padding for spacers const separator1X = width / 3 + margin; @@ -25,8 +35,8 @@ export const DatepickerInputShape = forwardRef( x={x} y={y} ref={ref} - width={width} - height={height} + width={restrictedWidth} + height={restrictedHeight} {...shapeProps} onClick={() => onSelected(id, 'datepickerinput')} > diff --git a/src/common/components/front-components/input-shape.tsx b/src/common/components/front-components/input-shape.tsx index f250793b..ef26a65b 100644 --- a/src/common/components/front-components/input-shape.tsx +++ b/src/common/components/front-components/input-shape.tsx @@ -1,8 +1,8 @@ import { ShapeSizeRestrictions } from '@/core/model'; import { forwardRef } from 'react'; import { ShapeProps } from './shape.model'; -import { Group, Rect, Text } from 'react-konva'; import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; +import { Group, Rect, Text } from 'react-konva'; const inputShapeRestrictions: ShapeSizeRestrictions = { minWidth: 60, diff --git a/src/common/components/front-components/progressbar-shape.tsx b/src/common/components/front-components/progressbar-shape.tsx index 668ca712..9d1dd76f 100644 --- a/src/common/components/front-components/progressbar-shape.tsx +++ b/src/common/components/front-components/progressbar-shape.tsx @@ -1,27 +1,37 @@ import { ShapeSizeRestrictions } from '@/core/model'; import { forwardRef } from 'react'; -import { Group, Rect } from 'react-konva'; import { ShapeProps } from './shape.model'; +import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; +import { Group, Rect } from 'react-konva'; -export const getProgressBarShapeSizeRestrictions = - (): ShapeSizeRestrictions => ({ - minWidth: 100, - minHeight: 20, - maxWidth: -1, - maxHeight: 30, - defaultWidth: 300, - defaultHeight: 20, - }); +const progressBarShapeRestrictions: ShapeSizeRestrictions = { + minWidth: 100, + minHeight: 20, + maxWidth: -1, + maxHeight: 30, + defaultWidth: 300, + defaultHeight: 20, +}; + +export const getProgressBarShapeSizeRestrictions = (): ShapeSizeRestrictions => + progressBarShapeRestrictions; export const ProgressBarShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions( + progressBarShapeRestrictions, + width, + height + ); + return ( onSelected(id, 'progressbar')} > @@ -29,8 +39,8 @@ export const ProgressBarShape = forwardRef( ( ({ +const textAreaShapeRestrictions: ShapeSizeRestrictions = { minWidth: 80, - minHeight: 90, + minHeight: 70, maxWidth: -1, maxHeight: 500, defaultWidth: 190, defaultHeight: 100, -}); +}; + +export const getTextAreaSizeRestrictions = (): ShapeSizeRestrictions => + textAreaShapeRestrictions; export const TextAreaShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions(textAreaShapeRestrictions, width, height); + return ( onSelected(id, 'textarea')} @@ -27,8 +34,8 @@ export const TextAreaShape = forwardRef( ( x={10} y={10} width={width} + height={height - 10} text="Your text here..." fontFamily="Comic Sans MS, cursive" fontSize={15} fill="gray" align="left" ellipsis={true} - height={height - 10} /> ); diff --git a/src/common/components/front-components/timepickerinput-shape.tsx b/src/common/components/front-components/timepickerinput-shape.tsx index dd8e3389..16d7a080 100644 --- a/src/common/components/front-components/timepickerinput-shape.tsx +++ b/src/common/components/front-components/timepickerinput-shape.tsx @@ -1,20 +1,30 @@ -import { Group, Rect, Text } from 'react-konva'; +import { ShapeSizeRestrictions } from '@/core/model'; import { forwardRef } from 'react'; import { ShapeProps } from './shape.model'; -import { ShapeSizeRestrictions } from '@/core/model'; +import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; +import { Group, Rect, Text } from 'react-konva'; + +const timepickerInputShapeRestrictions: ShapeSizeRestrictions = { + minWidth: 100, + minHeight: 50, + maxWidth: -1, + maxHeight: 50, + defaultWidth: 220, + defaultHeight: 50, +}; export const getTimepickerInputShapeSizeRestrictions = - (): ShapeSizeRestrictions => ({ - minWidth: 80, - minHeight: 50, - maxWidth: -1, - maxHeight: 50, - defaultWidth: 220, - defaultHeight: 50, - }); + (): ShapeSizeRestrictions => timepickerInputShapeRestrictions; export const TimepickerInputShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions( + timepickerInputShapeRestrictions, + width, + height + ); + const margin = 10; const separatorPadding = 15; // Extra padding for spacers const separator1X = width / 3 + margin; @@ -25,8 +35,8 @@ export const TimepickerInputShape = forwardRef( x={x} y={y} ref={ref} - width={width} - height={height} + width={restrictedWidth} + height={restrictedHeight} {...shapeProps} onClick={() => onSelected(id, 'timepickerinput')} > @@ -34,8 +44,8 @@ export const TimepickerInputShape = forwardRef( ( {/* Separators : */} ( /> ({ - minWidth: 50, - minHeight: 25, - maxWidth: 100, - maxHeight: 35, - defaultWidth: 60, - defaultHeight: 25, - }); +const toggleSwitchShapeRestrictions: ShapeSizeRestrictions = { + minWidth: 50, + minHeight: 25, + maxWidth: 100, + maxHeight: 35, + defaultWidth: 60, + defaultHeight: 25, +}; + +export const getToggleSwitchShapeSizeRestrictions = (): ShapeSizeRestrictions => + toggleSwitchShapeRestrictions; export const ToggleSwitch = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions( + toggleSwitchShapeRestrictions, + width, + height + ); + const [isOn, setIsOn] = useState(false); const handleSwitch = () => { @@ -29,16 +39,16 @@ export const ToggleSwitch = forwardRef( x={x} y={y} ref={ref} - width={width} - height={height} + width={restrictedWidth} + height={restrictedHeight} {...shapeProps} onClick={() => onSelected(id, 'toggleswitch')} > ( ( fontFamily="Comic Sans MS, cursive" fontSize={12} fill="black" + ellipsis={true} + wrap="none" /> ); From db9aa1d388831c2d0fb513b3c529d50900b6dfdd Mon Sep 17 00:00:00 2001 From: Fran Lopez Date: Wed, 31 Jul 2024 17:54:39 +0200 Subject: [PATCH 2/3] fix datepicker and timepicker shape --- .../datepickerinput-shape.tsx | 24 +++++++++---------- .../timepickerinput-shape.tsx | 17 +++++++------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/common/components/front-components/datepickerinput-shape.tsx b/src/common/components/front-components/datepickerinput-shape.tsx index 0dd8aa62..6e7f28c4 100644 --- a/src/common/components/front-components/datepickerinput-shape.tsx +++ b/src/common/components/front-components/datepickerinput-shape.tsx @@ -25,10 +25,9 @@ export const DatepickerInputShape = forwardRef( height ); - const margin = 10; - const separatorPadding = 15; // Extra padding for spacers - const separator1X = width / 3 + margin; - const separator2X = (2 * width) / 3 - margin; + const separatorPadding = 12; + const separator1X = restrictedWidth / 3; + const separator2X = (2 * restrictedWidth) / 3; return ( ( > {/* input frame */} - {/* Inverted diagonal spacers */} ( ( height ); - const margin = 10; - const separatorPadding = 15; // Extra padding for spacers - const separator1X = width / 3 + margin; - const separator2X = (2 * width) / 3 - margin; + const separatorPadding = 3; // Extra padding for spacers + const separator1X = restrictedWidth / 3; + const separator2X = (2 * restrictedWidth) / 3; return ( ( > {/* input frame */} ( {/* Separators : */} ( /> Date: Thu, 1 Aug 2024 13:22:32 +0200 Subject: [PATCH 3/3] refactor all shape front containers --- .../front-containers/browserwindow-shape.tsx | 47 ++++++++++++------- .../front-containers/tablet-shape.tsx | 33 ++++++++----- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/common/components/front-containers/browserwindow-shape.tsx b/src/common/components/front-containers/browserwindow-shape.tsx index f27e61dc..24728245 100644 --- a/src/common/components/front-containers/browserwindow-shape.tsx +++ b/src/common/components/front-containers/browserwindow-shape.tsx @@ -1,20 +1,29 @@ import { ShapeSizeRestrictions } from '@/core/model'; import { forwardRef } from 'react'; -import { Group, Rect, Circle, Text } from 'react-konva'; import { ShapeProps } from '../front-components/shape.model'; +import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; +import { Group, Rect, Circle, Text } from 'react-konva'; + +const browserWindowShapeSizeRestrictions: ShapeSizeRestrictions = { + minWidth: 200, + minHeight: 150, + maxWidth: 1000, + maxHeight: 1000, + defaultWidth: 400, + defaultHeight: 300, +}; export const getBrowserWindowShapeSizeRestrictions = - (): ShapeSizeRestrictions => ({ - minWidth: 200, - minHeight: 150, - maxWidth: 1000, - maxHeight: 1000, - defaultWidth: 400, - defaultHeight: 300, - }); + (): ShapeSizeRestrictions => browserWindowShapeSizeRestrictions; export const BrowserWindowShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions( + browserWindowShapeSizeRestrictions, + width, + height + ); const margin = 10; const titleBarHeight = 30; const buttonRadius = 6; @@ -25,8 +34,8 @@ export const BrowserWindowShape = forwardRef( x={x} y={y} ref={ref} - width={width} - height={height} + width={restrictedWidth} + height={restrictedHeight} {...shapeProps} onClick={() => onSelected(id, 'browser')} > @@ -34,8 +43,8 @@ export const BrowserWindowShape = forwardRef( ( ( {/* Content area */} ( ( ({ +const tabletShapeSizeRestrictions: ShapeSizeRestrictions = { minWidth: 200, minHeight: 150, maxWidth: 1000, maxHeight: 1000, defaultWidth: 400, defaultHeight: 300, -}); +}; + +export const getTabletShapeSizeRestrictions = (): ShapeSizeRestrictions => + tabletShapeSizeRestrictions; export const TabletShape = forwardRef( ({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { + const { width: restrictedWidth, height: restrictedHeight } = + fitSizeToShapeSizeRestrictions( + tabletShapeSizeRestrictions, + width, + height + ); const margin = 20; const screenMargin = 15; const cameraPadding = 3; const buttonPadding = 3; - const cameraRadius = 3; const buttonRadius = 5; @@ -27,8 +36,8 @@ export const TabletShape = forwardRef( x={x} y={y} ref={ref} - width={width} - height={height} + width={restrictedWidth} + height={restrictedHeight} {...shapeProps} onClick={() => onSelected(id, 'tablet')} > @@ -36,8 +45,8 @@ export const TabletShape = forwardRef( ( ( {/* Cámara frontal */} ( {/* Botón de inicio */}