2021-04-21 14:09:36 +02:00
|
|
|
<script>
|
2021-04-23 09:41:49 +02:00
|
|
|
import "@spectrum-css/avatar/dist/index-vars.css"
|
2021-05-05 10:43:06 +02:00
|
|
|
let sizes = new Map([
|
|
|
|
["XXS", "--spectrum-alias-avatar-size-50"],
|
|
|
|
["XS", "--spectrum-alias-avatar-size-75"],
|
|
|
|
["S", "--spectrum-alias-avatar-size-200"],
|
|
|
|
["M", "--spectrum-alias-avatar-size-300"],
|
|
|
|
["L", "--spectrum-alias-avatar-size-500"],
|
|
|
|
["XL", "--spectrum-alias-avatar-size-600"],
|
|
|
|
["XXL", "--spectrum-alias-avatar-size-700"],
|
|
|
|
])
|
|
|
|
export let size = "M"
|
2021-04-23 09:41:49 +02:00
|
|
|
export let url = ""
|
|
|
|
export let disabled = false
|
2021-05-05 11:00:04 +02:00
|
|
|
export let name = "John Doe"
|
|
|
|
|
|
|
|
function getInitials(name) {
|
|
|
|
let parts = name.split(" ")
|
2021-05-14 17:04:20 +02:00
|
|
|
if (parts.length > 0) {
|
|
|
|
return parts.map(name => name[0]).join("")
|
|
|
|
}
|
|
|
|
return name
|
2021-05-05 11:00:04 +02:00
|
|
|
}
|
2021-04-21 14:09:36 +02:00
|
|
|
</script>
|
|
|
|
|
2021-05-05 09:12:25 +02:00
|
|
|
{#if url}
|
|
|
|
<img
|
|
|
|
class:is-disabled={disabled}
|
|
|
|
class="spectrum-Avatar"
|
|
|
|
src={url}
|
|
|
|
alt="Avatar"
|
2021-05-05 10:43:06 +02:00
|
|
|
style="width: var({sizes.get(size)}); height: var({sizes.get(size)});"
|
2021-05-05 09:12:25 +02:00
|
|
|
/>
|
|
|
|
{:else}
|
2021-05-05 10:44:50 +02:00
|
|
|
<div
|
2021-05-05 11:00:04 +02:00
|
|
|
class:is-disabled={disabled}
|
2021-05-05 10:44:50 +02:00
|
|
|
style="width: var({sizes.get(size)}); height: var({sizes.get(
|
|
|
|
size
|
|
|
|
)}); font-size: calc(var({sizes.get(size)}) / 2)"
|
|
|
|
>
|
2021-05-05 11:00:04 +02:00
|
|
|
{getInitials(name)}
|
2021-05-05 10:43:06 +02:00
|
|
|
</div>
|
2021-05-05 09:12:25 +02:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
color: white;
|
|
|
|
display: grid;
|
|
|
|
place-items: center;
|
2021-05-05 11:00:04 +02:00
|
|
|
font-weight: 500;
|
2021-05-06 11:49:04 +02:00
|
|
|
background: #3aab87;
|
2021-05-05 09:12:25 +02:00
|
|
|
border-radius: 50%;
|
2021-05-05 10:44:50 +02:00
|
|
|
overflow: hidden;
|
2021-05-05 11:00:04 +02:00
|
|
|
user-select: none;
|
2021-05-05 09:12:25 +02:00
|
|
|
}
|
|
|
|
</style>
|