Skip to content

Commit 613d5e9

Browse files
committed
implement list styles
1 parent 4d6dcf5 commit 613d5e9

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

src/components/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ const Footer = ({ lastDeployLocaleTimestamp }: FooterProps) => {
316316
<h3 className="my-5 text-sm font-bold">
317317
<Translation id={section.title} />
318318
</h3>
319-
<List className="text-sm">
319+
<List className="m-0 mb-4 text-sm">
320320
{section.links.map((link, linkIdx) => (
321321
<ListItem key={linkIdx} className="mb-4">
322322
<BaseLink

src/components/ui/list.tsx

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,53 @@
11
import { BaseHTMLAttributes, ElementRef, forwardRef } from "react"
2+
import { Slot } from "@radix-ui/react-slot"
23

34
import { cn } from "@/lib/utils/cn"
45

5-
const List = forwardRef<ElementRef<"ul">, BaseHTMLAttributes<HTMLUListElement>>(
6-
({ className, ...props }, ref) => (
7-
<ul ref={ref} className={cn("m-0", className)} {...props} />
8-
)
6+
export type ListProps = BaseHTMLAttributes<HTMLUListElement> & {
7+
asChild?: boolean
8+
}
9+
10+
const List = forwardRef<ElementRef<"ul">, ListProps>(
11+
({ className, asChild, ...props }, ref) => {
12+
const Comp = asChild ? Slot : "ul"
13+
return (
14+
<Comp
15+
ref={ref}
16+
className={cn("mb-6 ms-6 list-disc", className)}
17+
{...props}
18+
/>
19+
)
20+
}
921
)
1022

1123
List.displayName = "List"
1224

25+
// Alias
26+
const UnorderedList = List
27+
28+
const OrderedList = forwardRef<ElementRef<"ol">, ListProps>(
29+
({ className, children, ...props }, ref) => (
30+
<List className={cn("list-decimal", className)} asChild>
31+
<ol ref={ref} {...props}>
32+
{children}
33+
</ol>
34+
</List>
35+
)
36+
)
37+
38+
OrderedList.displayName = "OrderedList"
39+
1340
const ListItem = forwardRef<
1441
ElementRef<"li">,
1542
BaseHTMLAttributes<HTMLLIElement>
1643
>(({ className, ...props }, ref) => (
17-
<li ref={ref} className={className} {...props} />
44+
<li
45+
ref={ref}
46+
className={cn("mb-3 last:mb-0 [&_ol]:mt-3 [&_ul]:mt-3", className)}
47+
{...props}
48+
/>
1849
))
1950

2051
ListItem.displayName = "ListItem"
2152

22-
export { List, ListItem }
53+
export { List, ListItem, OrderedList, UnorderedList }

src/styles/global.css

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -185,36 +185,6 @@
185185
@apply text-sm lg:text-md;
186186
}
187187

188-
/* TODO: to be replaced with list component styles */
189-
ul,
190-
ol {
191-
margin: 0px 0px 1.45rem 1.45rem;
192-
padding: 0;
193-
194-
& li {
195-
padding-inline-start: 0;
196-
}
197-
}
198-
199-
li {
200-
margin-bottom: calc(1.45rem / 2);
201-
202-
& > ol,
203-
& > ul {
204-
margin-inline-start: 1.45rem;
205-
margin-block: calc(1.45rem / 2);
206-
margin-top: calc(1.45rem / 2);
207-
}
208-
209-
& * {
210-
@apply last:mb-0;
211-
}
212-
213-
& > p {
214-
margin-bottom: calc(1.45rem / 2);
215-
}
216-
}
217-
218188
pre,
219189
code,
220190
kbd,

0 commit comments

Comments
 (0)