AvatarIcon.vue 2.8 KB

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