ProfilePicture.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <script setup lang="ts">
  2. import { ref, computed, onMounted } from "vue";
  3. const props = defineProps({
  4. avatar: {
  5. type: Object,
  6. default: () => {}
  7. },
  8. name: {
  9. type: String,
  10. default: ": )"
  11. }
  12. });
  13. const notes = ref("");
  14. const initials = computed(() =>
  15. props.name
  16. .replaceAll(/[^A-Za-z ]+/g, "")
  17. .replaceAll(/ +/g, " ")
  18. .split(" ")
  19. .map(word => word.charAt(0))
  20. .splice(0, 2)
  21. .join("")
  22. .toUpperCase()
  23. );
  24. onMounted(async () => {
  25. const frontendDomain = await lofig.get("frontendDomain");
  26. notes.value = encodeURI(`${frontendDomain}/assets/notes.png`);
  27. });
  28. </script>
  29. <template>
  30. <img
  31. class="profile-picture using-gravatar"
  32. v-if="avatar.type === 'gravatar'"
  33. :src="
  34. avatar.url ? `${avatar.url}?d=${notes}&s=250` : '/assets/notes.png'
  35. "
  36. onerror="this.src='/assets/notes.png'; this.onerror=''"
  37. />
  38. <div class="profile-picture using-initials" :class="avatar.color" v-else>
  39. <span>{{ initials }}</span>
  40. </div>
  41. </template>
  42. <style lang="less" scoped>
  43. .profile-picture {
  44. width: 100px;
  45. height: 100px;
  46. border-radius: 100%;
  47. border: 0.5px solid var(--light-grey-3);
  48. &.using-initials {
  49. display: flex;
  50. align-items: center;
  51. justify-content: center;
  52. background-color: var(--light-grey-2);
  53. font-family: "Inter", sans-serif;
  54. font-weight: 400;
  55. user-select: none;
  56. -webkit-user-select: none;
  57. span {
  58. font-size: 40px; // 2/5th of .profile-picture height/width
  59. }
  60. &.blue {
  61. background-color: var(--blue);
  62. color: var(--white);
  63. }
  64. &.orange {
  65. background-color: var(--orange);
  66. color: var(--white);
  67. }
  68. &.green {
  69. background-color: var(--green);
  70. color: var(--white);
  71. }
  72. &.purple {
  73. background-color: var(--purple);
  74. color: var(--white);
  75. }
  76. &.teal {
  77. background-color: var(--teal);
  78. color: var(--white);
  79. }
  80. &.grey {
  81. background-color: var(--grey);
  82. color: var(--white);
  83. }
  84. }
  85. }
  86. </style>