Skip to content

Commit 17f4b12

Browse files
committed
📚 Updated Demo app and docs.
1 parent 50474e1 commit 17f4b12

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A light-weight library for management of hierachical content. Most solutions I f
1313
- ✔️ Rendering (checkboxes or plain content)
1414
- Custom Context Menu depending on item type.
1515
5. Programmatically toggle item visibility based on the `type` property.
16+
6. Sorting items alphametically or grouping based on types
1617

1718
## What it looks like.
1819

@@ -24,7 +25,9 @@ A light-weight library for management of hierachical content. Most solutions I f
2425
<template>
2526
<tree-view :treeViewItems="treeViewNodes" />
2627
</template>
28+
```
2729

30+
```ts
2831
<script lang='ts'>
2932
import { Vue, Component} from 'vue-property-decorator';
3033

@@ -80,6 +83,8 @@ You can customise item based on their `type` property.
8083
```ts
8184
export interface TreeViewCreatedEventPayload {
8285
itemCustomisations: ItemTypeCustomisations;
86+
eventManager: EventManager
87+
...
8388
}
8489
```
8590

@@ -116,3 +121,17 @@ export default class App extends Vue {
116121
#### Output
117122

118123
![image](https://user-images.githubusercontent.com/39003759/121091770-7090b480-c7e2-11eb-9ee5-e79351bd8ed8.png)
124+
125+
### Listening to Items Checked
126+
127+
To carter for advanced cases where `children` of the hierachical tree may be of different types. And you want to perform some further actions whenever something happens to them. You can subscribe for checked events of item types you may be interested in. And perform further actions.
128+
129+
E.g A school has departments, and you want to check some departments and delete them.
130+
131+
| School
132+
|------- Department A
133+
|------- Department B
134+
135+
You can attach callbacks that notify you when departments have been checked on the tree.
136+
137+
Example

src/App.vue

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<template>
2-
<tree-view :treeViewItems="treeViewNodes" @created="customiseTreeView">
3-
<template v-slot:icon="treeViewItem">
4-
<img src="@/assets/folder.svg" alt="folder" v-if="treeViewItem.type === 'folder'" >
5-
<img src="@/assets/word.svg" alt="vue-logo" v-else-if="treeViewItem.type === '.doc'" height="18" width="18">
6-
<img src="@/assets/excel.svg" alt="vue-logo" v-else-if="treeViewItem.type === '.excel'" height="18" width="18">
7-
<img src="@/assets/playlist.svg" alt="vue-logo" v-else-if="treeViewItem.type === 'media'" height="18" width="18">
8-
</template>
9-
</tree-view>
2+
<div style="display: flex">
3+
<!-- Example of how to customise appearance of tree items -->
4+
<tree-view :treeViewItems="treeViewNodes" @created="customiseTreeView">
5+
<template v-slot:icon="treeViewItem">
6+
<img src="@/assets/folder.svg" alt="folder" v-if="treeViewItem.type === 'folder'" >
7+
<img src="@/assets/word.svg" alt="vue-logo" v-else-if="treeViewItem.type === '.doc'" height="18" width="18">
8+
<img src="@/assets/excel.svg" alt="vue-logo" v-else-if="treeViewItem.type === '.excel'" height="18" width="18">
9+
<img src="@/assets/playlist.svg" alt="vue-logo" v-else-if="treeViewItem.type === 'media'" height="18" width="18">
10+
</template>
11+
</tree-view>
12+
13+
<!-- Examples of how to subscribe for events -->
14+
<tree-view :treeViewItems="schools" @created="customiseSchools" />
15+
</div>
1016
</template>
1117

1218
<script lang='ts'>
@@ -20,11 +26,19 @@ export default class App extends Vue {
2026
customiseTreeView(treeCreatedEvent: TreeViewCreatedEventPayload) {
2127
const customisations = treeCreatedEvent.itemCustomisations;
2228
const eventManager = treeCreatedEvent.eventManager;
23-
24-
eventManager.subscribeToItemChecked(".doc", (items) => console.log(items));
29+
2530
customisations.makeItemsCheckable([".doc", ".excel", "media" ]);
2631
}
2732
33+
customiseSchools(treeCreatedEvent: TreeViewCreatedEventPayload) {
34+
const customisations = treeCreatedEvent.itemCustomisations;
35+
const eventManager = treeCreatedEvent.eventManager;
36+
37+
eventManager.subscribeToItemChecked("department", (items) => console.log(items));
38+
customisations.makeItemsCheckable(["department"]);
39+
}
40+
41+
2842
treeViewNodes: TreeViewItem[] = [
2943
{
3044
name: 'Desktop',
@@ -123,5 +137,27 @@ export default class App extends Vue {
123137
]
124138
}
125139
];
140+
141+
schools: TreeViewItem[] = [
142+
{
143+
id: '1',
144+
type: 'school',
145+
name: 'Vue School',
146+
children: [
147+
{
148+
id: '2',
149+
type: 'department',
150+
name: 'Typescript Department',
151+
parentId: '1'
152+
},
153+
{
154+
id: '3',
155+
type: 'department',
156+
name: 'Open Source Department',
157+
parentId: '1'
158+
}
159+
]
160+
}
161+
]
126162
}
127163
</script>

0 commit comments

Comments
 (0)