feat: cleanup CodeBlock & CodeGroup to better fit existing patterns

pull/232/head
Derek Pollard 5 years ago
parent e1fe1ded40
commit 1015054c8b

@ -5,9 +5,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from "vue"; import { defineComponent, PropType } from "vue"
export default defineComponent({ export default defineComponent({
name: "CodeBlock",
props: { props: {
title: { title: {
type: String, type: String,
@ -22,11 +23,6 @@ export default defineComponent({
return false return false
} }
} }
}, }
name: "CodeBlock"
}) })
</script> </script>
<style scoped>
</style>

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, h } from "vue"; import { defineComponent, h } from "vue"
import { CodeGroupTabState } from "/@theme/components/global/types"; import { CodeGroupTabState } from "/@theme/components/global/types"
import CodeBlock from "/@theme/components/global/CodeBlock.vue"; import CodeBlock from "/@theme/components/global/CodeBlock.vue"
export default defineComponent({ export default defineComponent({
name: "CodeGroup", name: "CodeGroup",
@ -13,14 +13,14 @@ export default defineComponent({
} }
}, },
mounted() { mounted() {
let activeTabIndex = -1; let activeTabIndex = -1
const tabs: CodeGroupTabState[] = []; const tabs: CodeGroupTabState[] = []
const blocks = (this.$slots.default?.() || []).filter(s => s.type.name === 'CodeBlock'); const blocks = (this.$slots.default?.() || []).filter(s => s.type.name === 'CodeBlock')
blocks.forEach(({ props: { title, active = false }, children }, index) => { blocks.forEach(({ props: { title, active = false }, children }, index) => {
if (activeTabIndex === -1 && typeof active === 'string') { if (activeTabIndex === -1 && typeof active === 'string' || active) {
activeTabIndex = index; activeTabIndex = index
} }
tabs.push({ tabs.push({
@ -28,11 +28,10 @@ export default defineComponent({
title: title, title: title,
content: children?.length content: children?.length
}) })
}); })
this.tabs = tabs this.tabs = tabs
this.activeTabIndex = activeTabIndex this.activeTabIndex = activeTabIndex
console.log(this)
}, },
render() { render() {
const hCodeBlocks = this.tabs.map( const hCodeBlocks = this.tabs.map(

Loading…
Cancel
Save