import { ComponentConfig } from "@reacteditor/core"; import { Menu as MenuIcon, ShoppingBag, Search, User, X } from "lucide-react"; import { useState } from "react"; import { useShopifyCart } from "~/editor/hooks/use-shopify-cart"; import { Sheet, SheetContent, SheetHeader, SheetTitle } from "~/editor/components/ui/sheet"; import { cn } from "~/editor/lib/utils"; export type NavigationProps = { brand: string; links: Array<{ label: string; href: string }>; showSearch: "yes" | "no"; showAccount: "yes" | "no"; showCart: "yes" | "no"; sticky: "yes" | "no"; tone: "default" | "muted" | "inverse"; }; function Navigation({ brand, links, showSearch, showAccount, showCart, sticky, tone, }: NavigationProps) { const [mobileOpen, setMobileOpen] = useState(false); const [cartOpen, setCartOpen] = useState(false); const cart = useShopifyCart(); const itemCount = cart?.itemCount ?? 0; const toneClass: Record = { default: "bg-background text-foreground border-b border-border", muted: "bg-muted/40 text-foreground border-b border-border", inverse: "bg-foreground text-background", }; return ( <>
{brand}
{showSearch === "yes" && ( )} {showAccount === "yes" && ( )} {showCart === "yes" && ( )}
{/* Mobile menu */} {brand} {/* Cart drawer */} Cart
{cart?.items?.length ? (
    {cart.items.map((line: any) => (
  • {line.merchandise?.product?.images?.edges?.[0]?.node?.url ? ( {line.merchandise.product.title} ) : null}

    {line.merchandise?.product?.title}

    {line.merchandise?.title && line.merchandise.title !== "Default Title" ? (

    {line.merchandise.title}

    ) : null}
    {line.quantity}
    {line.merchandise?.price ? new Intl.NumberFormat("en-US", { style: "currency", currency: line.merchandise.price.currencyCode, }).format(parseFloat(line.merchandise.price.amount) * line.quantity) : null}
  • ))}
) : (

Your cart is empty.

)}
{cart?.items?.length ? (
Subtotal {new Intl.NumberFormat("en-US", { style: "currency", currency: cart.cart?.cost?.totalAmount?.currencyCode ?? "USD", }).format(cart.totalAmount)}
Checkout
) : null}
); } export const navigationEditor: ComponentConfig = { label: "Navigation", icon: , category: "navigation", defaultProps: { brand: "Maison", links: [ { label: "Shop", href: "/collections" }, { label: "Lookbook", href: "/lookbook" }, { label: "Journal", href: "/journal" }, { label: "About", href: "/about" }, ], showSearch: "yes", showAccount: "yes", showCart: "yes", sticky: "yes", tone: "default", }, fields: { brand: { label: "Brand", type: "text", contentEditable: true }, links: { label: "Links", type: "array", defaultItemProps: { label: "Link", href: "/" }, getItemSummary: (it) => it?.label || "Link", arrayFields: { label: { label: "Label", type: "text", contentEditable: true }, href: { label: "Link", type: "text" }, }, }, showSearch: { label: "Search icon", type: "radio", options: [ { label: "Show", value: "yes" }, { label: "Hide", value: "no" }, ], }, showAccount: { label: "Account icon", type: "radio", options: [ { label: "Show", value: "yes" }, { label: "Hide", value: "no" }, ], }, showCart: { label: "Cart icon", type: "radio", options: [ { label: "Show", value: "yes" }, { label: "Hide", value: "no" }, ], }, sticky: { label: "Position", type: "radio", options: [ { label: "Sticky", value: "yes" }, { label: "Static", value: "no" }, ], }, tone: { label: "Tone", type: "select", options: [ { label: "Default", value: "default" }, { label: "Muted", value: "muted" }, { label: "Inverse (dark)", value: "inverse" }, ], }, }, render: (props) => , };