UNPKG

@itwin/presentation-hierarchies-react

Version:

React components based on `@itwin/presentation-hierarchies`

60 lines 3.2 kB
import { ComponentPropsWithoutRef } from "react"; import { NodeData, Tree } from "@itwin/itwinui-react"; import { PresentationTreeNode } from "../TreeNode.js"; import { SelectionMode } from "../UseSelectionHandler.js"; import { useTree } from "../UseTree.js"; import { LocalizationContextProvider } from "./LocalizationContext.js"; import { TreeNodeRenderer } from "./TreeNodeRenderer.js"; /** @public */ type TreeProps = ComponentPropsWithoutRef<typeof Tree<RenderedTreeNode>>; /** @public */ type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>; /** @public */ interface TreeRendererOwnProps { /** Root nodes of the tree. */ rootNodes: PresentationTreeNode[]; /** Active selection mode used by the tree. Defaults to `"single"`. */ selectionMode?: SelectionMode; } /** @public */ type TreeRendererProps = Pick<ReturnType<typeof useTree>, "rootNodes" | "expandNode"> & Partial<Pick<ReturnType<typeof useTree>, "selectNodes" | "isNodeSelected" | "getHierarchyLevelDetails" | "reloadTree">> & Pick<TreeNodeRendererProps, "onFilterClick" | "getIcon" | "getLabel" | "getSublabel" | "filterButtonsVisibility"> & TreeRendererOwnProps & Omit<TreeProps, "data" | "nodeRenderer" | "getNode" | "enableVirtualization"> & ComponentPropsWithoutRef<typeof LocalizationContextProvider>; /** * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes * are rendered using `TreeNodeRenderer` component from this package. * * @see https://itwinui.bentley.com/docs/tree * @public */ export declare function TreeRenderer({ rootNodes, expandNode, selectNodes, isNodeSelected, onFilterClick, getIcon, getLabel, getSublabel, getHierarchyLevelDetails, reloadTree, selectionMode, localizedStrings, size, filterButtonsVisibility, ...treeProps }: TreeRendererProps): import("react/jsx-runtime.js").JSX.Element; /** * A data structure for a tree node that is rendered using the `TreeRenderer` component. * * In addition to the `PresentationTreeNode` union, this type may have one additional variation - an informational * type of node with `ChildrenPlaceholder` type. This type of node is returned as the single child node of a parent * while its children are being loaded. This allows the node renderer to show a placeholder under the parent during * the process. * * @public */ export type RenderedTreeNode = PresentationTreeNode | { id: string; parentNodeId: string | undefined; type: "ChildrenPlaceholder"; }; /** * An utility function that creates an `@itwin/itwinui-react` `NodeData` object for the `Tree` component from a * `RenderedTreeNode` object. * * Usage example: * ```tsx * function MyComponent({ rootNodes, nodeRenderer }: MyComponentProps) { * const getNode = useCallback<TreeProps["getNode"]>((node) => createRenderedTreeNodeData(node, () => false), []); * return <Tree<RenderedTreeNode> data={rootNodes} getNode={getNode} nodeRenderer={nodeRenderer} />; * } * ``` * * @public */ export declare function createRenderedTreeNodeData(node: RenderedTreeNode, isNodeSelected: (nodeId: string) => boolean): NodeData<RenderedTreeNode>; export {}; //# sourceMappingURL=TreeRenderer.d.ts.map