Skip to content

Commit

Permalink
feat(list component): develop new horizontal state of list component (#…
Browse files Browse the repository at this point in the history
…1178)

* feat(list component): develop new horizontal state of list component

* refactor(list.ts): change the order of classes in twmerge
  • Loading branch information
paghar authored Dec 11, 2023
1 parent 770ab9d commit 1fbe6ca
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
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

1 comment on commit 1fbe6ca

@vercel
Copy link

@vercel vercel bot commented on 1fbe6ca Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.