import React, { ReactNode } from "react"; import { useColorModeValue, Flex, Text, FlexProps } from "@chakra-ui/react"; import PropTypes from "prop-types"; import { hexToRgb, luminance } from "utils"; interface ListItemProps extends FlexProps { icon?: ReactNode; iconBg: string; title: string; description?: string; selected?: boolean; isDisabled?: boolean; hasArrow?: boolean; compact?: boolean; children?: ReactNode; } export function ListItem({ icon, iconBg, title, description, selected, isDisabled, hasArrow, compact, children, ...rest }: ListItemProps) { let iconColor = "gray.700"; if (/^#[0-9A-F]{6}$/i.test(iconBg)) { const colorOne = hexToRgb(iconBg); if (colorOne) { const constrast = luminance(colorOne.r, colorOne.g, colorOne.b); iconColor = constrast < 0.31 ? "gray.100" : "gray.700"; } } const bg = useColorModeValue("gray.50", "gray.900"); const selectedBg = useColorModeValue("gray.100", "black"); const titleColor = useColorModeValue("gray.800", "gray.200"); const descriptionColor = useColorModeValue("gray.500", "gray.500"); return ( {children ? ( children ) : ( <> {icon ? icon : title && title.charAt(0)} {title} {!compact && description && ( {description} )} {hasArrow && ( )} )} ); } ListItem.propTypes = { icon: PropTypes.any, iconBg: PropTypes.string, title: PropTypes.string, description: PropTypes.string, selected: PropTypes.bool, isDisabled: PropTypes.bool, hasArrow: PropTypes.bool, compact: PropTypes.bool, children: PropTypes.any, };