You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserMenuEntry.vue 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!--
  2. - @copyright 2023 Christopher Ng <chrng8@gmail.com>
  3. -
  4. - @author Christopher Ng <chrng8@gmail.com>
  5. -
  6. - @license AGPL-3.0-or-later
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -
  21. -->
  22. <template>
  23. <li :id="id"
  24. class="menu-entry">
  25. <a v-if="href"
  26. :href="href"
  27. :class="{ active }"
  28. @click.exact="handleClick">
  29. <NcLoadingIcon v-if="loading"
  30. class="menu-entry__loading-icon"
  31. :size="18" />
  32. <img v-else :src="cachedIcon" alt="">
  33. {{ name }}
  34. </a>
  35. <button v-else>
  36. <img :src="cachedIcon" alt="">
  37. {{ name }}
  38. </button>
  39. </li>
  40. </template>
  41. <script>
  42. import { loadState } from '@nextcloud/initial-state'
  43. import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
  44. const versionHash = loadState('core', 'versionHash', '')
  45. export default {
  46. name: 'UserMenuEntry',
  47. components: {
  48. NcLoadingIcon,
  49. },
  50. props: {
  51. id: {
  52. type: String,
  53. required: true,
  54. },
  55. name: {
  56. type: String,
  57. required: true,
  58. },
  59. href: {
  60. type: String,
  61. required: true,
  62. },
  63. active: {
  64. type: Boolean,
  65. required: true,
  66. },
  67. icon: {
  68. type: String,
  69. required: true,
  70. },
  71. },
  72. data() {
  73. return {
  74. loading: false,
  75. }
  76. },
  77. computed: {
  78. cachedIcon() {
  79. return `${this.icon}?v=${versionHash}`
  80. },
  81. },
  82. methods: {
  83. handleClick() {
  84. this.loading = true
  85. },
  86. },
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .menu-entry {
  91. &__loading-icon {
  92. margin-right: 8px;
  93. }
  94. }
  95. </style>