Avatar Group

Displays a group of Avatar components.

Examples

Basic

PropDefaultDescription
max3The maximum number of avatars to display before the rest are hidden.
Preview
Code
+1DRAF

Size and Square

PropDefaultTypeDescription
sizemdstringSets the size of the avatar.
square2.5remstringSets the avatar to a square shape with specified dimensions. This does not affect the size of the fallback value.

🚀 Adjust input size freely using any size, breakpoints (e.g., sm:sm, xs:lg), or states (e.g., hover:lg, focus:3xl).

Preview
Code
+1PRDRAF

Customization

Similar to the size prop, any available props of the Avatar component can be directly passed to the AvatarGroup component. These props will then be automatically forwarded to the individual Avatar components within the group.

You can also use the una prop to add utility classes, refer to the Props and Presets sections for more information.

Preview
Code
+1DRAF

Slots

NamePropsDescription
default-The default slot for the AvatarGroup component.

Presets

shortcuts/avatar-group.ts
type AvatarGroupPrefix = 'avatar-group'

export const staticAvatarGroup: Record<`${AvatarGroupPrefix}-${string}` | AvatarGroupPrefix, string> = {
  'avatar-group': 'flex flex-row-reverse justify-end',
  'avatar-group-child': 'ring-2 ring-$c-background',
  'avatar-group-margin': '-me-1.5 first:me-0',
  'avatar-group-label': 'text-.9em',
}

export const dynamicAvatarGroup: [RegExp, (params: RegExpExecArray) => string][] = [
]

export const avatarGroup = [
  ...dynamicAvatarGroup,
  staticAvatarGroup,
]

Props

types/avatar-group.ts
import type { NAvatarProps } from './avatar'

/**
 * This extends the `NAvatarProps` interface.
 *
 * @see https://github.com/una-ui/una-ui/blob/main/packages/nuxt/src/runtime/types/avatar.ts
 */
export interface NAvatarGroupProps extends Omit<NAvatarProps, 'una'> {
  /**
   * Set the maximum number of avatars to show.
   *
   * @default 3
   */
  max: number

  /**
   * `Una
   *
   * @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/avatar-group.ts
   * @see https://github.com/una-ui/una-ui/blob/main/packages/preset/src/_shortcuts/avatar.ts
   */
  una?: {
    avatarGroup?: string
    avatarGroupChild?: string
    avatarGroupMargin?: string
    avatarGroupLabel?: string
  } & NAvatarProps['una']
}

Components

AvatarGroup.vue
AvatarGroupDefault.vue
<script setup lang="ts">
import type { NAvatarGroupProps } from '../../types'
import NAvatarGroupDefaultSlot from '../slots/AvatarGroupDefault'

const props = withDefaults(defineProps<NAvatarGroupProps>(), {
  max: 3,
})
</script>

<template>
  <div
    avatar-group
    :size
    :class="una?.avatarGroup"
  >
    <NAvatarGroupDefaultSlot
      :max
      :avatar="props"
    >
      <slot />
    </NAvatarGroupDefaultSlot>
  </div>
</template>