Skip to content

Commit ace5437

Browse files
committed
docs: updates information on trees
1 parent fc2ef8a commit ace5437

File tree

1 file changed

+42
-24
lines changed
  • 16/umbraco-cms/customizing/extending-overview/extension-types

1 file changed

+42
-24
lines changed

16/umbraco-cms/customizing/extending-overview/extension-types/tree.md

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ description: A guide to creating a custom tree in Umbraco
88
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
99
{% endhint %}
1010

11-
The tree is a hierarchical structure of nodes and is registered in the Backoffice extension registry. A tree can be rendered anywhere in the Backoffice with the help of the umb-tree element.
11+
The tree is a hierarchical structure of nodes and is registered in the Backoffice extension registry. A tree can be rendered anywhere in the Backoffice with the help of the `<umb-tree />` element.
12+
13+
{% hint style="info" %}
14+
If you are looking for information on how to register a tree as a menu in a section, please refer to the [Section Sidebar](./sections/section-sidebar.md) article.
15+
{% endhint %}
1216

1317
## Creating trees <a href="#creating-trees" id="creating-trees"></a>
1418

@@ -20,51 +24,58 @@ The backoffice comes with two different tree item kinds out of the box: entity a
2024

2125
Tree Manifest:
2226

23-
```typescript
24-
// TODO: add interface
27+
```json
2528
{
26-
"type": "tree",
27-
"alias": "My.Tree.Alias",
28-
"name": "My Tree",
29-
"meta": {
30-
"repositoryAlias": "My.Repository.Alias"
31-
}
29+
"type": "tree",
30+
"alias": "My.Tree.Alias",
31+
"name": "My Tree",
32+
"meta": {
33+
"repositoryAlias": "My.Repository.Alias"
34+
}
3235
},
3336
{
34-
"type": "treeItem",
35-
"kind": "entity",
36-
"alias": "My.TreeItem.Alias",
37-
"name": "My Tree Item",
38-
"conditions": {
39-
"entityType": "my-entity-type",
40-
},
37+
"type": "treeItem",
38+
"kind": "entity",
39+
"alias": "My.TreeItem.Alias",
40+
"name": "My Tree Item",
41+
"conditions": {
42+
"entityType": "my-entity-type",
43+
},
4144
}
4245
```
4346

4447
### Rendering a tree <a href="#rendering-a-tree" id="rendering-a-tree"></a>
4548

49+
To render a tree in the Backoffice, you can use the `<umb-tree>` element. You need to provide the alias of the tree you want to render. The alias is the same as the one you registered in the manifest.
50+
4651
```typescript
4752
<umb-tree alias="My.Tree.Alias"></umb-tree>
4853
```
4954

5055
### Render a Custom Tree Item <a href="#render-a-custom-tree-item" id="render-a-custom-tree-item"></a>
5156

57+
The `<umb-tree />` element will render the tree items based on the registered tree item alias. If you want to render a custom tree item, you need to register a tree item manifest. This manifest can then show a custom element for the tree item.
58+
5259
#### **The Tree Item Manifest**
5360

54-
```typescript
61+
```json
5562
{
56-
"type": "treeItem",
57-
"alias": "Umb.TreeItem.Alias",
58-
"name": "My Tree Item",
59-
"element": "./my-tree-item.element.js",
60-
"conditions": {
61-
"entityType": "my-entity-type",
62-
},
63+
"type": "treeItem",
64+
"alias": "Umb.TreeItem.Alias",
65+
"name": "My Tree Item",
66+
"element": "./my-tree-item.element.js",
67+
"conditions": {
68+
"entityType": "my-entity-type",
69+
},
6370
};
6471
```
6572

6673
#### The Tree Item Element <a href="#the-tree-item-element" id="the-tree-item-element"></a>
6774

75+
To create a custom tree item, you need to create a custom element. This element can choose to use the `<umb-tree-item-base>` element underneath. However, it can also be used as a standalone element if you prefer to implement the tree item logic yourself.
76+
77+
In this example, we will create a custom tree item that uses the `<umb-tree-item-base>` element. This base element provides the necessary context and functionality for the tree item.
78+
6879
```typescript
6980
import { css, html, nothing } from 'lit';
7081
import { customElement, property } from 'lit/decorators.js';
@@ -83,6 +94,7 @@ export class MyTreeItemElement extends UmbElementMixin(LitElement) {
8394
this.#context.setTreeItem(value);
8495
}
8596

97+
// Register the context for the tree item
8698
#context = new UmbMyTreeItemContext(this);
8799

88100
render() {
@@ -96,6 +108,10 @@ export default MyTreeItemElement;
96108

97109
#### The Tree Item Context <a href="#the-tree-item-context" id="the-tree-item-context"></a>
98110

111+
The tree item context is a class that provides the necessary functionality for the tree item. It is used to manage the state of the tree item, such as loading children, selecting, and deselecting the item.
112+
113+
You can create a custom tree item context by implementing the `UmbTreeItemContext<T>` interface.
114+
99115
```typescript
100116
// TODO: auto-generate this from the interface
101117
export interface UmbTreeItemContext<T> {
@@ -128,6 +144,8 @@ export interface UmbTreeItemContext<T> {
128144

129145
#### Extending the Tree Item Context base <a href="#extending-the-tree-item-context-base" id="extending-the-tree-item-context-base"></a>
130146

147+
The easiest way to create a custom tree item context is to extend the `UmbTreeItemContextBase<T>` class. This class provides a lot of the functionality you need out of the box, such as loading children, selecting, and deselecting the item.
148+
131149
We provide a base class for the tree item context. This class provides some default implementations for the context. You can extend this class to overwrite any of the default implementations.
132150

133151
```typescript

0 commit comments

Comments
 (0)