Skip to content

Commit

Permalink
refactor all shape front containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Franlop7 committed Aug 1, 2024
1 parent 4bf701c commit 69b2ecd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
47 changes: 29 additions & 18 deletions src/common/components/front-containers/browserwindow-shape.tsx
Original file line number Diff line number Diff line change
@@ -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<any, ShapeProps>(
({ 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;
Expand All @@ -25,17 +34,17 @@ export const BrowserWindowShape = forwardRef<any, ShapeProps>(
x={x}
y={y}
ref={ref}
width={width}
height={height}
width={restrictedWidth}
height={restrictedHeight}
{...shapeProps}
onClick={() => onSelected(id, 'browser')}
>
{/* Window frame */}
<Rect
x={margin}
y={margin}
width={width - 2 * margin}
height={height - 2 * margin}
width={restrictedWidth}
height={restrictedHeight}
cornerRadius={15}
stroke="black"
strokeWidth={2}
Expand All @@ -45,7 +54,7 @@ export const BrowserWindowShape = forwardRef<any, ShapeProps>(
<Rect
x={margin}
y={margin}
width={width - 2 * margin}
width={restrictedWidth}
height={titleBarHeight}
cornerRadius={10}
stroke="black"
Expand Down Expand Up @@ -80,9 +89,9 @@ export const BrowserWindowShape = forwardRef<any, ShapeProps>(
{/* Content area */}
<Rect
x={margin * 2}
y={margin + titleBarHeight + 7}
width={width - 4 * margin}
height={height - titleBarHeight - 3 * margin - 10}
y={margin + 40}
width={restrictedWidth - 20}
height={restrictedHeight - 50}
stroke="black"
strokeWidth={1}
fill="white"
Expand All @@ -91,7 +100,7 @@ export const BrowserWindowShape = forwardRef<any, ShapeProps>(
<Rect
x={margin * 3}
y={margin + titleBarHeight + 15}
width={width - 6 * margin}
width={restrictedWidth - 40}
height={urlBarHeight}
cornerRadius={5}
stroke="black"
Expand All @@ -101,6 +110,8 @@ export const BrowserWindowShape = forwardRef<any, ShapeProps>(
<Text
x={margin * 3 + 5}
y={margin + titleBarHeight + 20}
width={restrictedWidth - 50}
height={restrictedHeight - 50}
text="https://example.com"
fontFamily="Comic Sans MS, cursive"
fontSize={12}
Expand Down
33 changes: 21 additions & 12 deletions src/common/components/front-containers/tablet-shape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@ import { forwardRef } from 'react';
import { Group, Rect, Circle } from 'react-konva';
import { ShapeProps } from '../front-components/shape.model';
import { ShapeSizeRestrictions } from '@/core/model';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';

export const getTabletShapeSizeRestrictions = (): ShapeSizeRestrictions => ({
const tabletShapeSizeRestrictions: ShapeSizeRestrictions = {
minWidth: 200,
minHeight: 150,
maxWidth: 1000,
maxHeight: 1000,
defaultWidth: 400,
defaultHeight: 300,
});
};

export const getTabletShapeSizeRestrictions = (): ShapeSizeRestrictions =>
tabletShapeSizeRestrictions;

export const TabletShape = forwardRef<any, ShapeProps>(
({ 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;

Expand All @@ -27,17 +36,17 @@ export const TabletShape = forwardRef<any, ShapeProps>(
x={x}
y={y}
ref={ref}
width={width}
height={height}
width={restrictedWidth}
height={restrictedHeight}
{...shapeProps}
onClick={() => onSelected(id, 'tablet')}
>
{/* Marco de la tablet */}
<Rect
x={margin}
y={margin}
width={width - 2 * margin}
height={height - 2 * margin}
width={restrictedWidth - 2 * margin}
height={restrictedHeight - 2 * margin}
cornerRadius={20}
stroke="black"
strokeWidth={2}
Expand All @@ -48,8 +57,8 @@ export const TabletShape = forwardRef<any, ShapeProps>(
<Rect
x={margin + screenMargin}
y={margin + screenMargin}
width={width - 2 * margin - 2 * screenMargin}
height={height - 2 * margin - 2 * screenMargin}
width={restrictedWidth - 2 * margin - 2 * screenMargin}
height={restrictedHeight - 2 * margin - 2 * screenMargin}
cornerRadius={10}
stroke="black"
strokeWidth={1}
Expand All @@ -59,7 +68,7 @@ export const TabletShape = forwardRef<any, ShapeProps>(
{/* Cámara frontal */}
<Circle
x={margin + cameraPadding + cameraRadius}
y={height / 2}
y={restrictedHeight / 2}
radius={cameraRadius}
stroke="black"
strokeWidth={1}
Expand All @@ -68,8 +77,8 @@ export const TabletShape = forwardRef<any, ShapeProps>(

{/* Botón de inicio */}
<Circle
x={width - margin - buttonPadding - buttonRadius}
y={height / 2}
x={restrictedWidth - margin - buttonPadding - buttonRadius}
y={restrictedHeight / 2}
radius={buttonRadius}
stroke="black"
strokeWidth={1.5}
Expand Down

0 comments on commit 69b2ecd

Please sign in to comment.