0.0.2 • Published 1 year ago

@evangelos_bitsilis/v-treeview v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

V - Treeview

V - Treeview is a Vue 3 component with drag n drop and collapse functionality.

Installation

npm i @evangelos_bitsilis/v-treeview

Configuration (optional)

{
  colors: {
    indicators: {
      text: "White",
      lines: "RoyalBlue",
      background: "RoyalBlue",
    },
    ghost: {
      text: "White",
      background: "RoyalBlue"
    },
    notDraggable: {
      text: "Red"
    }
  }
}
Color ConfigTypeDefaultDescription
indicatorsobject-Holds tree's indicator colors
indicators.textstring"White"Changes the color of the hovering element's text. Works in conjunction with the background color
indicators.linesstring"RoyalBlue"Changes the indicator lines color
indicators.backgroundstring"RoyalBlue"Changes the background color of the hovering element
ghostobject-Contains ghost element's colors
ghost.textstring"White"Ghost's text color
ghost.backgroundstring"RoyalBlue"Ghost's background color
notDraggableobject-Contains the colors of the elements which can't be dragged
notDraggable.textstring"Red"Text color

Data structure

[{
  "id": 1,
  "text": "Root",
  "state": {
    "expanded": true,
    "draggable": true,
    "droppable": true
  },
  "children": [{
    "id": 2,
    "text": "Child",
    "state": {
      "expanded": true,
      "draggable": true,
      "droppable": true
    },
    "children": []
  }]
}]

Make sure it's a reactive property

Node properties

PropertyTypeRequiredDescription
idintegertrueUsed in the tree to differentiate each node
textstringtrueDisplayed text
stateobject / StatetrueNode's state
childrenarraytrueAn array with node's children. If any

Node's state

StateTypeDefaultDescription
expandedbooleantrueDetermines if the node is expanded or not
draggablebooleantrueDetermines if the node can be dragged
droppablebooleantrueDetermines if nodes allowed to be dropped

Initialization

<template>
  <Tree :data="data">
</template>

<script setup>
  import Tree from "@evangelos_bitsilis/v-treeview"
  import "@evangelos_bitsilis/v-treeview/dist/style.css";

  import someData from "someFile.json"
  const data = reactive(someData);
</script>

Events

treeMounted Emitted when the tree is mounted

orderChanged Emitted every time the order of the tree nodes changes. And returns the updated tree structure.

<template>
  <Tree :data="data" @orderChanged="foo"/>
</template>

<script setup>
  import Tree from "@evangelos_bitsilis/v-treeview"
  import "@evangelos_bitsilis/v-treeview/dist/style.css";

  import someData from "someFile.json";
  const data = reactive(someData);

  function foo(newData) {
    console.log(newData);
  }
</script>

Custom HTML

The Tree has 2 normal slots that can be used to add content before and after the node's default text

<Tree :data="data">
  <template #before="data">
    <div style="margin-right: 20px;">
      before {{ data.item.id }}
    </div>
  </template>
	
  <template #after="data">
    <div style="margin-left: 20px;">
      after {{ data.item.id }}
    </div>
  </template>
</Tree>