Newer
Older
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import type { ITreeItem } from '@interfaces/componentsProp';

Дмитрий Малюгин
committed
import TreeItems from '@components/TreeList/TreeItems.vue';
import type { ITLProps } from '@interfaces/componentsProps';

Дмитрий Малюгин
committed
import { convertThemeToColor, convertThemeToTextColor } from '@helpers/common';
interface IStateItem {
isOpen: boolean;
label: string;
}
const props = withDefaults(defineProps<ITLProps>(), {
theme: 'white',
maxWidth: 300,

Дмитрий Малюгин
committed
darknessTheme: '500',
const emit = defineEmits(['onClick']);
const items = computed(() => props.items);
const themeColor = computed(() => convertThemeToColor(props.theme, props.darknessTheme));

Дмитрий Малюгин
committed
const color = computed(() =>
props.textColor
? convertThemeToColor(props.textColor, props.darknessTextColor)
: convertThemeToTextColor(props.theme, props.darknessTheme),
);
const setItemChildrenToState = (items: ITreeItem[]) => {
for (const item of items) {
state.value.push({
if (item.children) {
}
}
};
const setInitialState = () => {
if (!props?.items) return;
setItemChildrenToState(props.items);
};
watch(
[items],
() => {
if (items.value) setInitialState();
},
{
immediate: true,
},
const toggleIsOpen = (item: ITreeItem) => {
if (item.isLinkClicked) {
item.isLinkClicked = false;
return;
}
state.value.map((itemState) => {
if (itemState.label === item.label) itemState.isOpen = !itemState.isOpen;
});
</script>
<template>
<div
:style="`background-color: ${themeColor ?? 'white'}; max-width: ${maxWidth}px; padding: 15px 25px 15px 15px`"
class="tree"
>
<TreeItems
:items="items"
:state="state"

Дмитрий Малюгин
committed
:color="color"
@toggleIsOpen="toggleIsOpen"
@onClick="emit('onClick')"
/>
</div>
</template>