Skip to content

Commit 60aa2f4

Browse files
authored
feat(lists component): add new with-icon state (#1304)
* feat(lists component): add new with-icon state * style(list.mdx): grammatical accuracy
1 parent 83396e8 commit 60aa2f4

File tree

6 files changed

+97
-9
lines changed

6 files changed

+97
-9
lines changed

content/docs/typography/list.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ Use this example to create a default unordered list of items using the `List` co
1717

1818
<Example name="list.root" />
1919

20+
## Icons
21+
22+
This example can be used to apply custom icons instead of the default bullets for the list items.
23+
24+
<Example name="list.icon" />
25+
2026
## Nested
2127

22-
Use this example to nested another list of items inside the parent list element.
28+
Use this example to nest another list of items inside the parent list element.
2329

2430
<Example name="list.nested" />
2531

examples/list/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { nested } from './list.nested';
22
export { ordered } from './list.ordered';
3+
export { icon } from './list.icon';
34
export { root } from './list.root';
45
export { unstyled } from './list.unstyled';
56
export { horizontal } from './list.horizontal';

examples/list/list.icon.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { type CodeData } from '~/components/code-demo';
2+
import { List, ListItem } from '~/src';
3+
import { HiCheckCircle } from 'react-icons/hi';
4+
5+
const code = `
6+
'use client';
7+
8+
import { List } from 'flowbite-react';
9+
import { HiCheckCircle } from 'react-icons/hi';
10+
11+
function Component() {
12+
return (
13+
<List>
14+
<List.Item icon={HiCheckCircle}>At least 10 characters (and up to 100 characters)</List.Item>
15+
<List.Item icon={HiCheckCircle}>At least one lowercase character</List.Item>
16+
<List.Item icon={HiCheckCircle}>Inclusion of at least one special character, e.g., ! @ # ?</List.Item>
17+
</List>
18+
);
19+
}
20+
`;
21+
22+
const codeRSC = `
23+
import { List, ListItem } from 'flowbite-react';
24+
import { HiCheckCircle } from 'react-icons/hi';
25+
26+
function Component() {
27+
return (
28+
<List>
29+
<ListItem icon={HiCheckCircle}>At least 10 characters (and up to 100 characters)</ListItem>
30+
<ListItem icon={HiCheckCircle}>At least one lowercase character</ListItem>
31+
<ListItem icon={HiCheckCircle}>Inclusion of at least one special character, e.g., ! @ # ?</ListItem>
32+
</List>
33+
);
34+
}
35+
`;
36+
37+
function Component() {
38+
return (
39+
<List>
40+
<ListItem icon={HiCheckCircle}>At least 10 characters (and up to 100 characters)</ListItem>
41+
<ListItem icon={HiCheckCircle}>At least one lowercase character</ListItem>
42+
<ListItem icon={HiCheckCircle}>Inclusion of at least one special character, e.g., ! @ # ?</ListItem>
43+
</List>
44+
);
45+
}
46+
47+
export const icon: CodeData = {
48+
type: 'single',
49+
code: [
50+
{
51+
fileName: 'client',
52+
language: 'tsx',
53+
code,
54+
},
55+
{
56+
fileName: 'server',
57+
language: 'tsx',
58+
code: codeRSC,
59+
},
60+
],
61+
githubSlug: 'list/list.icon.tsx',
62+
component: <Component />,
63+
};

src/components/List/List.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { ComponentProps, FC, PropsWithChildren } from 'react';
22
import { twMerge } from 'tailwind-merge';
3-
import type { FlowbiteStateColors } from '../..';
3+
import type { FlowbiteListItemTheme, FlowbiteStateColors } from '../..';
44
import { mergeDeep } from '../../helpers/merge-deep';
55
import { getTheme } from '../../theme-store';
66
import type { DeepPartial } from '../../types';
77
import { ListItem } from './ListItem';
88

99
export interface FlowbiteListTheme {
1010
root: FlowbiteListRootTheme;
11+
item: FlowbiteListItemTheme;
1112
}
1213

1314
export interface FlowbiteListRootTheme {

src/components/List/ListItem.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
import type { FC, PropsWithChildren } from 'react';
1+
import type { ComponentProps, FC } from 'react';
22
import { twMerge } from 'tailwind-merge';
33
import { mergeDeep } from '../../helpers/merge-deep';
44
import { getTheme } from '../../theme-store';
55
import type { DeepPartial } from '../../types';
66

77
export interface FlowbiteListItemTheme {
8-
base: string;
8+
icon: string;
9+
withIcon: {
10+
on: string;
11+
off: string;
12+
};
913
}
1014

11-
export interface ListItemProps extends PropsWithChildren {
12-
theme?: DeepPartial<FlowbiteListItemTheme>;
15+
export interface ListItemProps extends ComponentProps<'li'> {
1316
className?: string;
17+
icon?: FC<ComponentProps<'svg'>>;
18+
theme?: DeepPartial<FlowbiteListItemTheme>;
1419
}
1520

16-
export const ListItem: FC<ListItemProps> = ({ children, className, theme: customTheme = {} }) => {
17-
const theme = mergeDeep(getTheme().listGroup.item, customTheme);
21+
export const ListItem: FC<ListItemProps> = ({ children, className, icon: Icon, theme: customTheme = {}, ...props }) => {
22+
const theme = mergeDeep(getTheme().list.item, customTheme);
1823

19-
return <li className={twMerge(theme.base, className)}>{children}</li>;
24+
return (
25+
<li className={twMerge(theme.withIcon[Icon ? 'on' : 'off'], className)} {...props}>
26+
{Icon && <Icon className={twMerge(theme.icon)} />}
27+
{children}
28+
</li>
29+
);
2030
};

src/components/List/theme.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ export const listTheme: FlowbiteListTheme = {
1111
unstyled: 'list-none',
1212
nested: 'ps-5 mt-2',
1313
},
14+
item: {
15+
withIcon: {
16+
off: '',
17+
on: 'flex items-center',
18+
},
19+
icon: 'w-3.5 h-3.5 me-2 flex-shrink-0',
20+
},
1421
};

0 commit comments

Comments
 (0)