import React from 'react'; import type { ReactNode, ReactElement } from 'react'; import type { StyleProp, ViewStyle } from 'react-native'; import { View } from 'react-native'; import { useTheme } from '../../theme'; import type { IconName } from '../Icon'; import Icon from '../Icon'; import Typography from '../Typography'; import { StyledChildrenContainer, StyledContentContainer, StyledLeadingStatus, StyledListItemContainer, StyledPrefixContainer, StyledSuffixContainer, StyledTitleContainer, } from './StyledListItem'; export interface ListItemProps { /** * Name of Icon or ReactElement to render on the left side of title. */ prefix?: IconName | React.ReactElement; /** * Name of Icon or ReactElement to render on the right side of title. */ suffix?: IconName | React.ReactElement; /** * The title of the component. */ title?: string | ReactElement; /** * The subtile title of the component. */ subtitle?: string; /** * Additional wrapper style. */ style?: StyleProp; /** * Children to be rendered inside the component. */ children?: ReactNode; /** * Leading status of the component * */ leadingStatus?: 'success' | 'warning' | 'danger' | 'info' | 'archived'; /* * Card styles. Default is `full-width` */ variant?: 'full-width' | 'card'; /** * Whether the component is disabled. Default value is false */ disabled?: boolean; /** * Whether the component is selected. Default value is false */ selected?: boolean; /** * Testing id of the component. */ testID?: string; /** * Set the handler to handle press event. */ onPress?: () => void; } const ListItem = ({ prefix, suffix, title, subtitle, style, testID, selected = false, children, leadingStatus, variant = 'full-width', onPress, disabled = false, }: ListItemProps): ReactElement => { const theme = useTheme(); return ( <> {leadingStatus && ( )} {prefix && ( {typeof prefix === 'string' ? ( ) : ( prefix )} )} {typeof title === 'string' ? ( {title} ) : ( title )} {!!subtitle && ( {subtitle} )} {suffix && ( {typeof suffix === 'string' ? ( ) : ( suffix )} )} {children && ( {children} )} ); }; export default ListItem;