2023-07-06 00:00:59 +00:00
|
|
|
<template>
|
2023-07-12 02:06:57 +00:00
|
|
|
<cdx-tabs v-if="isChildTabber && tabsData.length > 0" v-model:active="currentTab">
|
|
|
|
<cdx-tab
|
|
|
|
v-for="( tab, index ) in tabsData"
|
|
|
|
:key="index"
|
|
|
|
:name="escapeId( tab.label )"
|
|
|
|
:label="tab.label"
|
|
|
|
>
|
|
|
|
<tab-content
|
|
|
|
:html="tab.content"
|
|
|
|
>
|
|
|
|
</tab-content>
|
|
|
|
</cdx-tab>
|
|
|
|
</cdx-tabs>
|
2023-07-06 02:10:01 +00:00
|
|
|
<div
|
2023-07-12 02:06:57 +00:00
|
|
|
v-else
|
2023-07-06 00:00:59 +00:00
|
|
|
v-html="html"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
const { defineComponent } = require( 'vue' );
|
2023-07-12 02:06:57 +00:00
|
|
|
const { CdxTabs, CdxTab } = require( '@wikimedia/codex' );
|
2023-07-06 00:00:59 +00:00
|
|
|
|
|
|
|
// @vue/component
|
|
|
|
module.exports = exports = defineComponent( {
|
|
|
|
name: 'TabContent',
|
|
|
|
compatConfig: {
|
|
|
|
MODE: 3
|
|
|
|
},
|
|
|
|
compilerOptions: {
|
|
|
|
whitespace: 'condense'
|
|
|
|
},
|
2023-07-12 02:07:37 +00:00
|
|
|
components: {
|
|
|
|
CdxTabs: CdxTabs,
|
|
|
|
CdxTab: CdxTab
|
2023-07-12 02:06:57 +00:00
|
|
|
},
|
2023-07-06 00:00:59 +00:00
|
|
|
props: {
|
|
|
|
html: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
2023-07-12 02:07:37 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tabsData: [],
|
|
|
|
|
|
|
|
currentTab: ''
|
|
|
|
};
|
2023-07-12 02:06:57 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
isChildTabber() {
|
2024-04-24 19:13:08 +00:00
|
|
|
// eslint-disable-next-line es-x/no-array-prototype-includes
|
2023-07-12 02:07:37 +00:00
|
|
|
return Array.isArray( this.html ) || this.html.includes( '{"label":' );
|
2023-07-12 02:06:57 +00:00
|
|
|
},
|
|
|
|
parse() {
|
2023-07-12 02:07:37 +00:00
|
|
|
if ( Array.isArray( this.html ) ) {
|
|
|
|
return this.html;
|
2023-07-12 02:06:57 +00:00
|
|
|
} else {
|
2023-07-12 02:07:37 +00:00
|
|
|
const tmp = document.createElement( 'div' );
|
2023-07-12 02:06:57 +00:00
|
|
|
tmp.innerHTML = this.html;
|
|
|
|
|
|
|
|
return JSON.parse( tmp.textContent.trim() );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
escapeId( id ) {
|
2023-07-12 02:07:37 +00:00
|
|
|
return mw.util.escapeIdForAttribute( id );
|
2023-07-12 02:06:57 +00:00
|
|
|
}
|
|
|
|
},
|
2023-07-06 00:00:59 +00:00
|
|
|
mounted: function () {
|
2023-07-12 02:07:37 +00:00
|
|
|
if ( this.isChildTabber() ) {
|
|
|
|
this.tabsData = this.parse( this.html );
|
|
|
|
this.currentTab = this.escapeId( this.tabsData[ 0 ].label );
|
2023-07-12 02:06:57 +00:00
|
|
|
}
|
2023-07-06 00:00:59 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
</script>
|