|
1 | | -import { forwardRef } from 'react'; |
2 | | -import { Group, Rect, Circle } from 'react-konva'; |
| 1 | +import { forwardRef, useEffect, useState } from 'react'; |
| 2 | +import { Group, Rect, Circle, Image } from 'react-konva'; |
3 | 3 | import { ShapeSizeRestrictions, ShapeType } from '@/core/model'; |
4 | 4 | import { ShapeProps } from '../shape.model'; |
5 | 5 | import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; |
6 | 6 | import { useGroupShapeProps } from '../mock-components.utils'; |
| 7 | +import { loadSvgWithFill } from '@/common/utils/svg.utils'; |
7 | 8 |
|
8 | 9 | const mobilePhoneShapeSizeRestrictions: ShapeSizeRestrictions = { |
9 | 10 | minWidth: 150, |
@@ -37,13 +38,45 @@ export const MobilePhoneShape = forwardRef<any, ShapeProps>((props, ref) => { |
37 | 38 | const speakerRadius = 2; |
38 | 39 | const buttonRadius = 9; |
39 | 40 |
|
| 41 | + const [wifiIcon, setWifiIcon] = useState<HTMLImageElement | null>(null); |
| 42 | + const [batteryIcon, setBatteryIcon] = useState<HTMLImageElement | null>(null); |
| 43 | + const [signalIcon, setSignalIcon] = useState<HTMLImageElement | null>(null); |
| 44 | + |
| 45 | + const adornerIconSize = 20; |
| 46 | + const adornerPadding = 5; |
| 47 | + const adornerTotalWidth = adornerIconSize * 3 + 17 * 2; |
| 48 | + |
| 49 | + // Calculate inner screen coordinates (excluding frame margins) |
| 50 | + const screenX = margin + screenMargin; // Left edge of inner screen |
| 51 | + const screenY = screenMargin * 3; // Top edge of inner screen |
| 52 | + const screenWidth = restrictedWidth - 2 * margin - 2 * screenMargin; // Available width inside screen |
| 53 | + |
| 54 | + // Position adorner in top-right corner of inner screen |
| 55 | + const adornerStartX = screenX + screenWidth - adornerTotalWidth; // Right-aligned positioning |
| 56 | + const adornerY = screenY + adornerPadding; // Top-aligned with padding |
| 57 | + |
| 58 | + // Individual icon positions within the adorner |
| 59 | + const wifiX = adornerStartX; |
| 60 | + const signalX = adornerStartX + 17; |
| 61 | + const batteryX = adornerStartX + 20 * 2; |
| 62 | + |
40 | 63 | const commonGroupProps = useGroupShapeProps( |
41 | 64 | props, |
42 | 65 | restrictedSize, |
43 | 66 | shapeType, |
44 | 67 | ref |
45 | 68 | ); |
46 | 69 |
|
| 70 | + useEffect(() => { |
| 71 | + loadSvgWithFill('/icons/wifi.svg', 'black').then(img => setWifiIcon(img)); |
| 72 | + loadSvgWithFill('/icons/cellsignal.svg', 'black').then(img => |
| 73 | + setSignalIcon(img) |
| 74 | + ); |
| 75 | + loadSvgWithFill('/icons/batteryfull.svg', 'black').then(img => |
| 76 | + setBatteryIcon(img) |
| 77 | + ); |
| 78 | + }, []); |
| 79 | + |
47 | 80 | return ( |
48 | 81 | <Group {...commonGroupProps} {...shapeProps}> |
49 | 82 | {/* Mobile Frame */} |
@@ -82,6 +115,41 @@ export const MobilePhoneShape = forwardRef<any, ShapeProps>((props, ref) => { |
82 | 115 | fill="white" |
83 | 116 | /> |
84 | 117 |
|
| 118 | + {/* Adorner */} |
| 119 | + |
| 120 | + {/* Wifi */} |
| 121 | + {wifiIcon && ( |
| 122 | + <Image |
| 123 | + image={wifiIcon} |
| 124 | + x={wifiX} |
| 125 | + y={adornerY - 2} |
| 126 | + width={adornerIconSize} |
| 127 | + height={adornerIconSize} |
| 128 | + /> |
| 129 | + )} |
| 130 | + |
| 131 | + {/* Cell signal */} |
| 132 | + {signalIcon && ( |
| 133 | + <Image |
| 134 | + image={signalIcon} |
| 135 | + x={signalX} |
| 136 | + y={adornerY} |
| 137 | + width={adornerIconSize} |
| 138 | + height={adornerIconSize} |
| 139 | + /> |
| 140 | + )} |
| 141 | + |
| 142 | + {/* Battery */} |
| 143 | + {batteryIcon && ( |
| 144 | + <Image |
| 145 | + image={batteryIcon} |
| 146 | + x={batteryX} |
| 147 | + y={adornerY} |
| 148 | + width={adornerIconSize} |
| 149 | + height={adornerIconSize} |
| 150 | + /> |
| 151 | + )} |
| 152 | + |
85 | 153 | {/* Init button */} |
86 | 154 | <Circle |
87 | 155 | x={restrictedWidth / 2} |
|
0 commit comments