Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: code group provides logical fallthrough behavior
  • Loading branch information
d-pollard committed Sep 2, 2020
commit e9bec76bdf48d0215254ae766502dd32be2aa3b6
27 changes: 22 additions & 5 deletions packages/@vuepress/theme-default/global-components/CodeGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
</button>
</div>
<slot />
<pre
v-if="codeTabs.length < 1"
class="pre-blank"
>// Make sure to add code blocks to your code group</pre>
</div>
</template>

Expand All @@ -21,7 +25,7 @@ export default {
data () {
return {
codeTabs: [],
activeCodeTabIndex: 0
activeCodeTabIndex: -1
}
},
watch: {
Expand All @@ -33,10 +37,20 @@ export default {
}
},
mounted () {
this.codeTabs = this.$slots.default.filter(slot => Boolean(slot.componentOptions)).map(slot => ({
title: slot.componentOptions.propsData.title,
elm: slot.elm
}))
this.codeTabs = (this.$slots.default || []).filter(slot => Boolean(slot.componentOptions)).map((slot, index) => {
if (slot.componentOptions.propsData.active === '') {
this.activeCodeTabIndex = index
}

return {
title: slot.componentOptions.propsData.title,
elm: slot.elm
}
})

if (this.activeCodeTabIndex === -1 && this.codeTabs.length > 0) {
this.activeCodeTabIndex = 0
}
},
methods: {
changeCodeTab (index) {
Expand Down Expand Up @@ -66,4 +80,7 @@ export default {
.theme-code-group__nav-tab-active {
border-bottom: #42b983 1px solid;
}
.pre-blank {
color: #42b983;
}
</style>