link
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useEffect, useRef, useMemo } from "react";
|
||||
import { Text } from "react-konva";
|
||||
import Konva from "konva";
|
||||
import type { ShapeProps } from "./types";
|
||||
|
||||
const getFontWeight = (fontWeight?: string): string => {
|
||||
const weightMap: Record<string, string> = {
|
||||
bold: "bold",
|
||||
normal: "normal",
|
||||
"300": "300",
|
||||
};
|
||||
return weightMap[fontWeight || "normal"] || "normal";
|
||||
};
|
||||
|
||||
const LinkShape = ({
|
||||
obj,
|
||||
isSelected,
|
||||
@@ -12,6 +21,7 @@ const LinkShape = ({
|
||||
draggable,
|
||||
}: ShapeProps) => {
|
||||
const shapeRef = useRef<Konva.Text>(null);
|
||||
const fontWeight = useMemo(() => getFontWeight(obj.fontWeight), [obj.fontWeight]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isSelected && shapeRef.current && transformerRef.current) {
|
||||
@@ -29,13 +39,13 @@ const LinkShape = ({
|
||||
fontSize={obj.fontSize || 24}
|
||||
fill={obj.fill || "#0000ff"}
|
||||
fontFamily="irancell"
|
||||
fontStyle={fontWeight}
|
||||
underline={true}
|
||||
rotation={obj.rotation || 0}
|
||||
draggable={draggable}
|
||||
onClick={() => {
|
||||
if (shapeRef.current && obj.linkUrl) {
|
||||
window.open(obj.linkUrl, "_blank");
|
||||
}
|
||||
// در حالت editor، لینکها قابل کلیک نیستند
|
||||
// این قابلیت در viewer اضافه خواهد شد
|
||||
if (shapeRef.current) {
|
||||
onSelect(obj.id, shapeRef.current);
|
||||
}
|
||||
@@ -67,5 +77,4 @@ const LinkShape = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default LinkShape;
|
||||
|
||||
export default LinkShape;
|
||||
Reference in New Issue
Block a user