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.

UserMenu.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. <NcHeaderMenu id="user-menu"
  24. class="user-menu"
  25. :aria-label="t('core', 'Open settings menu')">
  26. <template #trigger>
  27. <NcAvatar class="user-menu__avatar"
  28. :disable-menu="true"
  29. :disable-tooltip="true"
  30. :user="userId" />
  31. </template>
  32. <nav class="user-menu__nav"
  33. :aria-label="t('core', 'Settings menu')">
  34. <ul>
  35. <UserMenuEntry v-for="entry in settingsNavEntries"
  36. v-bind="entry"
  37. :key="entry.id" />
  38. </ul>
  39. </nav>
  40. </NcHeaderMenu>
  41. </template>
  42. <script>
  43. import { emit } from '@nextcloud/event-bus'
  44. import { getCurrentUser } from '@nextcloud/auth'
  45. import { loadState } from '@nextcloud/initial-state'
  46. import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'
  47. import NcHeaderMenu from '@nextcloud/vue/dist/Components/NcHeaderMenu.js'
  48. import UserMenuEntry from '../components/UserMenu/UserMenuEntry.vue'
  49. const settingsNavEntries = loadState('core', 'settingsNavEntries', [])
  50. export default {
  51. name: 'UserMenu',
  52. components: {
  53. NcAvatar,
  54. NcHeaderMenu,
  55. UserMenuEntry,
  56. },
  57. data() {
  58. return {
  59. settingsNavEntries,
  60. userId: getCurrentUser()?.uid,
  61. }
  62. },
  63. mounted() {
  64. emit('core:user-menu:mounted')
  65. },
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .user-menu {
  70. margin-right: 12px;
  71. &:deep {
  72. .header-menu {
  73. &__trigger {
  74. opacity: 1 !important;
  75. &:focus-visible {
  76. .user-menu__avatar {
  77. border: 2px solid var(--color-primary-element);
  78. }
  79. }
  80. }
  81. &__carret {
  82. display: none !important;
  83. }
  84. &__content {
  85. width: fit-content !important;
  86. }
  87. }
  88. }
  89. &__avatar {
  90. &:active,
  91. &:focus,
  92. &:hover {
  93. border: 2px solid var(--color-primary-element-text);
  94. }
  95. }
  96. &__nav {
  97. display: flex;
  98. width: 100%;
  99. ul {
  100. display: flex;
  101. flex-direction: column;
  102. gap: 2px;
  103. &:deep {
  104. li {
  105. a,
  106. button {
  107. border-radius: 6px;
  108. display: inline-flex;
  109. align-items: center;
  110. height: var(--header-menu-item-height);
  111. color: var(--color-main-text);
  112. padding: 10px 8px;
  113. box-sizing: border-box;
  114. white-space: nowrap;
  115. position: relative;
  116. width: 100%;
  117. &:hover {
  118. background-color: var(--color-background-hover);
  119. }
  120. &:focus-visible {
  121. background-color: var(--color-background-hover) !important;
  122. box-shadow: inset 0 0 0 2px var(--color-primary-element) !important;
  123. outline: none !important;
  124. }
  125. &:active,
  126. &.active {
  127. background-color: var(--color-primary-element-light);
  128. }
  129. span {
  130. padding-bottom: 0;
  131. color: var(--color-main-text);
  132. white-space: nowrap;
  133. overflow: hidden;
  134. text-overflow: ellipsis;
  135. max-width: 110px;
  136. }
  137. img {
  138. width: 16px;
  139. height: 16px;
  140. margin-right: 10px;
  141. }
  142. img,
  143. svg {
  144. opacity: .7;
  145. filter: var(--background-invert-if-dark);
  146. }
  147. }
  148. // Override global button styles
  149. button {
  150. background-color: transparent;
  151. border: none;
  152. font-weight: normal;
  153. margin: 0;
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. </style>