summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutlogins/content/components/login-timeline.mjs
blob: 52d053e99952e084df964e3935e0ab9e009cbbf7 (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import {
  styleMap,
  classMap,
  html,
  css,
} from "chrome://global/content/vendor/lit.all.mjs";
import { MozLitElement } from "chrome://global/content/lit-utils.mjs";

export default class Timeline extends MozLitElement {
  static get properties() {
    return {
      history: { type: Array },
    };
  }

  constructor() {
    super();
    this.history = [];
  }

  static styles = css`
    .timeline {
      display: grid;
      grid-template-rows: 24px auto auto;
      font-size: smaller;
      color: var(--text-color-deemphasized);
      padding-inline-start: 0px;
      text-align: center;
    }

    .timeline.empty {
      display: none;
    }

    .timeline > svg {
      grid-row: 1 / 1;
      fill: var(--in-content-box-background);
    }

    .timeline > .line {
      height: 2px;
      justify-self: stretch;
      align-self: center;
      background-color: var(--in-content-border-color);
      grid-row: 1;
    }

    .timeline > .line:nth-child(1) {
      grid-column: 1;
      width: 50%;
      justify-self: flex-end;
    }

    .timeline > .line:nth-child(2) {
      grid-column: 2/-2;
    }

    .timeline > .line:nth-child(3) {
      grid-column: -2;
      width: 50%;
      justify-self: flex-start;
    }

    .timeline > .point {
      width: 24px;
      height: 24px;
      stroke: var(--in-content-border-color);
      stroke-width: 30px;
      justify-self: center;
    }

    .timeline > .date {
      grid-row: 2;
      padding: 4px 8px;
    }

    .timeline > .action {
      grid-row: 3;
    }
  `;

  render() {
    this.history = this.history.filter(historyPoint => historyPoint.time);
    this.history.sort((a, b) => a.time - b.time);
    let columns = "auto";

    // Add each history event to the timeline
    let points = this.history.map((entry, index) => {
      if (index > 0) {
        // add a gap between previous point and current one
        columns += ` ${entry.time - this.history[index - 1].time}fr auto`;
      }

      let columnNumber = 2 * index + 1;
      let styles = styleMap({ gridColumn: columnNumber });
      return html`
        <svg
          style=${styles}
          class="point"
          viewBox="0 0 300 150"
          xmlns="http://www.w3.org/2000/svg"
        >
          <circle cx="150" cy="75" r="75" />
        </svg>
        <div
          style=${styles}
          class="date"
          data-l10n-id="login-item-timeline-point-date"
          data-l10n-args=${JSON.stringify({ datetime: entry.time })}
        ></div>
        <div
          style=${styles}
          class="action"
          data-l10n-id=${entry.actionId}
        </div>
      `;
    });

    return html`
      <div
        class="timeline ${classMap({ empty: !this.history.length })}"
        style=${styleMap({ gridTemplateColumns: columns })}
      >
        <div class="line"></div>
        <div class="line"></div>
        <div class="line"></div>
        ${points}
      </div>
    `;
  }
}

customElements.define("login-timeline", Timeline);