1import React, { useId } from "react"
2
3import { cn } from "@/lib/utils"
4
5interface StripedPatternProps extends React.SVGProps<SVGSVGElement> {
6 direction?: "left" | "right"
7}
8
9export function StripedPattern({
10 direction = "left",
11 className,
12 width = 10,
13 height = 10,
14 ...props
15}: StripedPatternProps) {
16 const id = useId()
17 const w = Number(width)
18 const h = Number(height)
19
20 return (
21 <svg
22 aria-hidden="true"
23 className={cn(
24 "pointer-events-none absolute inset-0 z-10 h-full w-full stroke-[0.5]",
25 className
26 )}
27 xmlns="http://www.w3.org/2000/svg"
28 {...props}
29 >
30 <defs>
31 <pattern id={id} width={w} height={h} patternUnits="userSpaceOnUse">
32 {direction === "left" ? (
33 <>
34 <line x1="0" y1={h} x2={w} y2="0" stroke="currentColor" />
35 <line x1={-w} y1={h} x2="0" y2="0" stroke="currentColor" />
36 <line x1={w} y1={h} x2={w * 2} y2="0" stroke="currentColor" />
37 </>
38 ) : (
39 <>
40 <line x1="0" y1="0" x2={w} y2={h} stroke="currentColor" />
41 <line x1={-w} y1="0" x2="0" y2={h} stroke="currentColor" />
42 <line x1={w} y1="0" x2={w * 2} y2={h} stroke="currentColor" />
43 </>
44 )}
45 </pattern>
46 </defs>
47 <rect width="100%" height="100%" fill={`url(#${id})`} />
48 </svg>
49 )
50}
51