All files / src/display TembaUser.ts

100% Statements 134/134
100% Branches 16/16
100% Functions 5/5
100% Lines 134/134

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135108x 112x 108x 108x 108x 108x 108x 108x 108x 108x 108x 108x 108x 108x 108x 108x 108x 2x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 115x 109x 115x 115x 115x 109x 1x 108x 115x 115x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 108x 108x 108x 108x 108x 108x 108x 108x 108x  
import { PropertyValues, TemplateResult, css, html } from 'lit';
import { property } from 'lit/decorators.js';
 
import { colorHash, extractInitials } from '../utils';
 
import { DEFAULT_AVATAR } from '../webchat/assets';
import { RapidElement } from '../RapidElement';
 
export const getFullName = (user: {
  name?: string;
  first_name?: string;
  last_name?: string;
}) => {
  return user.name || [user.first_name, user.last_name].join(' ');
};
 
export class TembaUser extends RapidElement {
  public static styles = css`
    :host {
      display: flex;
      transform: scale(var(--temba-scale, 1));
      box-sizing: border-box;
    }
 
    .wrapper {
      display: flex;
      flex-direction: row;
      align-items: center;
      flex-grow: 1;
    }
 
    .name {
      flex-grow: 1;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
  `;
 
  @property({ type: Number })
  scale: number;
 
  @property({ type: Boolean })
  showName: boolean;
 
  @property({ type: Boolean })
  system: boolean;
 
  @property({ type: String, attribute: false })
  bgimage: string = null;
 
  @property({ type: String, attribute: false })
  bgcolor: string = '#e6e6e6';
 
  @property({ type: String, attribute: false })
  initials: string = '';
 
  @property({ type: String })
  name: string;
 
  @property({ type: String })
  email: string;
 
  @property({ type: String })
  uuid: string;
 
  @property({ type: String })
  avatar: string;
 
  public willUpdate(changed: PropertyValues): void {
    super.willUpdate(changed);
 
    if (changed.has('system') && this.system) {
      this.bgimage = `url('${DEFAULT_AVATAR}') center / contain no-repeat`;
    }
 
    if (changed.has('name')) {
      if (this.name) {
        this.bgcolor = colorHash.hex(this.name);
        this.initials = extractInitials(this.name);
      } else {
        this.bgcolor = '#e6e6e6';
        this.initials = '';
      }
    }
 
    if (changed.has('avatar')) {
      if (this.avatar) {
        this.bgimage = `url('${this.avatar}') center / contain no-repeat`;
      }
    }
  }
 
  public render(): TemplateResult {
    return html`<div class="wrapper">
      <div
        class="avatar-circle"
        style="
              transform:scale(${this.scale || 1});
              display: flex;
              min-height: 26px;
              min-width: 26px;
              flex-direction: row;
              align-items: center;
              color: #fff;
              border-radius: 100%;
              font-weight: 400;
              overflow: hidden;
              font-size: 0.8em;
              margin-right: 0.75em;
              box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.1);
              background:${this.bgimage || this.bgcolor};"
      >
        ${this.initials && !this.bgimage
          ? html` <div
              style="border: 0px solid red; display:flex; flex-direction: column; align-items:center;flex-grow:1"
            >
              <div style="border:0px solid blue;">${this.initials}</div>
            </div>`
          : null}
      </div>
      ${this.showName
        ? html`<div
            class="name"
            style="margin: 0px ${this.scale - 0.5}em;font-size:${this.scale +
            0.2}em"
          >
            ${this.name}
          </div>`
        : null}
    </div>`;
  }
}