From c0b492b394731d31e1a1981152a70dec15c17bdb Mon Sep 17 00:00:00 2001 From: Nam Doan Date: Mon, 1 Dec 2025 16:34:06 +0700 Subject: [PATCH] refactor: dynamic icon button with medusajs and customize icon --- src/modules/common/icons/index.ts | 19 +++++++++++++ src/modules/common/icons/twitter.tsx | 27 +++++++++++++++++++ .../layout/templates/vt-button/index.tsx | 22 +++++++-------- 3 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 src/modules/common/icons/index.ts create mode 100644 src/modules/common/icons/twitter.tsx diff --git a/src/modules/common/icons/index.ts b/src/modules/common/icons/index.ts new file mode 100644 index 0000000..580d7f0 --- /dev/null +++ b/src/modules/common/icons/index.ts @@ -0,0 +1,19 @@ +export { default as Back } from "./back" +export { default as Bancontact } from "./bancontact" +export { default as ChevronDown } from "./chevron-down" +export { default as Eye } from "./eye" +export { default as EyeOff } from "./eye-off" +export { default as FastDelivery } from "./fast-delivery" +export { default as Ideal } from "./ideal" +export { default as MapPin } from "./map-pin" +export { default as Medusa } from "./medusa" +export { default as Nextjs } from "./nextjs" +export { default as Package } from "./package" +export { default as PayPal } from "./paypal" +export { default as PlaceholderImage } from "./placeholder-image" +export { default as Refresh } from "./refresh" +export { default as Spinner } from "./spinner" +export { default as Trash } from "./trash" +export { default as User } from "./user" +export { default as X } from "./x" +export { default as Twitter } from "./twitter" \ No newline at end of file diff --git a/src/modules/common/icons/twitter.tsx b/src/modules/common/icons/twitter.tsx new file mode 100644 index 0000000..94340c5 --- /dev/null +++ b/src/modules/common/icons/twitter.tsx @@ -0,0 +1,27 @@ +import React from "react" + +import { IconProps } from "types/icon" + +const Twitter: React.FC = ({ + size = "20", + color = "currentColor", + ...attributes +}) => { + return ( + + + + ) +} + +export default Twitter \ No newline at end of file diff --git a/src/modules/layout/templates/vt-button/index.tsx b/src/modules/layout/templates/vt-button/index.tsx index 7494f8f..e3602d8 100644 --- a/src/modules/layout/templates/vt-button/index.tsx +++ b/src/modules/layout/templates/vt-button/index.tsx @@ -1,5 +1,6 @@ import { Button, IconButton } from "@medusajs/ui" -import { MagnifyingGlass, User, ShoppingBag, Heart } from "@medusajs/icons" +import * as MedusaIcons from "@medusajs/icons" +import * as CustomIcons from "@modules/common/icons" import { LayoutComponentDefinition, LayoutContext, @@ -13,21 +14,20 @@ export default function VtButton({ context: LayoutContext }) { const props = nodes.config || {} - - const icons = { - search: MagnifyingGlass, - user: User, - cart: ShoppingBag, - heart: Heart - } - const Icon = props.icon && icons[props.icon as keyof typeof icons] + const iconName = props.icon as string | undefined + const IconComponent = iconName + ? (MedusaIcons as Record)[iconName] ?? + (CustomIcons as Record)[iconName] + : undefined return ( <> {props?.icon && ( - + {IconComponent && ( + + )} {props?.label && ( - {props.label} + {props.label} )} )}