-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add NodeIcon component for displaying icons in GenericNode (#…
…3459) * feat: Add NodeIcon component for displaying icons in GenericNode This commit adds a new component called NodeIcon to the GenericNode module. The NodeIcon component is responsible for displaying icons based on the data type of the node. It uses the nodeIconsLucide object from the styleUtils module to map the data type to the corresponding icon name. The component also handles the display of emojis as icons by checking if the icon is an emoji using the emoji-regex library. The icon color is determined based on the data type using the nodeColors object from the styleUtils module. The NodeIcon component is used in the GenericNode component to render the icon of the node. * [autofix.ci] apply automated fixes * feat: Remove useIconNodeRender hook from CustomNodes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a813ff4
commit 16b8b43
Showing
3 changed files
with
42 additions
and
77 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/frontend/src/CustomNodes/GenericNode/components/nodeIcon/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useTypesStore } from "@/stores/typesStore"; | ||
import { nodeColors, nodeIconsLucide } from "@/utils/styleUtils"; | ||
import emojiRegex from "emoji-regex"; | ||
import IconComponent from "../../../../components/genericIconComponent"; | ||
|
||
export function NodeIcon({ | ||
icon, | ||
dataType, | ||
showNode, | ||
isGroup, | ||
}: { | ||
icon?: string; | ||
dataType: string; | ||
showNode: boolean; | ||
isGroup?: boolean; | ||
}) { | ||
const types = useTypesStore((state) => state.types); | ||
const name = nodeIconsLucide[dataType] ? dataType : types[dataType]; | ||
const isEmoji = emojiRegex().test(icon ?? ""); | ||
const iconColor = nodeColors[types[dataType]]; | ||
const iconName = icon || (isGroup ? "group_components" : name); | ||
const iconClassName = `generic-node-icon ${ | ||
!showNode ? " absolute inset-x-6 h-12 w-12 " : "" | ||
}`; | ||
return icon && isEmoji ? ( | ||
<span className="text-lg">{icon}</span> | ||
) : ( | ||
<IconComponent | ||
name={iconName} | ||
className={iconClassName} | ||
iconColor={iconColor} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.