AvatarIcon.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <info-tooltip class='avatar_icon' @hover='loadUser'>
  3. <template slot='content'>
  4. <template v-if='ajaxUser'>
  5. {{ajaxUser.username}}
  6. </template>
  7. <template v-else>Loading...</template>
  8. </template>
  9. <div
  10. slot='display'
  11. class='avatar_icon__icon'
  12. :style='{ "background-color": user.color }'
  13. @click='$emit("click")'
  14. >
  15. {{user.username[0]}}
  16. </div>
  17. </info-tooltip>
  18. </template>
  19. <script>
  20. import InfoTooltip from './InfoTooltip'
  21. import AjaxErrorHandler from '../assets/js/errorHandler'
  22. export default {
  23. name: 'AvatarIcon',
  24. props: ['user'],
  25. components: { InfoTooltip },
  26. data () {
  27. return {
  28. ajaxUser: null
  29. }
  30. },
  31. methods: {
  32. loadUser () {
  33. if(this.ajaxUser) return
  34. this.axios
  35. .get('/api/v1/user/' + this.user.id)
  36. .then((res) => {
  37. this.ajaxUser = res.data
  38. })
  39. .catch(AjaxErrorHandler(this.$store))
  40. }
  41. }
  42. }
  43. </script>
  44. <style lang='scss'>
  45. @import '../assets/scss/variables.scss';
  46. .avatar_icon {
  47. @at-root #{&}__icon {
  48. font-size: 0.7rem;
  49. margin-right: 0.25rem;
  50. color: rgba(0, 0, 0, 0.87);
  51. }
  52. @at-root #{&}__date {
  53. display: inline-block;
  54. color: $color__gray--darkest;
  55. font-size: 0.8rem;
  56. }
  57. @at-root #{&}__username {
  58. display: inline-block;
  59. font-size: 0.9rem;
  60. color: #000;
  61. }
  62. @at-root #{&}__content {
  63. *:first-child, *:last-child {
  64. margin: 0;
  65. }
  66. p {
  67. margin: 0.25rem 0;
  68. }
  69. }
  70. @at-root #{&}__icon {
  71. height: 3rem;
  72. width: 3rem;
  73. line-height: 3rem;
  74. @include text($font--role-emphasis, 2rem)
  75. text-align: center;
  76. border-radius: 100%;
  77. background-color: $color__gray--darkest;
  78. color: #fff;
  79. }
  80. }
  81. </style>