import React from "react"; import { BoxProps } from "../box/box"; import Stack, { HStack } from "../stack/stack"; import Icon from "../icon/icon"; import Text from "../text/text"; export type ListProps = BoxProps & { /** * Icon to be displayed in the list. */ renderIcon?: (index: number) => React.ReactElement; }; /** * List is a layout component that arranges its children into a list. * Each child is given an equal amount of space. * An optional icon can be displayed next to each child. */ const List = React.memo( React.forwardRef( ({ children, renderIcon = undefined, ...props }: ListProps, ref: any) => { return ( {React.Children.map(children, (child, index) => ( {renderIcon && renderIcon(index)} {child} ))} ); } ) ); /** * OrderedList is a layout component that arranges its children into an ordered list. */ export const OrderedList = React.memo( React.forwardRef(({ children, ...rest }: ListProps, ref) => { return ( ( )} ref={ref} > {children} ); }) ); /** * UnorderedList is a layout component that arranges its children into an unordered list. */ export const UnorderedList = React.memo( React.forwardRef(({ children, ...rest }: ListProps, ref) => { return ( {index + 1}.} ref={ref} > {children} ); }) ); List.displayName = "List"; OrderedList.displayName = "OrderedList"; UnorderedList.displayName = "UnorderedList"; export default List;