Skip to content

Commit

Permalink
PT Viewer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Sep 13, 2024
1 parent 0f9cd79 commit c6dcd27
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
55 changes: 55 additions & 0 deletions apps/showcase/components/doc/DocPTViewer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<div ref="container" class="card flex flex-col md:flex-row !p-0">
<div class="flex items-center justify-center md:border-r border-b md:border-b-0 border-surface md:w-3/4 w-full p-4">
<slot />
</div>
<div class="flex flex-col gap-2 p-8 md:p-2 md:w-1/4 w-full max-h-[720px] overflow-y-auto">
<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="flex flex-col p-2 cursor-pointer hover:bg-emphasis" @mouseenter="enterSection(item, doc.key)" @mouseleave="leaveSection">
<span>{{ item.label }}</span>
<span class="text-muted-color text-sm">{{ 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);
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>
14 changes: 8 additions & 6 deletions apps/showcase/components/doc/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export const getPTOptions = (name) => {
objToReplace.type = prop.type;
}

data.push({
value: i + 1,
label: prop.name,
options: hasSubComp ? subOptions?.props : options?.props,
description: prop.description
});
if (!prop.deprecated) {
data.push({
value: i + 1,
label: prop.name,
options: hasSubComp ? subOptions?.props : options?.props,
description: prop.description
});
}
} else {
data.push({
value: i + 1,
Expand Down

0 comments on commit c6dcd27

Please sign in to comment.