Skip to content

Commit e592fed

Browse files
Merge pull request #518 from buildo/expand_list_config
Expand config and props of List/ListItem
2 parents fb5c5ee + 50b4c9b commit e592fed

File tree

7 files changed

+57
-7
lines changed

7 files changed

+57
-7
lines changed

packages/bento-design-system/src/Illustrations/IllustrationProps.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { AtLeast } from "../util/AtLeast";
22

3+
export type IllustrationColor = "default" | "disabled" | "inherit";
4+
35
// NOTE(gabro): we deprecated the `style` prop due to false positive warnings in
46
// popular ESLint configs, which expect `style` to be an object.
57
// We're still keeping the old props around for backwards compatibility.
@@ -25,5 +27,5 @@ export type IllustrationProps = {
2527
style: "outline";
2628
},
2729
"kind" | "style"
28-
> & { color: "default" | "disabled" | "inherit" })
30+
> & { color: IllustrationColor })
2931
);

packages/bento-design-system/src/List/Config.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IconProps } from "../Icons";
2-
import { IllustrationProps } from "../Illustrations";
2+
import { IllustrationColor, IllustrationProps } from "../Illustrations";
33
import { BentoSprinkles } from "../internal";
44
import { BodyProps } from "../Typography/Body/Body";
55
import { LabelProps } from "../Typography/Label/Label";
@@ -10,6 +10,7 @@ type ListItemSizeConfig<T> = {
1010
};
1111

1212
export type ListItemConfig = {
13+
borderRadius: BentoSprinkles["borderRadius"];
1314
paddingX: ListItemSizeConfig<BentoSprinkles["paddingX"]>;
1415
paddingY: ListItemSizeConfig<BentoSprinkles["paddingY"]>;
1516
fontSize: {
@@ -23,8 +24,14 @@ export type ListItemConfig = {
2324
trailing: IconProps["size"];
2425
illustration: IllustrationProps["size"];
2526
};
27+
iconColor: {
28+
leading: IconProps["color"];
29+
trailing: IconProps["color"];
30+
illustration: IllustrationColor;
31+
};
2632
};
2733

2834
export type ListConfig = {
2935
item: ListItemConfig;
36+
spacing: BentoSprinkles["gap"];
3037
};

packages/bento-design-system/src/List/InternalList.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { Stack, Children } from "..";
2+
import { useBentoConfig } from "../BentoConfigContext";
23
import type { ListProps } from "./List";
34

45
type Props = Omit<ListProps, "items" | "size"> & {
56
children: Children;
67
};
78

8-
export function InternalList({ dividers, children }: Props) {
9+
export function InternalList({ dividers, space, children }: Props) {
10+
const config = useBentoConfig().list;
911
return (
10-
<Stack space={0} as="ul" dividers={dividers}>
12+
<Stack space={space ?? config.spacing} as="ul" dividers={dividers}>
1113
{children}
1214
</Stack>
1315
);

packages/bento-design-system/src/List/List.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ListItem, ListItemProps } from "./ListItem";
22
import { InternalList } from "./InternalList";
3+
import { BentoSprinkles } from "../internal";
34

45
export type ListSize = "medium" | "large";
56
type Props = {
67
size: ListSize;
78
items: ListItemProps[];
9+
space?: BentoSprinkles["gap"];
810
dividers?: boolean;
911
};
1012

packages/bento-design-system/src/List/ListItem.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { element } from "../reset.css";
1919
import { Children } from "../util/Children";
2020
import { useBentoConfig } from "../BentoConfigContext";
2121
import type { ListItemConfig } from "./Config";
22+
import { BentoSprinkles } from "../internal";
2223

2324
type Kind =
2425
| {
@@ -55,6 +56,7 @@ type RightItem = {
5556
};
5657

5758
type CommonItemProps = {
59+
borderRadius?: BentoSprinkles["borderRadius"];
5860
disabled?: boolean;
5961
isFocused?: boolean;
6062
isSelected?: boolean;
@@ -105,6 +107,7 @@ export const ListItem = forwardRef<HTMLElement, Props>((props, ref) => {
105107
focused: !!props.isFocused,
106108
selected: !!props.isSelected,
107109
})}
110+
borderRadius={props.borderRadius ?? config.borderRadius}
108111
disabled={props.disabled}
109112
>
110113
<Box
@@ -136,7 +139,7 @@ function renderLeft(props: Props, config: ListItemConfig) {
136139
{props.illustration({
137140
size: config.iconSize.illustration,
138141
kind: "outline",
139-
color: props.disabled ? "disabled" : "default",
142+
color: props.disabled ? "disabled" : config.iconColor.illustration,
140143
})}
141144
</Column>
142145
);
@@ -147,7 +150,7 @@ function renderLeft(props: Props, config: ListItemConfig) {
147150
<Column width="content">
148151
{props.icon({
149152
size: config.iconSize.leading,
150-
color: props.disabled ? "disabled" : "default",
153+
color: props.disabled ? "disabled" : config.iconColor.leading,
151154
})}
152155
</Column>
153156
);
@@ -162,7 +165,7 @@ function renderRight(props: Props, config: ListItemConfig) {
162165
<Column width="content">
163166
{props.trailingIcon({
164167
size: config.iconSize.trailing,
165-
color: props.disabled ? "disabled" : "default",
168+
color: props.disabled ? "disabled" : config.iconColor.trailing,
166169
})}
167170
</Column>
168171
);

packages/bento-design-system/src/util/defaultConfigs.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export const iconButton: IconButtonConfig = {
323323

324324
export const list: ListConfig = {
325325
item: {
326+
borderRadius: 0,
326327
paddingX: {
327328
medium: 16,
328329
large: 16,
@@ -342,7 +343,13 @@ export const list: ListConfig = {
342343
trailing: 16,
343344
illustration: 32,
344345
},
346+
iconColor: {
347+
leading: "default",
348+
trailing: "default",
349+
illustration: "default",
350+
},
345351
},
352+
spacing: 0,
346353
};
347354

348355
export const menu: MenuConfig = {
@@ -433,6 +440,7 @@ export const dropdown: DropdownConfig = {
433440
menuPaddingY: 8,
434441
list: {
435442
item: {
443+
borderRadius: 0,
436444
paddingX: {
437445
medium: 16,
438446
large: 16,
@@ -452,7 +460,13 @@ export const dropdown: DropdownConfig = {
452460
trailing: 16,
453461
illustration: 32,
454462
},
463+
iconColor: {
464+
leading: "default",
465+
trailing: "default",
466+
illustration: "default",
467+
},
455468
},
469+
spacing: 0,
456470
},
457471
defaultMenuSize: "medium",
458472
openIndicatorIcon: IconChevronDown,

packages/storybook/stories/Components/List.stories.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,23 @@ export const OverlineIllustration = createStory({
155155
},
156156
],
157157
});
158+
159+
export const WithSpacing = createStory({
160+
items: [
161+
{ kind: "single-line", label, href },
162+
{ kind: "single-line", label: labelLong, href },
163+
{ kind: "single-line", label, href },
164+
{ kind: "single-line", label: labelRich, href },
165+
],
166+
space: 8,
167+
});
168+
169+
export const WithRoundBorders = createStory({
170+
items: [
171+
{ kind: "single-line", borderRadius: 8, label, href },
172+
{ kind: "single-line", borderRadius: 8, label: labelLong, href },
173+
{ kind: "single-line", borderRadius: 8, label, href },
174+
{ kind: "single-line", borderRadius: 8, label: labelRich, href },
175+
],
176+
space: 8,
177+
});

0 commit comments

Comments
 (0)