From 69b2ecd0b8d5db8b1d6ba85170ad7cb6df658133 Mon Sep 17 00:00:00 2001 From: Fran Lopez Date: Thu, 1 Aug 2024 13:22:32 +0200 Subject: [PATCH] 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 */}