Trees are used to visualize hierarchial information. They are often used to display navigational structures like nested lists of links.
import { DaffTreeComponent } from '@daffodil/design/tree'
The DaffTreeComponent
allows you to render tree structures as interactable ui.
@Component()
class DaffTreeComponent implements OnInit, OnChanges {
flatTree: DaffTreeFlatNode[] = []
@Input() renderMode: DaffTreeRenderMode
@Input() tree: DaffTreeData<unknown>
ngOnChanges(changes: SimpleChanges): void
trackByTreeElement(
index: number
el: any
): any
}
DaffTreeFlatNode[]
Default | [] |
---|---|
Description | The flattened tree data. You can iterate through this if you want to inspect the resulting array structure we computed to render the tree. |
void
Parameter | changes: SimpleChanges |
---|---|
Description |
any
The track-by function used to reduce tree-item re-renders
Parameter | index: number |
---|---|
Description |
Parameter | el: any |
---|---|
Description |
DaffTreeRenderMode
Default | – |
---|---|
Description | The rendering mode for nodes in the tree. Default value is 'in-dom', which means nodes are present in the DOM. Generally, |
DaffTreeData
Default | – |
---|---|
Description | The tree data you would like to render. |
import { DaffTreeItemDirective } from '@daffodil/design/tree'
The DaffTreeItemDirective
marks elements as tree child nodes that interact with the parent tree structure.
@Directive()
class DaffTreeItemDirective {
@HostBinding() depth: number
@HostBinding()
get selectedClass(): boolean
@HostBinding() openClass: boolean = false
@Input() node: DaffTreeFlatNode
@Input() selected: boolean = false
toggleParent(node: DaffTreeFlatNode): void
toggleTree(node: DaffTreeFlatNode): void
}
number
Default | – |
---|---|
Description | A css variable indicating the depth of the tree. You can use this to style your templates if you want to use different designs at different depths. |
boolean
Default | – |
---|---|
Description | The CSS class indicating whether or not the tree is |
boolean
Default | false |
---|---|
Description | The CSS class indicating whether or not the tree is |
void
Toggle the open state of the tree's parent.
Parameter | node: DaffTreeFlatNode |
---|---|
Description |
void
Toggle the open state of this specific subtree tree.
Parameter | node: DaffTreeFlatNode |
---|---|
Description |
DaffTreeFlatNode
Default | – |
---|---|
Description | The DaffTreeFlatNode associated with this specific tree item. |
boolean
Default | false |
---|---|
Description | Whether or not the tree item is the currently active item. Note that there is no requirement there there only be one active item at a time. |
import { DaffTreeModule } from '@daffodil/design/tree'
@NgModule()
class DaffTreeModule {}
import { DaffTreeData } from '@daffodil/design/tree'
A basic tree type supporting supplemental data on a tree node.
Tree elements are often slightly more than just basic titles and child items. There may be other important data that needs to be available at render time.
interface DaffTreeData<T> {
title: string
url: string
id: string
items: DaffTreeData<T>[]
data: T
}
import { DaffTreeRenderMode } from '@daffodil/design/tree'
Represents the mode of rendering for nodes in a tree UI.
type DaffTreeRenderMode = 'in-dom' | 'not-in-dom'
import { daffTransformTree } from '@daffodil/design/tree'
Transform a tree-like structure into a DaffTreeData
.
const daffTransformTree: <T extends Record<any, any>, V>(tree: T, transformFn: (type: T) => DaffTreeData<V>, key: keyof T) => DaffTreeData<V>