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

Commit 5fab948

Browse files
authored
fix: replace tw classes with custom ones (#115)
1 parent 20ea557 commit 5fab948

File tree

4 files changed

+70
-25
lines changed

4 files changed

+70
-25
lines changed

.changeset/pink-adults-refuse.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": patch
3+
---
4+
5+
replace tw classes with custom ones

src/components/List/List.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.bbn-list {
2+
@apply rounded border border-secondary-strokeLight;
3+
4+
&-horizontal {
5+
@apply flex py-3;
6+
}
7+
8+
&-vertical {
9+
@apply px-4;
10+
}
11+
12+
&-adaptive {
13+
@apply px-4 md:flex md:py-3;
14+
}
15+
}
16+
17+
.bbn-list-item {
18+
@apply flex;
19+
20+
&-horizontal {
21+
@apply flex-row items-center justify-between border-b border-secondary-strokeLight py-4 last-of-type:border-0;
22+
}
23+
24+
&-vertical {
25+
@apply flex-1 flex-col items-start justify-start gap-1.5 border-r border-secondary-strokeLight px-6 last-of-type:border-0;
26+
}
27+
28+
&-adaptive {
29+
@apply flex-row items-center justify-between border-b border-secondary-strokeLight py-4 last-of-type:border-0 md:flex-1 md:flex-col md:items-start md:justify-start md:gap-1.5 md:border-b-0 md:border-r md:px-6 md:py-0;
30+
}
31+
}
32+
33+
.bbn-list-title {
34+
@apply text-accent-secondary;
35+
36+
&-adaptive {
37+
@apply text-base md:text-sm;
38+
}
39+
}
40+
41+
.bbn-list-value {
42+
@apply text-accent-primary;
43+
44+
&-horizontal {
45+
@apply flex items-center gap-1;
46+
}
47+
48+
&-vertical {
49+
@apply flex w-full items-center justify-between;
50+
}
51+
52+
&-adaptive {
53+
@apply flex items-center gap-1 md:w-full md:justify-between;
54+
}
55+
}

src/components/List/List.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type PropsWithChildren, Children, cloneElement, isValidElement, ReactElement } from "react";
22
import { twMerge } from "tailwind-merge";
3+
import "./List.css";
34

45
import { type ListItemProps, ListItem } from "./components/ListItem";
56

@@ -9,12 +10,6 @@ export interface ListProps {
910
children: ReactElement<ListItemProps, typeof ListItem> | ReactElement<ListItemProps, typeof ListItem>[];
1011
}
1112

12-
const STYLES = {
13-
adaptive: "px-4 md:flex md:py-3",
14-
horizontal: "flex py-3",
15-
vertical: "px-4",
16-
};
17-
1813
const ROW_ORIENTATION = {
1914
adaptive: "adaptive",
2015
horizontal: "vertical",
@@ -23,7 +18,7 @@ const ROW_ORIENTATION = {
2318

2419
export function List({ className, orientation = "vertical", children }: PropsWithChildren<ListProps>) {
2520
return (
26-
<div className={twMerge("rounded border border-secondary-strokeLight", STYLES[orientation], className)}>
21+
<div className={twMerge("bbn-list", `bbn-list-${orientation}`, className)}>
2722
{Children.map(children, (item) =>
2823
isValidElement(item) ? cloneElement(item, { orientation: ROW_ORIENTATION[orientation] }) : item,
2924
)}

src/components/List/components/ListItem.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { twMerge } from "tailwind-merge";
1+
import { twJoin } from "tailwind-merge";
22

33
import { Text } from "@/components/Text";
44

@@ -10,28 +10,18 @@ export interface ListItemProps {
1010
suffix?: JSX.Element;
1111
}
1212

13-
const STYLES = {
14-
adaptive:
15-
"flex-row items-center justify-between border-b border-secondary-strokeLight last-of-type:border-0 py-4 md:flex-1 md:flex-col md:items-start md:justify-start md:gap-1.5 md:px-6 md:py-0 md:border-b-0 md:border-r",
16-
horizontal: "flex-row items-center justify-between border-b border-secondary-strokeLight last-of-type:border-0 py-4",
17-
vertical:
18-
"flex-1 flex-col items-start justify-start gap-1.5 px-6 border-r border-secondary-strokeLight last-of-type:border-0",
19-
};
20-
21-
const VALUE_STYLES = {
22-
adaptive: "flex items-center gap-1 md:justify-between md:w-full",
23-
horizontal: "flex items-center gap-1",
24-
vertical: "flex items-center justify-between w-full",
25-
};
26-
2713
export function ListItem({ className, orientation = "horizontal", title, value, suffix }: ListItemProps) {
2814
return (
29-
<div className={twMerge("flex", STYLES[orientation], className)}>
30-
<Text as="div" className="text-accent-secondary" variant={orientation === "horizontal" ? "body1" : "body2"}>
15+
<div className={twJoin("bbn-list-item", `bbn-list-item-${orientation}`, className)}>
16+
<Text
17+
as="div"
18+
className={twJoin("bbn-list-title", `bbn-list-title-${orientation}`)}
19+
variant={orientation === "horizontal" ? "body1" : "body2"}
20+
>
3121
{title}
3222
</Text>
3323

34-
<Text as="div" className={twMerge("text-accent-primary", VALUE_STYLES[orientation])} variant="body1">
24+
<Text as="div" className={twJoin("bbn-list-value", `bbn-list-value-${orientation}`)} variant="body1">
3525
{value}
3626
{suffix}
3727
</Text>

0 commit comments

Comments
 (0)