From 4f22c7fc1c18e8bf74a73812a945ef2e357ee913 Mon Sep 17 00:00:00 2001 From: metonym Date: Wed, 13 Oct 2021 08:28:08 -0700 Subject: [PATCH] feat(tree-view): update docs/types --- COMPONENT_INDEX.md | 22 ++++++++++-------- docs/src/COMPONENT_API.json | 44 ++++++++++++++++++++++++++++++++++++ src/TreeView/TreeView.svelte | 2 ++ types/TreeView/TreeView.d.ts | 28 ++++++++++++++++++++++- 4 files changed, 86 insertions(+), 10 deletions(-) diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 068af834..b4c56810 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -4752,15 +4752,19 @@ export interface TreeNode { ### Props -| Prop name | Kind | Reactive | Type | Default value | Description | -| :---------- | :--------------- | :------- | :------------------------------------------------------- | ---------------------- | --------------------------------------------------------------- | -| expandedIds | let | Yes | TreeNodeId[] | [] | Set the node ids to be expanded | -| selectedIds | let | Yes | TreeNodeId[] | [] | Set the node ids to be selected | -| activeId | let | Yes | TreeNodeId | "" | Set the current active node id
Only one node can be active | -| children | let | No | Array | [] | Provide an array of children nodes to render | -| size | let | No | "default" | "compact" | "default" | Specify the TreeView size | -| labelText | let | No | string | "" | Specify the label text | -| hideLabel | let | No | boolean | false | Set to `true` to visually hide the label text | +| Prop name | Kind | Reactive | Type | Default value | Description | +| :------------ | :-------------------- | :------- | :------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | +| expandedIds | let | Yes | TreeNodeId[] | [] | Set the node ids to be expanded | +| selectedIds | let | Yes | TreeNodeId[] | [] | Set the node ids to be selected | +| activeId | let | Yes | TreeNodeId | "" | Set the current active node id
Only one node can be active | +| children | let | No | Array | [] | Provide an array of children nodes to render | +| size | let | No | "default" | "compact" | "default" | Specify the TreeView size | +| labelText | let | No | string | "" | Specify the label text | +| hideLabel | let | No | boolean | false | Set to `true` to visually hide the label text | +| expandAll | function | No | () => void | () => { expandedIds = [...nodeIds]; } | Programmatically expand all nodes | +| collapseAll | function | No | () => void | () => { expandedIds = []; } | Programmatically collapse all nodes | +| expandNodes | function | No | (filterId?: (node: TreeNode) => boolean) => void | () => { expandedIds = nodes .filter((node) => !filterNode(node)) .map((node) => node.id); } | Programmatically expand a subset of nodes.
Expands all nodes if no argument is provided | +| collapseNodes | function | No | (filterId?: (node: TreeNode) => boolean) => void | () => { expandedIds = nodes .filter((node) => !filterNode(node)) .map((node) => node.id); } | Programmatically collapse a subset of nodes.
Collapses all nodes if no argument is provided | ### Slots diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index ea62c0b5..7a653e05 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -13152,6 +13152,50 @@ "isFunctionDeclaration": false, "constant": false, "reactive": false + }, + { + "name": "expandAll", + "kind": "function", + "description": "Programmatically expand all nodes", + "type": "() => void", + "value": "() => { expandedIds = [...nodeIds]; }", + "isFunction": true, + "isFunctionDeclaration": true, + "constant": false, + "reactive": false + }, + { + "name": "collapseAll", + "kind": "function", + "description": "Programmatically collapse all nodes", + "type": "() => void", + "value": "() => { expandedIds = []; }", + "isFunction": true, + "isFunctionDeclaration": true, + "constant": false, + "reactive": false + }, + { + "name": "expandNodes", + "kind": "function", + "description": "Programmatically expand a subset of nodes.\nExpands all nodes if no argument is provided", + "type": "(filterId?: (node: TreeNode) => boolean) => void", + "value": "() => { expandedIds = nodes .filter((node) => !filterNode(node)) .map((node) => node.id); }", + "isFunction": true, + "isFunctionDeclaration": true, + "constant": false, + "reactive": false + }, + { + "name": "collapseNodes", + "kind": "function", + "description": "Programmatically collapse a subset of nodes.\nCollapses all nodes if no argument is provided", + "type": "(filterId?: (node: TreeNode) => boolean) => void", + "value": "() => { expandedIds = nodes .filter((node) => !filterNode(node)) .map((node) => node.id); }", + "isFunction": true, + "isFunctionDeclaration": true, + "constant": false, + "reactive": false } ], "slots": [ diff --git a/src/TreeView/TreeView.svelte b/src/TreeView/TreeView.svelte index f0a19ccd..7e36da2e 100644 --- a/src/TreeView/TreeView.svelte +++ b/src/TreeView/TreeView.svelte @@ -46,6 +46,7 @@ /** * Programmatically expand all nodes + * @type {() => void} */ export function expandAll() { expandedIds = [...nodeIds]; @@ -53,6 +54,7 @@ /** * Programmatically collapse all nodes + * @type {() => void} */ export function collapseAll() { expandedIds = []; diff --git a/types/TreeView/TreeView.d.ts b/types/TreeView/TreeView.d.ts index 15c352c3..29678a9a 100644 --- a/types/TreeView/TreeView.d.ts +++ b/types/TreeView/TreeView.d.ts @@ -66,4 +66,30 @@ export default class TreeView extends SvelteComponentTyped< keydown: WindowEventMap["keydown"]; }, { labelText: {} } -> {} +> { + /** + * Programmatically expand all nodes + * @default () => { expandedIds = [...nodeIds]; } + */ + expandAll: () => void; + + /** + * Programmatically collapse all nodes + * @default () => { expandedIds = []; } + */ + collapseAll: () => void; + + /** + * Programmatically expand a subset of nodes. + * Expands all nodes if no argument is provided + * @default () => { expandedIds = nodes .filter((node) => !filterNode(node)) .map((node) => node.id); } + */ + expandNodes: (filterId?: (node: TreeNode) => boolean) => void; + + /** + * Programmatically collapse a subset of nodes. + * Collapses all nodes if no argument is provided + * @default () => { expandedIds = nodes .filter((node) => !filterNode(node)) .map((node) => node.id); } + */ + collapseNodes: (filterId?: (node: TreeNode) => boolean) => void; +}