diff options
Diffstat (limited to 'src/components/atoms/lists/list/list-item.tsx')
| -rw-r--r-- | src/components/atoms/lists/list/list-item.tsx | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/components/atoms/lists/list/list-item.tsx b/src/components/atoms/lists/list/list-item.tsx index 3438eac..41e90fc 100644 --- a/src/components/atoms/lists/list/list-item.tsx +++ b/src/components/atoms/lists/list/list-item.tsx @@ -1,23 +1,39 @@ -import type { FC, LiHTMLAttributes } from 'react'; +import { + forwardRef, + type LiHTMLAttributes, + type ForwardRefRenderFunction, +} from 'react'; import styles from './list.module.scss'; -export type ListItemProps = LiHTMLAttributes<HTMLElement>; +export type ListItemProps = LiHTMLAttributes<HTMLElement> & { + /** + * Should we hide the marker in front of the list item? + * + * @default false + */ + hideMarker?: boolean; +}; -/** - * ListItem component - * - * Used it inside a `<List />` component. - */ -export const ListItem: FC<ListItemProps> = ({ - children, - className = '', - ...props -}) => { - const itemClass = `${styles.item} ${className}`; +const ListItemWithRef: ForwardRefRenderFunction< + HTMLLIElement, + ListItemProps +> = ({ children, className = '', hideMarker = false, ...props }, ref) => { + const itemClass = [ + styles.item, + styles[hideMarker ? 'item--no-marker' : ''], + className, + ].join(' '); return ( - <li {...props} className={itemClass}> + <li {...props} className={itemClass} ref={ref}> {children} </li> ); }; + +/** + * ListItem component + * + * Used it inside a `<List />` component. + */ +export const ListItem = forwardRef(ListItemWithRef); |
