UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat(component): add hexagon pattern component (#940)
Matheus Sano470256f2d551
diff --git a/apps/www/config/docs.ts b/apps/www/config/docs.tsindex 5279544b..d4e5aa4c 100644--- a/apps/www/config/docs.ts+++ b/apps/www/config/docs.ts@@ -520,6 +520,12 @@ export const docsConfig: DocsConfig = {href: `/docs/components/grid-pattern`,items: [],},+ {+ title: "Hexagon Pattern",+ href: `/docs/components/hexagon-pattern`,+ items: [],+ label: "New",+ },{title: "Striped Pattern",href: `/docs/components/striped-pattern`,diff --git a/apps/www/content/docs/components/hexagon-pattern.mdx b/apps/www/content/docs/components/hexagon-pattern.mdxnew file mode 100644index 00000000..675bbb1b--- /dev/null+++ b/apps/www/content/docs/components/hexagon-pattern.mdx@@ -0,0 +1,84 @@+---+title: Hexagon Pattern+date: 2026-04-05+description: A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.+author: magicui+published: true+---++<ComponentPreview name="hexagon-pattern-demo" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>+<TabsContent value="cli">++```bash+npx shadcn@latest add @magicui/hexagon-pattern+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="hexagon-pattern" />++<Step>Update the import paths to match your project setup.</Step>++</Steps>++</TabsContent>++</Tabs>++## Examples++### Linear Gradient++<ComponentPreview name="hexagon-pattern-linear-gradient" />++### Dashed Stroke++<ComponentPreview name="hexagon-pattern-dashed" />++### Spacing++<ComponentPreview name="hexagon-pattern-spacing" />++## Usage++```tsx showLineNumbers+import { HexagonPattern } from "@/components/ui/hexagon-pattern"+```++```tsx showLineNumbers+<div className="relative h-[500px] w-full overflow-hidden">+ <HexagonPattern />+</div>+```++## Props++### HexagonPattern++| Prop | Type | Default | Description |+| ----------------- | ---------------------------- | -------------- | ------------------------------------------------------------------------- |+| `radius` | `number` | `40` | Radius from center to vertex for each hexagon |+| `gap` | `number` | `0` | Extra spacing between adjacent hexagons (pixels) |+| `x` | `number` | `-1` | X offset of the pattern origin |+| `y` | `number` | `-1` | Y offset of the pattern origin |+| `direction` | `"horizontal" \| "vertical"` | `"horizontal"` | `horizontal` — flat-top honeycomb; `vertical` — pointy-top honeycomb |+| `hexagons` | `Array<[col, row]>` | — | Grid coordinates of highlighted (filled) hexagons |+| `strokeDasharray` | `string` | `"0"` | SVG `stroke-dasharray` for outline hexagons in the repeating pattern |+| `className` | `string` | — | Additional classes on the root SVG (for example Tailwind color utilities) |++Also accepts standard SVG attributes on the root `<svg>` (for example `aria-hidden`, `role`) where applicable.diff --git a/apps/www/public/llms-full.txt b/apps/www/public/llms-full.txtindex feef2168..5b085e4c 100644--- a/apps/www/public/llms-full.txt+++ b/apps/www/public/llms-full.txt@@ -8566,6 +8566,409 @@ export default function HeroVideoDialogDemoTopInBottomOut() {+===== COMPONENT: hexagon-pattern =====+Title: Hexagon Pattern+Description: A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.++--- file: magicui/hexagon-pattern.tsx ---+import { useId } from "react"++import { cn } from "@/lib/utils"++interface HexagonPatternProps extends React.SVGProps<SVGSVGElement> {+ /**+ * The radius of each hexagon (center to vertex).+ * @default 40+ */+ radius?: number+ /**+ * Spacing in pixels between adjacent hexagons.+ * The tile grows by this amount while the visual radius stays fixed,+ * so the gap is evenly distributed on all sides of each hexagon.+ * @default 0+ */+ gap?: number+ /**+ * Offset applied to the pattern origin on the x-axis.+ * @default -1+ */+ x?: number+ /**+ * Offset applied to the pattern origin on the y-axis.+ * @default -1+ */+ y?: number+ /**+ * Controls the orientation of the hexagons.+ * - `"horizontal"` — flat-top hexagons tiled in a horizontal honeycomb grid.+ * - `"vertical"` — pointy-top hexagons tiled in a vertical honeycomb grid.+ * @default "horizontal"+ */+ direction?: "horizontal" | "vertical"+ /**+ * SVG stroke-dasharray applied to each hexagon outline.+ * @default "0"+ */+ strokeDasharray?: string+ /**+ * Array of [col, row] coordinates for hexagons that should be highlighted+ * (filled) on top of the repeating pattern — mirrors the `squares` prop of+ * GridPattern.+ */+ hexagons?: Array<[col: number, row: number]>+ className?: string+ [key: string]: unknown+}++type HexPoint = readonly [number, number]++function hexVertexList(+ cx: number,+ cy: number,+ r: number,+ direction: "horizontal" | "vertical"+): HexPoint[] {+ const startAngle = direction === "horizontal" ? 0 : 30+ return Array.from({ length: 6 }, (_, i) => {+ const angle = ((startAngle + i * 60) * Math.PI) / 180+ return [cx + r * Math.cos(angle), cy + r * Math.sin(angle)] as const+ })+}++function hexPoints(+ cx: number,+ cy: number,+ r: number,+ direction: "horizontal" | "vertical"+): string {+ return hexVertexList(cx, cy, r, direction)+ .map(([px, py]) => `${px},${py}`)+ .join(" ")+}++function edgeLexKey(a: HexPoint, b: HexPoint): string {+ const [p, q] =+ a[0] < b[0] || (a[0] === b[0] && a[1] <= b[1]) ? [a, b] : [b, a]+ return `${p[0].toFixed(6)},${p[1].toFixed(6)}|${q[0].toFixed(6)},${q[1].toFixed(6)}`+}++function collectUniqueHexEdges(+ centers: [number, number][],+ r: number,+ direction: "horizontal" | "vertical"+): [HexPoint, HexPoint][] {+ const seen = new Set<string>()+ const edges: [HexPoint, HexPoint][] = []+ for (const [cx, cy] of centers) {+ const verts = hexVertexList(cx, cy, r, direction)+ for (let i = 0; i < 6; i++) {+ const a = verts[i]+ const b = verts[(i + 1) % 6]+ const key = edgeLexKey(a, b)+ if (!seen.has(key)) {+ seen.add(key)+ edges.push([a, b])+ }+ }+ }+ return edges+}++function isSolidStrokeDasharray(strokeDasharray: string): boolean {+ const t = strokeDasharray.trim()+ return t === "" || t === "none" || t === "0"+}++function getHexSpacing(+ r: number,+ direction: "horizontal" | "vertical",+ gap: number+): {+ colStep: number+ rowStep: number+ tileW: number+ tileH: number+} {+ const sqrt3 = Math.sqrt(3)++ // `gap` should match the visible edge-to-edge spacing, so we add it along+ // the shared-edge normal instead of directly on the raw x/y axes.+ if (direction === "horizontal") {+ const colStep = (3 * r) / 2 + (sqrt3 * gap) / 2+ const rowStep = sqrt3 * r + gap++ return {+ colStep,+ rowStep,+ tileW: colStep * 2,+ tileH: rowStep,+ }+ }++ const colStep = sqrt3 * r + gap+ const rowStep = (3 * r) / 2 + (sqrt3 * gap) / 2++ return {+ colStep,+ rowStep,+ tileW: colStep,+ tileH: rowStep * 2,+ }+}++function getTileGeometry(+ r: number,+ direction: "horizontal" | "vertical",+ gap: number+): {+ tileW: number+ tileH: number+ centers: [number, number][]+} {+ if (direction === "horizontal") {+ const { colStep, rowStep, tileW, tileH } = getHexSpacing(r, direction, gap)++ const canonical: [number, number][] = [+ [colStep / 2, rowStep / 2],+ [(colStep * 3) / 2, rowStep],+ ]++ const centers: [number, number][] = []+ for (const [cx, cy] of canonical) {+ centers.push([cx, cy])+ if (cy - r < 0) centers.push([cx, cy + tileH])+ if (cy + r > tileH) centers.push([cx, cy - tileH])+ if (cx - r < 0) centers.push([cx + tileW, cy])+ if (cx + r > tileW) centers.push([cx - tileW, cy])+ if (cy - r < 0 && cx - r < 0) centers.push([cx + tileW, cy + tileH])+ if (cy - r < 0 && cx + r > tileW) centers.push([cx - tileW, cy + tileH])+ if (cy + r > tileH && cx - r < 0) centers.push([cx + tileW, cy - tileH])+ if (cy + r > tileH && cx + r > tileW)+ centers.push([cx - tileW, cy - tileH])+ }++ return { tileW, tileH, centers }+ } else {+ const { colStep, rowStep, tileW, tileH } = getHexSpacing(r, direction, gap)++ const canonical: [number, number][] = [+ [colStep / 2, rowStep / 2],+ [colStep, (rowStep * 3) / 2],+ ]++ const centers: [number, number][] = []+ for (const [cx, cy] of canonical) {+ centers.push([cx, cy])+ if (cy - r < 0) centers.push([cx, cy + tileH])+ if (cy + r > tileH) centers.push([cx, cy - tileH])+ if (cx - r < 0) centers.push([cx + tileW, cy])+ if (cx + r > tileW) centers.push([cx - tileW, cy])+ if (cy - r < 0 && cx - r < 0) centers.push([cx + tileW, cy + tileH])+ if (cy - r < 0 && cx + r > tileW) centers.push([cx - tileW, cy + tileH])+ if (cy + r > tileH && cx - r < 0) centers.push([cx + tileW, cy - tileH])+ if (cy + r > tileH && cx + r > tileW)+ centers.push([cx - tileW, cy - tileH])+ }++ return { tileW, tileH, centers }+ }+}++function hexCenter(+ col: number,+ row: number,+ r: number,+ direction: "horizontal" | "vertical",+ gap: number+): [number, number] {+ if (direction === "horizontal") {+ const { colStep, rowStep } = getHexSpacing(r, direction, gap)+ const x = col * colStep + colStep / 2+ const y = row * rowStep + rowStep / 2 + (col % 2 !== 0 ? rowStep / 2 : 0)+ return [x, y]+ } else {+ const { colStep, rowStep } = getHexSpacing(r, direction, gap)+ const x = col * colStep + colStep / 2 + (row % 2 !== 0 ? colStep / 2 : 0)+ const y = row * rowStep + rowStep / 2+ return [x, y]+ }+}++export function HexagonPattern({+ radius = 40,+ gap = 0,+ x = -1,+ y = -1,+ strokeDasharray = "0",+ direction = "horizontal",+ hexagons,+ className,+ ...props+}: HexagonPatternProps) {+ const id = useId()++ const { tileW, tileH, centers } = getTileGeometry(radius, direction, gap)+ const solidStroke = isSolidStrokeDasharray(strokeDasharray)+ const dashedEdges = solidStroke+ ? null+ : collectUniqueHexEdges(centers, radius, direction)++ return (+ <svg+ aria-hidden="true"+ className={cn(+ "pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30",+ className+ )}+ {...props}+ >+ <defs>+ <pattern+ id={id}+ width={tileW}+ height={tileH}+ patternUnits="userSpaceOnUse"+ x={x}+ y={y}+ >+ {solidStroke+ ? centers.map(([cx, cy]) => (+ <polygon+ className="fill-none"+ key={`${cx}-${cy}`}+ points={hexPoints(cx, cy, radius, direction)}+ strokeDasharray={strokeDasharray}+ />+ ))+ : dashedEdges?.map(([a, b]) => (+ <line+ className="fill-none"+ key={edgeLexKey(a, b)}+ x1={a[0]}+ x2={b[0]}+ y1={a[1]}+ y2={b[1]}+ strokeDasharray={strokeDasharray}+ />+ ))}+ </pattern>+ </defs>++ <rect width="100%" height="100%" fill={`url(#${id})`} stroke="none" />++ {hexagons && hexagons.length > 0 && (+ <svg aria-hidden="true" className="overflow-visible" x={x} y={y}>+ {hexagons.map(([col, row]) => {+ const [cx, cy] = hexCenter(col, row, radius, direction, gap)+ return (+ <polygon+ key={`${col}-${row}`}+ points={hexPoints(cx, cy, radius - 1, direction)}+ strokeWidth="0"+ />+ )+ })}+ </svg>+ )}+ </svg>+ )+}+++===== EXAMPLE: hexagon-pattern-demo =====+Title: Hexagon Pattern Demo++--- file: example/hexagon-pattern-demo.tsx ---+"use client"++import { cn } from "@/lib/utils"+import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternDemo() {+ return (+ <div className="bg-background relative flex h-[500px] w-full flex-col items-center justify-center overflow-hidden rounded-lg border">+ <HexagonPattern+ hexagons={[+ [1, 1],+ [4, 4],+ [2, 2],+ [3, 4],+ [5, 4],+ [8, 2],+ [6, 3],+ [8, 5],+ [10, 10],+ ]}+ className={cn(+ "mask-[radial-gradient(420px_circle_at_center,white,transparent)]",+ "inset-0 skew-y-6"+ )}+ />+ </div>+ )+}+++===== EXAMPLE: hexagon-pattern-linear-gradient =====+Title: Hexagon Pattern Linear Gradient++--- file: example/hexagon-pattern-linear-gradient.tsx ---+"use client"++import { cn } from "@/lib/utils"+import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternLinearGradient() {+ return (+ <div className="bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20">+ <HexagonPattern+ radius={40}+ x={-1}+ y={-1}+ className={cn(+ "[mask-image:linear-gradient(to_bottom_right,white,transparent,transparent)]"+ )}+ />+ </div>+ )+}+++===== EXAMPLE: hexagon-pattern-dashed =====+Title: Hexagon Pattern Dashed++--- file: example/hexagon-pattern-dashed.tsx ---+"use client"++import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternDashed() {+ return (+ <div className="bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20">+ <HexagonPattern radius={40} x={-1} y={-1} strokeDasharray="4 2" />+ </div>+ )+}+++===== EXAMPLE: hexagon-pattern-spacing =====+Title: Hexagon Pattern Spacing++--- file: example/hexagon-pattern-spacing.tsx ---+"use client"++import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternSpacing() {+ return (+ <div className="bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20">+ <HexagonPattern gap={20} radius={40} x={-1} y={-1} />+ </div>+ )+}+++===== COMPONENT: highlighter =====Title: HighlighterDescription: A text highlighter that mimics the effect of a human-drawn marker stroke.diff --git a/apps/www/public/llms.txt b/apps/www/public/llms.txtindex 77d58e16..e304bf1f 100644--- a/apps/www/public/llms.txt+++ b/apps/www/public/llms.txt@@ -34,6 +34,7 @@ This file provides LLM-friendly entry points to documentation and examples.- [Globe](https://magicui.design/docs/components/globe): An autorotating, interactive, and highly performant globe made using WebGL.- [Grid Pattern](https://magicui.design/docs/components/grid-pattern): A background grid pattern made with SVGs, fully customizable using Tailwind CSS.- [Hero Video Dialog](https://magicui.design/docs/components/hero-video-dialog): A hero video dialog component.+- [Hexagon Pattern](https://magicui.design/docs/components/hexagon-pattern): A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.- [Highlighter](https://magicui.design/docs/components/highlighter): A text highlighter that mimics the effect of a human-drawn marker stroke.- [Hyper Text](https://magicui.design/docs/components/hyper-text): A text animation that scrambles letters before revealing the final text.- [Icon Cloud](https://magicui.design/docs/components/icon-cloud): An interactive 3D tag cloud component@@ -104,6 +105,10 @@ This file provides LLM-friendly entry points to documentation and examples.- [Striped Pattern (Right)](https://github.com/magicuidesign/magicui/blob/main/example/striped-pattern-right.tsx): Example usage- [Grid Pattern Linear Gradient](https://github.com/magicuidesign/magicui/blob/main/example/grid-pattern-linear-gradient.tsx): Example usage- [Grid Pattern Dashed](https://github.com/magicuidesign/magicui/blob/main/example/grid-pattern-dashed.tsx): Example usage+- [Hexagon Pattern Demo](https://github.com/magicuidesign/magicui/blob/main/example/hexagon-pattern-demo.tsx): Example usage+- [Hexagon Pattern Linear Gradient](https://github.com/magicuidesign/magicui/blob/main/example/hexagon-pattern-linear-gradient.tsx): Example usage+- [Hexagon Pattern Dashed](https://github.com/magicuidesign/magicui/blob/main/example/hexagon-pattern-dashed.tsx): Example usage+- [Hexagon Pattern Spacing](https://github.com/magicuidesign/magicui/blob/main/example/hexagon-pattern-spacing.tsx): Example usage- [Dot Pattern Demo](https://github.com/magicuidesign/magicui/blob/main/example/dot-pattern-demo.tsx): Example usage- [Dot Pattern Linear Gradient](https://github.com/magicuidesign/magicui/blob/main/example/dot-pattern-linear-gradient.tsx): Example usage- [Dot Pattern with glow effect](https://github.com/magicuidesign/magicui/blob/main/example/dot-pattern-with-glow-effect.tsx): Example usagediff --git a/apps/www/public/r/hexagon-pattern-dashed.json b/apps/www/public/r/hexagon-pattern-dashed.jsonnew file mode 100644index 00000000..7a5f38df--- /dev/null+++ b/apps/www/public/r/hexagon-pattern-dashed.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "hexagon-pattern-dashed",+ "type": "registry:example",+ "title": "Hexagon Pattern Dashed",+ "description": "Example showing a dashed hexagon pattern.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-dashed.tsx",+ "content": "\"use client\"\n\nimport { HexagonPattern } from \"@/registry/magicui/hexagon-pattern\"\n\nexport default function HexagonPatternDashed() {\n return (\n <div className=\"bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20\">\n <HexagonPattern radius={40} x={-1} y={-1} strokeDasharray=\"4 2\" />\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/hexagon-pattern-demo.json b/apps/www/public/r/hexagon-pattern-demo.jsonnew file mode 100644index 00000000..f660a90c--- /dev/null+++ b/apps/www/public/r/hexagon-pattern-demo.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "hexagon-pattern-demo",+ "type": "registry:example",+ "title": "Hexagon Pattern Demo",+ "description": "Example showing a background hexagon pattern made with SVGs.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-demo.tsx",+ "content": "\"use client\"\n\nimport { cn } from \"@/lib/utils\"\nimport { HexagonPattern } from \"@/registry/magicui/hexagon-pattern\"\n\nexport default function HexagonPatternDemo() {\n return (\n <div className=\"bg-background relative flex h-[500px] w-full flex-col items-center justify-center overflow-hidden rounded-lg border\">\n <HexagonPattern\n hexagons={[\n [1, 1],\n [4, 4],\n [2, 2],\n [3, 4],\n [5, 4],\n [8, 2],\n [6, 3],\n [8, 5],\n [10, 10],\n ]}\n className={cn(\n \"mask-[radial-gradient(420px_circle_at_center,white,transparent)]\",\n \"inset-0 skew-y-6\"\n )}\n />\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/hexagon-pattern-linear-gradient.json b/apps/www/public/r/hexagon-pattern-linear-gradient.jsonnew file mode 100644index 00000000..f16b5df2--- /dev/null+++ b/apps/www/public/r/hexagon-pattern-linear-gradient.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "hexagon-pattern-linear-gradient",+ "type": "registry:example",+ "title": "Hexagon Pattern Linear Gradient",+ "description": "Example showing a hexagon pattern with linear gradient effects.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-linear-gradient.tsx",+ "content": "\"use client\"\n\nimport { cn } from \"@/lib/utils\"\nimport { HexagonPattern } from \"@/registry/magicui/hexagon-pattern\"\n\nexport default function HexagonPatternLinearGradient() {\n return (\n <div className=\"bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20\">\n <HexagonPattern\n radius={40}\n x={-1}\n y={-1}\n className={cn(\n \"[mask-image:linear-gradient(to_bottom_right,white,transparent,transparent)]\"\n )}\n />\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/hexagon-pattern-spacing.json b/apps/www/public/r/hexagon-pattern-spacing.jsonnew file mode 100644index 00000000..f04eb7c8--- /dev/null+++ b/apps/www/public/r/hexagon-pattern-spacing.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "hexagon-pattern-spacing",+ "type": "registry:example",+ "title": "Hexagon Pattern Spacing",+ "description": "Example showing a hexagon pattern with extra spacing between cells.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-spacing.tsx",+ "content": "\"use client\"\n\nimport { HexagonPattern } from \"@/registry/magicui/hexagon-pattern\"\n\nexport default function HexagonPatternSpacing() {\n return (\n <div className=\"bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20\">\n <HexagonPattern gap={20} radius={40} x={-1} y={-1} />\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/hexagon-pattern.json b/apps/www/public/r/hexagon-pattern.jsonnew file mode 100644index 00000000..5b73f546--- /dev/null+++ b/apps/www/public/r/hexagon-pattern.json@@ -0,0 +1,14 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "hexagon-pattern",+ "type": "registry:ui",+ "title": "Hexagon Pattern",+ "description": "A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.",+ "files": [+ {+ "path": "registry/magicui/hexagon-pattern.tsx",+ "content": "import { useId } from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface HexagonPatternProps extends React.SVGProps<SVGSVGElement> {\n /**\n * The radius of each hexagon (center to vertex).\n * @default 40\n */\n radius?: number\n /**\n * Spacing in pixels between adjacent hexagons.\n * The tile grows by this amount while the visual radius stays fixed,\n * so the gap is evenly distributed on all sides of each hexagon.\n * @default 0\n */\n gap?: number\n /**\n * Offset applied to the pattern origin on the x-axis.\n * @default -1\n */\n x?: number\n /**\n * Offset applied to the pattern origin on the y-axis.\n * @default -1\n */\n y?: number\n /**\n * Controls the orientation of the hexagons.\n * - `\"horizontal\"` — flat-top hexagons tiled in a horizontal honeycomb grid.\n * - `\"vertical\"` — pointy-top hexagons tiled in a vertical honeycomb grid.\n * @default \"horizontal\"\n */\n direction?: \"horizontal\" | \"vertical\"\n /**\n * SVG stroke-dasharray applied to each hexagon outline.\n * @default \"0\"\n */\n strokeDasharray?: string\n /**\n * Array of [col, row] coordinates for hexagons that should be highlighted\n * (filled) on top of the repeating pattern — mirrors the `squares` prop of\n * GridPattern.\n */\n hexagons?: Array<[col: number, row: number]>\n className?: string\n [key: string]: unknown\n}\n\ntype HexPoint = readonly [number, number]\n\nfunction hexVertexList(\n cx: number,\n cy: number,\n r: number,\n direction: \"horizontal\" | \"vertical\"\n): HexPoint[] {\n const startAngle = direction === \"horizontal\" ? 0 : 30\n return Array.from({ length: 6 }, (_, i) => {\n const angle = ((startAngle + i * 60) * Math.PI) / 180\n return [cx + r * Math.cos(angle), cy + r * Math.sin(angle)] as const\n })\n}\n\nfunction hexPoints(\n cx: number,\n cy: number,\n r: number,\n direction: \"horizontal\" | \"vertical\"\n): string {\n return hexVertexList(cx, cy, r, direction)\n .map(([px, py]) => `${px},${py}`)\n .join(\" \")\n}\n\nfunction edgeLexKey(a: HexPoint, b: HexPoint): string {\n const [p, q] =\n a[0] < b[0] || (a[0] === b[0] && a[1] <= b[1]) ? [a, b] : [b, a]\n return `${p[0].toFixed(6)},${p[1].toFixed(6)}|${q[0].toFixed(6)},${q[1].toFixed(6)}`\n}\n\nfunction collectUniqueHexEdges(\n centers: [number, number][],\n r: number,\n direction: \"horizontal\" | \"vertical\"\n): [HexPoint, HexPoint][] {\n const seen = new Set<string>()\n const edges: [HexPoint, HexPoint][] = []\n for (const [cx, cy] of centers) {\n const verts = hexVertexList(cx, cy, r, direction)\n for (let i = 0; i < 6; i++) {\n const a = verts[i]\n const b = verts[(i + 1) % 6]\n const key = edgeLexKey(a, b)\n if (!seen.has(key)) {\n seen.add(key)\n edges.push([a, b])\n }\n }\n }\n return edges\n}\n\nfunction isSolidStrokeDasharray(strokeDasharray: string): boolean {\n const t = strokeDasharray.trim()\n return t === \"\" || t === \"none\" || t === \"0\"\n}\n\nfunction getHexSpacing(\n r: number,\n direction: \"horizontal\" | \"vertical\",\n gap: number\n): {\n colStep: number\n rowStep: number\n tileW: number\n tileH: number\n} {\n const sqrt3 = Math.sqrt(3)\n\n // `gap` should match the visible edge-to-edge spacing, so we add it along\n // the shared-edge normal instead of directly on the raw x/y axes.\n if (direction === \"horizontal\") {\n const colStep = (3 * r) / 2 + (sqrt3 * gap) / 2\n const rowStep = sqrt3 * r + gap\n\n return {\n colStep,\n rowStep,\n tileW: colStep * 2,\n tileH: rowStep,\n }\n }\n\n const colStep = sqrt3 * r + gap\n const rowStep = (3 * r) / 2 + (sqrt3 * gap) / 2\n\n return {\n colStep,\n rowStep,\n tileW: colStep,\n tileH: rowStep * 2,\n }\n}\n\nfunction getTileGeometry(\n r: number,\n direction: \"horizontal\" | \"vertical\",\n gap: number\n): {\n tileW: number\n tileH: number\n centers: [number, number][]\n} {\n if (direction === \"horizontal\") {\n const { colStep, rowStep, tileW, tileH } = getHexSpacing(r, direction, gap)\n\n const canonical: [number, number][] = [\n [colStep / 2, rowStep / 2],\n [(colStep * 3) / 2, rowStep],\n ]\n\n const centers: [number, number][] = []\n for (const [cx, cy] of canonical) {\n centers.push([cx, cy])\n if (cy - r < 0) centers.push([cx, cy + tileH])\n if (cy + r > tileH) centers.push([cx, cy - tileH])\n if (cx - r < 0) centers.push([cx + tileW, cy])\n if (cx + r > tileW) centers.push([cx - tileW, cy])\n if (cy - r < 0 && cx - r < 0) centers.push([cx + tileW, cy + tileH])\n if (cy - r < 0 && cx + r > tileW) centers.push([cx - tileW, cy + tileH])\n if (cy + r > tileH && cx - r < 0) centers.push([cx + tileW, cy - tileH])\n if (cy + r > tileH && cx + r > tileW)\n centers.push([cx - tileW, cy - tileH])\n }\n\n return { tileW, tileH, centers }\n } else {\n const { colStep, rowStep, tileW, tileH } = getHexSpacing(r, direction, gap)\n\n const canonical: [number, number][] = [\n [colStep / 2, rowStep / 2],\n [colStep, (rowStep * 3) / 2],\n ]\n\n const centers: [number, number][] = []\n for (const [cx, cy] of canonical) {\n centers.push([cx, cy])\n if (cy - r < 0) centers.push([cx, cy + tileH])\n if (cy + r > tileH) centers.push([cx, cy - tileH])\n if (cx - r < 0) centers.push([cx + tileW, cy])\n if (cx + r > tileW) centers.push([cx - tileW, cy])\n if (cy - r < 0 && cx - r < 0) centers.push([cx + tileW, cy + tileH])\n if (cy - r < 0 && cx + r > tileW) centers.push([cx - tileW, cy + tileH])\n if (cy + r > tileH && cx - r < 0) centers.push([cx + tileW, cy - tileH])\n if (cy + r > tileH && cx + r > tileW)\n centers.push([cx - tileW, cy - tileH])\n }\n\n return { tileW, tileH, centers }\n }\n}\n\nfunction hexCenter(\n col: number,\n row: number,\n r: number,\n direction: \"horizontal\" | \"vertical\",\n gap: number\n): [number, number] {\n if (direction === \"horizontal\") {\n const { colStep, rowStep } = getHexSpacing(r, direction, gap)\n const x = col * colStep + colStep / 2\n const y = row * rowStep + rowStep / 2 + (col % 2 !== 0 ? rowStep / 2 : 0)\n return [x, y]\n } else {\n const { colStep, rowStep } = getHexSpacing(r, direction, gap)\n const x = col * colStep + colStep / 2 + (row % 2 !== 0 ? colStep / 2 : 0)\n const y = row * rowStep + rowStep / 2\n return [x, y]\n }\n}\n\nexport function HexagonPattern({\n radius = 40,\n gap = 0,\n x = -1,\n y = -1,\n strokeDasharray = \"0\",\n direction = \"horizontal\",\n hexagons,\n className,\n ...props\n}: HexagonPatternProps) {\n const id = useId()\n\n const { tileW, tileH, centers } = getTileGeometry(radius, direction, gap)\n const solidStroke = isSolidStrokeDasharray(strokeDasharray)\n const dashedEdges = solidStroke\n ? null\n : collectUniqueHexEdges(centers, radius, direction)\n\n return (\n <svg\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30\",\n className\n )}\n {...props}\n >\n <defs>\n <pattern\n id={id}\n width={tileW}\n height={tileH}\n patternUnits=\"userSpaceOnUse\"\n x={x}\n y={y}\n >\n {solidStroke\n ? centers.map(([cx, cy]) => (\n <polygon\n className=\"fill-none\"\n key={`${cx}-${cy}`}\n points={hexPoints(cx, cy, radius, direction)}\n strokeDasharray={strokeDasharray}\n />\n ))\n : dashedEdges?.map(([a, b]) => (\n <line\n className=\"fill-none\"\n key={edgeLexKey(a, b)}\n x1={a[0]}\n x2={b[0]}\n y1={a[1]}\n y2={b[1]}\n strokeDasharray={strokeDasharray}\n />\n ))}\n </pattern>\n </defs>\n\n <rect width=\"100%\" height=\"100%\" fill={`url(#${id})`} stroke=\"none\" />\n\n {hexagons && hexagons.length > 0 && (\n <svg aria-hidden=\"true\" className=\"overflow-visible\" x={x} y={y}>\n {hexagons.map(([col, row]) => {\n const [cx, cy] = hexCenter(col, row, radius, direction, gap)\n return (\n <polygon\n key={`${col}-${row}`}\n points={hexPoints(cx, cy, radius - 1, direction)}\n strokeWidth=\"0\"\n />\n )\n })}\n </svg>\n )}\n </svg>\n )\n}\n",+ "type": "registry:ui"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/registry.json b/apps/www/public/r/registry.jsonindex 9fe4a142..34ffc41b 100644--- a/apps/www/public/r/registry.json+++ b/apps/www/public/r/registry.json@@ -286,6 +286,18 @@}]},+ {+ "name": "hexagon-pattern",+ "type": "registry:ui",+ "title": "Hexagon Pattern",+ "description": "A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.",+ "files": [+ {+ "path": "registry/magicui/hexagon-pattern.tsx",+ "type": "registry:ui"+ }+ ]+ },{"name": "striped-pattern","type": "registry:ui",@@ -1649,6 +1661,66 @@}]},+ {+ "name": "hexagon-pattern-demo",+ "type": "registry:example",+ "title": "Hexagon Pattern Demo",+ "description": "Example showing a background hexagon pattern made with SVGs.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-demo.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-linear-gradient",+ "type": "registry:example",+ "title": "Hexagon Pattern Linear Gradient",+ "description": "Example showing a hexagon pattern with linear gradient effects.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-linear-gradient.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-dashed",+ "type": "registry:example",+ "title": "Hexagon Pattern Dashed",+ "description": "Example showing a dashed hexagon pattern.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-dashed.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-spacing",+ "type": "registry:example",+ "title": "Hexagon Pattern Spacing",+ "description": "Example showing a hexagon pattern with extra spacing between cells.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-spacing.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "dot-pattern-demo","type": "registry:example",diff --git a/apps/www/public/registry.json b/apps/www/public/registry.jsonindex 9fe4a142..34ffc41b 100644--- a/apps/www/public/registry.json+++ b/apps/www/public/registry.json@@ -286,6 +286,18 @@}]},+ {+ "name": "hexagon-pattern",+ "type": "registry:ui",+ "title": "Hexagon Pattern",+ "description": "A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.",+ "files": [+ {+ "path": "registry/magicui/hexagon-pattern.tsx",+ "type": "registry:ui"+ }+ ]+ },{"name": "striped-pattern","type": "registry:ui",@@ -1649,6 +1661,66 @@}]},+ {+ "name": "hexagon-pattern-demo",+ "type": "registry:example",+ "title": "Hexagon Pattern Demo",+ "description": "Example showing a background hexagon pattern made with SVGs.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-demo.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-linear-gradient",+ "type": "registry:example",+ "title": "Hexagon Pattern Linear Gradient",+ "description": "Example showing a hexagon pattern with linear gradient effects.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-linear-gradient.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-dashed",+ "type": "registry:example",+ "title": "Hexagon Pattern Dashed",+ "description": "Example showing a dashed hexagon pattern.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-dashed.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-spacing",+ "type": "registry:example",+ "title": "Hexagon Pattern Spacing",+ "description": "Example showing a hexagon pattern with extra spacing between cells.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-spacing.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "dot-pattern-demo","type": "registry:example",diff --git a/apps/www/registry.json b/apps/www/registry.jsonindex 9fe4a142..34ffc41b 100644--- a/apps/www/registry.json+++ b/apps/www/registry.json@@ -286,6 +286,18 @@}]},+ {+ "name": "hexagon-pattern",+ "type": "registry:ui",+ "title": "Hexagon Pattern",+ "description": "A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.",+ "files": [+ {+ "path": "registry/magicui/hexagon-pattern.tsx",+ "type": "registry:ui"+ }+ ]+ },{"name": "striped-pattern","type": "registry:ui",@@ -1649,6 +1661,66 @@}]},+ {+ "name": "hexagon-pattern-demo",+ "type": "registry:example",+ "title": "Hexagon Pattern Demo",+ "description": "Example showing a background hexagon pattern made with SVGs.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-demo.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-linear-gradient",+ "type": "registry:example",+ "title": "Hexagon Pattern Linear Gradient",+ "description": "Example showing a hexagon pattern with linear gradient effects.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-linear-gradient.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-dashed",+ "type": "registry:example",+ "title": "Hexagon Pattern Dashed",+ "description": "Example showing a dashed hexagon pattern.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-dashed.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "hexagon-pattern-spacing",+ "type": "registry:example",+ "title": "Hexagon Pattern Spacing",+ "description": "Example showing a hexagon pattern with extra spacing between cells.",+ "registryDependencies": [+ "@magicui/hexagon-pattern"+ ],+ "files": [+ {+ "path": "registry/example/hexagon-pattern-spacing.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "dot-pattern-demo","type": "registry:example",diff --git a/apps/www/registry/__index__.tsx b/apps/www/registry/__index__.tsxindex ea1a3e47..20ed79ef 100644--- a/apps/www/registry/__index__.tsx+++ b/apps/www/registry/__index__.tsx@@ -253,6 +253,23 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "hexagon-pattern": {+ name: "hexagon-pattern",+ description: "A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.",+ type: "registry:ui",+ registryDependencies: undefined,+ files: [{+ path: "registry/magicui/hexagon-pattern.tsx",+ type: "registry:ui",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/magicui/hexagon-pattern.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },"striped-pattern": {name: "striped-pattern",description: "A background striped pattern made with SVGs, fully customizable using Tailwind CSS.",@@ -1630,6 +1647,74 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "hexagon-pattern-demo": {+ name: "hexagon-pattern-demo",+ description: "Example showing a background hexagon pattern made with SVGs.",+ type: "registry:example",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [{+ path: "registry/example/hexagon-pattern-demo.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/hexagon-pattern-demo.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },+ "hexagon-pattern-linear-gradient": {+ name: "hexagon-pattern-linear-gradient",+ description: "Example showing a hexagon pattern with linear gradient effects.",+ type: "registry:example",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [{+ path: "registry/example/hexagon-pattern-linear-gradient.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/hexagon-pattern-linear-gradient.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },+ "hexagon-pattern-dashed": {+ name: "hexagon-pattern-dashed",+ description: "Example showing a dashed hexagon pattern.",+ type: "registry:example",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [{+ path: "registry/example/hexagon-pattern-dashed.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/hexagon-pattern-dashed.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },+ "hexagon-pattern-spacing": {+ name: "hexagon-pattern-spacing",+ description: "Example showing a hexagon pattern with extra spacing between cells.",+ type: "registry:example",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [{+ path: "registry/example/hexagon-pattern-spacing.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/hexagon-pattern-spacing.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name+ return { default: mod.default ?? mod[exportName] }+ }),+ meta: undefined,+ },"dot-pattern-demo": {name: "dot-pattern-demo",description: "Example showing a background dot pattern made with SVGs.",diff --git a/apps/www/registry/example/hexagon-pattern-dashed.tsx b/apps/www/registry/example/hexagon-pattern-dashed.tsxnew file mode 100644index 00000000..a2f42093--- /dev/null+++ b/apps/www/registry/example/hexagon-pattern-dashed.tsx@@ -0,0 +1,11 @@+"use client"++import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternDashed() {+ return (+ <div className="bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20">+ <HexagonPattern radius={40} x={-1} y={-1} strokeDasharray="4 2" />+ </div>+ )+}diff --git a/apps/www/registry/example/hexagon-pattern-demo.tsx b/apps/www/registry/example/hexagon-pattern-demo.tsxnew file mode 100644index 00000000..b15dbc65--- /dev/null+++ b/apps/www/registry/example/hexagon-pattern-demo.tsx@@ -0,0 +1,28 @@+"use client"++import { cn } from "@/lib/utils"+import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternDemo() {+ return (+ <div className="bg-background relative flex h-[500px] w-full flex-col items-center justify-center overflow-hidden rounded-lg border">+ <HexagonPattern+ hexagons={[+ [1, 1],+ [4, 4],+ [2, 2],+ [3, 4],+ [5, 4],+ [8, 2],+ [6, 3],+ [8, 5],+ [10, 10],+ ]}+ className={cn(+ "mask-[radial-gradient(420px_circle_at_center,white,transparent)]",+ "inset-0 skew-y-6"+ )}+ />+ </div>+ )+}diff --git a/apps/www/registry/example/hexagon-pattern-linear-gradient.tsx b/apps/www/registry/example/hexagon-pattern-linear-gradient.tsxnew file mode 100644index 00000000..b6741841--- /dev/null+++ b/apps/www/registry/example/hexagon-pattern-linear-gradient.tsx@@ -0,0 +1,19 @@+"use client"++import { cn } from "@/lib/utils"+import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternLinearGradient() {+ return (+ <div className="bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20">+ <HexagonPattern+ radius={40}+ x={-1}+ y={-1}+ className={cn(+ "[mask-image:linear-gradient(to_bottom_right,white,transparent,transparent)]"+ )}+ />+ </div>+ )+}diff --git a/apps/www/registry/example/hexagon-pattern-spacing.tsx b/apps/www/registry/example/hexagon-pattern-spacing.tsxnew file mode 100644index 00000000..a7537837--- /dev/null+++ b/apps/www/registry/example/hexagon-pattern-spacing.tsx@@ -0,0 +1,11 @@+"use client"++import { HexagonPattern } from "@/registry/magicui/hexagon-pattern"++export default function HexagonPatternSpacing() {+ return (+ <div className="bg-background relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border p-20">+ <HexagonPattern gap={20} radius={40} x={-1} y={-1} />+ </div>+ )+}diff --git a/apps/www/registry/magicui/hexagon-pattern.tsx b/apps/www/registry/magicui/hexagon-pattern.tsxnew file mode 100644index 00000000..dd8826ac--- /dev/null+++ b/apps/www/registry/magicui/hexagon-pattern.tsx@@ -0,0 +1,302 @@+import { useId } from "react"++import { cn } from "@/lib/utils"++interface HexagonPatternProps extends React.SVGProps<SVGSVGElement> {+ /**+ * The radius of each hexagon (center to vertex).+ * @default 40+ */+ radius?: number+ /**+ * Spacing in pixels between adjacent hexagons.+ * The tile grows by this amount while the visual radius stays fixed,+ * so the gap is evenly distributed on all sides of each hexagon.+ * @default 0+ */+ gap?: number+ /**+ * Offset applied to the pattern origin on the x-axis.+ * @default -1+ */+ x?: number+ /**+ * Offset applied to the pattern origin on the y-axis.+ * @default -1+ */+ y?: number+ /**+ * Controls the orientation of the hexagons.+ * - `"horizontal"` — flat-top hexagons tiled in a horizontal honeycomb grid.+ * - `"vertical"` — pointy-top hexagons tiled in a vertical honeycomb grid.+ * @default "horizontal"+ */+ direction?: "horizontal" | "vertical"+ /**+ * SVG stroke-dasharray applied to each hexagon outline.+ * @default "0"+ */+ strokeDasharray?: string+ /**+ * Array of [col, row] coordinates for hexagons that should be highlighted+ * (filled) on top of the repeating pattern — mirrors the `squares` prop of+ * GridPattern.+ */+ hexagons?: Array<[col: number, row: number]>+ className?: string+ [key: string]: unknown+}++type HexPoint = readonly [number, number]++function hexVertexList(+ cx: number,+ cy: number,+ r: number,+ direction: "horizontal" | "vertical"+): HexPoint[] {+ const startAngle = direction === "horizontal" ? 0 : 30+ return Array.from({ length: 6 }, (_, i) => {+ const angle = ((startAngle + i * 60) * Math.PI) / 180+ return [cx + r * Math.cos(angle), cy + r * Math.sin(angle)] as const+ })+}++function hexPoints(+ cx: number,+ cy: number,+ r: number,+ direction: "horizontal" | "vertical"+): string {+ return hexVertexList(cx, cy, r, direction)+ .map(([px, py]) => `${px},${py}`)+ .join(" ")+}++function edgeLexKey(a: HexPoint, b: HexPoint): string {+ const [p, q] =+ a[0] < b[0] || (a[0] === b[0] && a[1] <= b[1]) ? [a, b] : [b, a]+ return `${p[0].toFixed(6)},${p[1].toFixed(6)}|${q[0].toFixed(6)},${q[1].toFixed(6)}`+}++function collectUniqueHexEdges(+ centers: [number, number][],+ r: number,+ direction: "horizontal" | "vertical"+): [HexPoint, HexPoint][] {+ const seen = new Set<string>()+ const edges: [HexPoint, HexPoint][] = []+ for (const [cx, cy] of centers) {+ const verts = hexVertexList(cx, cy, r, direction)+ for (let i = 0; i < 6; i++) {+ const a = verts[i]+ const b = verts[(i + 1) % 6]+ const key = edgeLexKey(a, b)+ if (!seen.has(key)) {+ seen.add(key)+ edges.push([a, b])+ }+ }+ }+ return edges+}++function isSolidStrokeDasharray(strokeDasharray: string): boolean {+ const t = strokeDasharray.trim()+ return t === "" || t === "none" || t === "0"+}++function getHexSpacing(+ r: number,+ direction: "horizontal" | "vertical",+ gap: number+): {+ colStep: number+ rowStep: number+ tileW: number+ tileH: number+} {+ const sqrt3 = Math.sqrt(3)++ // `gap` should match the visible edge-to-edge spacing, so we add it along+ // the shared-edge normal instead of directly on the raw x/y axes.+ if (direction === "horizontal") {+ const colStep = (3 * r) / 2 + (sqrt3 * gap) / 2+ const rowStep = sqrt3 * r + gap++ return {+ colStep,+ rowStep,+ tileW: colStep * 2,+ tileH: rowStep,+ }+ }++ const colStep = sqrt3 * r + gap+ const rowStep = (3 * r) / 2 + (sqrt3 * gap) / 2++ return {+ colStep,+ rowStep,+ tileW: colStep,+ tileH: rowStep * 2,+ }+}++function getTileGeometry(+ r: number,+ direction: "horizontal" | "vertical",+ gap: number+): {+ tileW: number+ tileH: number+ centers: [number, number][]+} {+ if (direction === "horizontal") {+ const { colStep, rowStep, tileW, tileH } = getHexSpacing(r, direction, gap)++ const canonical: [number, number][] = [+ [colStep / 2, rowStep / 2],+ [(colStep * 3) / 2, rowStep],+ ]++ const centers: [number, number][] = []+ for (const [cx, cy] of canonical) {+ centers.push([cx, cy])+ if (cy - r < 0) centers.push([cx, cy + tileH])+ if (cy + r > tileH) centers.push([cx, cy - tileH])+ if (cx - r < 0) centers.push([cx + tileW, cy])+ if (cx + r > tileW) centers.push([cx - tileW, cy])+ if (cy - r < 0 && cx - r < 0) centers.push([cx + tileW, cy + tileH])+ if (cy - r < 0 && cx + r > tileW) centers.push([cx - tileW, cy + tileH])+ if (cy + r > tileH && cx - r < 0) centers.push([cx + tileW, cy - tileH])+ if (cy + r > tileH && cx + r > tileW)+ centers.push([cx - tileW, cy - tileH])+ }++ return { tileW, tileH, centers }+ } else {+ const { colStep, rowStep, tileW, tileH } = getHexSpacing(r, direction, gap)++ const canonical: [number, number][] = [+ [colStep / 2, rowStep / 2],+ [colStep, (rowStep * 3) / 2],+ ]++ const centers: [number, number][] = []+ for (const [cx, cy] of canonical) {+ centers.push([cx, cy])+ if (cy - r < 0) centers.push([cx, cy + tileH])+ if (cy + r > tileH) centers.push([cx, cy - tileH])+ if (cx - r < 0) centers.push([cx + tileW, cy])+ if (cx + r > tileW) centers.push([cx - tileW, cy])+ if (cy - r < 0 && cx - r < 0) centers.push([cx + tileW, cy + tileH])+ if (cy - r < 0 && cx + r > tileW) centers.push([cx - tileW, cy + tileH])+ if (cy + r > tileH && cx - r < 0) centers.push([cx + tileW, cy - tileH])+ if (cy + r > tileH && cx + r > tileW)+ centers.push([cx - tileW, cy - tileH])+ }++ return { tileW, tileH, centers }+ }+}++function hexCenter(+ col: number,+ row: number,+ r: number,+ direction: "horizontal" | "vertical",+ gap: number+): [number, number] {+ if (direction === "horizontal") {+ const { colStep, rowStep } = getHexSpacing(r, direction, gap)+ const x = col * colStep + colStep / 2+ const y = row * rowStep + rowStep / 2 + (col % 2 !== 0 ? rowStep / 2 : 0)+ return [x, y]+ } else {+ const { colStep, rowStep } = getHexSpacing(r, direction, gap)+ const x = col * colStep + colStep / 2 + (row % 2 !== 0 ? colStep / 2 : 0)+ const y = row * rowStep + rowStep / 2+ return [x, y]+ }+}++export function HexagonPattern({+ radius = 40,+ gap = 0,+ x = -1,+ y = -1,+ strokeDasharray = "0",+ direction = "horizontal",+ hexagons,+ className,+ ...props+}: HexagonPatternProps) {+ const id = useId()++ const { tileW, tileH, centers } = getTileGeometry(radius, direction, gap)+ const solidStroke = isSolidStrokeDasharray(strokeDasharray)+ const dashedEdges = solidStroke+ ? null+ : collectUniqueHexEdges(centers, radius, direction)++ return (+ <svg+ aria-hidden="true"+ className={cn(+ "pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30",+ className+ )}+ {...props}+ >+ <defs>+ <pattern+ id={id}+ width={tileW}+ height={tileH}+ patternUnits="userSpaceOnUse"+ x={x}+ y={y}+ >+ {solidStroke+ ? centers.map(([cx, cy]) => (+ <polygon+ className="fill-none"+ key={`${cx}-${cy}`}+ points={hexPoints(cx, cy, radius, direction)}+ strokeDasharray={strokeDasharray}+ />+ ))+ : dashedEdges?.map(([a, b]) => (+ <line+ className="fill-none"+ key={edgeLexKey(a, b)}+ x1={a[0]}+ x2={b[0]}+ y1={a[1]}+ y2={b[1]}+ strokeDasharray={strokeDasharray}+ />+ ))}+ </pattern>+ </defs>++ <rect width="100%" height="100%" fill={`url(#${id})`} stroke="none" />++ {hexagons && hexagons.length > 0 && (+ <svg aria-hidden="true" className="overflow-visible" x={x} y={y}>+ {hexagons.map(([col, row]) => {+ const [cx, cy] = hexCenter(col, row, radius, direction, gap)+ return (+ <polygon+ key={`${col}-${row}`}+ points={hexPoints(cx, cy, radius - 1, direction)}+ strokeWidth="0"+ />+ )+ })}+ </svg>+ )}+ </svg>+ )+}diff --git a/apps/www/registry/registry-examples.ts b/apps/www/registry/registry-examples.tsindex 99098ffa..98613dfd 100644--- a/apps/www/registry/registry-examples.ts+++ b/apps/www/registry/registry-examples.ts@@ -320,6 +320,60 @@ export const examples: Registry["items"] = [},],},+ {+ name: "hexagon-pattern-demo",+ type: "registry:example",+ title: "Hexagon Pattern Demo",+ description: "Example showing a background hexagon pattern made with SVGs.",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [+ {+ path: "example/hexagon-pattern-demo.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "hexagon-pattern-linear-gradient",+ type: "registry:example",+ title: "Hexagon Pattern Linear Gradient",+ description:+ "Example showing a hexagon pattern with linear gradient effects.",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [+ {+ path: "example/hexagon-pattern-linear-gradient.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "hexagon-pattern-dashed",+ type: "registry:example",+ title: "Hexagon Pattern Dashed",+ description: "Example showing a dashed hexagon pattern.",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [+ {+ path: "example/hexagon-pattern-dashed.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "hexagon-pattern-spacing",+ type: "registry:example",+ title: "Hexagon Pattern Spacing",+ description:+ "Example showing a hexagon pattern with extra spacing between cells.",+ registryDependencies: ["@magicui/hexagon-pattern"],+ files: [+ {+ path: "example/hexagon-pattern-spacing.tsx",+ type: "registry:example",+ },+ ],+ },{name: "dot-pattern-demo",type: "registry:example",diff --git a/apps/www/registry/registry-ui.ts b/apps/www/registry/registry-ui.tsindex 03a44d7f..7cd570a0 100644--- a/apps/www/registry/registry-ui.ts+++ b/apps/www/registry/registry-ui.ts@@ -255,6 +255,19 @@ export const ui: Registry["items"] = [},],},+ {+ name: "hexagon-pattern",+ type: "registry:ui",+ title: "Hexagon Pattern",+ description:+ "A background hexagon pattern made with SVGs, fully customizable using Tailwind CSS.",+ files: [+ {+ path: "magicui/hexagon-pattern.tsx",+ type: "registry:ui",+ },+ ],+ },{name: "striped-pattern",type: "registry:ui",