Tabs.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <nav class="tab-nav">
  3. <ul class="tab-bar">
  4. <li v-for="tab in tabs" :key="tab.component">
  5. <button
  6. class="tab"
  7. :class="value.component === tab.component ? 'tab-active' : ''"
  8. @click.prevent="$emit('input', tab)"
  9. >
  10. {{ tab.title }}
  11. </button>
  12. </li>
  13. </ul>
  14. <template v-if="shareButtonEnabled">
  15. <div class="tab-delimiter" />
  16. <ShareButton />
  17. </template>
  18. </nav>
  19. </template>
  20. <script>
  21. import ShareButton from './Shared/ShareButton';
  22. export default {
  23. inject: ['config', 'report'],
  24. components: { ShareButton },
  25. props: {
  26. value: { required: true },
  27. customTabs: { required: true },
  28. },
  29. data() {
  30. return {
  31. defaultTabs: [
  32. {
  33. component: 'StackTab',
  34. title: 'Stack trace',
  35. },
  36. {
  37. component: 'RequestTab',
  38. title: 'Request',
  39. },
  40. ...(this.report.context.livewire
  41. ? [
  42. {
  43. component: 'LivewireTab',
  44. title: 'Livewire',
  45. },
  46. ]
  47. : []),
  48. {
  49. component: 'AppTab',
  50. title: 'App',
  51. },
  52. {
  53. component: 'UserTab',
  54. title: 'User',
  55. },
  56. {
  57. component: 'ContextTab',
  58. title: 'Context',
  59. },
  60. {
  61. component: 'DebugTab',
  62. title: 'Debug',
  63. },
  64. ],
  65. shareButtonEnabled: this.config.enableShareButton,
  66. };
  67. },
  68. mounted() {
  69. this.applyDefaultTabProps();
  70. this.$emit('input', this.tabs[this.currentTabIndex]);
  71. },
  72. computed: {
  73. currentTabIndex() {
  74. return this.tabs.findIndex(tab => tab.component === this.value.component);
  75. },
  76. nextTab() {
  77. return this.tabs[this.currentTabIndex + 1] || this.tabs[0];
  78. },
  79. previousTab() {
  80. return this.tabs[this.currentTabIndex - 1] || this.tabs[this.tabs.length - 1];
  81. },
  82. tabs() {
  83. let tabs = {};
  84. this.defaultTabs.forEach(tab => {
  85. tabs[tab.component] = tab;
  86. });
  87. this.customTabs.forEach(tab => {
  88. tabs[tab.component] = tab;
  89. });
  90. return Object.values(tabs);
  91. },
  92. },
  93. methods: {
  94. applyDefaultTabProps() {
  95. this.defaultTabs.map(tab => {
  96. if (tab.component === this.value.component) {
  97. tab.props = this.value.props || {};
  98. }
  99. return tab;
  100. });
  101. },
  102. },
  103. };
  104. </script>