Skip to content

Commit

Permalink
feat: 이미지 placeholder 추가 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoSelf1 committed Aug 23, 2024
1 parent 5e1f765 commit 256e7a9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ export const handlePhoneNumberChange = (
setValue(formattedNumber);
}
};

// Base64 encoded SVG to use as placeholder
export const toBase64 = (str: string) =>
typeof window === 'undefined'
? Buffer.from(str).toString('base64')
: window.btoa(str);

// SVG shimmer effect
export const shimmer = (w: number, h: number) => `
<svg width="${w}" height="${h}" 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="#333" offset="20%" />
<stop stop-color="#222" offset="50%" />
<stop stop-color="#333" offset="70%" />
</linearGradient>
</defs>
<rect width="${w}" height="${h}" fill="#333" />
<rect id="r" width="${w}" height="${h}" fill="url(#g)" />
<animate xlink:href="#r" attributeName="x" from="-${w}" to="${w}" dur="1s" repeatCount="indefinite" />
</svg>`;

0 comments on commit 256e7a9

Please sign in to comment.