forked from carbon-design-system/carbon-components-svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeViewFlatArray.svelte
69 lines (65 loc) · 2.19 KB
/
TreeViewFlatArray.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<script>
import { TreeView, toHierarchy } from "carbon-components-svelte";
import WatsonMachineLearning from "carbon-icons-svelte/lib/WatsonMachineLearning.svelte";
import Analytics from "carbon-icons-svelte/lib/Analytics.svelte";
import Blockchain from "carbon-icons-svelte/lib/Blockchain.svelte";
import DataBase from "carbon-icons-svelte/lib/DataBase.svelte";
import SignalStrength from "carbon-icons-svelte/lib/SignalStrength.svelte";
let activeId = "";
let selectedIds = [];
let nodesFlat = [
{ id: 0, text: "AI / Machine learning", icon: WatsonMachineLearning },
{ id: 1, text: "Analytics", icon: Analytics },
{ id: 2, text: "IBM Analytics Engine", pid: 1, icon: Analytics },
{ id: 3, text: "Apache Spark", pid: 2, icon: Analytics },
{ id: 4, text: "Hadoop", icon: Analytics, pid: 2 },
{ id: 5, text: "IBM Cloud SQL Query", icon: Analytics, pid: 1 },
{ id: 6, text: "IBM Db2 Warehouse on Cloud", icon: Analytics, pid: 1 },
{ id: 7, text: "Blockchain", icon: Blockchain },
{ id: 8, text: "IBM Blockchain Platform", icon: Blockchain, pid: 7 },
{ id: 9, text: "Databases", icon: DataBase },
{
id: 10,
text: "IBM Cloud Databases for Elasticsearch",
icon: DataBase,
pid: 9,
},
{
id: 11,
text: "IBM Cloud Databases for Enterprise DB",
icon: DataBase,
pid: 9,
},
{ id: 12, text: "IBM Cloud Databases for MongoDB", icon: DataBase, pid: 9 },
{
id: 13,
text: "IBM Cloud Databases for PostgreSQL",
icon: DataBase,
pid: 9,
},
{ id: 14, text: "Integration", icon: SignalStrength, disabled: true },
{
id: 15,
text: "IBM API Connect",
icon: SignalStrength,
disabled: true,
pid: 14,
},
];
</script>
<TreeView
labelText="Cloud Products"
nodes={toHierarchy(nodesFlat)}
bind:activeId
bind:selectedIds
on:select={({ detail }) => console.log("select", detail)}
on:toggle={({ detail }) => console.log("toggle", detail)}
on:focus={({ detail }) => console.log("focus", detail)}
/>
<div>Active node id: {activeId}</div>
<div>Selected ids: {JSON.stringify(selectedIds)}</div>
<style>
div {
margin-top: var(--cds-spacing-05);
}
</style>