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.

151 lines
3.0 KiB

  1. <template lang="pug">
  2. .tabset.elevation-2
  3. ul.tabset-tabs(ref='tabs')
  4. slot(name='tabs')
  5. .tabset-content(ref='content')
  6. slot(name='content')
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. currentTab: 0
  13. }
  14. },
  15. watch: {
  16. currentTab (newValue, oldValue) {
  17. this.setActiveTab()
  18. }
  19. },
  20. methods: {
  21. setActiveTab () {
  22. this.$refs.tabs.childNodes.forEach((node, idx) => {
  23. if (idx === this.currentTab) {
  24. node.className = 'is-active'
  25. } else {
  26. node.className = ''
  27. }
  28. })
  29. this.$refs.content.childNodes.forEach((node, idx) => {
  30. if (idx === this.currentTab) {
  31. node.className = 'tabset-panel is-active'
  32. } else {
  33. node.className = 'tabset-panel'
  34. }
  35. })
  36. }
  37. },
  38. mounted () {
  39. this.setActiveTab()
  40. this.$refs.tabs.childNodes.forEach((node, idx) => {
  41. node.addEventListener('click', ev => {
  42. this.currentTab = [].indexOf.call(ev.target.parentNode.children, ev.target)
  43. })
  44. })
  45. }
  46. }
  47. </script>
  48. <style lang="scss">
  49. .tabset {
  50. border-radius: 5px;
  51. margin-top: 10px;
  52. @at-root .theme--dark & {
  53. background-color: #292929;
  54. }
  55. > .tabset-tabs {
  56. padding-left: 0;
  57. margin: 0;
  58. display: flex;
  59. align-items: center;
  60. background: linear-gradient(to bottom, #FFF, #FAFAFA);
  61. box-shadow: inset 0 -1px 0 0 #DDD;
  62. border-radius: 5px 5px 0 0;
  63. overflow: hidden;
  64. @at-root .theme--dark & {
  65. background: linear-gradient(to bottom, #424242, #333);
  66. box-shadow: inset 0 -1px 0 0 #555;
  67. }
  68. > li {
  69. display: block;
  70. padding: 16px;
  71. margin-top: 0;
  72. cursor: pointer;
  73. transition: color 1s ease;
  74. border-right: 1px solid #FFF;
  75. font-size: 14px;
  76. font-weight: 500;
  77. margin-bottom: 1px;
  78. user-select: none;
  79. @at-root .theme--dark & {
  80. border-right-color: #555;
  81. }
  82. &.is-active {
  83. background-color: #FFF;
  84. margin-bottom: 0;
  85. padding-bottom: 17px;
  86. color: mc('blue', '700');
  87. @at-root .theme--dark & {
  88. background-color: #292929;
  89. color: mc('blue', '300');
  90. }
  91. }
  92. &:last-child {
  93. border-right: none;
  94. &.is-active {
  95. border-right: 1px solid #EEE;
  96. @at-root .theme--dark & {
  97. border-right-color: #555;
  98. }
  99. }
  100. }
  101. &:hover {
  102. background-color: rgba(#CCC, .1);
  103. @at-root .theme--dark & {
  104. background-color: rgba(#222, .25);
  105. }
  106. &.is-active {
  107. background-color: #FFF;
  108. @at-root .theme--dark & {
  109. background-color: #292929;
  110. }
  111. }
  112. }
  113. & + li {
  114. border-left: 1px solid #EEE;
  115. @at-root .theme--dark & {
  116. border-left-color: #222;
  117. }
  118. }
  119. }
  120. }
  121. > .tabset-content {
  122. .tabset-panel {
  123. padding: 2px 16px 16px;
  124. display: none;
  125. &.is-active {
  126. display: block;
  127. }
  128. }
  129. }
  130. }
  131. </style>