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

61 lines
2.1 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">
2024-09-16 10:18:28 +00:00
<div id="doc-ptviewer" 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) {
2024-09-16 10:18:28 +00:00
let selector,
cmpName = componentName;
2024-09-13 14:23:04 +00:00
2024-09-16 10:18:28 +00:00
if (componentName === 'ConfirmDialog') cmpName = 'Dialog';
if (item.label === 'root') selector = `[data-pc-name="${cmpName.toLowerCase()}"]`;
2024-09-13 14:23:04 +00:00
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 10:18:28 +00:00
if (this.hoveredElements.length === 0) this.hoveredElements = find(document.querySelector('body'), selector); //TODO:
2024-09-16 08:24:54 +00:00
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>