Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 1 | import '@material/web/button/filled-tonal-button.js'; |
| 2 | import '@material/web/icon/icon.js'; |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 3 | import './QuoteAuthor.js'; |
| 4 | |
| 5 | // Other components imported so they are also injected: |
| 6 | import './ReplyButton.js'; |
| 7 | |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 8 | import {msg} from '@lit/localize'; |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 9 | import * as DOMPurify from 'dompurify'; |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 10 | import {css, html} from 'lit'; |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 11 | import {classMap} from 'lit/directives/class-map.js'; |
| 12 | import {unsafeHTML} from 'lit/directives/unsafe-html.js'; |
| 13 | |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 14 | import {I18nLitElement} from '../../../../common/litI18nUtils.js'; |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 15 | import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js'; |
| 16 | |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 17 | export default class TwptFlattenThreadQuote extends I18nLitElement { |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 18 | static properties = { |
| 19 | prevMessage: {type: Object}, |
| 20 | _expanded: {type: Boolean}, |
| 21 | }; |
| 22 | |
| 23 | static styles = [ |
| 24 | SHARED_MD3_STYLES, |
| 25 | css` |
| 26 | :host { |
| 27 | display: block; |
| 28 | } |
| 29 | |
| 30 | .quote-container { |
| 31 | position: relative; |
| 32 | background-color: var(--TWPT-secondary-background, rgba(242, 242, 242, 0.502)); |
| 33 | margin-bottom: 16px; |
| 34 | padding: 0 12px 12px 12px; |
| 35 | border-radius: 12px; |
| 36 | } |
| 37 | |
| 38 | .payload-container { |
| 39 | padding-top: 12px; |
| 40 | } |
| 41 | |
| 42 | .quote-container:not(.quote-container--expanded) .payload-container { |
Adrià Vilanova Martínez | 90257dd | 2023-02-14 22:08:56 +0100 | [diff] [blame] | 43 | max-height: 2.8rem; |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 44 | overflow: hidden; |
Adrià Vilanova Martínez | 90257dd | 2023-02-14 22:08:56 +0100 | [diff] [blame] | 45 | mask-image: linear-gradient(rgb(0, 0, 0) 76%, transparent); |
| 46 | -webkit-mask-image: linear-gradient(rgb(0, 0, 0) 76%, transparent); |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | .payload-container twpt-flatten-thread-quote-author { |
| 50 | float: right; |
| 51 | margin-left: 12px; |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 52 | margin-top: -8px; |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | .payload { |
| 56 | display: inline; |
| 57 | } |
| 58 | |
| 59 | .payload img { |
| 60 | max-width: 100%; |
| 61 | max-height: calc(100vh - 2*64px); |
| 62 | } |
| 63 | |
| 64 | .payload blockquote { |
| 65 | border-left: 1px solid #757575; |
| 66 | margin: 0 0 0 4px; |
| 67 | padding: 0 0 0 4px; |
| 68 | } |
| 69 | |
| 70 | .buttons-row { |
| 71 | position: absolute; |
| 72 | width: calc(100% - 24px); |
| 73 | display: flex; |
| 74 | flex-direction: row; |
| 75 | justify-content: center; |
| 76 | bottom: -20px; |
| 77 | transition: opacity .25s; |
| 78 | } |
| 79 | |
Adrià Vilanova Martínez | db38d7f | 2023-01-10 22:40:58 +0100 | [diff] [blame] | 80 | @media (hover: hover) { |
| 81 | @supports selector(:has(div)) { |
Adrià Vilanova Martínez | d583673 | 2023-03-03 21:33:16 +0100 | [diff] [blame] | 82 | .quote-container:not(:hover) .buttons-row:not(:focus-within) { |
Adrià Vilanova Martínez | db38d7f | 2023-01-10 22:40:58 +0100 | [diff] [blame] | 83 | opacity: 0; |
| 84 | } |
| 85 | } |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 88 | .buttons-row md-filled-tonal-button { |
| 89 | --md-filled-tonal-button-container-color: var(--TWPT-dark-flatten-replies-more-bg, rgba(222, 222, 222, 0.9)); |
| 90 | --md-filled-tonal-button-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 91 | --md-filled-tonal-button-hover-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 92 | --md-filled-tonal-button-focus-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 93 | --md-filled-tonal-button-pressed-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 94 | --md-filled-tonal-button-icon-color: var(--TWPT-md-sys-color-on-surface); |
| 95 | --md-filled-tonal-button-hover-icon-color: var(--TWPT-md-sys-color-on-surface); |
| 96 | --md-filled-tonal-button-focus-icon-color: var(--TWPT-md-sys-color-on-surface); |
| 97 | --md-filled-tonal-button-pressed-icon-color: var(--TWPT-md-sys-color-on-surface); |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 98 | } |
| 99 | `, |
| 100 | ]; |
| 101 | |
| 102 | constructor() { |
| 103 | super(); |
| 104 | this.prevMessage = {}; |
| 105 | this._expanded = false; |
| 106 | } |
| 107 | |
| 108 | getTrustedPayload() { |
| 109 | return DOMPurify.sanitize(this.prevMessage?.payload ?? ''); |
| 110 | } |
| 111 | |
| 112 | render() { |
| 113 | const containerClasses = classMap({ |
| 114 | 'quote-container': true, |
| 115 | 'quote-container--expanded': this._expanded, |
| 116 | }); |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 117 | const lessMsg = msg('Less', { |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 118 | desc: |
| 119 | 'Button to collapse the quote message (used in the flatten threads feature).', |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 120 | }); |
| 121 | const moreMsg = msg('More', { |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 122 | desc: |
| 123 | 'Button to expand the quote message (used in the flatten threads feature).', |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 124 | }); |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 125 | return html` |
| 126 | <div class=${containerClasses}> |
| 127 | <div class="payload-container"> |
| 128 | <twpt-flatten-thread-quote-author |
| 129 | .prevMessage=${this.prevMessage}> |
| 130 | </twpt-flatten-thread-quote-author> |
| 131 | <div class="payload"> |
| 132 | ${unsafeHTML(this.getTrustedPayload())} |
| 133 | </div> |
| 134 | </div> |
| 135 | <div class="buttons-row"> |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 136 | <md-filled-tonal-button |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 137 | @click=${this.toggleExpanded}> |
Renovate bot | aa5fb8e | 2024-02-25 18:10:09 +0000 | [diff] [blame] | 138 | <md-icon slot="icon"> |
| 139 | ${this._expanded ? 'expand_less' : 'expand_more'} |
| 140 | </md-icon> |
| 141 | ${this._expanded ? lessMsg : moreMsg} |
| 142 | </md-filled-tonal-button> |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 143 | </div> |
| 144 | </div> |
| 145 | `; |
| 146 | } |
| 147 | |
| 148 | toggleExpanded() { |
| 149 | this._expanded = !this._expanded; |
| 150 | } |
| 151 | } |
| 152 | window.customElements.define( |
| 153 | 'twpt-flatten-thread-quote', TwptFlattenThreadQuote); |