-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(type): Add `ListGroup` to `FlowbiteTheme` * feat(component): Use theme in `ListGroup`s, resolves #137 * refactor(docs): Update `ListGroup` examples to use themes * test(component): Add numerous unit tests for `ListGroup`s
- Loading branch information
1 parent
b6fcf6a
commit 360a723
Showing
6 changed files
with
246 additions
and
99 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
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,46 +1,42 @@ | ||
import type { ComponentProps, FC, PropsWithChildren } from 'react'; | ||
import classNames from 'classnames'; | ||
import type { ComponentProps, FC, PropsWithChildren } from 'react'; | ||
|
||
export type ListGroupItemProps = PropsWithChildren<{ | ||
className?: string; | ||
import { useTheme } from '../Flowbite/ThemeContext'; | ||
|
||
export interface ListGroupItemProps extends PropsWithChildren<Omit<ComponentProps<'a' | 'button'>, 'className'>> { | ||
active?: boolean; | ||
disabled?: boolean; | ||
href?: string; | ||
icon?: FC<ComponentProps<'svg'>>; | ||
active?: boolean; | ||
onClick?: () => void; | ||
disabled?: boolean; | ||
}>; | ||
} | ||
|
||
export const ListGroupItem: FC<ListGroupItemProps> = ({ children, className, href, onClick, active, icon: Icon }) => { | ||
const Wrapper = ({ children, className }: PropsWithChildren<{ className?: string }>) => | ||
!href ? ( | ||
<button | ||
className={classNames('text-left', className)} | ||
data-testid="list-group-item" | ||
export const ListGroupItem: FC<ListGroupItemProps> = ({ | ||
active: isActive, | ||
children, | ||
href, | ||
icon: Icon, | ||
onClick, | ||
}): JSX.Element => { | ||
const theme = useTheme().theme.listGroup.item; | ||
|
||
const Component = typeof href === 'undefined' ? 'button' : 'a'; | ||
|
||
return ( | ||
<li> | ||
<Component | ||
className={classNames( | ||
theme.active[isActive ? 'on' : 'off'], | ||
theme.base, | ||
theme.href[typeof href === 'undefined' ? 'off' : 'on'], | ||
)} | ||
href={href} | ||
onClick={onClick} | ||
type="button" | ||
> | ||
{Icon && <Icon aria-hidden className={theme.icon} data-testid="flowbite-list-group-item-icon" />} | ||
{children} | ||
</button> | ||
) : ( | ||
<a className={className} data-testid="list-group-item" href={href}> | ||
{children} | ||
</a> | ||
); | ||
|
||
return ( | ||
<Wrapper | ||
className={classNames( | ||
'flex w-full cursor-pointer border-b border-gray-200 py-2 px-4 first:rounded-t-lg last:rounded-b-lg last:border-b-0 dark:border-gray-600', | ||
{ | ||
'bg-blue-700 text-white dark:bg-gray-800': active, | ||
'hover:bg-gray-100 hover:text-blue-700 focus:text-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-700 dark:border-gray-600 dark:hover:bg-gray-600 dark:hover:text-white dark:focus:text-white dark:focus:ring-gray-500': | ||
!active, | ||
}, | ||
className, | ||
)} | ||
> | ||
{Icon && <Icon className="mr-2 h-4 w-4 fill-current" />} | ||
{children} | ||
</Wrapper> | ||
</Component> | ||
</li> | ||
); | ||
}; |
Oops, something went wrong.