Skip to content

Commit ed5887b

Browse files
authored
feat(Tree): add shape prop and container padding (#1136)
1 parent ec2dc93 commit ed5887b

5 files changed

Lines changed: 51 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": minor
3+
---
4+
5+
Added `shape` prop to `Tree` with `default` and `card` values for controlling border and radius. Added `containerPadding` prop for adjustable padding around the tree content via virtualizer configuration.

src/components/content/Tree/Tree.stories.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,23 @@ const meta = {
142142
},
143143

144144
/* Presentation */
145+
shape: {
146+
control: 'radio',
147+
options: ['default', 'card'],
148+
description: 'Visual shape of the tree container',
149+
table: {
150+
defaultValue: { summary: 'default' },
151+
type: { summary: "'default' | 'card'" },
152+
},
153+
},
154+
containerPadding: {
155+
control: 'number',
156+
description: 'Padding (px) around the tree content',
157+
table: {
158+
defaultValue: { summary: '4' },
159+
type: { summary: 'number' },
160+
},
161+
},
145162
height: {
146163
control: 'number',
147164
description:
@@ -409,6 +426,13 @@ export const AutoExpandParent: Story = {
409426
render: AutoExpandParentRender,
410427
};
411428

429+
export const CardShape: Story = {
430+
args: {
431+
shape: 'card',
432+
defaultExpandedKeys: ['src', 'src/components'],
433+
},
434+
};
435+
412436
export const Empty: Story = {
413437
args: {
414438
treeData: [],
@@ -426,11 +450,10 @@ const WrappedFileIcon = () => (
426450
export const DirectoryTree: Story = {
427451
args: {
428452
selectionMode: 'none',
453+
shape: 'card',
429454
defaultExpandedKeys: ['src', 'src/components'],
430455
styles: {
431456
width: '200px',
432-
border: true,
433-
radius: '1cr',
434457
},
435458
itemProps: (data, { isExpanded }) => {
436459
const isFolder = !!data.children;

src/components/content/Tree/Tree.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ function TreeBase(props: CubeTreeProps, ref: ForwardedRef<HTMLDivElement>) {
116116
isSelectable,
117117
selectionMode: selectionModeProp,
118118
size = 'medium',
119+
shape = 'default',
120+
containerPadding = 4,
119121
isDisabled = false,
120122
defaultExpandedKeys,
121123
expandedKeys,
@@ -348,6 +350,8 @@ function TreeBase(props: CubeTreeProps, ref: ForwardedRef<HTMLDivElement>) {
348350
estimateSize: () => SIZES[SIZE_NAME_TO_KEY[size]],
349351
gap: 1,
350352
overscan: 10,
353+
paddingStart: containerPadding,
354+
paddingEnd: containerPadding,
351355
});
352356

353357
const containerStyle = useMemo<CSSProperties>(() => {
@@ -380,8 +384,9 @@ function TreeBase(props: CubeTreeProps, ref: ForwardedRef<HTMLDivElement>) {
380384
const mods = useMemo(
381385
() => ({
382386
'has-height': height != null,
387+
shape,
383388
}),
384-
[height],
389+
[height, shape],
385390
);
386391

387392
// Both `useTree` and the consumer need the same DOM node.
@@ -422,8 +427,8 @@ function TreeBase(props: CubeTreeProps, ref: ForwardedRef<HTMLDivElement>) {
422427
virtualStyle={{
423428
position: 'absolute',
424429
top: 0,
425-
left: 0,
426-
right: 0,
430+
left: containerPadding,
431+
right: containerPadding,
427432
transform: `translateY(${virtualItem.start}px)`,
428433
}}
429434
virtualRef={rowVirtualizer.measureElement}

src/components/content/Tree/styled.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const TreeElement = tasty({
3030
transition: 'theme',
3131
outline: 0,
3232
padding: 0,
33+
radius: { '': 0, 'shape=card': '1cr' },
34+
border: { '': 0, 'shape=card': true },
3335
},
3436
});
3537

@@ -45,7 +47,6 @@ export const TreeNodeRow = tasty({
4547
qa: 'TreeRow',
4648
styles: {
4749
display: 'block',
48-
width: '100%',
4950
outline: 0,
5051
},
5152
});

src/components/content/Tree/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ export interface CubeTreeProps extends BaseProps, OuterStyleProps {
121121
/** Row size. Defaults to `'medium'`. */
122122
size?: SizeName;
123123

124+
/**
125+
* Visual shape of the tree container.
126+
* - `default` — no border or radius
127+
* - `card` — rounded corners with a border
128+
* @default "default"
129+
*/
130+
shape?: 'default' | 'card';
131+
132+
/** Padding (px) around the tree content. Applied via the virtualizer for vertical and CSS for horizontal. @default 4 */
133+
containerPadding?: number;
134+
124135
/** Disable the entire tree. */
125136
isDisabled?: boolean;
126137

0 commit comments

Comments
 (0)