primevue-mirror/apps/showcase/components/doc/DocPTViewer.vue

58 lines
1.9 KiB
Vue

<template>
<div ref="container" class="doc-ptviewerwrapper card">
<div class="doc-ptviewer">
<slot />
</div>
<div class="doc-ptoptions">
<template v-if="docs[0].data">
<template v-for="doc of docs" :key="doc.key">
<div v-for="item of handleData(doc.data)" :key="item.value" class="doc-ptoption" @mouseenter="enterSection(item, doc.key)" @mouseleave="leaveSection">
<span>{{ item.label }}</span>
<span class="doc-ptoption-text">{{ item.label }} element of {{ doc.key }} component</span>
</div>
</template>
</template>
</div>
</div>
</template>
<script>
import { addClass, find, removeClass } from '@primeuix/utils/dom';
export default {
props: ['docs'],
data() {
return {
hoveredElements: []
};
},
methods: {
enterSection(item, componentName) {
let selector;
if (item.label === 'root') selector = `[data-pc-name="${componentName.toLowerCase()}"]`;
else if (item.label.startsWith('pc')) selector = `[data-pc-name="${item.label.toLowerCase()}"]`;
else selector = `[data-pc-section="${item.label.toLowerCase()}"]`;
this.hoveredElements = find(this.$refs.container, selector);
if (this.hoveredElements.length === 0) this.hoveredElements = find(document.querySelector('body'), selector);
this.hoveredElements?.forEach((el) => {
addClass(el, '!ring !ring-red-500');
});
},
leaveSection() {
this.hoveredElements.forEach((el) => {
removeClass(el, '!ring !ring-red-500');
});
this.hoveredElements = [];
},
handleData(doc) {
return doc.filter((item) => item.label !== 'hooks' && item.label !== 'transition');
}
}
};
</script>