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

66 lines
2.4 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-17 10:20:40 +00:00
<span class="doc-ptoption-text">
{{ item.label }}
<template v-if="docs.length > 1">| {{ doc.key }}</template>
</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';
2024-09-17 09:09:24 +00:00
else if (componentName === 'ScrollTop') cmpName = 'Button';
2024-09-19 07:36:09 +00:00
else if (componentName === 'Galleria') cmpName = 'GalleriaContent';
2024-09-16 10:18:28 +00:00
2024-09-19 12:26:58 +00:00
if (componentName === 'InputMask') selector = `[data-pc-extend="inputtext"][data-pc-section="root"]`;
else 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-17 10:20:40 +00:00
addClass(el, '!ring !ring-blue-500 !z-10');
2024-09-13 14:23:04 +00:00
});
},
leaveSection() {
this.hoveredElements.forEach((el) => {
2024-09-17 10:20:40 +00:00
removeClass(el, '!ring !ring-blue-500 !z-10');
2024-09-13 14:23:04 +00:00
});
this.hoveredElements = [];
},
handleData(doc) {
2024-09-18 07:59:38 +00:00
return doc.filter((item) => item.label !== 'hooks' && item.label !== 'transition' && !item.label.includes('hidden'));
2024-09-13 14:23:04 +00:00
}
}
};
</script>