All files / src/display Label.ts

100% Statements 147/147
100% Branches 6/6
100% Functions 2/2
100% Lines 147/147

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 135 136 137 138 139 140 141 142 143 144 145 146 147 14892x 98x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 90x 92x 90x 90x 90x 90x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x  
import { LitElement, TemplateResult, html, css } from 'lit';
import { property } from 'lit/decorators.js';
import { getClasses } from '../utils';
import { styleMap } from 'lit-html/directives/style-map.js';
 
export default class Label extends LitElement {
  static get styles() {
    return css`
      :host {
        display: inline-block;
      }
 
      slot {
        white-space: nowrap;
        overflow-x: hidden;
        text-overflow: ellipsis;
        display: block;
      }
 
      .mask {
        padding: 3px 8px;
        border-radius: 12px;
        display: flex;
      }
 
      temba-icon {
        margin-right: 0.3em;
        padding-bottom: 0.1em;
      }
 
      .label.clickable .mask:hover {
        background: var(--color-background-hover, rgb(0, 0, 0, 0.05));
      }
 
      .label {
        font-size: 0.8em;
        font-weight: 400;
        border-radius: 12px;
        box-shadow: var(--widget-shadow, 0 0.04em 0.08em rgba(0, 0, 0, 0.15));
        background: var(--color-overlay-light);
        color: var(--color-overlay-light-text);
        --icon-color: var(--color-overlay-light-text);
        text-shadow: none;
      }
 
      .danger {
        background: tomato;
        color: #fff;
        --icon-color: #fff;
      }
 
      .primary {
        background: var(--color-primary-dark);
        color: var(--color-text-light);
        --icon-color: var(--color-text-light);
      }
 
      .secondary {
        background: var(--color-secondary-dark);
        color: var(--color-text-light);
        --icon-color: var(--color-text-light);
      }
 
      .tertiary {
        background: var(--color-tertiary);
        color: var(--color-text-light);
        --icon-color: var(--color-text-light);
      }
 
      .dark {
        background: var(--color-overlay-dark);
        text-shadow: none;
      }
 
      .clickable {
        cursor: pointer;
      }
 
      .shadow {
        box-shadow: 1px 1px 2px 1px rgba(0, 0, 0, 0.1);
      }
    `;
  }
 
  @property({ type: Boolean })
  clickable: boolean;
 
  @property({ type: Boolean })
  primary: boolean;
 
  @property({ type: Boolean })
  secondary: boolean;
 
  @property({ type: Boolean })
  tertiary: boolean;
 
  @property({ type: Boolean })
  danger: boolean;
 
  @property({ type: Boolean })
  dark: boolean;
 
  @property({ type: Boolean })
  shadow: boolean;
 
  @property({ type: String })
  icon: string;
 
  @property()
  backgroundColor: string;
 
  @property()
  textColor: string;
 
  public render(): TemplateResult {
    const labelStyle = {};
 
    if (this.backgroundColor) {
      labelStyle['background'] = this.backgroundColor;
    }
 
    if (this.textColor) {
      labelStyle['color'] = this.textColor;
      labelStyle['--icon-color'] = this.textColor;
    }
 
    return html`
      <div
        class="label ${getClasses({
          clickable: this.clickable,
          primary: this.primary,
          secondary: this.secondary,
          tertiary: this.tertiary,
          shadow: this.shadow,
          danger: this.danger,
          dark: this.dark
        })}"
        style=${styleMap(labelStyle)}
      >
        <div class="mask">
          ${this.icon ? html`<temba-icon name=${this.icon} />` : null}
          <slot></slot>
        </div>
      </div>
    `;
  }
}