Skip to content

Commit 1fbe6ca

Browse files
authored
feat(list component): develop new horizontal state of list component (#1178)
* feat(list component): develop new horizontal state of list component * refactor(list.ts): change the order of classes in twmerge
1 parent 770ab9d commit 1fbe6ca

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

content/docs/typography/list.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Use the `ordered` prop tag to create an ordered list of items with numbers.
3535

3636
<Example name="list.ordered" />
3737

38+
## Horizontal list
39+
40+
Use this example to create a horizontally aligned list of items.
41+
42+
<Example name="list.horizontal" />
43+
3844
## Theme
3945

4046
To learn more about how to customize the appearance of components, please see the [Theme docs](/docs/customize/theme).

examples/list/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { nested } from './list.nested';
22
export { ordered } from './list.ordered';
33
export { root } from './list.root';
44
export { unstyled } from './list.unstyled';
5+
export { horizontal } from './list.horizontal';

examples/list/list.horizontal.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { type CodeData } from '~/components/code-demo';
2+
import { List, ListItem } from '~/src';
3+
4+
const code = `
5+
'use client';
6+
7+
import { List } from 'flowbite-react';
8+
9+
function Component() {
10+
return (
11+
<List horizontal>
12+
<List.Item>About</List.Item>
13+
<List.Item>Premium</List.Item>
14+
<List.Item>Campaigns</List.Item>
15+
<List.Item>Blog</List.Item>
16+
<List.Item>Affiliate Program</List.Item>
17+
<List.Item>FAQs</List.Item>
18+
<List.Item>Contact</List.Item>
19+
</List>
20+
);
21+
}
22+
`;
23+
24+
const codeRSC = `
25+
import { List, ListItem } from 'flowbite-react';
26+
27+
function Component() {
28+
return (
29+
<List horizontal>
30+
<ListItem>About</ListItem>
31+
<ListItem>Premium</ListItem>
32+
<ListItem>Campaigns</ListItem>
33+
<ListItem>Blog</ListItem>
34+
<ListItem>Affiliate Program</ListItem>
35+
<ListItem>FAQs</ListItem>
36+
<ListItem>Contact</ListItem>
37+
</List>
38+
);
39+
}
40+
`;
41+
42+
function Component() {
43+
return (
44+
<List horizontal>
45+
<ListItem>About</ListItem>
46+
<ListItem>Premium</ListItem>
47+
<ListItem>Campaigns</ListItem>
48+
<ListItem>Blog</ListItem>
49+
<ListItem>Affiliate Program</ListItem>
50+
<ListItem>FAQs</ListItem>
51+
<ListItem>Contact</ListItem>
52+
</List>
53+
);
54+
}
55+
56+
export const horizontal: CodeData = {
57+
type: 'single',
58+
code: [
59+
{
60+
fileName: 'client',
61+
language: 'tsx',
62+
code,
63+
},
64+
{
65+
fileName: 'server',
66+
language: 'tsx',
67+
code: codeRSC,
68+
},
69+
],
70+
githubSlug: 'list/list.horizontal.tsx',
71+
component: <Component />,
72+
};

src/components/List/List.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface FlowbiteListRootTheme {
1616
on: string;
1717
off: string;
1818
};
19+
horizontal: string;
1920
unstyled: string;
2021
nested: string;
2122
}
@@ -30,6 +31,7 @@ export interface ListProps extends PropsWithChildren<ComponentProps<'ul'> & Comp
3031
ordered?: boolean;
3132
unstyled?: boolean;
3233
nested?: boolean;
34+
horizontal?: boolean;
3335
}
3436

3537
const ListComponent: FC<ListProps> = ({
@@ -38,6 +40,7 @@ const ListComponent: FC<ListProps> = ({
3840
unstyled,
3941
nested,
4042
ordered,
43+
horizontal,
4144
theme: customTheme = {},
4245
...props
4346
}) => {
@@ -47,10 +50,11 @@ const ListComponent: FC<ListProps> = ({
4750
return (
4851
<Component
4952
className={twMerge(
53+
theme.root.base,
5054
theme.root.ordered[ordered ? 'on' : 'off'],
5155
unstyled && theme.root.unstyled,
5256
nested && theme.root.nested,
53-
theme.root.base,
57+
horizontal && theme.root.horizontal,
5458
className,
5559
)}
5660
{...props}

src/components/List/theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const listTheme: FlowbiteListTheme = {
77
off: 'list-disc',
88
on: 'list-decimal',
99
},
10+
horizontal: 'flex flex-wrap items-center space-x-4 space-y-0 justify-center list-none',
1011
unstyled: 'list-none',
1112
nested: 'ps-5 mt-2',
1213
},

0 commit comments

Comments
 (0)