Grid Pattern
Install: npx shadcn@latest add https://jiguang132.com/r/magic-ui/grid-pattern.json
Use case
Draw a repeating SVG grid with selected highlighted cells.
Native props used by the examples
Extracted from all local examples for this entry, grouped by imported module and native owner, including other Magic components used by compound demos. This is not an exhaustive API or a universal host variant. Inspect spread object declarations and the source types/defaults below.
| Owning component prop | Explanation | Example source |
|---|---|---|
GridPattern.squares (grid-pattern) | Highlighted cells as [x, y] coordinates. | examples/grid-pattern-demo.tsx |
GridPattern.className (grid-pattern) | Classes on this native component; initialize Tailwind and its required CSS first. | examples/grid-pattern-demo.tsx、examples/grid-pattern-linear-gradient.tsx、examples/grid-pattern-dashed.tsx |
GridPattern.width (grid-pattern) | Native grid spacing/canvas width according to the owning type. | examples/grid-pattern-linear-gradient.tsx、examples/grid-pattern-dashed.tsx |
GridPattern.height (grid-pattern) | Native cell/canvas height or CSS extent according to the owning type. | examples/grid-pattern-linear-gradient.tsx、examples/grid-pattern-dashed.tsx |
GridPattern.x (grid-pattern) | Horizontal SVG pattern origin offset. | examples/grid-pattern-linear-gradient.tsx、examples/grid-pattern-dashed.tsx |
GridPattern.y (grid-pattern) | Vertical SVG pattern origin offset. | examples/grid-pattern-linear-gradient.tsx、examples/grid-pattern-dashed.tsx |
GridPattern.strokeDasharray (grid-pattern) | SVG outline dash pattern; retain the owning type's string/number constraint. | examples/grid-pattern-dashed.tsx |
Interaction and state checks
- Grid Pattern Demo —
grid-pattern-demo - Grid Pattern Linear Gradient —
grid-pattern-linear-gradient - Grid Pattern Dashed —
grid-pattern-dashed
These names identify real example entries, not new component props or extra components. Check pointer/keyboard behavior, themes, small screens and failures for the selected example. Decorative effects must not invent disabled/error/submission states. Complete example installation includes the actual dependency closure.
Business integration boundary
squares contains grid coordinates, not interactive selected values. The pattern does not manage selection.
Host and motion setup
Initialize Tailwind CSS v4, semantic CSS variables and the dark variant; import the independent local Registry namespace. Reuse an existing next-themes Provider without substituting JGuang UI/Base UI/HeroUI APIs. Mount effects in view and unmount offscreen; provide static alternatives for unavailable Canvas/WebGL or failed remote media. Respect prefers-reduced-motion and verify timer/RAF/observer/listener cleanup: stopping CSS alone does not prove the engine stopped. Examples provide no backend, login, payment or real AI stream. This practical guide is bilingual; detailed upstream references and demo text retain their original language.
Available examples
grid-pattern-demo, grid-pattern-linear-gradient, grid-pattern-dashed
Demo state and mock data do not provide a backend service. Inspect the component props before wiring real data.
Installation
<Tabs defaultValue="cli"> <TabsList> <TabsTrigger value="cli">CLI</TabsTrigger> <TabsTrigger value="manual">Manual</TabsTrigger> </TabsList> <TabsContent value="cli">npx shadcn@latest add @magicui/grid-pattern
</TabsContent>
<TabsContent value="manual">
<Steps>
<Step>Copy and paste the following code into your project.</Step>
<Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </Tabs>Examples
Linear Gradient
Dashed Stroke
Usage
import { GridPattern } from "@/components/ui/grid-pattern"
<div className="relative h-[500px] w-full overflow-hidden">
<GridPattern />
</div>
Props
GridPattern
| Prop | Type | Default | Description |
|---|---|---|---|
width | number | 40 | Width of the pattern |
height | number | 40 | Height of the pattern |
x | number | -1 | X offset of the pattern |
y | number | -1 | Y offset of the pattern |
squares | number | [] | X Y coordinates of filled squares as 2D array |
strokeDasharray | string | 0 | Stroke dash array for the pattern |
Complete example installation
The component command installs the component. Each example command also includes its actual imported components, native support UI, utilities and pinned dependencies. Helpers are not additional catalog components.
Grid Pattern Demo
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/grid-pattern/grid-pattern-demo.json
Default import: @/components/magicui/examples/grid-pattern-demo
Dependencies: clsx@2.1.1, tailwind-merge@3.6.0
Grid Pattern Linear Gradient
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/grid-pattern/grid-pattern-linear-gradient.json
Default import: @/components/magicui/examples/grid-pattern-linear-gradient
Dependencies: clsx@2.1.1, tailwind-merge@3.6.0
Grid Pattern Dashed
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/grid-pattern/grid-pattern-dashed.json
Default import: @/components/magicui/examples/grid-pattern-dashed
Dependencies: clsx@2.1.1, tailwind-merge@3.6.0
Minimal usage and theme
import Demo from '@/components/magicui/examples/grid-pattern-demo';
import { ThemeProvider } from 'next-themes';
export default function Example() {
return <ThemeProvider attribute="class" defaultTheme="system" enableSystem><Demo /></ThemeProvider>;
}
Initialize Tailwind CSS v4, semantic color variables and the dark variant first. Reuse an existing next-themes provider rather than nesting another. Next Link examples require a Next.js environment; in static Vite projects adapt the demo links to your router without changing the native component API. Some media and tweets require network access. Examples do not supply authentication or backend services.
Source-backed parameter reference
Implementation signatures and types are generated from the pinned local source. Optional props, native inherited types, union branches and never exclusions are preserved. A forwardRef implementation's ref is a React reference, not an additional business prop.
GridPattern({
width = 40,
height = 40,
x = -1,
y = -1,
strokeDasharray = "0",
squares,
className,
...props
}: GridPatternProps)
interface GridPatternProps extends React.SVGProps<SVGSVGElement> {
width?: number
height?: number
x?: number
y?: number
squares?: Array<[x: number, y: number]>
strokeDasharray?: string
className?: string
[key: string]: unknown
}
Destructuring defaults in source
Only defaults written directly in parameter/props destructuring are listed. Conditional expressions, runtime theme and computed values require source inspection; this is not an exhaustive behavior-default list.
// GridPattern
width = 40
// GridPattern
height = 40
// GridPattern
x = -1
// GridPattern
y = -1
// GridPattern
strokeDasharray = "0"
Native and external types
External types remain defined by React or native dependencies, not manually expanded into guessed props. The installed version's TypeScript definitions are authoritative.
React.SVGProps<SVGSVGElement>
SVGSVGElement
Array<[x: number, y: number]>