AvatarIcon.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <info-tooltip class='avatar_icon' @hover='loadUser' :noEvents='user === null'>
  3. <template slot='content'>
  4. <template v-if='ajaxUser'>
  5. <div class='avatar_icon__header'>
  6. <div
  7. class='avatar_icon__icon avatar_icon__icon--small picture_circle'
  8. :style='{
  9. "background-color": user.color,
  10. "background-image": user.picture ? "url(" + user.picture + ")" : null,
  11. }'
  12. @click='goToUser'
  13. >
  14. {{userLetter}}
  15. </div>
  16. <div class='avatar_icon__header_info'>
  17. <span class='avatar_icon__username' @click.stop='goToUser'>{{ajaxUser.username}}</span>
  18. <span class='avatar_icon__date'>Created: {{ajaxUser.createdAt | formatDate('date') }}</span>
  19. </div>
  20. </div>
  21. <div class='avatar_icon__description' v-if='ajaxUser.description'>
  22. {{ajaxUser.description}}
  23. </div>
  24. </template>
  25. <template v-else>Loading...</template>
  26. </template>
  27. <div
  28. slot='display'
  29. class='avatar_icon__icon picture_circle'
  30. :class='{"avatar_icon__icon--small": size === "small"}'
  31. :style='{ "background-color": userColor, "background-image": userPicture, }'
  32. @click.stop='goToUser'
  33. >
  34. {{userLetter}}
  35. </div>
  36. </info-tooltip>
  37. </template>
  38. <script>
  39. import InfoTooltip from './InfoTooltip'
  40. import AjaxErrorHandler from '../assets/js/errorHandler'
  41. export default {
  42. name: 'AvatarIcon',
  43. props: ['user', 'size'],
  44. components: { InfoTooltip },
  45. data () {
  46. return {
  47. ajaxUser: null
  48. }
  49. },
  50. computed: {
  51. userLetter () {
  52. if(this.user) {
  53. if(this.userPicture) {
  54. return ''
  55. } else {
  56. return this.user.username[0].toUpperCase()
  57. }
  58. } else {
  59. return ''
  60. }
  61. },
  62. userColor () {
  63. if(this.user) {
  64. return this.user.color
  65. } else {
  66. return null
  67. }
  68. },
  69. userPicture () {
  70. if(this.user && this.user.picture) {
  71. return "url(" + this.user.picture + ")"
  72. } else {
  73. return null
  74. }
  75. }
  76. },
  77. methods: {
  78. loadUser () {
  79. if(this.ajaxUser || this.user === null) return
  80. this.axios
  81. .get('/api/v1/user/' + this.user.username)
  82. .then((res) => {
  83. this.ajaxUser = res.data
  84. })
  85. .catch(AjaxErrorHandler(this.$store))
  86. },
  87. goToUser () {
  88. if(this.user === null) return
  89. this.$router.push('/user/' + this.user.username)
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang='scss'>
  95. @import '../assets/scss/variables.scss';
  96. .avatar_icon {
  97. @at-root #{&}__icon {
  98. font-size: 0.7rem;
  99. margin-right: 0.25rem;
  100. color: rgba(0, 0, 0, 0.87);
  101. }
  102. @at-root #{&}__header {
  103. display: flex;
  104. align-items: center;
  105. }
  106. @at-root #{&}__icon {
  107. height: 3rem;
  108. width: 3rem;
  109. line-height: 3rem;
  110. cursor: pointer;
  111. @include text($font--role-emphasis, 2rem)
  112. text-align: center;
  113. border-radius: 100%;
  114. background-color: $color__gray--darkest;
  115. color: #fff;
  116. @at-root #{&}--small {
  117. height: 2.5rem;
  118. width: 2.5rem;
  119. font-size: 1.75rem;
  120. line-height: 2.5rem;
  121. }
  122. }
  123. @at-root #{&}__header_info {
  124. display: flex;
  125. flex-direction: column;
  126. height: 2.5rem;
  127. }
  128. @at-root #{&}__username {
  129. cursor: pointer;
  130. }
  131. @at-root #{&}__date {
  132. color: $color__gray--darkest;
  133. font-size: 0.9rem;
  134. }
  135. @at-root #{&}__description {
  136. margin-top: 0.25rem;
  137. font-size: 0.9rem;
  138. }
  139. }
  140. </style>