Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(list component): develop new horizontal state of list component #1178

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions content/docs/typography/list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Use the `ordered` prop tag to create an ordered list of items with numbers.

<Example name="list.ordered" />

## Horizontal list

Use this example to create a horizontally aligned list of items.

<Example name="list.horizontal" />

## Theme

To learn more about how to customize the appearance of components, please see the [Theme docs](/docs/customize/theme).
Expand Down
1 change: 1 addition & 0 deletions examples/list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { nested } from './list.nested';
export { ordered } from './list.ordered';
export { root } from './list.root';
export { unstyled } from './list.unstyled';
export { horizontal } from './list.horizontal';
72 changes: 72 additions & 0 deletions examples/list/list.horizontal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { type CodeData } from '~/components/code-demo';
import { List, ListItem } from '~/src';

const code = `
'use client';

import { List } from 'flowbite-react';

function Component() {
return (
<List horizontal>
<List.Item>About</List.Item>
<List.Item>Premium</List.Item>
<List.Item>Campaigns</List.Item>
<List.Item>Blog</List.Item>
<List.Item>Affiliate Program</List.Item>
<List.Item>FAQs</List.Item>
<List.Item>Contact</List.Item>
</List>
);
}
`;

const codeRSC = `
import { List, ListItem } from 'flowbite-react';

function Component() {
return (
<List horizontal>
<ListItem>About</ListItem>
<ListItem>Premium</ListItem>
<ListItem>Campaigns</ListItem>
<ListItem>Blog</ListItem>
<ListItem>Affiliate Program</ListItem>
<ListItem>FAQs</ListItem>
<ListItem>Contact</ListItem>
</List>
);
}
`;

function Component() {
return (
<List horizontal>
<ListItem>About</ListItem>
<ListItem>Premium</ListItem>
<ListItem>Campaigns</ListItem>
<ListItem>Blog</ListItem>
<ListItem>Affiliate Program</ListItem>
<ListItem>FAQs</ListItem>
<ListItem>Contact</ListItem>
</List>
);
}

export const horizontal: CodeData = {
type: 'single',
code: [
{
fileName: 'client',
language: 'tsx',
code,
},
{
fileName: 'server',
language: 'tsx',
code: codeRSC,
},
],
githubSlug: 'list/list.horizontal.tsx',
component: <Component />,
};
6 changes: 5 additions & 1 deletion src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface FlowbiteListRootTheme {
on: string;
off: string;
};
horizontal: string;
unstyled: string;
nested: string;
}
Expand All @@ -30,6 +31,7 @@ export interface ListProps extends PropsWithChildren<ComponentProps<'ul'> & Comp
ordered?: boolean;
unstyled?: boolean;
nested?: boolean;
horizontal?: boolean;
}

const ListComponent: FC<ListProps> = ({
Expand All @@ -38,6 +40,7 @@ const ListComponent: FC<ListProps> = ({
unstyled,
nested,
ordered,
horizontal,
theme: customTheme = {},
...props
}) => {
Expand All @@ -47,10 +50,11 @@ const ListComponent: FC<ListProps> = ({
return (
<Component
className={twMerge(
theme.root.base,
theme.root.ordered[ordered ? 'on' : 'off'],
unstyled && theme.root.unstyled,
nested && theme.root.nested,
theme.root.base,
horizontal && theme.root.horizontal,
className,
)}
{...props}
Expand Down
1 change: 1 addition & 0 deletions src/components/List/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const listTheme: FlowbiteListTheme = {
off: 'list-disc',
on: 'list-decimal',
},
horizontal: 'flex flex-wrap items-center space-x-4 space-y-0 justify-center list-none',
unstyled: 'list-none',
nested: 'ps-5 mt-2',
},
Expand Down