0.3.2 • Published 4 years ago

tree-nodes-dl v0.3.2

Weekly downloads
57
License
-
Repository
-
Last release
4 years ago

tree-nodes-dl

code Pen

https://codepen.io/JOSEJUAN/pen/jOWBreV?editors=1101

Install

npm install tree-nodes-dl

Use

global use

import Vue from 'vue';
import treeNodesDl from 'tree-nodes-dl';

Vue.use(treeNodesDl);

local use

import treeNodes from 'tree-nodes-dl';
...
export default {
    components: {
        treeNodes,
    }
}

html

<template>
    <tree-nodes-dl
    class="tree-container"
    children=inner
    text=title
    :indent="15"
    :nodes="treeData"
     v-slot="{ node, isOpen }"
  >
    <div class="slot-node">
      <span v-if="!isOpen && node.inner">+</span>
      <span v-if="isOpen && node.inner">-</span>
      <h2
        :class="{'lm': !node.inner }"
      >Desde slot: {{node.title}}</h2>
      <button
        type="button"
        @click.stop
      >click me!</button>
    </div>
  </tree-nodes-dl>
</template>
<script>
import treeNodes from 'tree-nodes-dl';

function data() {
  return {
    treeData: [
        {
            title: "A",
            otherProp: false,
            inner: [
                {
                    title: "A.1",
                    inner: [
                        {
                            title: "A.1.1"
                        }
                    ]
                },
                {
                    title: "A.2",
                    inner: [
                        {
                            title: "A.2.1"
                        },
                        {
                            title: "A.2.2"
                        }
                    ]
                },
                {
                    title: "A.3",
                    inner: [
                        {
                            title: "A.3.1"
                        }
                    ]
                },
                {
                    title: "A.4",
                    inner: [
                        {
                            title: "A.4.1"
                        }
                    ]
                }
            ]
        },
        {
            title: "B",
            inner: [
                {
                    title: "B.1",
                    inner: [
                        {
                            title: "B.1.1"
                        },
                        {
                            title: "B.1.2"
                        }
                    ]
                },
                {
                    title: "B.2",
                    inner: [
                        {
                            title: "B.2.1"
                        }
                    ]
                },
                {
                    title: "B.3",
                    inner: [
                        {
                            title: "B.3.1"
                        }
                    ]
                },
                {
                    title: "B.4",
                    inner: [
                        {
                        title: "B.4.1"
                        }
                    ]
                }
            ]
        },
        {
            title: "C"
        },
        {
            title: "D"
        }
    ],
  }
}

export default {
    components: {
        treeNodes,
    },
    data,
}
</script>
.slot-node {
  align-items: center;
  cursor: default;
  display: flex;
  span {
    font-weight: bold;
    font-size: 20px;
    height: 20px;
    margin-right: 10px;
    width: 20px;
  }
  h2 {
    width: 100%;
    
    &.lm { 
      margin-left: 30px;  
    }
  }
  button {
    cursor:pointer;
    width: 10%;
  }
}

Slot - scoped

nametypeobservation
nodeObjectElement of the array
isOpenBooleantrue: node open. false node collapsed

Note: you can use event handlers like click in de slot but this will change the node state (collapsed or opened). If you don't want this behavior just add stop as modifier in the event (@click.stop="clickHandler") or stopPropagation() (function clickHandler(e, node, isOpen) { e.stopPropagation()...})

Classes

nameObservation
.node-container-wrapperThis is the main class and it's wrapping the node. You can access the node through this class.
collapsingThis is de vue transition name. You can use it to apply custom transitions for collaping the node
.nodeThis is the node class.

Note: If you want more details please check here.

0.3.2

4 years ago

0.3.1

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago