Zubra UI
Code for
GitHub

user-avatar

A person's picture, or their initials when there's no picture or it fails to load. name is the picture's text alternative (and where the initials come from). size is sm, md, lg or xl. status (online, away, busy, offline) adds a dot, and says so in words for screen readers.

This one has no events: it shows what it's given.

Sizes and statuses

Source: user-avatar.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/user-avatar.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/user-avatar.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/user-avatar.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/user-avatar.json
One file, no dependencies (2.9 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/user-avatar.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/user-avatar.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/user-avatar.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/user-avatar.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/user-avatar.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/user-avatar.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/user-avatar.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/user-avatar.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/user-avatar.js"></script>

The compiled install writes src/components/zubra/user-avatar.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<user-avatar name="Ada Lovelace" size="lg" status="online"></user-avatar>

<script type="module">
  import './components/zubra/user-avatar.js';
</script>
Example.jsx
import './components/zubra/user-avatar.js';

export function UserAvatarExample() {
  return (
    <user-avatar name="Ada Lovelace" size="lg" status="online"></user-avatar>
  );
}
Example.vue
<script setup>
import './components/zubra/user-avatar.js';
</script>

<template>
  <user-avatar name="Ada Lovelace" size="lg" status="online"></user-avatar>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/user-avatar.js';
</script>

<user-avatar name="Ada Lovelace" size="lg" status="online"></user-avatar>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/user-avatar.js';

@Component({
  selector: 'app-user-avatar-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <user-avatar name="Ada Lovelace" size="lg" status="online"></user-avatar>
  `,
})
export class UserAvatarExample {

}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
srcstring""
namestring""
size"sm" | "md" | "lg" | "xl""md"
status"" | "online" | "away" | "busy" | "offline"""

Size

1.2 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.8 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour