refactor: icon fragments functions
This commit is contained in:
parent
7af1f7cf41
commit
4d750c2180
1 changed files with 24 additions and 31 deletions
|
|
@ -111,42 +111,35 @@ export default function GenericNode({
|
||||||
const isEmoji = emojiRegex.test(data?.node?.icon!);
|
const isEmoji = emojiRegex.test(data?.node?.icon!);
|
||||||
|
|
||||||
const iconNodeRender = useCallback(() => {
|
const iconNodeRender = useCallback(() => {
|
||||||
if (data?.node?.icon) {
|
const iconElement = data?.node?.icon;
|
||||||
if (isEmoji) {
|
const iconColor = nodeColors[types[data.type]];
|
||||||
return <span className="text-lg">{data.node.icon}</span>;
|
const iconName =
|
||||||
} else {
|
iconElement || (data.node?.flow ? "group_components" : name);
|
||||||
const iconName =
|
const iconClassName = `generic-node-icon ${
|
||||||
data.node.icon || (data.node?.flow ? "group_components" : name);
|
!showNode ? "absolute inset-x-6 h-12 w-12" : ""
|
||||||
const iconClassName = `generic-node-icon ${
|
}`;
|
||||||
!showNode ? "absolute inset-x-6 h-12 w-12" : ""
|
|
||||||
}`;
|
|
||||||
const iconColor = nodeColors[types[data.type]];
|
|
||||||
|
|
||||||
return (
|
if (iconElement && isEmoji) {
|
||||||
<IconComponent
|
return nodeIconFragment(iconElement);
|
||||||
name={iconName}
|
|
||||||
className={iconClassName}
|
|
||||||
iconColor={iconColor}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const iconName = data.node?.flow ? "group_components" : name;
|
return checkNodeIconFragment(iconColor, iconName, iconClassName);
|
||||||
const iconClassName = `generic-node-icon ${
|
|
||||||
!showNode ? "absolute inset-x-6 h-12 w-12" : ""
|
|
||||||
}`;
|
|
||||||
const iconColor = nodeColors[types[data.type]];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IconComponent
|
|
||||||
name={iconName}
|
|
||||||
className={iconClassName}
|
|
||||||
iconColor={iconColor}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}, [data, isEmoji, name, showNode]);
|
}, [data, isEmoji, name, showNode]);
|
||||||
|
|
||||||
|
const nodeIconFragment = (icon) => {
|
||||||
|
return <span className="text-lg">{icon}</span>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkNodeIconFragment = (iconColor, iconName, iconClassName) => {
|
||||||
|
return (
|
||||||
|
<IconComponent
|
||||||
|
name={iconName}
|
||||||
|
className={iconClassName}
|
||||||
|
iconColor={iconColor}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NodeToolbar>
|
<NodeToolbar>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue