'use client' import { Fragment, forwardRef } from 'react' import { isBezierIcon } from '@channel.io/bezier-icons' import classNames from 'classnames' import { isEmpty, isNil, isString } from '~/src/utils/type' import { BaseButton } from '~/src/components/BaseButton' import { Icon } from '~/src/components/Icon' import { Text } from '~/src/components/Text' import { type ListItemProps } from './ListItem.types' import styles from './ListItem.module.scss' function renderNewLineComponent(value: string) { return value.split('\n').map((str, index) => ( // eslint-disable-next-line react/no-array-index-key {index !== 0 &&
} {str}
)) } export const LIST_ITEM_TEST_ID = 'bezier-list-item' export const ListItem = forwardRef( function ListItem( { className, as, variant = 'monochrome', size = 's', content, description, descriptionMaxLines, leftContent, rightContent, active = false, focused = false, disabled = false, clickable: clickableProp = false, href, onClick, ...rest }, forwardedRef ) { const isLink = !isEmpty(href) const isButton = !isNil(onClick) const Comp = isLink ? 'a' : isButton ? BaseButton : ((as ?? 'div') as 'div') const clickable = isLink || clickableProp || isButton return (
{!isNil(leftContent) && (
{isBezierIcon(leftContent) ? ( ) : ( leftContent )}
)}
{isString(content) ? ( {content} ) : ( content )}
{description && (
{isString(description) ? renderNewLineComponent(description) : description}
)}
{rightContent && (
{rightContent}
)}
) } )