import { Children, cloneElement, isValidElement, type PropsWithChildren, type ReactElement, } from "react"; import { StyleSheet, View, type ViewProps, type ViewStyle } from "react-native"; import { Text } from "../common/Text"; interface Props extends ViewProps { title?: string | null | undefined; description?: ReactElement; } export const ListGroup: React.FC> = ({ title, children, description, ...props }) => { const childrenArray = Children.toArray(children); return ( {title} {Children.map(childrenArray, (child, index) => { if (isValidElement<{ style?: ViewStyle }>(child)) { return cloneElement(child as any, { style: StyleSheet.compose( child.props.style, index < childrenArray.length - 1 ? styles.borderBottom : undefined, ), }); } return child; })} {description && {description}} ); }; const styles = StyleSheet.create({ borderBottom: { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: "#3D3C40", }, });