0.2.4 • Published 4 years ago

g8-vue-tree v0.2.4

Weekly downloads
7
License
GPL-3.0
Repository
github
Last release
4 years ago

vue-tree

master build vulnerabilities maintainability master coverage dev build dev coverage

A Vue tree view component with stable DOM structure. By stable, it means the DOM structure will not change once it is rendered.

Demo

Performance Consideration

The DOM structure of this component doesn't change once rendered. Comparing to others using v-if, which generate sub-nodes while expanded. While working on long list of items, lags will be obvious.

  • This component will have a lag when it is being rendered for the first time. After it is rendered, sub-trees are controlled by CSS, no DOM structure change.
  • v-if components will lag whenever sub-trees are expanded, every time they are expanded.

There is an issue for this. Check out more detail there.

Props

Prop nameDescriptionTypeDefault
item-idKey of the field in item to be used as element's id attribute.string'id'
item-labelKey of the field in item that holds node label.string'name'
tags-keyKey of the field in item that holds tags array.string'tags'
children-keyKey of the field in item that holds child nodes array.string'children'
tag-idKey of the field in tags list of item to be used as tag element's id attribute.string'id'
tag-labelKey of the field in tags list of item that holds tag label.string'label'
tag-hintKey of the field in tags list of item that holds tag tooltip.string'hint'
checkerWhether to add a checkbox before each item,allowing multiple nodes tobe checked.booleanfalse
itemThe tree data to be rendered.Please note that data passed may be mutated by thiscomponent to reflect various states of tree nodes.Mutated fields include:- checked- intermediate- renderedG8TreeItem

Scoped slots

Default slot

<span class="g8-tree__node__entry__label">
  <slot :item="item">{{ item[itemLabel] }}</slot>
</span>

This is the entry's main content slot. Defaults to {{ item[itemLabel] }}. The current item entry is exposed as scoped variable item.

Tag (badge) slot

<label
  class="g8-tree__node__entry__tags__tag"
  v-for="(tag, idx) in item[tagsKey]"
  :key="idx"
  :id="tag[tagId]"
  :title="tag[tagHint]"
>
  <slot name="tag" :tag="tag" :item="item">{{ tag[tagLabel] }}</slot>
</label>

This is the entry's tag content slot. Defaults to {{ tag[tagLabel] }}. The current item entry is exposed as scoped variable item. The current tag is exposed as scoped variable tag.

Types

G8TreeItem

Below is a list of presumable fields, all of them are optional. You can place whatever data you want to a tree item, then use the props mentioned above to specify content you want to display.

Field nameTypeDescription
namestringItem name, serves as label, will be rendered as node label.
checkedbooleanWhether the node is checked.
intermediatebooleanIntermediate check box state. Active while some children were checked.
renderedbooleanWhether the sub-tree of this node has been rendered.
tagsG8TreeItemTag[]List of tags.
childrenG8TreeItem[]List of child nodes.

G8TreeItemTag

Below is a list of presumable fields, all of them are optional. You can place whatever data you want to tags, then use the props mentioned above to specify content you want to display.

Field nameTypeDescription
labelstringTag label.
hintstringTag tooltip. Visible when mouse hovers on the tag.

G8ClickEvent

extends MouseEvent

Field nameTypeDescription
data{ expanded: boolean, item: G8TreeItem}The item triggered the event and if it were expanded (true).

Events

This component defines only two events, for expanding/collapsing nodes, and checkbox state changes.

Event nameTypeDescription
clickG8ClickEventA tree node has been clicked. Use the data.expanded to determine if the node were expanded (true).
state-changedG8TreeItemCheckbox state of the node has changed.

Other events

Theming

Colors

The bundled style sheet can be imported from 'g8-vue-tree/dist/g8-vue-tree.css'. This component provides a dark theme out of box. To use it, just add the g8--dark class to the element.

<ul class="g8-tree__view g8--dark">
  <g8-tree__view></g8-tree__view>
</ul>

If you want to change the color of the component, just define two variables before importing the scss file.

/* index.scss */

/* define these two variables before importing the scss file */
$g8-tree-bg: #ccc;
$g8-tree-fg: #333;

@import '~vue-tree/src/components/tree-view.scss';

Fonts

This component deliberately left out font-family from CSS. You can use whatever font you like, just add something like below to you styles:

.g8-tree__view {
  font-family: 'you favorite font';
}
0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.13

4 years ago