Adrià Vilanova MartÃnez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 1 | import '@material/web/icon/icon.js'; |
| 2 | import '@material/web/iconbutton/standard-icon-button.js'; |
| 3 | |
| 4 | import {css, html, LitElement} from 'lit'; |
| 5 | |
| 6 | import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js'; |
| 7 | |
| 8 | export 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 | } |
| 59 | window.customElements.define( |
| 60 | 'twpt-flatten-thread-quote-author', TwptFlattenThreadQuoteAuthor); |