import { ComponentConfig } from "@reacteditor/core"; import { useEffect, useState } from "react"; import { FolderOpen } from "lucide-react"; import { shopifyFetch } from "~/editor/services/shopify/client"; import { GET_COLLECTIONS_QUERY } from "~/editor/graphql/collections"; import { Typography } from "~/editor/theme/Typography"; export type CollectionGridProps = { tagline: string; heading: string; subheading: string; layout: "tiles" | "editorial"; limit: number; }; type CollectionRow = { id: string; handle: string; title: string; description?: string; image?: { url: string; altText?: string }; }; function CollectionGrid({ tagline, heading, subheading, layout, limit, }: CollectionGridProps) { const [collections, setCollections] = useState([]); useEffect(() => { shopifyFetch({ query: GET_COLLECTIONS_QUERY, variables: { first: limit }, }) .then((res) => { const list = (res.data?.collections?.edges ?? []).map((e: any) => e.node); setCollections(list); }) .catch(() => setCollections([])); }, [limit]); const isEditorial = layout === "editorial"; return (
{tagline ? (

{tagline}

) : null} {heading} {subheading ? ( {subheading} ) : null}
{(collections.length === 0 ? Array.from({ length: limit }).map((_, i) => ({ id: `sk-${i}` }) as any) : collections ).map((c: CollectionRow) => (
{c.image?.url ? ( {c.image.altText ) : null} {isEditorial ? (
{c.title} Shop now →
) : null}
{!isEditorial ? (

{c.title}

) : null}
))}
); } export const collectionGridEditor: ComponentConfig = { label: "Collections", icon: , category: "commerce", defaultProps: { tagline: "Shop by collection", heading: "Curated edits", subheading: "Bundles built around the way you actually live.", layout: "tiles", limit: 6, }, fields: { tagline: { label: "Tagline", type: "text", contentEditable: true }, heading: { label: "Heading", type: "text", contentEditable: true }, subheading: { label: "Subheading", type: "textarea", contentEditable: true }, layout: { label: "Layout", type: "radio", options: [ { label: "Tiles", value: "tiles" }, { label: "Editorial", value: "editorial" }, ], }, limit: { label: "Limit", type: "number", min: 2, max: 12 }, }, render: (props) => , };