Data display

Avatar

A round picture of a person, or their initials when there is no image.

JxAvatar import 'package:jx_cli/ui.dart' Available since 0.0.2

Preview

When to use it

  • Authors of comments.
  • Members of a team.
  • The signed-in user in a menu.

Minimal example

Dart
JxAvatar(name: 'Grace Hopper')                    // initials: GH
JxAvatar(name: 'Grace Hopper', src: '/grace.jpg')  // picture

Complete example

A full Jaspr component you can paste into a project.

Dart
import 'package:jaspr/dom.dart';
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';

/// Overlapping avatars of a team.
class TeamStack extends StatelessComponent {
  const TeamStack(this.names, {super.key});

  final List<String> names;

  @override
  Component build(BuildContext context) {
    return div(classes: 'flex', [
      for (final (i, name) in names.indexed)
        JxAvatar(name: name, size: JxAvatarSize.sm, classes: i == 0 ? 'bw:2 bc:white' : '-ml:2 bw:2 bc:white'),
    ]);
  }
}

Properties

Property Type Default Description
name String required Used for the initials and as the accessible name.
src String? null Picture URL. The image alt is the name.
size JxAvatarSize md sm (32 px), md (40 px) or lg (56 px).
classes String? null Extra JX classes, appended after the component classes.

Related types

Name Role
JxAvatar.initials(name) Static helper: up to two initials, "Ada Lovelace" → "AL".

Customizing

  • Pass classes to add or override utilities: they come last, so classes: 'w:full' wins over the default width.
  • Use another color for initials: classes: 'bg:green-100 c:green-900'.

Accessibility

  • With a picture, the image alt is the name; with initials, the avatar is role="img" with an aria-label.
  • Initials are hidden from screen readers, so the full name is read instead of letters.