Skip to content

Commit f49e6bb

Browse files
feat(file-tree): add dynamic width calculation to prevent icon overflow
1 parent 31c8e40 commit f49e6bb

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/common/components/mock-components/front-rich-components/file-tree/file-tree.business.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ interface FileTreeDynamicSizeParams {
6969
width: number;
7070
elementHeight: number;
7171
paddingY: number;
72+
paddingX: number;
73+
iconDimension: number;
74+
indentationStep: number;
7275
baseRestrictions: ShapeSizeRestrictions;
7376
}
7477

@@ -122,14 +125,28 @@ export const calculateFileTreeDynamicSize = (
122125
treeItems: FileTreeItem[],
123126
params: FileTreeDynamicSizeParams
124127
): Size => {
125-
const { width, elementHeight, paddingY, baseRestrictions } = params;
128+
const {
129+
width,
130+
elementHeight,
131+
paddingY,
132+
paddingX,
133+
iconDimension,
134+
indentationStep,
135+
baseRestrictions,
136+
} = params;
137+
138+
const maxIconX = Math.max(
139+
...treeItems.map(item => paddingX + item.level * indentationStep)
140+
);
141+
const requiredWidth = maxIconX + iconDimension + paddingX;
126142

127143
// Calculate minimum height required based on content
128144
const minContentHeight = treeItems.length * elementHeight + paddingY * 2;
129145

130146
// Create dynamic constraints with adaptive minimum height
131147
const dynamicRestrictions: ShapeSizeRestrictions = {
132148
...baseRestrictions,
149+
minWidth: Math.max(baseRestrictions.minWidth, requiredWidth),
133150
minHeight: minContentHeight,
134151
defaultHeight: Math.max(
135152
baseRestrictions.defaultHeight || 200,

src/common/components/mock-components/front-rich-components/file-tree/file-tree.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export const FileTreeShape = forwardRef<any, FileTreeShapeProps>(
7171
width,
7272
elementHeight,
7373
paddingY,
74+
paddingX,
75+
iconDimension,
76+
indentationStep,
7477
baseRestrictions: fileTreeShapeRestrictions,
7578
});
7679

0 commit comments

Comments
 (0)