blob: 2f1fb95f0e7bc8e2b7ab2e2031d7a4021393b68a [file] [log] [blame]
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +01001import '@material/web/icon/icon.js';
2import '@material/web/iconbutton/standard-icon-button.js';
3
4import {css, html, LitElement} from 'lit';
5
6import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js';
7
8export default class TwptFlattenThreadQuoteAuthor extends LitElement {
9 static properties = {
10 prevMessage: {type: Object},
11 };
12
13 static styles = [
14 SHARED_MD3_STYLES,
15 css`
16 :host {
17 display: flex;
18 flex-direction: row;
19 align-items: center;
20 max-width: max(25%, 150px);
21 color: var(--TWPT-interop-secondary-text, #444746);
22 }
23
24 :host > *:not(:last-child) {
25 margin-right: 4px;
26 }
27
28 .name {
29 overflow: hidden;
30 white-space: nowrap;
31 text-overflow: ellipsis;
32 }
33 `,
34 ];
35
36 constructor() {
37 super();
38 this.prevMessage = {};
39 }
40
41 render() {
42 return html`
43 <md-icon>reply</md-icon>
44 <span class="name">${this.prevMessage?.author?.[1]?.[1]}</span>
45 <md-standard-icon-button
46 icon="arrow_upward"
47 @click=${this.focusParent}>
48 </md-standard-icon-button>
49 `;
50 }
51
52 focusParent() {
53 const parentNode = document.querySelector(
54 '[data-twpt-message-id="' + this.prevMessage?.id + '"]');
55 parentNode.focus({preventScroll: true});
56 parentNode.scrollIntoView({behavior: 'smooth', block: 'start'});
57 }
58}
59window.customElements.define(
60 'twpt-flatten-thread-quote-author', TwptFlattenThreadQuoteAuthor);