NotificationButton.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class='notification_button'>
  3. <div
  4. class='notification_button__overlay'
  5. :class='{ "notification_button__overlay--show" : showMenu}'
  6. @click='setShowMenu(false)'
  7. ></div>
  8. <button class='button notification_button__button' @click='setShowMenu(!showMenu)'>
  9. <span>Notifications</span>
  10. <span
  11. class='notification_button__button__count'
  12. :class='{
  13. "notification_button__button__count--none": !count,
  14. "notification_button__button__count--two_figure": count > 9,
  15. "notification_button__button__count--three_figure": count > 99
  16. }'
  17. >{{countText}}</span>
  18. </button>
  19. <div
  20. class='notification_button__menu_group'
  21. :class='{ "notification_button__menu_group--show" : showMenu}'
  22. >
  23. <div class='notification_button__big_triangle'></div>
  24. <div
  25. class='notification_button__small_triangle'
  26. :class='{ "notification_button__small_triangle--empty": !notifications.length}'
  27. ></div>
  28. <div class='notification_button__menu'>
  29. <div v-for='notification in notifications' class='notification_button__menu__item'>qwertyuiopasdfghjkl</div>
  30. <div class='notification_button__menu__empty' v-if='!notifications.length'>
  31. <span>{{emojis[emojiIndex % 6]}}</span>
  32. No notifications
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. name: 'NotificationButton',
  41. data () {
  42. return {
  43. count: 3,
  44. notifications: [],
  45. showMenu: false,
  46. emojis: ['😢', '🤷', '😘', '😒', '😔', '💩'],
  47. emojiIndex: Math.round(Math.random()*5)
  48. }
  49. },
  50. computed: {
  51. countText () {
  52. if(this.count > 99) {
  53. return '99+'
  54. } else {
  55. return this.count
  56. }
  57. }
  58. },
  59. methods: {
  60. setShowMenu (val) {
  61. this.showMenu = val
  62. if(!val) {
  63. setTimeout(_ => {
  64. this.emojiIndex++
  65. }, 200)
  66. }
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang='scss' scoped>
  72. @import '../assets/scss/variables.scss';
  73. .notification_button {
  74. position: relative;
  75. @at-root #{&}__overlay {
  76. width: 100%;
  77. height: 100%;
  78. top: 0;
  79. left: 0;
  80. position: fixed;
  81. z-index: 5;
  82. pointer-events: none;
  83. @at-root #{&}--show {
  84. pointer-events: all;
  85. }
  86. }
  87. @at-root #{&}__menu_group {
  88. position: relative;
  89. top: -3rem;
  90. pointer-events: none;
  91. opacity: 0;
  92. transition: opacity 0.2s, top 0.2s;
  93. @at-root #{&}--show {
  94. pointer-events: all;
  95. opacity: 1;
  96. top: -2.5rem;
  97. }
  98. }
  99. @at-root #{&}__big_triangle {
  100. width: 1rem;
  101. height: 1rem;
  102. background-color: #fff;
  103. transform: rotate(45deg);
  104. position: absolute;
  105. box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.75);
  106. top: 2.4rem;
  107. border-radius: 0.125rem 0 0 0;
  108. border: 0.125rem solid $color__gray--primary;
  109. left: calc(50% - 1.414rem /2);
  110. z-index: 6;
  111. }
  112. @at-root #{&}__small_triangle {
  113. width: 0;
  114. left: calc(50% - 1.414rem / 2 - .125rem);
  115. height: 0;
  116. border-left: 0.625rem solid transparent;
  117. top: 2.4rem;
  118. border-right: 0.625rem solid transparent;
  119. border-bottom: 0.625rem solid #ffffff;
  120. position: absolute;
  121. z-index: 8;
  122. @at-root #{&}--empty {
  123. border-bottom-color: #fafafa;
  124. }
  125. }
  126. @at-root #{&}__menu {
  127. left: -50%;
  128. position: absolute;
  129. top: 2.9rem;
  130. background-color: #fff;
  131. width: 20rem;
  132. border-radius: 0.25rem;
  133. border: 0.125rem solid $color__gray--darker;
  134. box-shadow: 0 7px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
  135. min-height: 8rem;
  136. max-height: 15rem;
  137. overflow-y: auto;
  138. z-index: 7;
  139. @at-root #{&}__empty {
  140. background-color: #fafafa;
  141. display: flex;
  142. flex-direction: column;
  143. align-items: center;
  144. padding: 2rem;
  145. height: 8rem;
  146. justify-content: center;
  147. font-size: 1rem;
  148. user-select: none;
  149. cursor: default;
  150. transition: none;
  151. color: $color__gray--darkest;
  152. span {
  153. font-size: 2rem;
  154. color: $color__gray--darker;
  155. margin-bottom: 0.5rem;
  156. }
  157. }
  158. &:last-child {
  159. border-bottom: none;
  160. }
  161. @at-root #{&}__item {
  162. padding: 0.5rem;
  163. border-bottom: thin solid $color__gray--primary;
  164. cursor: default;
  165. transition: background-color 0.2s;
  166. &:hover {
  167. background-color: $color__lightgray--primary;
  168. }
  169. &:active {
  170. background-color: $color__lightgray--darker;
  171. }
  172. }
  173. }
  174. @at-root #{&}__button {
  175. position: relative;
  176. padding-right: 2.5rem;
  177. @at-root #{&}__count {
  178. position: absolute;
  179. background-color: $color__blue--primary;
  180. line-height: 1;
  181. margin-left: 0.25rem;
  182. color: #fff;
  183. top: 0.35rem;
  184. right: 0.5rem;
  185. border-radius: 100%;
  186. height: 1rem;
  187. width: 1rem;
  188. display: inline-flex;
  189. align-items: center;
  190. padding: 0.75rem;
  191. font-size: 0.9rem;
  192. justify-content: center;
  193. transition: all 0.2s;
  194. @at-root #{&}--none {
  195. background-color: rgba(white, 0.75);
  196. font-weight: 300;
  197. color: initial;
  198. border: 0.0125rem solid $color__blue--darker;
  199. padding: calc(0.75rem - 4*0.0125rem);
  200. }
  201. @at-root #{&}--two_figure {
  202. font-size: 0.8rem;
  203. }
  204. @at-root #{&}--three_figure {
  205. font-size: 0.7rem;
  206. }
  207. }
  208. }
  209. }
  210. </style>