Gooey SVG Filter
An svg filter component that creates a gooey effect on the background. Can be used to create fluid interfaces or rounded-at-all-corners panels. Limited support for Safari.
- learning-to-meditate.md
- spring-garden-plans.md
- travel-wishlist.md
- new-coding-projects.md
Installation
npx shadcn@latest add "https://fancycomponents.dev/r/gooey-svg-filter.json"
Usage
Add the GooeySvgFilter
component to your project, pass an id
prop to the component (optional), then use the same id
prop in the filter
CSS property of the container you want to apply the filter to. High-level example:
<GooeySvgFilter id="gooey-filter" />
<div style={{ filter: "url(#gooey-filter)" }}>
filter will be applied here
</div>
Understanding the component
The filter is surprisingly simple. First, we apply a blur, which makes closer element to 'bleed' or blur into each other. Then, we just increase the contrast of our alpha channel with a color matrix. Lastly, we composite these two layers together with an atop
operator, which will mask out anything outside the filter.
Please refer to this article by Lucas Bebber for more details. The entire component is derived from this work, and Lucas does a much better job explaining the filter than I do:).
Examples
Fluid interface
Open the menu in the top left corner
Rounded corners
The following example combines the PixelTrail component with this svg filter to create a rounded-at-all-corners effect. Unfortunately, the component doesn't support Safari, so you'll need to create a fallback for that.
Speaking things into existence
Notes
- Safari support for SVG filters is still very limited, so make sure to check compatibility, and create fallbacks (in the demos above, you can also see that the motion is disabled for Safari). For a fully supported solution, your best bet is to create a shader instead. Let us know if you would like to see a component for that!
- Keep a large enough space for the filter to avoid clipping.
Props
Prop | Type | Default | Description |
---|---|---|---|
id | string | - | The id of the filter |
strength | number | 15 | The strength of the gooey effect |
Credits
The component is derived from this article by Lucas Bebber.