All files / apps / web/src / helpers presence.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26        6x           6x               87x         31x    
export type Presence = 'online' | 'away' | 'offline'
 
// Full class names so Tailwind sees them. Online is filled green, away filled amber, offline a hollow ring,
// so the three differ by shape as well as colour.
const PRESENCE_CLASSES: Record<Presence, string> = {
  online: 'bg-ok',
  away: 'bg-warn',
  offline: 'bg-card ring-faint',
}
 
const PRESENCE_LABELS: Record<Presence, string> = {
  online: 'Online',
  away: 'Away',
  offline: 'Offline',
}
 
// Classes for the dot on an avatar (`AvatarBadge`).
export function presenceClass(presence: Presence): string {
  return PRESENCE_CLASSES[presence]
}
 
// The word a screen reader gets in place of the dot's colour.
export function presenceLabel(presence: Presence): string {
  return PRESENCE_LABELS[presence]
}