Skip to content

Commit e5f928f

Browse files
committed
fix(ListBox): add noCard flag
1 parent daa2f6f commit e5f928f

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
lines changed

.changeset/afraid-adults-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Add `noCard` flag to ListBox to remove the border and the padding.

src/components/fields/ListBox/ListBox.stories.tsx

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ const meta: any = {
8282
defaultValue: { summary: 'medium' },
8383
},
8484
},
85+
noCard: {
86+
control: { type: 'boolean' },
87+
description: 'Remove card styling (border and outer margin)',
88+
table: {
89+
defaultValue: { summary: false },
90+
},
91+
},
8592
header: {
8693
control: { type: 'text' },
8794
description: 'Custom header content',
@@ -1392,3 +1399,81 @@ export const AllValuePropsExample: Story = {
13921399
},
13931400
},
13941401
};
1402+
1403+
export const NoCardStyling: Story = {
1404+
render: () => (
1405+
<Space gap="4x" flow="column">
1406+
<div>
1407+
<Text preset="t3" weight="600">
1408+
Default Card Styling
1409+
</Text>
1410+
<Text preset="t4" color="#dark.60">
1411+
With border and outer margin
1412+
</Text>
1413+
<Space height="1x" />
1414+
<ListBox
1415+
label="Select a fruit"
1416+
selectionMode="single"
1417+
defaultSelectedKey="apple"
1418+
>
1419+
{fruits.slice(0, 4).map((fruit) => (
1420+
<ListBox.Item key={fruit.key}>{fruit.label}</ListBox.Item>
1421+
))}
1422+
</ListBox>
1423+
</div>
1424+
1425+
<div>
1426+
<Text preset="t3" weight="600">
1427+
No Card Styling (noCard=true)
1428+
</Text>
1429+
<Text preset="t4" color="#dark.60">
1430+
Without border and outer margin
1431+
</Text>
1432+
<Space height="1x" />
1433+
<ListBox
1434+
noCard
1435+
label="Select a fruit"
1436+
selectionMode="single"
1437+
defaultSelectedKey="banana"
1438+
>
1439+
{fruits.slice(0, 4).map((fruit) => (
1440+
<ListBox.Item key={fruit.key}>{fruit.label}</ListBox.Item>
1441+
))}
1442+
</ListBox>
1443+
</div>
1444+
1445+
<div>
1446+
<Text preset="t3" weight="600">
1447+
No Card with Sections
1448+
</Text>
1449+
<Text preset="t4" color="#dark.60">
1450+
Section margins are preserved
1451+
</Text>
1452+
<Space height="1x" />
1453+
<ListBox
1454+
noCard
1455+
label="Select food items"
1456+
selectionMode="single"
1457+
defaultSelectedKey="carrot"
1458+
>
1459+
<ListBox.Section title="Fruits">
1460+
<ListBox.Item key="apple">Apple</ListBox.Item>
1461+
<ListBox.Item key="banana">Banana</ListBox.Item>
1462+
</ListBox.Section>
1463+
<ListBox.Section title="Vegetables">
1464+
<ListBox.Item key="carrot">Carrot</ListBox.Item>
1465+
<ListBox.Item key="broccoli">Broccoli</ListBox.Item>
1466+
</ListBox.Section>
1467+
</ListBox>
1468+
</div>
1469+
</Space>
1470+
),
1471+
parameters: {
1472+
docs: {
1473+
description: {
1474+
story:
1475+
'The `noCard` prop removes the border and outer margin from the ListBox, making it suitable for use in contexts where the card styling is not needed (e.g., inside popovers or dialogs). Section margins are preserved to maintain proper spacing.',
1476+
},
1477+
},
1478+
},
1479+
};

src/components/fields/ListBox/ListBox.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const ListBoxWrapperElement = tasty({
7979
valid: '#success-text.50',
8080
invalid: '#danger-text.50',
8181
disabled: true,
82-
'popover | searchable': false,
82+
'popover | searchable | !card': false,
8383
},
8484
},
8585
});
@@ -93,7 +93,7 @@ const ListElement = tasty({
9393
boxSizing: 'border-box',
9494
margin: {
9595
'': '.5x .5x 0 .5x',
96-
sections: '.5x .5x 0 .5x',
96+
'!card': '0',
9797
},
9898
height: 'max-content',
9999
},
@@ -309,6 +309,13 @@ export interface CubeListBoxProps<T>
309309
* Defaults to "No items".
310310
*/
311311
emptyLabel?: ReactNode;
312+
313+
/**
314+
* Whether to remove the card styling (border and outer margin).
315+
* When true, removes the border and outer margin while keeping section margins.
316+
* Defaults to false (card styling is applied).
317+
*/
318+
noCard?: boolean;
312319
}
313320

314321
const PROP_STYLES = [...BASE_STYLES, ...OUTER_STYLES, ...COLOR_STYLES];
@@ -516,6 +523,7 @@ export const ListBox = forwardRef(function ListBox<T extends object>(
516523
allValueProps,
517524
filter,
518525
emptyLabel = 'No items',
526+
noCard = false,
519527
form,
520528
...otherProps
521529
} = props;
@@ -840,6 +848,7 @@ export const ListBox = forwardRef(function ListBox<T extends object>(
840848
header: !!header || (showSelectAll && props.selectionMode === 'multiple'),
841849
footer: !!footer,
842850
selectAll: showSelectAll && props.selectionMode === 'multiple',
851+
card: !noCard,
843852
...externalMods,
844853
}),
845854
[
@@ -851,6 +860,7 @@ export const ListBox = forwardRef(function ListBox<T extends object>(
851860
footer,
852861
showSelectAll,
853862
props.selectionMode,
863+
noCard,
854864
externalMods,
855865
],
856866
);
@@ -901,7 +911,7 @@ export const ListBox = forwardRef(function ListBox<T extends object>(
901911
ref={listRef}
902912
styles={listStyles}
903913
aria-disabled={isDisabled || undefined}
904-
mods={{ sections: hasSections }}
914+
mods={{ sections: hasSections, card: !noCard }}
905915
style={
906916
shouldVirtualize
907917
? {

0 commit comments

Comments
 (0)