Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/ui/user-icon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import UserDefaultIcon from './user-default-icon.svelte'

export { UserDefaultIcon }
33 changes: 33 additions & 0 deletions src/components/ui/user-icon/user-default-icon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts">
export const firstname: string = 'Nomen'
export const lastname: string = 'Nescio'

function hashCode(str: string) {
let hash = 0
for (let i = 0, len = str.length; i < len; i++) {
let chr = str.charCodeAt(i)
hash = (hash << 3) - hash + chr
hash |= 0
}

return Math.abs(hash)
}

function generateColor(firstname: string, lastname: string) {
const hue = hashCode(firstname + lastname) % 360
const saturation = 40
const lightness = 55

return `hsl(${hue},${saturation}%,${lightness}%)`
}

const backgroundColor = generateColor(firstname, lastname)
const initials = `${firstname.charAt(0).toUpperCase()}${lastname.charAt(0).toUpperCase()}`
</script>

<div
class="text- flex h-10 w-10 items-center justify-center rounded-full text-xl"
style="background-color: {backgroundColor};"
>
{initials}
</div>