Skip to content

Commit 6774128

Browse files
feat: add current time display to MobilePhoneShape component
1 parent 61a616b commit 6774128

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

src/common/components/mock-components/front-containers/mobilephone-shape.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { forwardRef, useEffect, useState } from 'react';
2-
import { Group, Rect, Circle, Image } from 'react-konva';
2+
import { Group, Rect, Circle, Image, Text } from 'react-konva';
33
import { ShapeSizeRestrictions, ShapeType } from '@/core/model';
44
import { ShapeProps } from '../shape.model';
55
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
66
import { useGroupShapeProps } from '../mock-components.utils';
77
import { loadSvgWithFill } from '@/common/utils/svg.utils';
8+
import { BASIC_SHAPE } from '../front-components/shape.const';
89

910
const mobilePhoneShapeSizeRestrictions: ShapeSizeRestrictions = {
1011
minWidth: 150,
@@ -41,10 +42,11 @@ export const MobilePhoneShape = forwardRef<any, ShapeProps>((props, ref) => {
4142
const [wifiIcon, setWifiIcon] = useState<HTMLImageElement | null>(null);
4243
const [batteryIcon, setBatteryIcon] = useState<HTMLImageElement | null>(null);
4344
const [signalIcon, setSignalIcon] = useState<HTMLImageElement | null>(null);
45+
const [currentTime, setCurrentTime] = useState('');
4446

4547
const adornerIconSize = 20;
4648
const adornerPadding = 5;
47-
const adornerTotalWidth = adornerIconSize * 3 + 17 * 2;
49+
const adornerTotalWidth = adornerIconSize * 3 + 17 * 2 + 30;
4850

4951
// Calculate inner screen coordinates (excluding frame margins)
5052
const screenX = margin + screenMargin; // Left edge of inner screen
@@ -60,6 +62,10 @@ export const MobilePhoneShape = forwardRef<any, ShapeProps>((props, ref) => {
6062
const signalX = adornerStartX + 17;
6163
const batteryX = adornerStartX + 20 * 2;
6264

65+
const timeX = adornerStartX + 23 * 3;
66+
const timeY = adornerY + 4;
67+
const timeWidth = 40;
68+
6369
const commonGroupProps = useGroupShapeProps(
6470
props,
6571
restrictedSize,
@@ -77,6 +83,24 @@ export const MobilePhoneShape = forwardRef<any, ShapeProps>((props, ref) => {
7783
);
7884
}, []);
7985

86+
useEffect(() => {
87+
const updateTime = () => {
88+
const now = new Date();
89+
setCurrentTime(
90+
now.toLocaleTimeString('es-ES', {
91+
hour: '2-digit',
92+
minute: '2-digit',
93+
hour12: false,
94+
})
95+
);
96+
};
97+
98+
updateTime();
99+
const timer = setInterval(updateTime, 1000);
100+
101+
return () => clearInterval(timer);
102+
}, []);
103+
80104
return (
81105
<Group {...commonGroupProps} {...shapeProps}>
82106
{/* Mobile Frame */}
@@ -150,6 +174,18 @@ export const MobilePhoneShape = forwardRef<any, ShapeProps>((props, ref) => {
150174
/>
151175
)}
152176

177+
{/* Current time */}
178+
<Text
179+
x={timeX}
180+
y={timeY}
181+
width={timeWidth}
182+
height={adornerIconSize}
183+
text={currentTime}
184+
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
185+
fontSize={14}
186+
wrap="none"
187+
/>
188+
153189
{/* Init button */}
154190
<Circle
155191
x={restrictedWidth / 2}

0 commit comments

Comments
 (0)