mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
78 lines
No EOL
2.2 KiB
Text
78 lines
No EOL
2.2 KiB
Text
<script>
|
|
import { InlineNotification } from "carbon-components-svelte";
|
|
import Preview from "../../components/Preview.svelte";
|
|
</script>
|
|
|
|
## Default
|
|
|
|
The `children` prop accepts an array of child nodes. Each node should contain `id` and `text` properties.
|
|
|
|
Optional properties include `disabled`, `expanded`, `icon`, and `children`.
|
|
|
|
A parent node contains `children` while a leaf node does not.
|
|
|
|
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
|
|
<div class="body-short-01">Every node must have a unique id.</div>
|
|
</InlineNotification>
|
|
|
|
<FileSource src="/framed/TreeView/TreeView" />
|
|
|
|
## Initial active node
|
|
|
|
The active node can be set through `activeId`.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewActive" />
|
|
|
|
## Compact size
|
|
|
|
Set `size` to `"compact"` to use the compact variant.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewCompact" />
|
|
|
|
## With icons
|
|
|
|
To render a node with an icon, define an `icon` property with a Carbon Svelte icon as its value.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewIcons" />
|
|
|
|
## Initial expanded nodes
|
|
|
|
Expanded nodes can be set using `expandedIds`.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewExpanded" />
|
|
|
|
## Initial multiple selected nodes
|
|
|
|
Initial multiple selected nodes can be set using `selectedIds`.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewMultiselect" />
|
|
|
|
## Expand all nodes
|
|
|
|
To programmatically expand all nodes, access the component instance using the [bind:this](https://svelte.dev/docs#bind_element) directive and invoke the `TreeView.expandAll()` accessor.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewExpandAll" />
|
|
|
|
## Collapse all nodes
|
|
|
|
Similarly, invoke `TreeView.collapseAll()` to collapse all nodes.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewCollapseAll" />
|
|
|
|
## Expand a subset of nodes
|
|
|
|
Use the `TreeView.expandNodes` method to expand only a subset of nodes.
|
|
|
|
The method accepts an argument that takes a node and returns a boolean.
|
|
|
|
If no argument is provided, all nodes will be expanded.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewExpandNodes" />
|
|
|
|
## Collapse a subset of nodes
|
|
|
|
Use the `TreeView.collapseNodes` method to collapse a subset of nodes.
|
|
|
|
If no argument is provided, all nodes will be collapsed.
|
|
|
|
<FileSource src="/framed/TreeView/TreeViewCollapseNodes" /> |