npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-y-tree

v0.1.3

Published

yet another flexible tree component for vue

Downloads

6

Readme

vue-y-tree

Yet another tree component for vue

Demo

Install

vue-y-tree is a UMD module, it means:

  • you can use it as an npm package
  • or you can load it directly in browser, and access it with the global variable VueTree
npm install vue-y-tree

Usage

<body style="background: #fff">
  <div>selected: {{ text }}</div>
  <hr/>
  <tree :tree="tree" :display-args="args" @tree-select="onSelect"></tree>
</body>
// directly used in browser
// var yTree = VueTree.yTree;

var yTree = require('vue-y-tree').yTree;

new Vue({
    el: 'body',
		components: {
    	tree: yTree
    },
    methods: {
    	onSelect: function (data) {
      	this.text = data;
      }
    },
    data: function () {
    	return {
      	text: 'none',
      	tree: {
        	value: 'level 1',
          children: [
          	{
            	value: 'level 2 A'
            },
            {
            	value: 'level 2 B',
              children: [
              	{ value: 'level 3 A'},
                { value: 'level 3 B'},
                { value: 'level 3 C'}
              ]
            }
          ]
        },
        args: {
        	valueToString: x => x
        }
      }
    }
})

Tips

Two vue components are exported in vue-y-tree:

  • xTree
    • the more general tree component, including recursive render, fold/unfold and select, but without any css
  • yTree
    • wrap xTree with a little more fancy display

xTree is implemented with flexibility. It is all about how to interact with a tree, but it doesn't care how to display your tree node. You can pass in your own component to display whatever exists in your tree data (checkout the dom tree demo).

Use yTree if you just want to display normal text in each tree node, while it is recommended to use xTree if you have a complex data structure and want to customize the display.

Props

xTree

Name | type | required | default | Description ----- | ----- | ----- | ----- | ----- tree | Object | true | | tree data to be rendered childrenName | String | false | 'children' | the children key in the tree data valueName | String | false | 'value' | the children key in the tree data idName | String | false | | the key to determine whether one node is selected, could be omitted. If omitted, all nodes will be assigned a unique id. isFold | Boolean | false | false | whether a tree is folded in the first place isSelected | Boolean | false | false | where a tree is selected in the first place displayComponent | Object | false | | the Component to display tree value displayArgs | Object | false | | extra args to be passed to displayComponent extraClass | String | false | | extra class to be added on the root element, use it for your own css treeStyle | Object | false | {} | customized inline style for the tree

displayComponent

Your customized displayComponent will get the following props:

Name | type | Description ----- | ----- | ----- | ----- | ----- value | Object, String | the value to be displayed toggleFold | Function | (no args) the method to fold/unfold the whole tree select | Function | (no args) the method to select the tree node isRoot | Boolean | whether the node is a root node or not isFold | Boolean | whether the node is folded or not isSelected | Boolean | whether the node is selected or not hasChildren | Boolean | whether the node has children or not args | Object | the extra args passed from xTree's displayArgs

yTree

props of yTree is almost the same as xTree, expect that there is no more displayComponent. yTree has already set the displayComponent for you, all you need is to pass in the displayArgs. so, let's get some insights of the displayArgs for yTree.

var displayArgs = {
  // a function turning tree value to string text to display
  valueToString: function (value) {
    return some_function(value);
  },

  // a display component that accept tree value as props 
  valueToDisplay: component      
}

valueToDisplay

Your customized valueToDisplay will get the following props:

Name | type | Description ----- | ----- | ----- | ----- | ----- value | Object, String | the value to be displayed select | Function | (no args) the method to select the tree node isRoot | Boolean | whether the node is a root node or not isFold | Boolean | whether the node is folded or not isSelected | Boolean | whether the node is selected or not hasChildren | Boolean | whether the node has children or not

Dev

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

Licence

MIT