2.0.11 • Published 10 months ago

vue3-tree-vue v2.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

A Simple vue3 project for rendering items in a tree.

npm i vue3-tree-vue

<template>    
    <vue3-tree-vue :items="items" 
                   :isCheckable="false"  //Set to true if you want to get checkable items
                   :hideGuideLines="false"
                   @onCheck="onItemChecked"
                   @dropValidator="onBeforeItemDropped"
                   @onSelect="onItemSelected"
                   @onExpand="onItemExpanded"
                   >
      <!-- Applying some simple styling to tree-items -->
       <template v-slot:item-prepend-icon="treeViewItem" >
              <img src="./assets/folder.svg"
                   alt="folder"
                   v-if="treeViewItem.type === 'folder'"
                   height="20" width="20" />
       </template>
    </vue3-tree-vue>
</template>
import 'vue3-tree-vue/dist/style.css'; // remember to add this in your component or maint.[ts/js]
 
  setup() {
    const onItemChecked = (checkedItems: TreeViewItem[]) => console.log(checkedItems);
    const onItemSelected = (item: TreeViewItem) => console.log(item);
    const onBeforeItemDropped = (droppedItem: TreeViewItem, dropHost: TreeViewItem | undefined) => {
      // dropHost == undefined means dropping at the root of the tree.
      
      // Here you can specify any kind of drop validation you will like.
      // this function should return true if the drop operation is valid.

      if (dropHost.type !== playlist) return false
      return true;
    }
    const onItemExpanded = (expandedItem: TreeViewItem) => {
      //to use this feature properly you need to set lazyLoad property as true 
      //fetch data
      const lazyLoadedItems = fetchFromApi(...);
      expandedItem.children.push(...lazyLoadedItems)
    }
    const items = ref<TreeViewItem[]>([]); // define your tree items here.
    
    return {
      onItemChecked,
      onItemSelected,
      onBeforeItemDropped,
      onItemExpanded,
      items
    }
  }

Selectable Tree Items

image

Checkable Tree Items

image

Drag and Drop

GIF

Properties of the TreeView

PropertyDefaultDescription
itemsEmpty arrayAn array of TreeViewItem.
hideGuideLinesfalseDetermines the visibility of the guidelines
lazyLoadfalseDetermines if the tree supports lazy-loading
isCheckablefalseDefines if items can be selected (one at a time) or selected (using a checkbox)
checkboxStyleundefinedDefines the style to be applied to the checkboxes on the tree.
dropValidatorundefinedSpecifies a callback of drag and drop rules.

Basic properties of each tree-node.

export interface TreeViewItem {
  name: string;
  id?: string | number;
  children?: TreeViewItem[];
  checked?: boolean;
  selected?: boolean;
  expanded?: boolean;
  disabled?: boolean;// When disabled, an item can neither be selected nor checked
  meta?: any;// provides meta-data of any type per node.
}

Event Handlers

EventsDescription
onSelectCallback function when an item is selected from the tree .Returns an ItemEventArgs.
onCheckCallback function when an item is checked/unchecked from the tree.
onExpandCallback function when an item is expanded (Can be used for lazy-loading)
onCollapseCallback function when an item is collapsed

Styles

ClassDescription
selected-tree-itemDefines the style for the selectedItem

Slots

NameDescription
item-prepend-iconDefines the node's prepend icon.
item-prependDefines a slot to house content before the node's label.
item-expanderDefines a slot for custom expander implementations
item-appendDefines a slot for adding custom content after the item name
child-appendDefines a slot for adding a custom item after the last child

Classes

NameDescription
on-item-hoverUse in child-append and item-append slots to only show when the cursor is hovering on the node
2.0.11

10 months ago

2.0.10

1 year ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

2.0.2-alpha

2 years ago

2.0.3

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

2.0.0-alpha

2 years ago

2.0.1-alpha

2 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago