@itwin/presentation-hierarchies-react 2.0.0-alpha.8 → 2.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @itwin/presentation-hierarchies-react
2
2
 
3
+ ## 2.0.0-alpha.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#906](https://github.com/iTwin/presentation/pull/906): Replaced `TreeNodeRenderer.getIcon` prop with `getDecorations` prop.
8
+
9
+ The `getIcon` prop took either an icon URI, or a `ReactElement`. The new `getDecorations` prop allows passing multiple React elements, allowing consumers to render not just the icon, but also addition components like a tag or a color swatch. Migration:
10
+
11
+ ```ts
12
+ // previously, when `getIcon` returned a `ReactElement`:
13
+ function myGetIcon(node: PresentationHierarchyNode): React.ReactElement {
14
+ // implementation...
15
+ }
16
+ <TreeNodeRenderer getIcon={myGetIcon} />
17
+
18
+ // now:
19
+ <TreeNodeRenderer getDecorations={myGetIcon} />
20
+
21
+ // previously, when `getIcon` returned an icon URI:
22
+ function myGetIconUri(node: PresentationHierarchyNode): string {
23
+ // implementation...
24
+ }
25
+ <TreeNodeRenderer getIcon={myGetIconUri} />
26
+
27
+ // now:
28
+ <TreeNodeRenderer getDecorations={(node) => <Icon href={myGetIconUri(node)} />} />
29
+ ```
30
+
31
+ - [#911](https://github.com/iTwin/presentation/pull/911): Fix incorrect left padding on tree items
32
+
3
33
  ## 2.0.0-alpha.8
4
34
 
5
35
  ### Patch Changes
@@ -9,7 +9,7 @@ export function isPlaceholderNode(node) {
9
9
  }
10
10
  /** @alpha */
11
11
  export function flattenNodes(rootNodes) {
12
- return getFlatNodes(rootNodes, 0);
12
+ return getFlatNodes(rootNodes, 1);
13
13
  }
14
14
  function getFlatNodes(nodes, level) {
15
15
  const flatNodes = [];
@@ -1 +1 @@
1
- {"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,2BAA2B,EAAwB,MAAM,gBAAgB,CAAC;AAmBnF,aAAa;AACb,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IAClD,OAAO,aAAa,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED,aAAa;AACb,MAAM,UAAU,YAAY,CAAC,SAAiC;IAC5D,OAAO,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,YAAY,CAAC,KAA6B,EAAE,KAAa;IAChE,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YAC1D,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,uBAAuB,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,EAA4B,CAAC,CAAC;IAC3H,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { isPresentationHierarchyNode, PresentationTreeNode } from \"../TreeNode.js\";\n\n/** @alpha */\ninterface PlaceholderNode {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/** @alpha */\nexport type FlatNode<TNode extends PresentationTreeNode = PresentationTreeNode> = {\n level: number;\n levelSize: number;\n posInLevel: number;\n} & TNode;\n\n/** @alpha */\nexport type FlatTreeNode<TNode extends PresentationTreeNode = PresentationTreeNode> = FlatNode<TNode> | PlaceholderNode;\n\n/** @alpha */\nexport function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode {\n return \"placeholder\" in node;\n}\n\n/** @alpha */\nexport function flattenNodes(rootNodes: PresentationTreeNode[]) {\n return getFlatNodes(rootNodes, 0);\n}\n\nfunction getFlatNodes(nodes: PresentationTreeNode[], level: number) {\n const flatNodes: FlatTreeNode[] = [];\n nodes.forEach((node, index) => {\n flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!isPresentationHierarchyNode(node) || !node.isExpanded) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatNodes(node.children, level + 1);\n flatNodes.push(...childNodes);\n return;\n }\n\n flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies PlaceholderNode);\n });\n return flatNodes;\n}\n"]}
1
+ {"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,2BAA2B,EAAwB,MAAM,gBAAgB,CAAC;AAmBnF,aAAa;AACb,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IAClD,OAAO,aAAa,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED,aAAa;AACb,MAAM,UAAU,YAAY,CAAC,SAAiC;IAC5D,OAAO,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,YAAY,CAAC,KAA6B,EAAE,KAAa;IAChE,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YAC1D,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,uBAAuB,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,EAA4B,CAAC,CAAC;IAC3H,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { isPresentationHierarchyNode, PresentationTreeNode } from \"../TreeNode.js\";\n\n/** @alpha */\ninterface PlaceholderNode {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/** @alpha */\nexport type FlatNode<TNode extends PresentationTreeNode = PresentationTreeNode> = {\n level: number;\n levelSize: number;\n posInLevel: number;\n} & TNode;\n\n/** @alpha */\nexport type FlatTreeNode<TNode extends PresentationTreeNode = PresentationTreeNode> = FlatNode<TNode> | PlaceholderNode;\n\n/** @alpha */\nexport function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode {\n return \"placeholder\" in node;\n}\n\n/** @alpha */\nexport function flattenNodes(rootNodes: PresentationTreeNode[]) {\n return getFlatNodes(rootNodes, 1);\n}\n\nfunction getFlatNodes(nodes: PresentationTreeNode[], level: number) {\n const flatNodes: FlatTreeNode[] = [];\n nodes.forEach((node, index) => {\n flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!isPresentationHierarchyNode(node) || !node.isExpanded) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatNodes(node.children, level + 1);\n flatNodes.push(...childNodes);\n return;\n }\n\n flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies PlaceholderNode);\n });\n return flatNodes;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import "./TreeNodeRenderer.css";
2
- import { ComponentPropsWithoutRef, ForwardRefExoticComponent, ReactElement, RefAttributes } from "react";
2
+ import { ComponentPropsWithoutRef, ForwardRefExoticComponent, ReactElement, ReactNode, RefAttributes } from "react";
3
3
  import { Tree } from "@itwin/itwinui-react/bricks";
4
4
  import { PresentationHierarchyNode } from "../TreeNode.js";
5
5
  import { useTree } from "../UseTree.js";
@@ -12,8 +12,6 @@ type TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;
12
12
  export interface TreeNodeRendererOwnProps {
13
13
  /** Node that is rendered. */
14
14
  node: FlatTreeNode;
15
- /** Returns an icon or icon href for a given node. */
16
- getIcon?: (node: PresentationHierarchyNode) => string | ReactElement | undefined;
17
15
  /** Returns a label for a given node. */
18
16
  getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;
19
17
  /** Returns sublabel for a given node. */
@@ -26,9 +24,14 @@ export interface TreeNodeRendererOwnProps {
26
24
  * Actions for tree item.
27
25
  */
28
26
  actions?: Array<(node: PresentationHierarchyNode) => TreeItemAction>;
27
+ /**
28
+ * Used to render elements between expander and label.
29
+ * E.g. icons, color picker, etc.
30
+ */
31
+ getDecorations?: (node: PresentationHierarchyNode) => ReactNode;
29
32
  }
30
33
  /** @alpha */
31
- type TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode" | "isNodeSelected"> & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">> & Omit<TreeNodeProps, "actions" | "aria-level" | "aria-posinset" | "aria-setsize" | "label" | "icon" | "expanded" | "selected"> & TreeNodeRendererOwnProps & TreeErrorItemProps;
34
+ type TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode" | "isNodeSelected"> & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">> & Omit<TreeNodeProps, "actions" | "aria-level" | "aria-posinset" | "aria-setsize" | "label" | "icon" | "expanded" | "selected" | "unstable_decorations"> & TreeNodeRendererOwnProps & TreeErrorItemProps;
32
35
  /**
33
36
  * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.
34
37
  *
@@ -1 +1 @@
1
- {"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,wBAAwB,CAAC;AAChC,OAAO,EACL,wBAAwB,EAExB,yBAAyB,EAGzB,YAAY,EAEZ,aAAa,EAGd,MAAM,OAAO,CAAC;AACf,OAAO,EAAyB,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAA+B,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAoB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAqB,MAAM,wBAAwB,CAA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KAAK,IAAI,CAAC;IAC/H,2EAA2E;IAC3E,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACxH;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,yBAAyB,KAAK,cAAc,CAAC,CAAC;IACrE;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,KAAK,SAAS,CAAC;CACjE;AAED,aAAa;AACb,KAAK,qBAAqB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,YAAY,GAAG,gBAAgB,CAAC,GAC5F,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,GACrE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,GAAG,eAAe,GAAG,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,sBAAsB,CAAC,GACtJ,wBAAwB,GACxB,kBAAkB,CAAC;AAErB;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,yBAAyB,CAAC,qBAAqB,GAAG,aAAa,CAAC,WAAW,CAAC,CAgG1G,CAAC"}
@@ -19,7 +19,7 @@ const dropdownIcon = new URL("@itwin/itwinui-icons/more-horizontal.svg", import.
19
19
  * @see https://itwinui.bentley.com/docs/tree
20
20
  * @public
21
21
  */
22
- export const TreeNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isNodeSelected, getHierarchyLevelDetails, reloadTree, actions, ...treeItemProps }, forwardedRef) => {
22
+ export const TreeNodeRenderer = forwardRef(({ node, expandNode, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isNodeSelected, getHierarchyLevelDetails, reloadTree, actions, getDecorations, ...treeItemProps }, forwardedRef) => {
23
23
  const nodeRef = useRef(null);
24
24
  const ref = useMergedRefs(forwardedRef, nodeRef);
25
25
  if (isPlaceholderNode(node)) {
@@ -57,7 +57,7 @@ export const TreeNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabe
57
57
  if (!treeItemProps["aria-disabled"] && event.target === nodeRef.current) {
58
58
  onNodeKeyDown?.(node, !selected, event);
59
59
  }
60
- }, icon: getIcon ? getIcon(node) : undefined, actions: getActions() }));
60
+ }, actions: getActions(), unstable_decorations: getDecorations && getDecorations(node) }));
61
61
  });
62
62
  TreeNodeRenderer.displayName = "TreeNodeRenderer";
63
63
  const PlaceholderNode = forwardRef(({ level, ...props }, forwardedRef) => {
@@ -1 +1 @@
1
- {"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAChC,OAAO,EAEL,UAAU,EAOV,WAAW,EACX,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAA6B,MAAM,gBAAgB,CAAC;AAExF,OAAO,EAAgB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAgC/F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkF,UAAU,CACvH,CACE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AI,EAAE,KAAC,OAAO,IAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO,GAAI,GACjE,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AACH,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAEhD,SAAS,aAAa,CAAI,GAAG,IAA6D;IACxF,OAAO,WAAW,CAChB,CAAC,QAAkB,EAAE,EAAE;QACrB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAkC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\nimport {\n ComponentPropsWithoutRef,\n forwardRef,\n ForwardRefExoticComponent,\n LegacyRef,\n MutableRefObject,\n ReactElement,\n Ref,\n RefAttributes,\n useCallback,\n useRef,\n} from \"react\";\nimport { DropdownMenu, Spinner, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { FlatTreeNode, isPlaceholderNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionButton, TreeItemAction } from \"./TreeActionButton.js\";\nimport { TreeErrorItemProps, TreeErrorRenderer } from \"./TreeErrorRenderer.js\";\n\nconst dropdownIcon = new URL(\"@itwin/itwinui-icons/more-horizontal.svg\", import.meta.url).href;\n\n/** @alpha */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: FlatTreeNode;\n /** Returns an icon or icon href for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => string | ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /**\n * Actions for tree item.\n */\n actions?: Array<(node: PresentationHierarchyNode) => TreeItemAction>;\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\" | \"isNodeSelected\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"label\" | \"icon\" | \"expanded\" | \"selected\"> &\n TreeNodeRendererOwnProps &\n TreeErrorItemProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isNodeSelected,\n getHierarchyLevelDetails,\n reloadTree,\n actions,\n ...treeItemProps\n },\n forwardedRef,\n ) => {\n const nodeRef = useRef<HTMLElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n if (isPlaceholderNode(node)) {\n return <PlaceholderNode {...treeItemProps} level={node.level} ref={ref} />;\n }\n\n if (!isPresentationHierarchyNode(node)) {\n return (\n <TreeErrorRenderer\n style={treeItemProps.style}\n ref={ref}\n node={node}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n reloadTree={reloadTree}\n onFilterClick={onFilterClick}\n />\n );\n }\n\n const getActions = () => {\n if (!actions || actions.length === 0) {\n return undefined;\n }\n\n if (actions.length < 4) {\n return actions.map((action, index) => {\n const actionInfo = action(node);\n return <TreeActionButton key={index} {...actionInfo} />;\n });\n }\n\n return [\n <TreeActionButton key={0} {...actions[0](node)} />,\n <TreeActionButton key={1} {...actions[1](node)} />,\n <DropdownMenu.Root key={2}>\n <DropdownMenu.Button render={<Tree.ItemAction icon={dropdownIcon} label=\"Tree actions dropdown\" />} />\n <DropdownMenu.Content>\n {actions.slice(2, actions.length).map((action) => {\n const info = action(node);\n return <DropdownMenu.Item label={info.label} key={info.label} onClick={() => info.action()} />;\n })}\n </DropdownMenu.Content>\n </DropdownMenu.Root>,\n ];\n };\n\n const selected = isNodeSelected(node.id);\n return (\n <Tree.Item\n {...treeItemProps}\n className={\"presentation-hierarchies-node\"}\n ref={ref}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={getLabel ? getLabel(node) : node.label}\n description={getSublabel ? getSublabel(node) : undefined}\n selected={selected}\n expanded={node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined}\n onExpandedChange={(isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n onClick={(event) => {\n !treeItemProps[\"aria-disabled\"] && onNodeClick?.(node, !selected, event);\n }}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!treeItemProps[\"aria-disabled\"] && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n }}\n icon={getIcon ? getIcon(node) : undefined}\n actions={getActions()}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"icon\"> & { level: number }\n>(({ level, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n aria-level={level}\n aria-posinset={1}\n aria-setsize={1}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
1
+ {"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAChC,OAAO,EAEL,UAAU,EAQV,WAAW,EACX,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAA6B,MAAM,gBAAgB,CAAC;AAExF,OAAO,EAAgB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAs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AAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,OAAO,CACL,KAAC,IAAI,CAAC,IAAI,OACJ,KAAK,gBACG,KAAK,mBACF,CAAC,kBACF,CAAC,EACf,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAC/B,IAAI,EAAE,KAAC,OAAO,IAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO,GAAI,GACjE,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AACH,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAEhD,SAAS,aAAa,CAAI,GAAG,IAA6D;IACxF,OAAO,WAAW,CAChB,CAAC,QAAkB,EAAE,EAAE;QACrB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAkC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\nimport {\n ComponentPropsWithoutRef,\n forwardRef,\n ForwardRefExoticComponent,\n LegacyRef,\n MutableRefObject,\n ReactElement,\n ReactNode,\n Ref,\n RefAttributes,\n useCallback,\n useRef,\n} from \"react\";\nimport { DropdownMenu, Spinner, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { FlatTreeNode, isPlaceholderNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionButton, TreeItemAction } from \"./TreeActionButton.js\";\nimport { TreeErrorItemProps, TreeErrorRenderer } from \"./TreeErrorRenderer.js\";\n\nconst dropdownIcon = new URL(\"@itwin/itwinui-icons/more-horizontal.svg\", import.meta.url).href;\n\n/** @alpha */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: FlatTreeNode;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /**\n * Actions for tree item.\n */\n actions?: Array<(node: PresentationHierarchyNode) => TreeItemAction>;\n /**\n * Used to render elements between expander and label.\n * E.g. icons, color picker, etc.\n */\n getDecorations?: (node: PresentationHierarchyNode) => ReactNode;\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\" | \"isNodeSelected\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"label\" | \"icon\" | \"expanded\" | \"selected\" | \"unstable_decorations\"> &\n TreeNodeRendererOwnProps &\n TreeErrorItemProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isNodeSelected,\n getHierarchyLevelDetails,\n reloadTree,\n actions,\n getDecorations,\n ...treeItemProps\n },\n forwardedRef,\n ) => {\n const nodeRef = useRef<HTMLElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n if (isPlaceholderNode(node)) {\n return <PlaceholderNode {...treeItemProps} level={node.level} ref={ref} />;\n }\n\n if (!isPresentationHierarchyNode(node)) {\n return (\n <TreeErrorRenderer\n style={treeItemProps.style}\n ref={ref}\n node={node}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n reloadTree={reloadTree}\n onFilterClick={onFilterClick}\n />\n );\n }\n\n const getActions = () => {\n if (!actions || actions.length === 0) {\n return undefined;\n }\n\n if (actions.length < 4) {\n return actions.map((action, index) => {\n const actionInfo = action(node);\n return <TreeActionButton key={index} {...actionInfo} />;\n });\n }\n\n return [\n <TreeActionButton key={0} {...actions[0](node)} />,\n <TreeActionButton key={1} {...actions[1](node)} />,\n <DropdownMenu.Root key={2}>\n <DropdownMenu.Button render={<Tree.ItemAction icon={dropdownIcon} label=\"Tree actions dropdown\" />} />\n <DropdownMenu.Content>\n {actions.slice(2, actions.length).map((action) => {\n const info = action(node);\n return <DropdownMenu.Item label={info.label} key={info.label} onClick={() => info.action()} />;\n })}\n </DropdownMenu.Content>\n </DropdownMenu.Root>,\n ];\n };\n\n const selected = isNodeSelected(node.id);\n return (\n <Tree.Item\n {...treeItemProps}\n className={\"presentation-hierarchies-node\"}\n ref={ref}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={getLabel ? getLabel(node) : node.label}\n description={getSublabel ? getSublabel(node) : undefined}\n selected={selected}\n expanded={node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined}\n onExpandedChange={(isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n onClick={(event) => {\n !treeItemProps[\"aria-disabled\"] && onNodeClick?.(node, !selected, event);\n }}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!treeItemProps[\"aria-disabled\"] && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n }}\n actions={getActions()}\n unstable_decorations={getDecorations && getDecorations(node)}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"icon\"> & { level: number }\n>(({ level, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n aria-level={level}\n aria-posinset={1}\n aria-setsize={1}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-hierarchies-react",
3
- "version": "2.0.0-alpha.8",
3
+ "version": "2.0.0-alpha.9",
4
4
  "description": "React components based on `@itwin/presentation-hierarchies`",
5
5
  "license": "MIT",
6
6
  "author": {