Beautiful map components. 100% Free, Zero config, one command setup.
TypeScript
style(docs): unify component preview, derive toc, restyle prop tables
Anmold5d287dfdb21
diff --git a/src/app/(main)/docs/_components/component-preview-client.tsx b/src/app/(main)/docs/_components/component-preview-client.tsxindex 8eb822d..d6a98ca 100644--- a/src/app/(main)/docs/_components/component-preview-client.tsx+++ b/src/app/(main)/docs/_components/component-preview-client.tsx@@ -10,6 +10,8 @@ interface ComponentPreviewClientProps {children: React.ReactNode;code: string;highlightedCode: string;+ /** Height of the preview panel. The expanded code block caps separately. */+ height?: string;className?: string;}@@ -17,23 +19,22 @@ export function ComponentPreviewClient({children,code,highlightedCode,+ height = "420px",className,}: ComponentPreviewClientProps) {const [expanded, setExpanded] = useState(false);const codeId = useId();return (- <div className="space-y-4">- <div- className={cn(- "h-[420px] w-full overflow-hidden rounded-lg border",- className,- )}- >+ <div+ className={cn("w-full overflow-hidden rounded-lg border", className)}+ style={{ "--preview-height": height } as React.CSSProperties}+ >+ <div className="h-(--preview-height) w-full overflow-hidden">{children}</div>- <div className="relative w-full overflow-hidden rounded-lg border">+ <div className="relative w-full overflow-hidden border-t"><div className="absolute top-2 right-2 z-10"><CodeCopyButton text={code} /></div>@@ -41,20 +42,20 @@ export function ComponentPreviewClient({id={codeId}className={cn(expanded- ? "max-h-[420px] overflow-x-auto"- : "max-h-42 overflow-hidden",+ ? "max-h-[420px] overflow-auto"+ : "max-h-36 overflow-hidden",)}html={highlightedCode}/>{!expanded && (- <div className="from-surface to-surface/0 absolute inset-x-0 bottom-0 flex w-full items-center justify-center bg-linear-to-t pt-16 pb-6">+ <div className="from-surface to-surface/0 pointer-events-none absolute inset-x-0 bottom-0 flex w-full items-center justify-center bg-linear-to-t pt-22 pb-4"><Buttonvariant="outline"size="sm"onClick={() => setExpanded(true)}aria-expanded={expanded}aria-controls={codeId}- className="bg-background hover:bg-muted dark:bg-background dark:hover:bg-muted"+ className="bg-background hover:bg-muted dark:bg-background dark:hover:bg-muted pointer-events-auto">View Code</Button>diff --git a/src/app/(main)/docs/_components/component-preview.tsx b/src/app/(main)/docs/_components/component-preview.tsxindex 2f91c80..6f6a681 100644--- a/src/app/(main)/docs/_components/component-preview.tsx+++ b/src/app/(main)/docs/_components/component-preview.tsx@@ -4,12 +4,14 @@ import { ComponentPreviewClient } from "./component-preview-client";interface ComponentPreviewProps {children: React.ReactNode;code: string;+ height?: string;className?: string;}export async function ComponentPreview({children,code,+ height,className,}: ComponentPreviewProps) {const highlightedCode = await highlightCode(code, "tsx");@@ -18,6 +20,7 @@ export async function ComponentPreview({<ComponentPreviewClientcode={code}highlightedCode={highlightedCode}+ height={height}className={className}>{children}diff --git a/src/app/(main)/docs/_components/docs.tsx b/src/app/(main)/docs/_components/docs.tsxindex ffe2d6f..c005e55 100644--- a/src/app/(main)/docs/_components/docs.tsx+++ b/src/app/(main)/docs/_components/docs.tsx@@ -1,4 +1,5 @@import Link from "next/link";+import { Children, Fragment, isValidElement } from "react";import { Button } from "@/components/ui/button";import {Table,@@ -32,7 +33,7 @@ interface DocsTitleProps {function DocsTitle({ title, description }: DocsTitleProps) {return (- <div className="space-y-3">+ <div className="space-y-2"><h1 className="text-foreground text-3xl font-semibold tracking-tight">{title}</h1>@@ -43,6 +44,29 @@ function DocsTitle({ title, description }: DocsTitleProps) {);}+function collectToc(children: React.ReactNode): TocItem[] {+ const items: TocItem[] = [];++ for (const child of Children.toArray(children)) {+ if (!isValidElement(child)) continue;++ if (child.type === Fragment) {+ const { children: nested } = child.props as {+ children?: React.ReactNode;+ };+ items.push(...collectToc(nested));+ continue;+ }++ if (child.type === DocsSection) {+ const { title } = child.props as DocsSectionProps;+ if (title) items.push({ title, slug: slugify(title) });+ }+ }++ return items;+}+// DocsLayout - Full page wrapper with navinterface DocsLayoutProps {title: string;@@ -59,8 +83,10 @@ export function DocsLayout({children,prev,next,- toc = [],+ toc,}: DocsLayoutProps) {+ const tocItems = toc ?? collectToc(children);+return (<div className="flex size-full"><div className="mx-auto flex max-w-[50rem] min-w-0 flex-1 flex-col pt-10 pb-20 lg:px-4">@@ -100,7 +126,7 @@ export function DocsLayout({<aside className="hidden w-48 shrink-0 xl:block"><nav className="sticky top-14 max-h-[calc(100svh-3.5rem)] overflow-y-auto pt-10 pb-10 [scrollbar-gutter:stable]">- {toc.length > 0 && <DocsToc items={toc} />}+ {tocItems.length > 0 && <DocsToc items={tocItems} />}</nav></aside></div>@@ -190,51 +216,51 @@ interface DocsPropTableProps {default?: string;description: string;}[];+ title?: string;}-export function DocsPropTable({ props }: DocsPropTableProps) {+export function DocsPropTable({ props, title }: DocsPropTableProps) {return (- <div className="my-6 overflow-hidden rounded-lg border">- <Table>- <TableHeader>- <TableRow className="bg-surface">- <TableHead className="h-10 px-4 text-xs font-medium">- Prop- </TableHead>- <TableHead className="h-10 px-4 text-xs font-medium">- Type- </TableHead>- <TableHead className="h-10 px-4 text-xs font-medium">- Default- </TableHead>- <TableHead className="h-10 px-4 text-xs font-medium">- Description- </TableHead>- </TableRow>- </TableHeader>- <TableBody>- {props.map((prop) => (- <TableRow key={prop.name}>- <TableCell className="px-4 py-3 align-top">- <DocsCode className="text-[13px]">{prop.name}</DocsCode>- </TableCell>- <TableCell className="px-4 py-3 align-top whitespace-normal">- <DocsCode className="text-foreground/70 text-xs">- {prop.type}- </DocsCode>- </TableCell>- <TableCell className="px-4 py-3 align-top">- <DocsCode className="text-foreground/70 text-xs whitespace-normal">- {prop.default ?? "—"}- </DocsCode>- </TableCell>- <TableCell className="text-foreground/70 min-w-[180px] px-4 py-3 text-sm leading-relaxed whitespace-normal">- {prop.description}- </TableCell>+ <div className="prop-table space-y-3 [.prop-table+&]:mt-8">+ {title && <h3 className="text-foreground font-semibold">{title}</h3>}+ <div className="overflow-hidden">+ <Table className="[&_tbody_tr:last-child]:border-b [&_td:first-child]:pl-0 [&_td:last-child]:pr-0 [&_th:first-child]:pl-0 [&_th:last-child]:pr-0">+ <TableHeader>+ <TableRow>+ <TableHead className="h-10 text-xs font-medium">Prop</TableHead>+ <TableHead className="h-10 text-xs font-medium">Type</TableHead>+ <TableHead className="h-10 text-xs font-medium">+ Default+ </TableHead>+ <TableHead className="h-10 text-xs font-medium">+ Description+ </TableHead></TableRow>- ))}- </TableBody>- </Table>+ </TableHeader>+ <TableBody>+ {props.map((prop) => (+ <TableRow key={prop.name}>+ <TableCell className="py-3 align-top">+ <DocsCode className="text-[13px]">{prop.name}</DocsCode>+ </TableCell>+ <TableCell className="py-3 align-top whitespace-normal">+ <DocsCode className="text-foreground/70 text-xs">+ {prop.type}+ </DocsCode>+ </TableCell>+ <TableCell className="py-3 align-top">+ <DocsCode className="text-foreground/70 text-xs whitespace-normal">+ {prop.default ?? "—"}+ </DocsCode>+ </TableCell>+ <TableCell className="text-foreground/70 min-w-[180px] py-3 text-sm leading-relaxed whitespace-normal">+ {prop.description}+ </TableCell>+ </TableRow>+ ))}+ </TableBody>+ </Table>+ </div></div>);}diff --git a/src/app/(main)/docs/_components/examples/geojson-example.tsx b/src/app/(main)/docs/_components/examples/geojson-example.tsxindex 5c12f51..3f2b70e 100644--- a/src/app/(main)/docs/_components/examples/geojson-example.tsx+++ b/src/app/(main)/docs/_components/examples/geojson-example.tsx@@ -3,7 +3,7 @@ import { WORLD_GEOJSON } from "@/lib/use-world-data";export function GeoJSONExample() {return (- <div className="bg-card h-[420px] w-full">+ <div className="h-[420px] w-full"><Map blank center={[10, 25]}><MapGeoJSON data={WORLD_GEOJSON} linePaint={false} /></Map>diff --git a/src/app/(main)/docs/advanced-usage/page.tsx b/src/app/(main)/docs/advanced-usage/page.tsxindex a094110..dfccbf2 100644--- a/src/app/(main)/docs/advanced-usage/page.tsx+++ b/src/app/(main)/docs/advanced-usage/page.tsx@@ -72,20 +72,6 @@ export default function AdvancedPage() {title="Advanced"description="Access the underlying MapLibre GL instance for advanced customization."prev={{ title: "Clusters", href: "/docs/clusters" }}- toc={[- { title: "Using a Ref", slug: "using-a-ref" },- { title: "Using the Hook", slug: "using-the-hook" },- { title: "Example: Custom Controls", slug: "example-custom-controls" },- {- title: "Example: Custom GeoJSON Layer",- slug: "example-custom-geojson-layer",- },- {- title: "Example: Markers via Layers",- slug: "example-markers-via-layers",- },- { title: "Extend to Build", slug: "extend-to-build" },- ]}><DocsSection><p>diff --git a/src/app/(main)/docs/api-reference/page.tsx b/src/app/(main)/docs/api-reference/page.tsxindex 8a98a33..0ae2882 100644--- a/src/app/(main)/docs/api-reference/page.tsx+++ b/src/app/(main)/docs/api-reference/page.tsx@@ -39,22 +39,6 @@ export default function ApiReferencePage() {description="Complete reference for all map components and their props."prev={{ title: "Installation", href: "/docs/installation" }}next={{ title: "Map", href: "/docs/basic-map" }}- toc={[- { title: "Component Anatomy", slug: "component-anatomy" },- { title: "Map", slug: "map" },- { title: "useMap", slug: "usemap" },- { title: "MapControls", slug: "mapcontrols" },- { title: "MapMarker", slug: "mapmarker" },- { title: "MarkerContent", slug: "markercontent" },- { title: "MarkerPopup", slug: "markerpopup" },- { title: "MarkerTooltip", slug: "markertooltip" },- { title: "MarkerLabel", slug: "markerlabel" },- { title: "MapPopup", slug: "mappopup" },- { title: "MapRoute", slug: "maproute" },- { title: "MapArc", slug: "maparc" },- { title: "MapGeoJSON", slug: "mapgeojson" },- { title: "MapClusterLayer", slug: "mapclusterlayer" },- ]}><DocsNote><strong>Note:</strong> This library is built on top of{" "}@@ -341,11 +325,10 @@ export default function ApiReferencePage() {<DocsCode>closeButton</DocsCode>).</p><DocsNote>- The <DocsCode>className</DocsCode> and{" "}- <DocsCode>closeButton</DocsCode> from MapLibre's PopupOptions are- excluded to prevent style conflicts. Use the component's own- props to style the popup. MapLibre's default popup styles are- reset via CSS.+ MapLibre's own <DocsCode>className</DocsCode> and{" "}+ <DocsCode>closeButton</DocsCode> options are excluded to prevent style+ conflicts. Use the component's props of the same name instead.+ MapLibre's default popup styles are reset via CSS.</DocsNote><DocsPropTableprops={[@@ -389,10 +372,10 @@ export default function ApiReferencePage() {out).</p><DocsNote>- The <DocsCode>className</DocsCode> from MapLibre's PopupOptions- is excluded to prevent style conflicts. Use the component's own{" "}- <DocsCode>className</DocsCode> prop to style the tooltip content.- MapLibre's default popup styles are reset via CSS.+ MapLibre's own <DocsCode>className</DocsCode> and{" "}+ <DocsCode>closeButton</DocsCode> options are excluded to prevent style+ conflicts. Use the component's <DocsCode>className</DocsCode>{" "}+ instead. MapLibre's default popup styles are reset via CSS.</DocsNote><DocsPropTableprops={[@@ -456,11 +439,10 @@ export default function ApiReferencePage() {<DocsCode>closeButton</DocsCode>).</p><DocsNote>- The <DocsCode>className</DocsCode> and{" "}- <DocsCode>closeButton</DocsCode> from MapLibre's PopupOptions are- excluded to prevent style conflicts. Use the component's own- props to style the popup. MapLibre's default popup styles are- reset via CSS.+ MapLibre's own <DocsCode>className</DocsCode> and{" "}+ <DocsCode>closeButton</DocsCode> options are excluded to prevent style+ conflicts. Use the component's props of the same name instead.+ MapLibre's default popup styles are reset via CSS.</DocsNote><DocsPropTableprops={[diff --git a/src/app/(main)/docs/arcs/page.tsx b/src/app/(main)/docs/arcs/page.tsxindex 06e8745..8049b56 100644--- a/src/app/(main)/docs/arcs/page.tsx+++ b/src/app/(main)/docs/arcs/page.tsx@@ -19,10 +19,6 @@ export default function ArcsPage() {description="Draw curved connections between two coordinates with hover and click support."prev={{ title: "Routes", href: "/docs/routes" }}next={{ title: "GeoJSON", href: "/docs/geojson" }}- toc={[- { title: "Basic Arc", slug: "basic-arc" },- { title: "Interactive Arcs", slug: "interactive-arcs" },- ]}><DocsSection><p>diff --git a/src/app/(main)/docs/basic-map/page.tsx b/src/app/(main)/docs/basic-map/page.tsxindex e9f6380..c499763 100644--- a/src/app/(main)/docs/basic-map/page.tsx+++ b/src/app/(main)/docs/basic-map/page.tsx@@ -29,12 +29,6 @@ export default function BasicMapPage() {description="The simplest way to add an interactive map to your application."prev={{ title: "API Reference", href: "/docs/api-reference" }}next={{ title: "Controls", href: "/docs/controls" }}- toc={[- { title: "Basic Usage", slug: "basic-usage" },- { title: "Controlled Mode", slug: "controlled-mode" },- { title: "Blank Basemap", slug: "blank-basemap" },- { title: "Custom Styles", slug: "custom-styles" },- ]}><DocsSection title="Basic Usage"><p>diff --git a/src/app/(main)/docs/controls/page.tsx b/src/app/(main)/docs/controls/page.tsxindex 4c739ee..f45bdb7 100644--- a/src/app/(main)/docs/controls/page.tsx+++ b/src/app/(main)/docs/controls/page.tsx@@ -18,7 +18,7 @@ export default function ControlsPage() {prev={{ title: "Map", href: "/docs/basic-map" }}next={{ title: "Markers", href: "/docs/markers" }}>- <DocsSection>+ <DocsSection title="Basic Usage"><p>The <DocsCode>MapControls</DocsCode> component provides a set ofinteractive controls that can be positioned on any corner of the map.diff --git a/src/app/(main)/docs/geojson/page.tsx b/src/app/(main)/docs/geojson/page.tsxindex 574464e..1f079ee 100644--- a/src/app/(main)/docs/geojson/page.tsx+++ b/src/app/(main)/docs/geojson/page.tsx@@ -19,10 +19,6 @@ export default function GeoJSONPage() {description="Render arbitrary GeoJSON as fill and outline layers for choropleths and region maps."prev={{ title: "Arcs", href: "/docs/arcs" }}next={{ title: "Clusters", href: "/docs/clusters" }}- toc={[- { title: "Basic GeoJSON", slug: "basic-geojson" },- { title: "Overlay on a Map", slug: "overlay-on-a-map" },- ]}><DocsSection><p>diff --git a/src/app/(main)/docs/installation/page.tsx b/src/app/(main)/docs/installation/page.tsxindex c2a1405..83d0a38 100644--- a/src/app/(main)/docs/installation/page.tsx+++ b/src/app/(main)/docs/installation/page.tsx@@ -44,12 +44,6 @@ export default function InstallationPage() {description="How to install and set up mapcn in your project."prev={{ title: "Introduction", href: "/docs" }}next={{ title: "API Reference", href: "/docs/api-reference" }}- toc={[- { title: "Prerequisites", slug: "prerequisites" },- { title: "Installation", slug: "installation" },- { title: "Usage", slug: "usage" },- { title: "Web Worker", slug: "web-worker" },- ]}><DocsSection title="Prerequisites"><p>diff --git a/src/app/(main)/docs/markers/page.tsx b/src/app/(main)/docs/markers/page.tsxindex 7e11d17..fe9c1fc 100644--- a/src/app/(main)/docs/markers/page.tsx+++ b/src/app/(main)/docs/markers/page.tsx@@ -20,7 +20,7 @@ export default function MarkersPage() {const markersSource = getExampleSource("markers-example.tsx");const popupSource = getExampleSource("popup-example.tsx");const draggableMarkerSource = getExampleSource(- "draggable-marker-example.tsx"+ "draggable-marker-example.tsx",);return (@@ -29,11 +29,6 @@ export default function MarkersPage() {description="Add interactive markers to your map with popups and tooltips."prev={{ title: "Controls", href: "/docs/controls" }}next={{ title: "Popups", href: "/docs/popups" }}- toc={[- { title: "Basic Example", slug: "basic-example" },- { title: "Rich Popups", slug: "rich-popups" },- { title: "Draggable Marker", slug: "draggable-marker" },- ]}><DocsSection><p>@@ -67,7 +62,7 @@ export default function MarkersPage() {Build complex popups with images, ratings, and action buttons usingshadcn/ui components.</p>- <ComponentPreview code={popupSource} className="h-[500px]">+ <ComponentPreview code={popupSource} height="500px"><PopupExample /></ComponentPreview></DocsSection>diff --git a/src/app/(main)/docs/page.tsx b/src/app/(main)/docs/page.tsxindex 841e132..ea7ab55 100644--- a/src/app/(main)/docs/page.tsx+++ b/src/app/(main)/docs/page.tsx@@ -47,12 +47,6 @@ export default function IntroductionPage() {title="Introduction"description="Copy-paste map components for React."next={{ title: "Installation", href: "/docs/installation" }}- toc={[- { title: "Philosophy", slug: "philosophy" },- { title: "Why mapcn?", slug: "why-mapcn" },- { title: "Any Map Style", slug: "any-map-style" },- { title: "Features", slug: "features" },- ]}><DocsSection><p>diff --git a/src/app/(main)/docs/routes/page.tsx b/src/app/(main)/docs/routes/page.tsxindex 0fd4b52..3635d7d 100644--- a/src/app/(main)/docs/routes/page.tsx+++ b/src/app/(main)/docs/routes/page.tsx@@ -24,10 +24,6 @@ export default function RoutesPage() {description="Draw lines and paths connecting coordinates on the map."prev={{ title: "Popups", href: "/docs/popups" }}next={{ title: "Arcs", href: "/docs/arcs" }}- toc={[- { title: "Basic Route", slug: "basic-route" },- { title: "Route Planning", slug: "route-planning" },- ]}><DocsSection><p>@@ -53,7 +49,7 @@ export default function RoutesPage() {</DocsLink>. Click on a route or use the buttons to switch.</p>- <ComponentPreview code={osrmRouteSource} className="h-[500px]">+ <ComponentPreview code={osrmRouteSource} height="500px"><OsrmRouteExample /></ComponentPreview></DocsSection>diff --git a/src/components/page-header.tsx b/src/components/page-header.tsxindex 8790307..5bf3f94 100644--- a/src/components/page-header.tsx+++ b/src/components/page-header.tsx@@ -69,7 +69,7 @@ function PageHeaderHeading({return (<CompclassName={cn(- "animate-fade-up animate-stagger max-w-4xl font-bold tracking-tight",+ "animate-fade-up animate-stagger text-primary max-w-4xl font-bold tracking-tight",size === "sm"? "text-4xl font-semibold md:text-5xl": "text-4xl sm:text-5xl md:text-6xl",@@ -82,9 +82,7 @@ function PageHeaderHeading({} as CSSProperties}>- <span className="from-foreground via-foreground to-foreground/65 bg-linear-to-b bg-clip-text text-transparent">- {children}- </span>+ {children}</Comp>);}