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

58 lines
1.9 KiB
Vue
Raw Normal View History

2024-09-13 14:23:04 +00:00
<template>
2024-09-16 08:24:54 +00:00
<div ref="container" class="doc-ptviewerwrapper card">
<div class="doc-ptviewer">
2024-09-13 14:23:04 +00:00
<slot />
</div>
2024-09-16 08:24:54 +00:00
<div class="doc-ptoptions">
2024-09-13 14:23:04 +00:00
<template v-if="docs[0].data">
<template v-for="doc of docs" :key="doc.key">
2024-09-16 08:24:54 +00:00
<div v-for="item of handleData(doc.data)" :key="item.value" class="doc-ptoption" @mouseenter="enterSection(item, doc.key)" @mouseleave="leaveSection">
2024-09-13 14:23:04 +00:00
<span>{{ item.label }}</span>
2024-09-16 08:24:54 +00:00
<span class="doc-ptoption-text">{{ item.label }} element of {{ doc.key }} component</span>
2024-09-13 14:23:04 +00:00
</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);
2024-09-16 08:24:54 +00:00
if (this.hoveredElements.length === 0) this.hoveredElements = find(document.querySelector('body'), selector);
this.hoveredElements?.forEach((el) => {
2024-09-13 14:23:04 +00:00
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>