Blur Vignette Effect

Apple Vision Pro like Blur Effect, we can use it in images, video, card etc. lets make something great with this component

Read Docs to know more Blur Vignette

Video

Card

grid
grid

Image

grid

UiLayout

Lorem, ipsum dolor sit amet consectetur adipisicing elit. Debitis, quaerat ab? Rerum facilis dignissimos voluptatum!

grid

UiLayout

Lorem, ipsum dolor sit amet consectetur adipisicing elit. Debitis, quaerat ab? Rerum facilis dignissimos voluptatum!

Usage

blur-vignette.tsx
1
import React, { createContext, useContext } from 'react';
2
import { cn } from '@/lib/utils';
3
interface BlurVignetteContextProps {
4
radius?: string;
5
inset?: string;
6
transitionLength?: string;
7
blur?: string;
8
}
9
10
const BlurVignetteContext = createContext<BlurVignetteContextProps>({
11
radius: '24px',
12
inset: '20px',
13
transitionLength: '44px',
14
blur: '6px',
15
});
16
17
export const useBlurVignetteContext = () => useContext(BlurVignetteContext);
18
19
interface BlurVignetteProps {
20
classname?: string;
21
children: React.ReactNode;
22
radius?: string;
23
inset?: string;
24
transitionLength?: string;
25
blur?: string;
26
blurclassname?: string;
27
}
28
29
export const BlurVignette: React.FC<BlurVignetteProps> = ({
30
classname,
31
children,
32
radius = '24px',
33
inset = '20px',
34
transitionLength = '44px',
35
blur = '6px',
36
}) => {
37
return (
38
<BlurVignetteContext.Provider
39
value={{ radius, inset, transitionLength, blur }}
40
>
41
<div
42
className={cn('relative aspect-square overflow-hidden', classname)}
43
style={{ borderRadius: radius }}
44
>
45
{children}
46
</div>
47
</BlurVignetteContext.Provider>
48
);
49
};
50
interface BlurVignetteArticleProps {
51
children?: React.ReactNode;
52
classname?: string;
53
}
54
55
export const BlurVignetteArticle: React.FC<BlurVignetteArticleProps> = ({
56
children,
57
classname,
58
}) => {
59
const { radius, inset, transitionLength, blur } = useBlurVignetteContext();
60
61
return (
62
<div
63
className={cn(
64
'blur-vignette bottom-0 left-0 w-full h-full z-[1]',
65
classname
66
)}
67
style={
68
{
69
'--radius': radius,
70
'--inset': inset,
71
'--transition-length': transitionLength,
72
'--blur': blur,
73
} as React.CSSProperties
74
}
75
>
76
{children}
77
</div>
78
);
79
};
globals.css
@layer utilities {
.blur-vignette {
position: absolute;
inset: 0;
border-radius: var(--radius);
-webkit-backdrop-filter: blur(var(--blur));
backdrop-filter: blur(var(--blur));
--r: max(var(--transition-length), calc(var(--radius) - var(--inset)));
--corner-size: calc(var(--r) + var(--inset)) calc(var(--r) + var(--inset));
--corner-gradient: transparent 0px,
transparent calc(var(--r) - var(--transition-length)), black var(--r);
--fill-gradient: black, black var(--inset),
transparent calc(var(--inset) + var(--transition-length)),
transparent calc(100% - var(--transition-length) - var(--inset)),
black calc(100% - var(--inset));
--fill-narrow-size: calc(100% - (var(--inset) + var(--r)) * 2);
--fill-farther-position: calc(var(--inset) + var(--r));
-webkit-mask-image: linear-gradient(to right, var(--fill-gradient)),
linear-gradient(to bottom, var(--fill-gradient)),
radial-gradient(at bottom right, var(--corner-gradient)),
radial-gradient(at bottom left, var(--corner-gradient)),
radial-gradient(at top left, var(--corner-gradient)),
radial-gradient(at top right, var(--corner-gradient));
-webkit-mask-size:
100% var(--fill-narrow-size),
var(--fill-narrow-size) 100%,
var(--corner-size),
var(--corner-size),
var(--corner-size),
var(--corner-size);
-webkit-mask-position:
0 var(--fill-farther-position),
var(--fill-farther-position) 0,
0 0,
100% 0,
100% 100%,
0 100%;
-webkit-mask-repeat: no-repeat;
}
}

Props

PropTypeDefaultDescription
classnamestringOptional CSS class for styling the main vignette container.
childrenReact.ReactNodeThe content to display inside the vignette effect.
radiusstring24pxThe radius for the vignette effect.
insetstring20pxThe inset value for the vignette effect.
transitionLengthstring44pxThe length of the transition effect applied to the vignette.
blurstring6pxThe blur amount for the vignette effect.
blurclassnamestringOptional CSS class for styling the blur effect container.