* feat(tree-view): add TreeView

* fix(tree-view): select initial active node, correct typedefs

* docs(tree-view): update examples

* chore(tree-view): add test for types

* docs(tree-view): rename example

* docs(tree-view): improve docs

* docs(tree-view): refine examples

* docs: fix invalid syntax

* chore: rebuild component index/api

* docs(layout): increase height of sidenav menu [ci skip]
This commit is contained in:
Eric Liu 2021-07-05 09:11:15 -07:00 committed by GitHub
commit 6ed4aaa86e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 1176 additions and 4 deletions

View file

@ -84,6 +84,8 @@
@import "carbon-components/scss/globals/scss/_css--body";
@import "carbon-components/scss/globals/grid/grid";
@import "carbon-components/src/components/treeview/treeview";
// Import all component styles
@import "carbon-components/scss/globals/scss/styles";
</style>

View file

@ -1,5 +1,5 @@
{
"total": 169,
"total": 170,
"components": [
{
"moduleName": "Accordion",
@ -11834,6 +11834,111 @@
"typedefs": [],
"rest_props": { "type": "Element", "name": "button" }
},
{
"moduleName": "TreeView",
"filePath": "src/TreeView/TreeView.svelte",
"props": [
{
"name": "children",
"kind": "let",
"description": "Provide an array of children nodes to render",
"type": "Array<TreeNode & { children?: TreeNode[] }>",
"value": "[]",
"isFunction": false,
"constant": false,
"reactive": false
},
{
"name": "activeId",
"kind": "let",
"description": "Set the current active node id\nOnly one node can be active",
"type": "TreeNodeId",
"value": "\"\"",
"isFunction": false,
"constant": false,
"reactive": true
},
{
"name": "selectedIds",
"kind": "let",
"description": "Set the node ids to be selected",
"type": "TreeNodeId[]",
"value": "[]",
"isFunction": false,
"constant": false,
"reactive": true
},
{
"name": "size",
"kind": "let",
"description": "Specify the TreeView size",
"type": "\"default\" | \"compact\"",
"value": "\"default\"",
"isFunction": false,
"constant": false,
"reactive": false
},
{
"name": "labelText",
"kind": "let",
"description": "Specify the label text",
"type": "string",
"value": "\"\"",
"isFunction": false,
"constant": false,
"reactive": false
},
{
"name": "hideLabel",
"kind": "let",
"description": "Set to `true` to visually hide the label text",
"type": "boolean",
"value": "false",
"isFunction": false,
"constant": false,
"reactive": false
}
],
"slots": [
{
"name": "labelText",
"default": false,
"fallback": "{labelText}",
"slot_props": "{}"
}
],
"events": [
{
"type": "dispatched",
"name": "select",
"detail": "TreeNode & { expanded: boolean; leaf: boolean; }"
},
{
"type": "dispatched",
"name": "toggle",
"detail": "TreeNode & { expanded: boolean; leaf: boolean; }"
},
{
"type": "dispatched",
"name": "focus",
"detail": "TreeNode & { expanded: boolean; leaf: boolean; }"
},
{ "type": "forwarded", "name": "keydown", "element": "ul" }
],
"typedefs": [
{
"type": "string | number",
"name": "TreeNodeId",
"ts": "type TreeNodeId = string | number"
},
{
"type": "{ id: TreeNodeId; text: string; icon?: typeof import(\"carbon-icons-svelte\").CarbonIcon; disabled?: boolean; expanded?: boolean; }",
"name": "TreeNode",
"ts": "interface TreeNode { id: TreeNodeId; text: string; icon?: typeof import(\"carbon-icons-svelte\").CarbonIcon; disabled?: boolean; expanded?: boolean; }"
}
],
"rest_props": { "type": "Element", "name": "ul" }
},
{
"moduleName": "Truncate",
"filePath": "src/Truncate/Truncate.svelte",

View file

@ -20,7 +20,7 @@
import Footer from "../components/Footer.svelte";
const deprecated = ["ToggleSmall", "Icon"];
const new_components = ["ProgressBar", "RecursiveList"];
const new_components = ["ProgressBar", "RecursiveList", "TreeView"];
let isOpen = false;
let isSideNavOpen = true;
@ -264,6 +264,6 @@
}
.bx--side-nav__submenu[aria-expanded="true"] + .bx--side-nav__menu {
max-height: 124rem;
max-height: 132rem;
}
</style>

View file

@ -0,0 +1,48 @@
<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 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
Set `expanded` to `true` on nodes that should be expanded by default.
<FileSource src="/framed/TreeView/TreeViewExpanded" />
### Initial multiple selected nodes
Initial multiple selected nodes can be set using `selectedIds`.
<FileSource src="/framed/TreeView/TreeViewMultiselect" />

View file

@ -0,0 +1,65 @@
<script>
import { TreeView } from "carbon-components-svelte";
let activeId = "";
let selectedIds = [];
let children = [
{ id: 0, text: "AI / Machine learning" },
{
id: 1,
text: "Analytics",
children: [
{
id: 2,
text: "IBM Analytics Engine",
children: [
{ id: 3, text: "Apache Spark" },
{ id: 4, text: "Hadoop" },
],
},
{ id: 5, text: "IBM Cloud SQL Query" },
{ id: 6, text: "IBM Db2 Warehouse on Cloud" },
],
},
{
id: 7,
text: "Blockchain",
children: [{ id: 8, text: "IBM Blockchain Platform" }],
},
{
id: 9,
text: "Databases",
children: [
{ id: 10, text: "IBM Cloud Databases for Elasticsearch" },
{ id: 11, text: "IBM Cloud Databases for Enterprise DB" },
{ id: 12, text: "IBM Cloud Databases for MongoDB" },
{ id: 13, text: "IBM Cloud Databases for PostgreSQL" },
],
},
{
id: 14,
text: "Integration",
disabled: true,
children: [{ id: 15, text: "IBM API Connect", disabled: true }],
},
];
</script>
<TreeView
labelText="Cloud Products"
children="{children}"
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>

View file

@ -0,0 +1,65 @@
<script>
import { TreeView } from "carbon-components-svelte";
let activeId = 0;
let selectedIds = [];
let children = [
{ id: 0, text: "AI / Machine learning" },
{
id: 1,
text: "Analytics",
children: [
{
id: 2,
text: "IBM Analytics Engine",
children: [
{ id: 3, text: "Apache Spark" },
{ id: 4, text: "Hadoop" },
],
},
{ id: 5, text: "IBM Cloud SQL Query" },
{ id: 6, text: "IBM Db2 Warehouse on Cloud" },
],
},
{
id: 7,
text: "Blockchain",
children: [{ id: 8, text: "IBM Blockchain Platform" }],
},
{
id: 9,
text: "Databases",
children: [
{ id: 10, text: "IBM Cloud Databases for Elasticsearch" },
{ id: 11, text: "IBM Cloud Databases for Enterprise DB" },
{ id: 12, text: "IBM Cloud Databases for MongoDB" },
{ id: 13, text: "IBM Cloud Databases for PostgreSQL" },
],
},
{
id: 14,
text: "Integration",
disabled: true,
children: [{ id: 15, text: "IBM API Connect", disabled: true }],
},
];
</script>
<TreeView
labelText="Cloud Products"
children="{children}"
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>

View file

@ -0,0 +1,66 @@
<script>
import { TreeView } from "carbon-components-svelte";
let activeId = 0;
let selectedIds = [];
let children = [
{ id: 0, text: "AI / Machine learning" },
{
id: 1,
text: "Analytics",
children: [
{
id: 2,
text: "IBM Analytics Engine",
children: [
{ id: 3, text: "Apache Spark" },
{ id: 4, text: "Hadoop" },
],
},
{ id: 5, text: "IBM Cloud SQL Query" },
{ id: 6, text: "IBM Db2 Warehouse on Cloud" },
],
},
{
id: 7,
text: "Blockchain",
children: [{ id: 8, text: "IBM Blockchain Platform" }],
},
{
id: 9,
text: "Databases",
children: [
{ id: 10, text: "IBM Cloud Databases for Elasticsearch" },
{ id: 11, text: "IBM Cloud Databases for Enterprise DB" },
{ id: 12, text: "IBM Cloud Databases for MongoDB" },
{ id: 13, text: "IBM Cloud Databases for PostgreSQL" },
],
},
{
id: 14,
text: "Integration",
disabled: true,
children: [{ id: 15, text: "IBM API Connect", disabled: true }],
},
];
</script>
<TreeView
size="compact"
labelText="Cloud Products"
children="{children}"
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>

View file

@ -0,0 +1,67 @@
<script>
import { TreeView } from "carbon-components-svelte";
let activeId = 1;
let selectedIds = [];
let children = [
{ id: 0, text: "AI / Machine learning" },
{
id: 1,
text: "Analytics",
expanded: true,
children: [
{
id: 2,
text: "IBM Analytics Engine",
expanded: true,
children: [
{ id: 3, text: "Apache Spark" },
{ id: 4, text: "Hadoop" },
],
},
{ id: 5, text: "IBM Cloud SQL Query" },
{ id: 6, text: "IBM Db2 Warehouse on Cloud" },
],
},
{
id: 7,
text: "Blockchain",
children: [{ id: 8, text: "IBM Blockchain Platform" }],
},
{
id: 9,
text: "Databases",
children: [
{ id: 10, text: "IBM Cloud Databases for Elasticsearch" },
{ id: 11, text: "IBM Cloud Databases for Enterprise DB" },
{ id: 12, text: "IBM Cloud Databases for MongoDB" },
{ id: 13, text: "IBM Cloud Databases for PostgreSQL" },
],
},
{
id: 14,
text: "Integration",
disabled: true,
children: [{ id: 15, text: "IBM API Connect", disabled: true }],
},
];
</script>
<TreeView
labelText="Cloud Products"
children="{children}"
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>

View file

@ -0,0 +1,98 @@
<script>
import { TreeView } from "carbon-components-svelte";
import WatsonMachineLearning16 from "carbon-icons-svelte/lib/WatsonMachineLearning16";
import Analytics16 from "carbon-icons-svelte/lib/Analytics16";
import Blockchain16 from "carbon-icons-svelte/lib/Blockchain16";
import DataBase16 from "carbon-icons-svelte/lib/DataBase16";
import SignalStrength16 from "carbon-icons-svelte/lib/SignalStrength16";
let activeId = 1;
let selectedIds = [];
let children = [
{ id: 0, text: "AI / Machine learning", icon: WatsonMachineLearning16 },
{
id: 1,
text: "Analytics",
icon: Analytics16,
expanded: true,
children: [
{
id: 2,
text: "IBM Analytics Engine",
icon: Analytics16,
expanded: true,
children: [
{ id: 3, text: "Apache Spark", icon: Analytics16 },
{ id: 4, text: "Hadoop", icon: Analytics16 },
],
},
{ id: 5, text: "IBM Cloud SQL Query", icon: Analytics16 },
{ id: 6, text: "IBM Db2 Warehouse on Cloud", icon: Analytics16 },
],
},
{
id: 7,
text: "Blockchain",
icon: Blockchain16,
children: [
{ id: 8, text: "IBM Blockchain Platform", icon: Blockchain16 },
],
},
{
id: 9,
text: "Databases",
icon: DataBase16,
children: [
{
id: 10,
text: "IBM Cloud Databases for Elasticsearch",
icon: DataBase16,
},
{
id: 11,
text: "IBM Cloud Databases for Enterprise DB",
icon: DataBase16,
},
{ id: 12, text: "IBM Cloud Databases for MongoDB", icon: DataBase16 },
{
id: 13,
text: "IBM Cloud Databases for PostgreSQL",
icon: DataBase16,
},
],
},
{
id: 14,
text: "Integration",
icon: SignalStrength16,
disabled: true,
children: [
{
id: 15,
text: "IBM API Connect",
icon: SignalStrength16,
disabled: true,
},
],
},
];
</script>
<TreeView
labelText="Cloud Products"
children="{children}"
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>

View file

@ -0,0 +1,65 @@
<script>
import { TreeView } from "carbon-components-svelte";
let activeId = 0;
let selectedIds = [0, 7, 9];
let children = [
{ id: 0, text: "AI / Machine learning" },
{
id: 1,
text: "Analytics",
children: [
{
id: 2,
text: "IBM Analytics Engine",
children: [
{ id: 3, text: "Apache Spark" },
{ id: 4, text: "Hadoop" },
],
},
{ id: 5, text: "IBM Cloud SQL Query" },
{ id: 6, text: "IBM Db2 Warehouse on Cloud" },
],
},
{
id: 7,
text: "Blockchain",
children: [{ id: 8, text: "IBM Blockchain Platform" }],
},
{
id: 9,
text: "Databases",
children: [
{ id: 10, text: "IBM Cloud Databases for Elasticsearch" },
{ id: 11, text: "IBM Cloud Databases for Enterprise DB" },
{ id: 12, text: "IBM Cloud Databases for MongoDB" },
{ id: 13, text: "IBM Cloud Databases for PostgreSQL" },
],
},
{
id: 14,
text: "Integration",
disabled: true,
children: [{ id: 15, text: "IBM API Connect", disabled: true }],
},
];
</script>
<TreeView
labelText="Cloud Products"
children="{children}"
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>