@fluid-topics/ft-tree-selector 1.2.32 → 1.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { html, nothing } from "lit";
|
|
8
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
8
9
|
import { FtLitElement, hasChanged, ParametrizedLabelResolver, } from "@fluid-topics/ft-wc-utils";
|
|
9
10
|
import { styles } from "./ft-tree-selector.styles";
|
|
10
11
|
import { FtCheckbox } from "@fluid-topics/ft-checkbox";
|
|
@@ -55,8 +56,9 @@ class FtTreeSelector extends FtLitElement {
|
|
|
55
56
|
}
|
|
56
57
|
render() {
|
|
57
58
|
var _a;
|
|
59
|
+
const atLeastOneRootNodeIsExpandable = this.data.rootNodes.some(rootNode => rootNode.children.length > 0);
|
|
58
60
|
return html `
|
|
59
|
-
<div class="ft-tree-selector">
|
|
61
|
+
<div class="ft-tree-selector ${atLeastOneRootNodeIsExpandable ? "with-expandable" : ""}">
|
|
60
62
|
<div part="header">
|
|
61
63
|
<ft-typography variant="overline" part="label">
|
|
62
64
|
${this.label}
|
|
@@ -94,6 +96,11 @@ class FtTreeSelector extends FtLitElement {
|
|
|
94
96
|
}
|
|
95
97
|
renderNode(node) {
|
|
96
98
|
const isNodeExpanded = this.isNodeExpanded(node);
|
|
99
|
+
const childrenClasses = {
|
|
100
|
+
"expanded": isNodeExpanded,
|
|
101
|
+
"collapsed": isNodeExpanded,
|
|
102
|
+
"with-expandable": this.hasExpandableChildren(node),
|
|
103
|
+
};
|
|
97
104
|
return html `
|
|
98
105
|
<div part="level" class="${node.children.length != 0 ? "expandable" : "leaf"}"
|
|
99
106
|
data-value="${node.value}">
|
|
@@ -110,9 +117,7 @@ class FtTreeSelector extends FtLitElement {
|
|
|
110
117
|
</div>
|
|
111
118
|
${node.children.length != 0 && this.isNodeExpanded(node)
|
|
112
119
|
? html `
|
|
113
|
-
<div part="children"
|
|
114
|
-
class="${isNodeExpanded ? "expanded" : "collapsed"}"
|
|
115
|
-
id=${this.getAriaControlId(node)}>
|
|
120
|
+
<div part="children" class=${classMap(childrenClasses)} id=${this.getAriaControlId(node)}>
|
|
116
121
|
${isNodeExpanded
|
|
117
122
|
? html `${repeat(node.children, (c) => c.value, (c) => this.renderNode(c))}`
|
|
118
123
|
: nothing}
|
|
@@ -207,6 +212,9 @@ class FtTreeSelector extends FtLitElement {
|
|
|
207
212
|
isNodeExpanded(node) {
|
|
208
213
|
return !this.userClosedNodes.has(node.value) && (node.expanded || this.userOpenedNodes.has(node.value));
|
|
209
214
|
}
|
|
215
|
+
hasExpandableChildren(node) {
|
|
216
|
+
return node.children.some(child => child.children.length > 0);
|
|
217
|
+
}
|
|
210
218
|
expandAll() {
|
|
211
219
|
this.userClosedNodes = new Set();
|
|
212
220
|
this.userOpenedNodes = new Set(this.data.rootNodes.flatMap((n) => this.getAllClosedNodes(n)));
|