diff --git a/src/components/ListGroup.tsx b/src/components/ListGroup.tsx deleted file mode 100644 index da7a6bd84..000000000 --- a/src/components/ListGroup.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { ComponentProps, FC, Fragment, ReactNode } from 'react'; -import classNames from 'classnames'; - -export type ListGroupProps = { - items: ListGroupItem[]; -}; -export type ListGroupItem = { - title: ReactNode; - link?: string; - icon?: FC>; - active?: boolean; - onClick?: () => void; - disabled?: boolean; -}; - -export const ListGroup: FC = ({ items }) => { - return ( -
- {items.map((item, index) => ( - - {!item.link ? ( - - ) : ( - - {item.title} - - )} - - ))} -
- ); -}; diff --git a/src/components/index.ts b/src/components/index.ts index c6881b44b..27e7a2016 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -9,6 +9,7 @@ export * from './Carousel'; export * from './dropdown/Dropdown'; export * from './DarkThemeToggle'; export * from './form-controls'; +export * from './list-group/ListGroup'; export * from './Navbar'; export * from './Sidebar'; export * from './Spinner'; diff --git a/src/components/list-group/ListGroup.tsx b/src/components/list-group/ListGroup.tsx new file mode 100644 index 000000000..7b00ed3df --- /dev/null +++ b/src/components/list-group/ListGroup.tsx @@ -0,0 +1,23 @@ +import { FC } from 'react'; +import classNames from 'classnames'; + +import { ListGroupItem } from './ListGroupItem'; + +export type ListGroupProps = { + className?: string; +}; + +const ListGroupComponent: FC = ({ children, className }) => ( +
+ {children} +
+); + +ListGroupItem.displayName = 'ListGroup.Item'; + +export const ListGroup = Object.assign(ListGroupComponent, { Item: ListGroupItem }); diff --git a/src/components/list-group/ListGroupItem.tsx b/src/components/list-group/ListGroupItem.tsx new file mode 100644 index 000000000..5554ae678 --- /dev/null +++ b/src/components/list-group/ListGroupItem.tsx @@ -0,0 +1,41 @@ +import { ComponentProps, FC, PropsWithChildren } from 'react'; +import classNames from 'classnames'; + +export type ListGroupItemProps = { + className?: string; + href?: string; + icon?: FC>; + active?: boolean; + onClick?: () => void; + disabled?: boolean; +}; + +export const ListGroupItem: FC = ({ children, className, href, onClick, active, icon: Icon }) => { + const Wrapper = ({ children, className }: PropsWithChildren<{ className?: string }>) => + !href ? ( + + ) : ( + + {children} + + ); + + return ( + + {Icon && } + {children} + + ); +}; diff --git a/src/pages/ListGroupPage.tsx b/src/pages/ListGroupPage.tsx index 962412f13..6999facca 100644 --- a/src/pages/ListGroupPage.tsx +++ b/src/pages/ListGroupPage.tsx @@ -1,84 +1,64 @@ import { FC } from 'react'; -import { ListGroup, ListGroupItem } from '../components/ListGroup'; -import { CodeExample, DemoPage } from './DemoPage'; import { HiCloudDownload, HiInbox, HiOutlineAdjustments, HiUserCircle } from 'react-icons/hi'; -const ListGroupPage: FC = () => { - const defaultItems: ListGroupItem[] = [ - { - title: 'Profile', - }, - { - title: 'Settings', - }, - { - title: 'Messages', - }, - { - title: 'Download', - }, - ]; - - const itemsWithLinks: ListGroupItem[] = [ - { - title: 'Profile', - link: '#/list-group', - active: true, - }, - { - title: 'Settings', - link: '#/list-group', - }, - { - title: 'Messages', - link: '#/list-group', - }, - { - title: 'Download', - link: '#/list-group', - }, - ]; - - const itemsWithIcons: ListGroupItem[] = [ - { - title: 'Profile', - icon: HiUserCircle, - onClick: () => alert('profile'), - }, - { - title: 'Settings', - icon: HiOutlineAdjustments, - }, - { - title: 'Messages', - icon: HiInbox, - }, - { - title: 'Download', - icon: HiCloudDownload, - }, - ]; +import { ListGroup } from '../components'; +import { CodeExample, DemoPage } from './DemoPage'; +const ListGroupPage: FC = () => { const examples: CodeExample[] = [ { title: 'Default list', - code: , + code: ( + + Profile + Settings + Messages + Download + + ), }, { title: 'List group with links', - code: , + code: ( + + + Profile + + Settings + Messages + Download + + ), }, { title: 'List group with buttons', - code: , - }, - { - title: 'List group with icons', - code: , + code: ( + + alert('Profile clicked!')}> + Profile + + Settings + Messages + Download + + ), codeStringifierOptions: { functionValue: (fn) => (fn.name === 'onClick' ? fn : fn.name), }, }, + { + title: 'List group with icons', + code: ( + + + Profile + + Settings + Messages + Download + + ), + }, ]; return ;