1"use client"
2
3import React from "react"
4
5import { cn } from "@/lib/utils"
6
7export interface ProgressiveBlurProps {
8 className?: string
9 height?: string
10 position?: "top" | "bottom" | "both"
11 blurLevels?: number[]
12 children?: React.ReactNode
13}
14
15export function ProgressiveBlur({
16 className,
17 height = "30%",
18 position = "bottom",
19 blurLevels = [0.5, 1, 2, 4, 8, 16, 32, 64],
20}: ProgressiveBlurProps) {
21 // Create array with length equal to blurLevels.length - 2 (for before/after pseudo elements)
22 const divElements = Array(blurLevels.length - 2).fill(null)
23
24 return (
25 <div
26 className={cn(
27 "gradient-blur pointer-events-none absolute inset-x-0 z-10",
28 className,
29 position === "top"
30 ? "top-0"
31 : position === "bottom"
32 ? "bottom-0"
33 : "inset-y-0"
34 )}
35 style={{
36 height: position === "both" ? "100%" : height,
37 }}
38 >
39 {/* First blur layer (pseudo element) */}
40 <div
41 className="absolute inset-0"
42 style={{
43 zIndex: 1,
44 backdropFilter: `blur(${blurLevels[0]}px)`,
45 WebkitBackdropFilter: `blur(${blurLevels[0]}px)`,
46 maskImage:
47 position === "bottom"
48 ? `linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 12.5%, rgba(0,0,0,1) 25%, rgba(0,0,0,0) 37.5%)`
49 : position === "top"
50 ? `linear-gradient(to top, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 12.5%, rgba(0,0,0,1) 25%, rgba(0,0,0,0) 37.5%)`
51 : `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`,
52 WebkitMaskImage:
53 position === "bottom"
54 ? `linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 12.5%, rgba(0,0,0,1) 25%, rgba(0,0,0,0) 37.5%)`
55 : position === "top"
56 ? `linear-gradient(to top, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 12.5%, rgba(0,0,0,1) 25%, rgba(0,0,0,0) 37.5%)`
57 : `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`,
58 }}
59 />
60
61 {/* Middle blur layers */}
62 {divElements.map((_, index) => {
63 const blurIndex = index + 1
64 const startPercent = blurIndex * 12.5
65 const midPercent = (blurIndex + 1) * 12.5
66 const endPercent = (blurIndex + 2) * 12.5
67
68 const maskGradient =
69 position === "bottom"
70 ? `linear-gradient(to bottom, rgba(0,0,0,0) ${startPercent}%, rgba(0,0,0,1) ${midPercent}%, rgba(0,0,0,1) ${endPercent}%, rgba(0,0,0,0) ${endPercent + 12.5}%)`
71 : position === "top"
72 ? `linear-gradient(to top, rgba(0,0,0,0) ${startPercent}%, rgba(0,0,0,1) ${midPercent}%, rgba(0,0,0,1) ${endPercent}%, rgba(0,0,0,0) ${endPercent + 12.5}%)`
73 : `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`
74
75 return (
76 <div
77 key={`blur-${index}`}
78 className="absolute inset-0"
79 style={{
80 zIndex: index + 2,
81 backdropFilter: `blur(${blurLevels[blurIndex]}px)`,
82 WebkitBackdropFilter: `blur(${blurLevels[blurIndex]}px)`,
83 maskImage: maskGradient,
84 WebkitMaskImage: maskGradient,
85 }}
86 />
87 )
88 })}
89
90 {/* Last blur layer (pseudo element) */}
91 <div
92 className="absolute inset-0"
93 style={{
94 zIndex: blurLevels.length,
95 backdropFilter: `blur(${blurLevels[blurLevels.length - 1]}px)`,
96 WebkitBackdropFilter: `blur(${blurLevels[blurLevels.length - 1]}px)`,
97 maskImage:
98 position === "bottom"
99 ? `linear-gradient(to bottom, rgba(0,0,0,0) 87.5%, rgba(0,0,0,1) 100%)`
100 : position === "top"
101 ? `linear-gradient(to top, rgba(0,0,0,0) 87.5%, rgba(0,0,0,1) 100%)`
102 : `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`,
103 WebkitMaskImage:
104 position === "bottom"
105 ? `linear-gradient(to bottom, rgba(0,0,0,0) 87.5%, rgba(0,0,0,1) 100%)`
106 : position === "top"
107 ? `linear-gradient(to top, rgba(0,0,0,0) 87.5%, rgba(0,0,0,1) 100%)`
108 : `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`,
109 }}
110 />
111 </div>
112 )
113}
114