import { Avatar, Group, Menu, Portal } from "@chakra-ui/react" const names = [ "Naruto Uzumaki", "Sakura Haruno", "Kakashi Hatake", "Hinata Hyuga", "Shikamaru Nara", ] const maxAvatars = 3 export const AvatarWithOverflow = () => { const { items, overflow } = partition(names, maxAvatars) return ( {items.map((item) => ( ))} {overflow.length > 0 && ( +{overflow.length} {overflow.map((item) => ( {item} ))} )} ) } const colorPalette = ["red", "blue", "green", "yellow", "purple", "orange"] const pickPalette = (name: string) => { const index = name.charCodeAt(0) % colorPalette.length return colorPalette[index] } const partition = (arr: string[], max: number) => { const items = [] const overflow = [] for (const item of arr) { if (items.length < max) items.push(item) else overflow.push(item) } return { items, overflow } }