mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
TreeView (#725)
* 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:
parent
f4a3646cb4
commit
6ed4aaa86e
25 changed files with 1176 additions and 4 deletions
63
types/TreeView/TreeView.d.ts
vendored
Normal file
63
types/TreeView/TreeView.d.ts
vendored
Normal file
|
@ -0,0 +1,63 @@
|
|||
/// <reference types="svelte" />
|
||||
import { SvelteComponentTyped } from "svelte";
|
||||
|
||||
export type TreeNodeId = string | number;
|
||||
|
||||
export interface TreeNode {
|
||||
id: TreeNodeId;
|
||||
text: string;
|
||||
icon?: typeof import("carbon-icons-svelte").CarbonIcon;
|
||||
disabled?: boolean;
|
||||
expanded?: boolean;
|
||||
}
|
||||
|
||||
export interface TreeViewProps
|
||||
extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["ul"]> {
|
||||
/**
|
||||
* Provide an array of children nodes to render
|
||||
* @default []
|
||||
*/
|
||||
children?: Array<TreeNode & { children?: TreeNode[] }>;
|
||||
|
||||
/**
|
||||
* Set the current active node id
|
||||
* Only one node can be active
|
||||
* @default ""
|
||||
*/
|
||||
activeId?: TreeNodeId;
|
||||
|
||||
/**
|
||||
* Set the node ids to be selected
|
||||
* @default []
|
||||
*/
|
||||
selectedIds?: TreeNodeId[];
|
||||
|
||||
/**
|
||||
* Specify the TreeView size
|
||||
* @default "default"
|
||||
*/
|
||||
size?: "default" | "compact";
|
||||
|
||||
/**
|
||||
* Specify the label text
|
||||
* @default ""
|
||||
*/
|
||||
labelText?: string;
|
||||
|
||||
/**
|
||||
* Set to `true` to visually hide the label text
|
||||
* @default false
|
||||
*/
|
||||
hideLabel?: boolean;
|
||||
}
|
||||
|
||||
export default class TreeView extends SvelteComponentTyped<
|
||||
TreeViewProps,
|
||||
{
|
||||
select: CustomEvent<TreeNode & { expanded: boolean; leaf: boolean }>;
|
||||
toggle: CustomEvent<TreeNode & { expanded: boolean; leaf: boolean }>;
|
||||
focus: CustomEvent<TreeNode & { expanded: boolean; leaf: boolean }>;
|
||||
keydown: WindowEventMap["keydown"];
|
||||
},
|
||||
{ labelText: {} }
|
||||
> {}
|
Loading…
Add table
Add a link
Reference in a new issue