File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
src/components/ui/user-icon Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import UserDefaultIcon from './user-default-icon.svelte'
2+
3+ export { UserDefaultIcon }
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ export const firstname: string = ' Nomen'
3+ export const lastname: string = ' Nescio'
4+
5+ function hashCode(str : string ) {
6+ let hash = 0
7+ for (let i = 0 , len = str .length ; i < len ; i ++ ) {
8+ let chr = str .charCodeAt (i )
9+ hash = (hash << 3 ) - hash + chr
10+ hash |= 0
11+ }
12+
13+ return Math .abs (hash )
14+ }
15+
16+ function generateColor(firstname : string , lastname : string ) {
17+ const hue = hashCode (firstname + lastname ) % 360
18+ const saturation = 40
19+ const lightness = 55
20+
21+ return ` hsl(${hue },${saturation }%,${lightness }%) `
22+ }
23+
24+ const backgroundColor = generateColor (firstname , lastname )
25+ const initials = ` ${firstname .charAt (0 ).toUpperCase ()}${lastname .charAt (0 ).toUpperCase ()} `
26+ </script >
27+
28+ <div
29+ class =" text- flex h-10 w-10 items-center justify-center rounded-full text-xl"
30+ style ="background-color: {backgroundColor };"
31+ >
32+ {initials }
33+ </div >
You can’t perform that action at this time.
0 commit comments