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
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
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Debitis, quaerat ab? Rerum facilis dignissimos voluptatum!
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Debitis, quaerat ab? Rerum facilis dignissimos voluptatum!
1import React, { createContext, useContext } from 'react';2import { cn } from '@/lib/utils';3interface BlurVignetteContextProps {4radius?: string;5inset?: string;6transitionLength?: string;7blur?: string;8}910const BlurVignetteContext = createContext<BlurVignetteContextProps>({11radius: '24px',12inset: '20px',13transitionLength: '44px',14blur: '6px',15});1617export const useBlurVignetteContext = () => useContext(BlurVignetteContext);1819interface BlurVignetteProps {20classname?: string;21children: React.ReactNode;22radius?: string;23inset?: string;24transitionLength?: string;25blur?: string;26blurclassname?: string;27}2829export const BlurVignette: React.FC<BlurVignetteProps> = ({30classname,31children,32radius = '24px',33inset = '20px',34transitionLength = '44px',35blur = '6px',36}) => {37return (38<BlurVignetteContext.Provider39value={{ radius, inset, transitionLength, blur }}40>41<div42className={cn('relative aspect-square overflow-hidden', classname)}43style={{ borderRadius: radius }}44>45{children}46</div>47</BlurVignetteContext.Provider>48);49};50interface BlurVignetteArticleProps {51children?: React.ReactNode;52classname?: string;53}5455export const BlurVignetteArticle: React.FC<BlurVignetteArticleProps> = ({56children,57classname,58}) => {59const { radius, inset, transitionLength, blur } = useBlurVignetteContext();6061return (62<div63className={cn(64'blur-vignette bottom-0 left-0 w-full h-full z-[1]',65classname66)}67style={68{69'--radius': radius,70'--inset': inset,71'--transition-length': transitionLength,72'--blur': blur,73} as React.CSSProperties74}75>76{children}77</div>78);79};
@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;}}
Prop | Type | Default | Description |
---|---|---|---|
classname | string | Optional CSS class for styling the main vignette container. | |
children | React.ReactNode | The content to display inside the vignette effect. | |
radius | string | 24px | The radius for the vignette effect. |
inset | string | 20px | The inset value for the vignette effect. |
transitionLength | string | 44px | The length of the transition effect applied to the vignette. |
blur | string | 6px | The blur amount for the vignette effect. |
blurclassname | string | Optional CSS class for styling the blur effect container. |