Skip to content

Commit

Permalink
hierarchies-react: adjust tree node loading indicator in small tree (
Browse files Browse the repository at this point in the history
…#795)

* Adjust tree node loading indicator to match other icons size

* change

* extract-api

* change
  • Loading branch information
saskliutas authored Nov 28, 2024
1 parent 1b69393 commit 40db6ca
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-ducks-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@itwin/presentation-hierarchies-react": patch
---

Fix tree node loading indicator to match other icons size.
5 changes: 5 additions & 0 deletions .changeset/seven-turtles-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@itwin/presentation-hierarchies-react": minor
---

Added `size` property to `TreeNodeRenderer` to improve styling of `small` tree.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ interface TreeNodeRendererOwnProps {
parentNodeId: string | undefined;
state: "reset";
}) => void;
size?: "default" | "small";
}

// @public (undocumented)
Expand All @@ -191,7 +192,7 @@ type TreeNodeRendererProps_2 = ComponentPropsWithoutRef<typeof TreeNodeRenderer>
type TreeProps = ComponentPropsWithoutRef<typeof Tree<RenderedTreeNode>>;

// @public
export function TreeRenderer({ rootNodes, expandNode, selectNodes, isNodeSelected, onFilterClick, getIcon, getLabel, getSublabel, getHierarchyLevelDetails, reloadTree, selectionMode, localizedStrings, ...treeProps }: TreeRendererProps): JSX_3.Element;
export function TreeRenderer({ rootNodes, expandNode, selectNodes, isNodeSelected, onFilterClick, getIcon, getLabel, getSublabel, getHierarchyLevelDetails, reloadTree, selectionMode, localizedStrings, size, ...treeProps }: TreeRendererProps): JSX_3.Element;

// @public (undocumented)
interface TreeRendererOwnProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
.stateless-tree-node:focus-within .action-buttons {
visibility: visible;
}

.stateless-tree-node-small-spinner {
height: var(--iui-size-s);
width: var(--iui-size-s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ interface TreeNodeRendererOwnProps {
reloadTree?: (options: { parentNodeId: string | undefined; state: "reset" }) => void;
/** CSS class name for the action buttons. */
actionButtonsClassName?: string;
/** Tree node size. Should match the size passed to `TreeRenderer` component. */
size?: "default" | "small";
}

/** @public */
Expand Down Expand Up @@ -68,6 +70,7 @@ export const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererP
actionButtonsClassName,
getHierarchyLevelDetails,
reloadTree,
size,
...treeNodeProps
},
forwardedRef,
Expand All @@ -77,7 +80,7 @@ export const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererP
const nodeRef = useRef<HTMLDivElement>(null);
const ref = useMergedRefs(forwardedRef, nodeRef);
if ("type" in node && node.type === "ChildrenPlaceholder") {
return <PlaceholderNode {...treeNodeProps} ref={ref} />;
return <PlaceholderNode {...treeNodeProps} ref={ref} size={size} />;
}

if (isPresentationHierarchyNode(node)) {
Expand Down Expand Up @@ -176,14 +179,26 @@ export const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererP
);
TreeNodeRenderer.displayName = "TreeNodeRenderer";

const PlaceholderNode = forwardRef<HTMLDivElement, Omit<TreeNodeProps, "onExpanded" | "label">>((props, forwardedRef) => {
const PlaceholderNode = forwardRef<
HTMLDivElement,
Omit<TreeNodeProps, "onExpanded" | "label"> & {
size?: "default" | "small";
}
>(({ size, ...props }, forwardedRef) => {
const { localizedStrings } = useLocalizationContext();
return (
<TreeNode
{...props}
ref={forwardedRef}
label={localizedStrings.loading}
icon={<ProgressRadial size="x-small" indeterminate title={localizedStrings.loading} />}
icon={
<ProgressRadial
size="x-small"
indeterminate
title={localizedStrings.loading}
className={cx(props.className, { "stateless-tree-node-small-spinner": size === "small" })}
/>
}
onExpanded={/* c8 ignore next */ () => {}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function TreeRenderer({
reloadTree,
selectionMode,
localizedStrings,
size,
...treeProps
}: TreeRendererProps) {
const { onNodeClick, onNodeKeyDown } = useSelectionHandler({
Expand All @@ -74,17 +75,18 @@ export function TreeRenderer({
getLabel={getLabel}
getSublabel={getSublabel}
reloadTree={reloadTree}
size={size}
/>
);
},
[expandNode, getHierarchyLevelDetails, onFilterClick, onNodeClick, onNodeKeyDown, getIcon, getLabel, getSublabel, reloadTree],
[expandNode, getHierarchyLevelDetails, onFilterClick, onNodeClick, onNodeKeyDown, getIcon, getLabel, getSublabel, reloadTree, size],
);

const getNode = useCallback<TreeProps["getNode"]>((node) => createRenderedTreeNodeData(node, isNodeSelected ?? noopIsNodeSelected), [isNodeSelected]);

return (
<LocalizationContextProvider localizedStrings={localizedStrings}>
<Tree<RenderedTreeNode> {...treeProps} data={rootNodes} nodeRenderer={nodeRenderer} getNode={getNode} enableVirtualization={true} />
<Tree<RenderedTreeNode> {...treeProps} size={size} data={rootNodes} nodeRenderer={nodeRenderer} getNode={getNode} enableVirtualization={true} />
</LocalizationContextProvider>
);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/models-tree/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"declaration": true,
"declarationMap": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"lib": ["ES2022"]
"resolveJsonModule": true
},
"include": ["src"]
}

0 comments on commit 40db6ca

Please sign in to comment.