Elementos anidados como filas de lista que se abren y se cierran, con casillas opcionales.
Carpetas
Carpetas anidadas como filas de lista: un clic o Intro selecciona y abre; las flechas mueven, abren y cierran.
<script setup>
import { ref } from 'vue';
import { FolderIcon, FolderOpenIcon, ImageIcon } from '@lucide/vue';
import { Tree, TreeItem } from '@aisgroup/design/ui/tree';
const items = [
{ id: 'pcb', title: 'PCB inspection', children: [
{ id: 'pcb-ok', title: 'Normal', children: [{ id: 'pcb-0412', title: 'board-0412.png' }, { id: 'pcb-0413', title: 'board-0413.png' }] },
{ id: 'pcb-nok', title: 'Anomaly', children: [{ id: 'pcb-0398', title: 'board-0398.png' }] },
] },
{ id: 'food', title: 'Tortilla line', children: [{ id: 'food-0021', title: 'tortilla-0021.png' }] },
];
const selected = ref();
</script>
<template>
<Tree v-slot="{ flattenItems }" v-model="selected" :items="items" :get-key="(item) => item.id" :default-expanded="['pcb', 'pcb-ok']" class="w-full max-w-xs">
<TreeItem v-for="item in flattenItems" :key="item._id" v-slot="{ isExpanded }" v-bind="item.bind" :has-children="item.hasChildren">
<component :is="item.hasChildren ? (isExpanded ? FolderOpenIcon : FolderIcon) : ImageIcon" class="text-muted-foreground" />
<span class="truncate">{{ item.value.title }}</span>
</TreeItem>
</Tree>
</template>Casillas
Elegir varias ramas: la casilla de un elemento padre sigue a sus hijos, y marcarla los marca todos.
<script setup>
import { ref } from 'vue';
import { Tree, TreeItem } from '@aisgroup/design/ui/tree';
const items = [
{ id: 'line-1', title: 'Line 1', children: [{ id: 'cam-1', title: 'Camera 1' }, { id: 'cam-2', title: 'Camera 2' }] },
{ id: 'line-2', title: 'Line 2', children: [{ id: 'cam-3', title: 'Camera 3' }, { id: 'cam-4', title: 'Camera 4' }, { id: 'cam-5', title: 'Camera 5' }] },
];
const checked = ref([items[0].children[0]]);
</script>
<template>
<Tree v-slot="{ flattenItems }" v-model="checked" :items="items" :get-key="(item) => item.id" :default-expanded="['line-1', 'line-2']" multiple propagate-select bubble-select class="w-full max-w-xs">
<TreeItem v-for="item in flattenItems" :key="item._id" v-bind="item.bind" :has-children="item.hasChildren" checkbox>
{{ item.value.title }}
</TreeItem>
</Tree>
</template>