SideMenu.vue
233 lines
| 1 | <template> |
| 2 | <div role="navigation" aria-label="Catalog categories" class="am-cat__sidemenu" :style="cssVars"> |
| 3 | <div class="am-cat__sidemenu-item__wrapper" role="group"> |
| 4 | <div |
| 5 | v-for="(item, index) in menuItems" |
| 6 | :key="index" |
| 7 | class="am-cat__sidemenu-item" |
| 8 | role="button" |
| 9 | tabindex="0" |
| 10 | :aria-current="isItemSelected(item) ? 'true' : undefined" |
| 11 | :aria-label="getItemLabel(item)" |
| 12 | :class="{ 'am-active': isItemSelected(item) }" |
| 13 | @click="() => selectItem(item)" |
| 14 | @keydown.enter.prevent="selectItem(item)" |
| 15 | @keydown.space.prevent="selectItem(item)" |
| 16 | @keydown.down.prevent="focusSideMenuItem($event, index + 1)" |
| 17 | @keydown.up.prevent="focusSideMenuItem($event, index - 1)" |
| 18 | @keydown.home.prevent="focusSideMenuItem($event, 0)" |
| 19 | @keydown.end.prevent="focusSideMenuItem($event, menuItems.length - 1)" |
| 20 | > |
| 21 | {{ item[props.nameIdentifier] }} |
| 22 | </div> |
| 23 | </div> |
| 24 | <div v-if="props.companyEmail" class="am-cat__sidemenu-footer"> |
| 25 | <span class="am-cat__sidemenu-footer__text"> |
| 26 | {{ props.footerString }} |
| 27 | </span> |
| 28 | <a class="am-cat__sidemenu-footer__email" :href="`mailto:${props.companyEmail}`"> |
| 29 | {{ props.companyEmail }} |
| 30 | </a> |
| 31 | </div> |
| 32 | </div> |
| 33 | </template> |
| 34 | |
| 35 | <script setup> |
| 36 | import { computed, inject } from 'vue' |
| 37 | import { useColorTransparency } from '../../../../assets/js/common/colorManipulation' |
| 38 | |
| 39 | let props = defineProps({ |
| 40 | menuItems: { |
| 41 | type: Array, |
| 42 | required: true, |
| 43 | }, |
| 44 | initSelection: { |
| 45 | type: [String, Number], |
| 46 | }, |
| 47 | identifier: { |
| 48 | type: String, |
| 49 | required: true, |
| 50 | }, |
| 51 | nameIdentifier: { |
| 52 | type: String, |
| 53 | required: true, |
| 54 | }, |
| 55 | footerString: { |
| 56 | type: String, |
| 57 | default: '', |
| 58 | }, |
| 59 | companyEmail: { |
| 60 | type: String, |
| 61 | default: '', |
| 62 | }, |
| 63 | }) |
| 64 | let emits = defineEmits(['click']) |
| 65 | |
| 66 | function selectItem(item) { |
| 67 | emits('click', item) |
| 68 | } |
| 69 | |
| 70 | function isItemSelected(item) { |
| 71 | return props.initSelection === item[props.identifier] |
| 72 | } |
| 73 | |
| 74 | function getItemLabel(item) { |
| 75 | return item[props.nameIdentifier] |
| 76 | } |
| 77 | |
| 78 | function focusSideMenuItem(event, index) { |
| 79 | let items = event.currentTarget.parentElement.querySelectorAll('.am-cat__sidemenu-item') |
| 80 | let targetIndex = index |
| 81 | |
| 82 | if (targetIndex < 0) { |
| 83 | targetIndex = items.length - 1 |
| 84 | } |
| 85 | |
| 86 | if (targetIndex >= items.length) { |
| 87 | targetIndex = 0 |
| 88 | } |
| 89 | |
| 90 | items[targetIndex].focus() |
| 91 | } |
| 92 | |
| 93 | // * Colors |
| 94 | let amColors = inject('amColors') |
| 95 | |
| 96 | let cssVars = computed(() => { |
| 97 | return { |
| 98 | '--am-c-csm-text-op10': useColorTransparency(amColors.value.colorSbText, 0.1), |
| 99 | '--am-c-csm-primary-op10': useColorTransparency(amColors.value.colorPrimary, 0.1), |
| 100 | '--am-c-csm-text-op60': useColorTransparency(amColors.value.colorSbText, 0.6), |
| 101 | '--am-c-csm-text-op80': useColorTransparency(amColors.value.colorSbText, 0.8), |
| 102 | } |
| 103 | }) |
| 104 | </script> |
| 105 | |
| 106 | <script> |
| 107 | export default { |
| 108 | name: 'SideMenu', |
| 109 | } |
| 110 | </script> |
| 111 | |
| 112 | <style lang="scss"> |
| 113 | @mixin catalog-sidebar { |
| 114 | // am- amelia |
| 115 | // -c- color |
| 116 | // -csm- category side menu |
| 117 | // -bgr background |
| 118 | .am-cat { |
| 119 | &__sidemenu { |
| 120 | --am-c-csm-bgr: var(--am-c-sb-bgr); |
| 121 | --am-c-csm-text: var(--am-c-sb-text); |
| 122 | --am-c-csm-primary: var(--am-c-primary); |
| 123 | |
| 124 | width: 100%; |
| 125 | max-width: 208px; |
| 126 | position: relative; |
| 127 | display: flex; |
| 128 | flex-direction: column; |
| 129 | background-color: var(--am-c-csm-bgr); |
| 130 | border-radius: 6px; |
| 131 | margin: 0 12px 0 0; |
| 132 | padding: 0 0 80px; |
| 133 | |
| 134 | &-item { |
| 135 | font-size: 14px; |
| 136 | font-weight: 500; |
| 137 | line-height: 1.42857; |
| 138 | text-overflow: ellipsis; |
| 139 | overflow: hidden; |
| 140 | white-space: nowrap; |
| 141 | color: var(--am-c-csm-text); |
| 142 | padding: 12px 8px; |
| 143 | margin: 0 0 2px; |
| 144 | border-radius: 6px; |
| 145 | cursor: pointer; |
| 146 | transition: all 0.2s ease-in-out; |
| 147 | |
| 148 | &:last-child { |
| 149 | margin-bottom: 0; |
| 150 | } |
| 151 | |
| 152 | &:hover { |
| 153 | background-color: var(--am-c-csm-text-op10); |
| 154 | } |
| 155 | |
| 156 | &:focus-visible { |
| 157 | outline: 2px solid var(--am-c-csm-primary); |
| 158 | outline-offset: 2px; |
| 159 | background-color: var(--am-c-csm-text-op10); |
| 160 | } |
| 161 | |
| 162 | &.am-active { |
| 163 | color: var(--am-c-csm-primary); |
| 164 | background-color: var(--am-c-csm-primary-op10); |
| 165 | } |
| 166 | |
| 167 | &__wrapper { |
| 168 | margin: 8px; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | &-footer { |
| 173 | width: 100%; |
| 174 | position: absolute; |
| 175 | bottom: 0; |
| 176 | left: 0; |
| 177 | display: flex; |
| 178 | flex-direction: column; |
| 179 | align-items: center; |
| 180 | justify-content: center; |
| 181 | |
| 182 | &__text { |
| 183 | display: -webkit-box; |
| 184 | line-clamp: 2; |
| 185 | -webkit-line-clamp: 2; |
| 186 | -webkit-box-orient: vertical; |
| 187 | overflow: hidden; |
| 188 | text-overflow: ellipsis; |
| 189 | text-align: center; |
| 190 | font-size: 14px; |
| 191 | font-weight: 500; |
| 192 | line-height: 1.428571; |
| 193 | color: var(--am-c-csm-text-op60); |
| 194 | } |
| 195 | |
| 196 | &__email { |
| 197 | display: -webkit-box; |
| 198 | line-clamp: 2; |
| 199 | -webkit-line-clamp: 2; |
| 200 | -webkit-box-orient: vertical; |
| 201 | overflow: hidden; |
| 202 | text-overflow: ellipsis; |
| 203 | text-align: center; |
| 204 | color: var(--am-c-csm-text-op80); |
| 205 | text-decoration: none; |
| 206 | font-size: 14px; |
| 207 | font-weight: 400; |
| 208 | line-height: 1.428571; |
| 209 | |
| 210 | &:hover { |
| 211 | color: var(--am-c-csm-text); |
| 212 | } |
| 213 | |
| 214 | &:focus-visible { |
| 215 | color: var(--am-c-csm-text); |
| 216 | outline: 2px solid var(--am-c-csm-primary); |
| 217 | outline-offset: 2px; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | .amelia-v2-booking #amelia-container { |
| 226 | @include catalog-sidebar; |
| 227 | } |
| 228 | |
| 229 | #amelia-app-backend-new #amelia-container { |
| 230 | @include catalog-sidebar; |
| 231 | } |
| 232 | </style> |
| 233 |