Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit 8981de4

Browse files
authored
feat: List component (#111)
1 parent 9a6a554 commit 8981de4

File tree

7 files changed

+101
-2
lines changed

7 files changed

+101
-2
lines changed

.changeset/brave-lamps-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@babylonlabs-io/bbn-core-ui": minor
3+
---
4+
5+
List component

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { MdOutlineInfo } from "react-icons/md";
3+
4+
import { List } from "./List";
5+
import { ListItem } from "./components/ListItem";
6+
7+
const meta: Meta<typeof List> = {
8+
component: List,
9+
tags: ["autodocs"],
10+
};
11+
12+
export default meta;
13+
14+
type Story = StoryObj<typeof meta>;
15+
16+
export const Default: Story = {
17+
args: {
18+
orientation: "horizontal",
19+
children: [
20+
<ListItem title="Signet Bitcoin Balance" value="100.123456 sBTC" />,
21+
<ListItem title="Signet Bitcoin Balance" value="100.123456 sBTC" />,
22+
<ListItem title="Signet Bitcoin Balance" value="100.123456 sBTC" suffix={<MdOutlineInfo size={24} />} />,
23+
],
24+
},
25+
};

src/components/List/List.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { type PropsWithChildren, Children, cloneElement, isValidElement, ReactElement } from "react";
2+
import { twMerge } from "tailwind-merge";
3+
4+
import { type ListItemProps, ListItem } from "./components/ListItem";
5+
6+
export interface ListProps {
7+
className?: string;
8+
orientation: "horizontal" | "vertical";
9+
children: ReactElement<ListItemProps, typeof ListItem> | ReactElement<ListItemProps, typeof ListItem>[];
10+
}
11+
12+
const STYLES = {
13+
horizontal: "flex py-3",
14+
vertical: "px-4",
15+
};
16+
17+
const ROW_ORIENTATION = {
18+
horizontal: "vertical",
19+
vertical: "horizontal",
20+
} as const;
21+
22+
export function List({ className, orientation = "vertical", children }: PropsWithChildren<ListProps>) {
23+
return (
24+
<div className={twMerge("rounded border border-secondary-strokeLight", STYLES[orientation], className)}>
25+
{Children.map(children, (item) =>
26+
isValidElement(item) ? cloneElement(item, { orientation: ROW_ORIENTATION[orientation] }) : item,
27+
)}
28+
</div>
29+
);
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { twMerge } from "tailwind-merge";
2+
3+
import { Text } from "@/components/Text";
4+
5+
export interface ListItemProps {
6+
className?: string;
7+
orientation?: "horizontal" | "vertical";
8+
title: string | JSX.Element;
9+
value: string | JSX.Element;
10+
suffix?: JSX.Element;
11+
}
12+
13+
const STYLES = {
14+
horizontal: "flex-row items-center justify-between border-b border-secondary-strokeLight last-of-type:border-0 py-4",
15+
vertical: "flex-1 flex-col items-start justify-start gap-1.5 px-6 border-r border-secondary-strokeLight",
16+
};
17+
18+
const VALUE_STYLES = {
19+
horizontal: "flex item-center gap-1",
20+
vertical: "flex items-center justify-between w-full",
21+
};
22+
23+
export function ListItem({ className, orientation = "horizontal", title, value, suffix }: ListItemProps) {
24+
return (
25+
<div className={twMerge("flex", STYLES[orientation], className)}>
26+
<Text as="div" className="text-accent-secondary" variant={orientation === "horizontal" ? "body1" : "body2"}>
27+
{title}
28+
</Text>
29+
30+
<Text as="div" className={twMerge("text-accent-primary", VALUE_STYLES[orientation])} variant="body1">
31+
{value}
32+
{suffix}
33+
</Text>
34+
</div>
35+
);
36+
}

src/components/List/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./List";
2+
export * from "./components/ListItem";

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from "./components/Table";
1414
export * from "./components/Popover";
1515
export * from "./components/Card";
1616
export * from "./components/Toggle";
17+
export * from "./components/List";
1718

1819
export * from "./widgets/form/Form";
1920
export * from "./widgets/form/NumberField";

0 commit comments

Comments
 (0)