ProfilePicture.vue 1.9 KB

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