|
1 | 1 | <template> |
2 | 2 | <!-- eslint-disable max-len --> |
3 | | - <div class="ml-auto mr-8 cursor-pointer relative pr-1"> |
4 | | - <img src="../../assets/bell.png" class="w-5"> |
5 | | - <div v-if="notify" class="w-3 h-3 bg-purple-matcha rounded-full absolute right-0 bottom-0 ml-2 pl-1"></div> |
| 3 | + <div class="ml-auto mr-8 relative pr-1 z-50 outline-none" @focusout="close" tabindex="1"> |
| 4 | + <div class="outline-none"> |
| 5 | + <img v-on:click="toggle()" src="../../assets/bell.png" class="w-5 cursor-pointer"> |
| 6 | + <div v-on:click="toggle()" v-if="notify" class="w-3 h-3 bg-purple-matcha cursor-pointer rounded-full absolute right-0 bottom-0 ml-2 pl-1"></div> |
| 7 | + </div> |
| 8 | + <div |
| 9 | + id="notifications" |
| 10 | + v-bind:class="{ |
| 11 | + 'hidden': !showNotifications, |
| 12 | + 'p-4': true, |
| 13 | + 'overflow-scroll': notifications.length > 3, |
| 14 | + 'bg-white': true, |
| 15 | + 'shadow': true, |
| 16 | + 'w-64': true, |
| 17 | + 'h-auto': notifications.length <= 3, |
| 18 | + 'h-48': notifications.length > 3, |
| 19 | + 'absolute': true, |
| 20 | + 'top-0': true, |
| 21 | + 'mt-10': true, |
| 22 | + 'z-50': true, |
| 23 | + 'rounded-md': true}"> |
| 24 | + <div v-for="notification in notifications" :key="notification.id">{{notification.text}}</div> |
| 25 | + </div> |
6 | 26 | </div> |
7 | 27 | </template> |
8 | 28 |
|
9 | 29 | <script> |
10 | 30 | export default { |
11 | 31 | data: () => ({ |
12 | | - notify: false, |
| 32 | + notify: true, |
| 33 | + notifications: [ |
| 34 | + { text: 'Samantha liked you', id: 1 }, |
| 35 | + { text: 'Bae liked you', id: 2 }, |
| 36 | + { text: 'Samantha liked you', id: 3 }, |
| 37 | + { text: 'Bae liked you', id: 4 }, |
| 38 | + { text: 'Samantha liked you', id: 5 }, |
| 39 | + { text: 'Bae liked you', id: 6 }, |
| 40 | + { text: 'Samantha liked you', id: 7 }, |
| 41 | + { text: 'Bae liked you', id: 8 }, |
| 42 | + { text: 'Samantha liked you', id: 9 }, |
| 43 | + { text: 'Bae liked you', id: 10 }, |
| 44 | + ], |
| 45 | + showNotifications: false, |
13 | 46 | }), |
| 47 | + methods: { |
| 48 | + toggle() { |
| 49 | + this.showNotifications = !this.showNotifications; |
| 50 | + }, |
| 51 | + close(event) { |
| 52 | + if (!event.currentTarget.contains(event.relatedTarget)) { |
| 53 | + this.showNotifications = false; |
| 54 | + this.notify = false; |
| 55 | + } |
| 56 | + }, |
| 57 | + }, |
14 | 58 | }; |
15 | 59 | </script> |
| 60 | + |
| 61 | +<style> |
| 62 | +
|
| 63 | +#notifications { |
| 64 | + @apply -ml-64; |
| 65 | +} |
| 66 | +
|
| 67 | +@screen md { |
| 68 | + #notifications { |
| 69 | + @apply ml-0; |
| 70 | + } |
| 71 | +} |
| 72 | +</style> |
0 commit comments