UNPKG

@carbon/react

Version:

React components for the Carbon Design System

64 lines (63 loc) 2.14 kB
/** * Copyright IBM Corp. 2016, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import React, { type JSX } from 'react'; import TreeNode, { type TreeNodeProps } from './TreeNode'; type UncontrolledOnSelect = (event: React.MouseEvent | React.KeyboardEvent, payload: Parameters<NonNullable<TreeNodeProps['onSelect']>>[1] & { activeNodeId?: TreeViewProps['active']; }) => void; type ControlledOnSelect = (selected: TreeViewProps['selected']) => void; export type TreeViewProps = { /** * Mark the active node in the tree, represented by its ID */ active?: string | number; /** * Specify the children of the TreeView */ children?: React.ReactNode; /** * Specify an optional className to be applied to the TreeView */ className?: string; /** * Specify whether or not the label should be hidden */ hideLabel?: boolean; /** * Provide the label text that will be read by a screen reader */ label: string; /** * **[Experimental]** Specify the selection mode of the tree. * If `multiselect` is `false` then only one node can be selected at a time */ multiselect?: boolean; /** * **[Experimental]** Callback function that is called when any node is activated. * *This is only supported with the `enable-treeview-controllable` feature flag!* */ onActivate?: (active: TreeViewProps['active']) => void; /** * Callback function that is called when any node is selected */ onSelect?: UncontrolledOnSelect | ControlledOnSelect; /** * Array representing all selected node IDs in the tree */ selected?: Array<string | number>; /** * Specify the size of the tree from a list of available sizes. */ size?: 'xs' | 'sm'; } & Omit<React.HTMLAttributes<HTMLUListElement>, 'onSelect'>; type TreeViewComponent = { (props: TreeViewProps): JSX.Element; propTypes?: any; TreeNode: typeof TreeNode; }; declare const TreeView: TreeViewComponent; export default TreeView;