-
-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lists component): add new with-icon state (#1304)
* feat(lists component): add new with-icon state * style(list.mdx): grammatical accuracy
- Loading branch information
Showing
6 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export { nested } from './list.nested'; | ||
export { ordered } from './list.ordered'; | ||
export { icon } from './list.icon'; | ||
export { root } from './list.root'; | ||
export { unstyled } from './list.unstyled'; | ||
export { horizontal } from './list.horizontal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { type CodeData } from '~/components/code-demo'; | ||
import { List, ListItem } from '~/src'; | ||
import { HiCheckCircle } from 'react-icons/hi'; | ||
|
||
const code = ` | ||
'use client'; | ||
import { List } from 'flowbite-react'; | ||
import { HiCheckCircle } from 'react-icons/hi'; | ||
function Component() { | ||
return ( | ||
<List> | ||
<List.Item icon={HiCheckCircle}>At least 10 characters (and up to 100 characters)</List.Item> | ||
<List.Item icon={HiCheckCircle}>At least one lowercase character</List.Item> | ||
<List.Item icon={HiCheckCircle}>Inclusion of at least one special character, e.g., ! @ # ?</List.Item> | ||
</List> | ||
); | ||
} | ||
`; | ||
|
||
const codeRSC = ` | ||
import { List, ListItem } from 'flowbite-react'; | ||
import { HiCheckCircle } from 'react-icons/hi'; | ||
function Component() { | ||
return ( | ||
<List> | ||
<ListItem icon={HiCheckCircle}>At least 10 characters (and up to 100 characters)</ListItem> | ||
<ListItem icon={HiCheckCircle}>At least one lowercase character</ListItem> | ||
<ListItem icon={HiCheckCircle}>Inclusion of at least one special character, e.g., ! @ # ?</ListItem> | ||
</List> | ||
); | ||
} | ||
`; | ||
|
||
function Component() { | ||
return ( | ||
<List> | ||
<ListItem icon={HiCheckCircle}>At least 10 characters (and up to 100 characters)</ListItem> | ||
<ListItem icon={HiCheckCircle}>At least one lowercase character</ListItem> | ||
<ListItem icon={HiCheckCircle}>Inclusion of at least one special character, e.g., ! @ # ?</ListItem> | ||
</List> | ||
); | ||
} | ||
|
||
export const icon: CodeData = { | ||
type: 'single', | ||
code: [ | ||
{ | ||
fileName: 'client', | ||
language: 'tsx', | ||
code, | ||
}, | ||
{ | ||
fileName: 'server', | ||
language: 'tsx', | ||
code: codeRSC, | ||
}, | ||
], | ||
githubSlug: 'list/list.icon.tsx', | ||
component: <Component />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
import type { FC, PropsWithChildren } from 'react'; | ||
import type { ComponentProps, FC } from 'react'; | ||
import { twMerge } from 'tailwind-merge'; | ||
import { mergeDeep } from '../../helpers/merge-deep'; | ||
import { getTheme } from '../../theme-store'; | ||
import type { DeepPartial } from '../../types'; | ||
|
||
export interface FlowbiteListItemTheme { | ||
base: string; | ||
icon: string; | ||
withIcon: { | ||
on: string; | ||
off: string; | ||
}; | ||
} | ||
|
||
export interface ListItemProps extends PropsWithChildren { | ||
theme?: DeepPartial<FlowbiteListItemTheme>; | ||
export interface ListItemProps extends ComponentProps<'li'> { | ||
className?: string; | ||
icon?: FC<ComponentProps<'svg'>>; | ||
theme?: DeepPartial<FlowbiteListItemTheme>; | ||
} | ||
|
||
export const ListItem: FC<ListItemProps> = ({ children, className, theme: customTheme = {} }) => { | ||
const theme = mergeDeep(getTheme().listGroup.item, customTheme); | ||
export const ListItem: FC<ListItemProps> = ({ children, className, icon: Icon, theme: customTheme = {}, ...props }) => { | ||
const theme = mergeDeep(getTheme().list.item, customTheme); | ||
|
||
return <li className={twMerge(theme.base, className)}>{children}</li>; | ||
return ( | ||
<li className={twMerge(theme.withIcon[Icon ? 'on' : 'off'], className)} {...props}> | ||
{Icon && <Icon className={twMerge(theme.icon)} />} | ||
{children} | ||
</li> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters