Skip to content
LIBRARYBaseUpdated

AvatarGroup ​

Preview for Vue Web and NativeScript on iOS and Android.

Web preview
Open example ↗
vue
<MAvatarGroup :members="contributors" :maxVisible="3" size="lg" />

Pass members in display order, each with a unique string id, a name and an optional image src. The first maxVisible portraits appear in the stack, followed by the count of additional people. The default is four portraits. Each uses the image and initials fallback from Avatar. Size accepts sm, md, lg and xl.

On Web, pointing at the stack opens the overlap a little from its middle, so every face shows in full, and closes it again when the pointer leaves. Nothing in the group takes focus, so there is no focus variant; touch screens and NativeScript keep the stack still. When the number of hidden people changes, the count bumps once on both renderers. The group never changes its own size: the stack opens outward by a few pixels on each side, so keep that room around it in tight layouts. With reduced motion the stack opens and closes without travelling, and the count changes without a bump.

vue
<script setup lang="ts">
import { avatarImage } from '../assets/avatar-image'
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const t = (en: string, pt: string) => ((props.lang ?? locale.value) === 'pt' ? pt : en)
const { theme } = useMavisTheme()
const expanded = ref(false)
const guests = ref(0)
const members = computed(() => [
  {
    id: 'marina',
    name: 'Marina Costa',
    role: t('Photo editor', 'Editora de fotografia'),
    src: avatarImage,
  },
  { id: 'aya', name: 'Aya Mori', role: t('Art director', 'Diretora de arte') },
  { id: 'luis', name: 'Luís Reis', role: t('Photographer', 'Fotógrafo') },
  { id: 'iman', name: 'Iman Noor', role: t('Producer', 'Produtora') },
  { id: 'jules', name: 'Jules Park', role: t('Writer', 'Redator') },
  ...Array.from({ length: guests.value }, (_, index) => ({
    id: `guest-${index + 1}`,
    name: t(`Guest ${index + 1}`, `Convidado ${index + 1}`),
    role: t('Guest contributor', 'Colaboração convidada'),
  })),
])
</script>
<template>
  <MColumn id="avatar-group-preview" :backgroundColor="theme.colors.background" gap="lg">
    <MColumn padding="lg" gap="lg" radius="lg" :backgroundColor="theme.colors.primarySoft">
      <MColumn gap="xs">
        <MText
          variant="overline"
          tone="primary"
          :text="t('PHOTO DESK', 'EDITORIA DE FOTOGRAFIA')"
        />
        <MText variant="title" :text="t('Behind the edition', 'Quem faz a edição')" />
      </MColumn>
      <MAvatarGroup :members="members" :maxVisible="expanded ? members.length : 3" size="lg" />
    </MColumn>
    <MRow gap="sm" wrap>
      <MButton
        variant="secondary"
        :text="
          expanded
            ? t('Hide credits', 'Ocultar créditos')
            : t(`Show all ${members.length} credits`, `Ver os ${members.length} créditos`)
        "
        @click="expanded = !expanded"
      />
      <MButton
        variant="ghost"
        icon="user-plus"
        :text="t('Invite a guest', 'Convidar alguém')"
        :disabled="guests >= 4"
        @click="guests++"
      />
    </MRow>
    <MColumn v-if="expanded" gap="md">
      <MRow v-for="person in members" :key="person.id" align="center" gap="md">
        <MAvatar :name="person.name" :src="person.src" size="sm" />
        <MColumn
          ><MText :text="person.name" /><MText tone="muted" variant="caption" :text="person.role"
        /></MColumn>
      </MRow>
    </MColumn>
  </MColumn>
</template>

On Web, iOS and Android, keep member IDs stable when the group changes. A member leaving the visible stack fades out as the remaining avatars settle into their new positions.

Desktop ​

On the Mac and on Windows the avatars overlap in one row and the ones past maxVisible become a count. Pointing at the group spreads the avatars apart. See Desktop components.

Removing a visible member fades its cell while the remaining avatars close the gap. Hover still spreads the faces independently of that movement.

Components for NativeScript and Web. Starting with Vue.