-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds blur placeholders to images
- Loading branch information
Showing
7 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const shimmerSvg = (width: number, height: number) => ` | ||
<svg width="${width}" height="${height}" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
<defs> | ||
<linearGradient id="g"> | ||
<stop stop-color="rgba(100, 100, 100, 0.2)" offset="20%" /> | ||
<stop stop-color="rgba(100, 100, 100, 0.5)" offset="50%" /> | ||
<stop stop-color="rgba(100, 100, 100, 0.2)" offset="70%" /> | ||
</linearGradient> | ||
</defs> | ||
<rect width="${width}" height="${height}" fill="rgba(100, 100, 100, 0.2)" /> | ||
<rect id="r" width="${width}" height="${height}" fill="url(#g)" /> | ||
<animate xlink:href="#r" attributeName="x" from="-${width}" to="${width}" dur="1s" repeatCount="indefinite" /> | ||
</svg>`; | ||
|
||
const toBase64 = (str: string) => | ||
typeof window === 'undefined' | ||
? Buffer.from(str).toString('base64') | ||
: window.btoa(str); | ||
|
||
export const shimmer = (width: number, height: number) => { | ||
return `data:image/svg+xml;base64,${toBase64(shimmerSvg(width, height))}`; | ||
}; |