Skip to content

Commit 0098fa8

Browse files
authored
Merge pull request #58 from eidng8/dev
Dev
2 parents 9d682ce + 4c4ac81 commit 0098fa8

21 files changed

+410
-405
lines changed

README.md

+48-31
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@ There is an [issue](https://github.com/eidng8/vue-tree/issues/24) for this. Chec
1515

1616
## Props
1717

18-
| Prop name | Description | Type | Default |
19-
| --- | --- | :-: | :-: |
20-
| item-id | Key of the field in `item` to be used as element's `id` attribute. | string | 'id' |
21-
| item-label | Key of the field in `item` that holds node label. | string | 'name' |
22-
| tags-key | Key of the field in `item` that holds tags array. | string | 'tags' |
23-
| children-key | Key of the field in `item` that holds child nodes array. | string | 'children' |
24-
| tag-id | Key of the field in tags list of `item` to be used as tag element's `id` attribute. | string | 'id' |
25-
| tag-label | Key of the field in tags list of `item` that holds tag label. | string | 'label' |
26-
| tag-hint | Key of the field in tags list of `item` that holds tag tooltip. | string | 'hint' |
27-
| checker | Whether to add a checkbox before each item,<br>allowing multiple nodes tobe checked. | boolean | false |
28-
| item | The tree data to be rendered.<br>Please note that data passed **_may_** be mutated by this<br>component to reflect various states of tree nodes.<br>Mutated fields include:<br>- checked<br>- intermediate<br>- rendered | [G8TreeItem](#g8treeitem) | |
18+
<!-- prettier-ignore -->
19+
| Prop name | Description | Type | Default |
20+
| ------------ | ------------------------------------------------------------------------------------ | :-----: | :--------: |
21+
| item-id | Key of the field in `item` to be used as element's `id` attribute. | string | 'id' |
22+
| item-label | Key of the field in `item` that holds node label. | string | 'name' |
23+
| tags-key | Key of the field in `item` that holds tags array. | string | 'tags' |
24+
| children-key | Key of the field in `item` that holds child nodes array. | string | 'children' |
25+
| tag-id | Key of the field in tags list of `item` to be used as tag element's `id` attribute. | string | 'id' |
26+
| tag-label | Key of the field in tags list of `item` that holds tag label. | string | 'label' |
27+
| tag-hint | Key of the field in tags list of `item` that holds tag tooltip. | string | 'hint' |
28+
| checker | Whether to add a checkbox before each item,<br>allowing multiple nodes tobe checked. | boolean | false |
29+
| item | The tree data to be rendered.<br>Please note that data passed **_may_** be mutated by this<br>component to reflect various states of tree nodes.<br>Mutated fields include:<br>- checked<br>- intermediate<br>- rendered | [G8TreeItem](#g8treeitem) | |
2930

3031
## Scoped slots
3132

3233
#### Default slot
3334

3435
```vue
35-
<span class="g8-tree__node_entry_label">
36+
<span class="g8-tree__node__entry__label">
3637
<slot :item="item">{{ item[itemLabel] }}</slot>
3738
</span>
3839
```
@@ -43,7 +44,7 @@ This is the entry's main content slot. Defaults to `{{ item[itemLabel] }}`. The
4344

4445
```vue
4546
<label
46-
class="g8-tree__node_entry_tags_tag"
47+
class="g8-tree__node__entry__tags__tag"
4748
v-for="(tag, idx) in item[tagsKey]"
4849
:key="idx"
4950
:id="tag[tagId]"
@@ -61,19 +62,21 @@ This is the entry's tag content slot. Defaults to `{{ tag[tagLabel] }}`. The cur
6162

6263
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](#props) mentioned above to specify content you want to display.
6364

64-
| Field name | Type | Description |
65-
| --- | :-: | --- |
66-
| name | string | Item name, serves as label, will be rendered as node label. |
67-
| checked | boolean | Whether the node is checked. |
68-
| intermediate | boolean | Intermediate check box state. Active while some children were checked. |
69-
| rendered | boolean | Whether the sub-tree of this node has been rendered. |
70-
| tags | [G8TreeItemTag](#g8treeitemtag)\[] | List of tags. |
71-
| children | [G8TreeItem](#g8treeitem)\[] | List of child nodes. |
65+
<!-- prettier-ignore -->
66+
| Field name | Type | Description |
67+
| ------------ | :--------------------------------: | ---------------------------------------------------------------------- |
68+
| name | string | Item name, serves as label, will be rendered as node label. |
69+
| checked | boolean | Whether the node is checked. |
70+
| intermediate | boolean | Intermediate check box state. Active while some children were checked. |
71+
| rendered | boolean | Whether the sub-tree of this node has been rendered. |
72+
| tags | [G8TreeItemTag](#g8treeitemtag)\[] | List of tags. |
73+
| children | [G8TreeItem](#g8treeitem)\[] | List of child nodes. |
7274

7375
#### G8TreeItemTag
7476

7577
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](#props) mentioned above to specify content you want to display.
7678

79+
<!-- prettier-ignore -->
7780
| Field name | Type | Description |
7881
| ---------- | :----: | -------------------------------------------------- |
7982
| label | string | Tag label. |
@@ -83,28 +86,32 @@ Below is a list of presumable fields, all of them are optional. You can place wh
8386

8487
extends `MouseEvent`
8588

86-
| Field name | Type | Description |
87-
| --- | :-: | --- |
88-
| data | { expanded: boolean, item: [G8TreeItem](#g8treeitem)} | The item triggered the event and if it were expanded (`true`). |
89+
<!-- prettier-ignore -->
90+
| Field name | Type | Description |
91+
| ---------- | :---------------------------------------------------: | -------------------------------------------------------------- |
92+
| data | { expanded: boolean, item: [G8TreeItem](#g8treeitem)} | The item triggered the event and if it were expanded (`true`). |
8993

9094
## Events
9195

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

94-
| Event name | Type | Description |
95-
| --- | :-: | --- |
96-
| click | [G8ClickEvent](#g8clickevent) | A tree node has been clicked. Use the `data.expanded` to determine if the node were expanded (`true`). |
97-
| state-changed | [G8TreeItem](#g8treeitem) | Checkbox state of the node has changed. |
98+
<!-- prettier-ignore -->
99+
| Event name | Type | Description |
100+
| ------------- | :---------------------------: | ------------------------------------------------------------------------------------------------------ |
101+
| click | [G8ClickEvent](#g8clickevent) | A tree node has been clicked. Use the `data.expanded` to determine if the node were expanded (`true`). |
102+
| state-changed | [G8TreeItem](#g8treeitem) | Checkbox state of the node has changed. |
98103

99104
#### Other events
100105

101106
## Theming
102107

103-
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-tree__dark` class to the element.
108+
#### Colors
109+
110+
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-tree--dark` class to the element.
104111

105112
```html
106-
<ul class="g8-tree-view g8-tree__dark">
107-
<g8-tree-view></g8-tree-view>
113+
<ul class="g8-tree__view g8-tree--dark">
114+
<g8-tree__view></g8-tree__view>
108115
</ul>
109116
```
110117

@@ -119,3 +126,13 @@ $g8-tree-fg: #333;
119126

120127
@import '~vue-tree/src/components/tree-view.scss';
121128
```
129+
130+
#### Fonts
131+
132+
This component deliberately left out `font-family` from CSS. You can use whatever font you like, just add something like below to you styles:
133+
134+
```css
135+
.g8-tree__view {
136+
font-family: 'you favorite font';
137+
}
138+
```

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "g8-vue-tree",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"description": "A Vue.js tree view component with stable DOM tree.",
55
"repository": "git@github.com:eidng8/vue-tree.git",
66
"bugs": "git@github.com:eidng8/vue-tree/issues",

scripts/build.sh

-15
This file was deleted.

scripts/test.sh

-46
This file was deleted.

src/App.vue

+12-9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
</div>
1818
<div>
1919
<button id="populate" @click="populate()">populate tree</button>
20-
<ul class="g8-tree-view g8-tree__dark g8-tree__highlight_hover">
21-
<g8-tree-view
20+
<ul class="g8-tree__view g8-tree--dark g8-tree--highlight-hover">
21+
<g8-vue-tree
2222
item-id="key"
2323
item-label="text"
2424
tags-key="badges"
@@ -52,25 +52,28 @@
5252
{{ tag.text }}
5353
</span>
5454
</template>
55-
</g8-tree-view>
55+
</g8-vue-tree>
5656
</ul>
5757
</div>
5858
</div>
5959
</template>
6060

6161
<script lang="ts">
6262
import { Component, Vue } from 'vue-property-decorator';
63-
import { G8TreeItem, G8TreeView } from './';
63+
import { G8TreeItem, G8VueTree } from './';
6464

65-
@Component({
66-
components: {
67-
G8TreeView,
68-
},
69-
})
65+
@Component({ components: { G8VueTree } })
7066
export default class App extends Vue {
7167
item = {
7268
key: 'root',
7369
text: 'Click the button above to populate me.',
70+
nodes: [
71+
{
72+
key: 'sub',
73+
text: 'A very long line that goes on' + ' and on'.repeat(20),
74+
badges: new Array(10).fill({ text: 'just a badge' }),
75+
},
76+
],
7477
} as G8TreeItem;
7578

7679
itemClicked = '';

src/components/G8TreeView.vue renamed to src/components/G8VueTree.vue

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@
88
<li
99
:id="item[itemId]"
1010
class="g8-tree__node"
11-
:class="{ 'g8-tree__node_expended': expanded }"
11+
:class="{ 'g8-tree__node--expended': expanded }"
1212
>
1313
<div
14-
class="g8-tree__node_entry"
15-
:class="{ 'g8-tree__branch_label': hasChild }"
14+
class="g8-tree__node__entry"
15+
:class="{ 'g8-tree__node__branch': hasChild }"
1616
@click="clicked($event)"
1717
>
18-
<span class="g8-tree__node_branch_toggle"></span>
18+
<span class="g8-tree__node__entry__toggle"></span>
1919
<span
2020
v-if="checker"
21-
class="g8-tree__node_entry_checker"
21+
class="g8-tree__checker"
2222
@click.stop.prevent="setState(!checked)"
2323
:class="{
24-
'g8-tree__node_entry_checker_checked': checked,
25-
'g8-tree__node_entry_checker_checked_some': intermediate,
24+
'g8-tree__checker--checked': checked,
25+
'g8-tree__checker--checked--intermediate': intermediate,
2626
}"
2727
></span>
28-
<span class="g8-tree__node_entry_label">
28+
<span class="g8-tree__node__entry__label">
2929
<slot :item="item">{{ item[itemLabel] }}</slot>
3030
</span>
31-
<span class="g8-tree__node_entry_tags">
31+
<span class="g8-tree__node__entry__tags">
3232
<label
33-
class="g8-tree__node_entry_tags_tag"
33+
class="g8-tree__node__entry__tags__tag"
3434
v-for="(tag, idx) in item[tagsKey]"
3535
:key="idx"
3636
:id="tag[tagId]"
@@ -41,7 +41,7 @@
4141
</span>
4242
</div>
4343
<ul v-if="expanded || item.rendered" class="g8-tree__branch">
44-
<g8-tree-view
44+
<g8-vue-tree
4545
v-for="(child, index) in item[childrenKey]"
4646
:key="index"
4747
:item="child"
@@ -63,7 +63,7 @@
6363
>
6464
<slot :name="slot" v-bind="scope" />
6565
</template>
66-
</g8-tree-view>
66+
</g8-vue-tree>
6767
</ul>
6868
</li>
6969
</template>
@@ -81,8 +81,8 @@ import { G8ClickEvent, G8TreeItem } from './types';
8181
* [issue](https://github.com/eidng8/vue-tree/issues/24) about performance
8282
* problem of large tree data set.
8383
*/
84-
@Component({ name: 'g8-tree-view' })
85-
export default class G8TreeView extends Vue {
84+
@Component({ name: 'g8-vue-tree' })
85+
export default class G8VueTree extends Vue {
8686
/**
8787
* Key of the field in `item` to be used as element's `id` attribute.
8888
*/
@@ -183,7 +183,7 @@ export default class G8TreeView extends Vue {
183183
// descend to all descendant sub-components and update their states,
184184
// also triggers their `state-changed` event.
185185
this.$children.forEach(c => {
186-
(c as G8TreeView).setState(state);
186+
(c as G8VueTree).setState(state);
187187
});
188188
} else if (
189189
this.item[this.childrenKey] &&

0 commit comments

Comments
 (0)