Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 1 | import '@material/web/button/tonal-button.js'; |
| 2 | |
| 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; |
| 52 | margin-top: -12px; |
| 53 | shape-outside: inset(0 10px 10px 0); |
| 54 | } |
| 55 | |
| 56 | .payload { |
| 57 | display: inline; |
| 58 | } |
| 59 | |
| 60 | .payload img { |
| 61 | max-width: 100%; |
| 62 | max-height: calc(100vh - 2*64px); |
| 63 | } |
| 64 | |
| 65 | .payload blockquote { |
| 66 | border-left: 1px solid #757575; |
| 67 | margin: 0 0 0 4px; |
| 68 | padding: 0 0 0 4px; |
| 69 | } |
| 70 | |
| 71 | .buttons-row { |
| 72 | position: absolute; |
| 73 | width: calc(100% - 24px); |
| 74 | display: flex; |
| 75 | flex-direction: row; |
| 76 | justify-content: center; |
| 77 | bottom: -20px; |
| 78 | transition: opacity .25s; |
| 79 | } |
| 80 | |
Adrià Vilanova Martínez | db38d7f | 2023-01-10 22:40:58 +0100 | [diff] [blame] | 81 | @media (hover: hover) { |
| 82 | @supports selector(:has(div)) { |
Adrià Vilanova Martínez | d583673 | 2023-03-03 21:33:16 +0100 | [diff] [blame] | 83 | .quote-container:not(:hover) .buttons-row:not(:focus-within) { |
Adrià Vilanova Martínez | db38d7f | 2023-01-10 22:40:58 +0100 | [diff] [blame] | 84 | opacity: 0; |
| 85 | } |
| 86 | } |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | .buttons-row md-tonal-button { |
| 90 | --md-tonal-button-container-color: var(--TWPT-dark-flatten-replies-more-bg, rgba(222, 222, 222, 0.9)); |
| 91 | --md-tonal-button-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 92 | --md-tonal-button-hover-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 93 | --md-tonal-button-focus-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 94 | --md-tonal-button-pressed-label-text-color: var(--TWPT-md-sys-color-on-surface); |
| 95 | --md-tonal-button-with-icon-icon-color: var(--TWPT-md-sys-color-on-surface); |
| 96 | --md-tonal-button-with-icon-hover-icon-color: var(--TWPT-md-sys-color-on-surface); |
| 97 | --md-tonal-button-with-icon-focus-icon-color: var(--TWPT-md-sys-color-on-surface); |
| 98 | --md-tonal-button-with-icon-pressed-icon-color: var(--TWPT-md-sys-color-on-surface); |
| 99 | } |
| 100 | `, |
| 101 | ]; |
| 102 | |
| 103 | constructor() { |
| 104 | super(); |
| 105 | this.prevMessage = {}; |
| 106 | this._expanded = false; |
| 107 | } |
| 108 | |
| 109 | getTrustedPayload() { |
| 110 | return DOMPurify.sanitize(this.prevMessage?.payload ?? ''); |
| 111 | } |
| 112 | |
| 113 | render() { |
| 114 | const containerClasses = classMap({ |
| 115 | 'quote-container': true, |
| 116 | 'quote-container--expanded': this._expanded, |
| 117 | }); |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 118 | const lessMsg = msg('Less', { |
| 119 | desc: 'Button to collapse the quote message (used in the flatten threads feature).', |
| 120 | }); |
| 121 | const moreMsg = msg('More', { |
| 122 | desc: 'Button to expand the quote message (used in the flatten threads feature).', |
| 123 | }); |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 124 | return html` |
| 125 | <div class=${containerClasses}> |
| 126 | <div class="payload-container"> |
| 127 | <twpt-flatten-thread-quote-author |
| 128 | .prevMessage=${this.prevMessage}> |
| 129 | </twpt-flatten-thread-quote-author> |
| 130 | <div class="payload"> |
| 131 | ${unsafeHTML(this.getTrustedPayload())} |
| 132 | </div> |
| 133 | </div> |
| 134 | <div class="buttons-row"> |
| 135 | <md-tonal-button |
| 136 | icon="${this._expanded ? 'expand_less' : 'expand_more'}" |
Adrià Vilanova Martínez | a03d03a | 2023-03-11 23:30:07 +0100 | [diff] [blame] | 137 | label="${this._expanded ? lessMsg : moreMsg}" |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 138 | @click=${this.toggleExpanded}> |
| 139 | </md-tonal-button> |
| 140 | </div> |
| 141 | </div> |
| 142 | `; |
| 143 | } |
| 144 | |
| 145 | toggleExpanded() { |
| 146 | this._expanded = !this._expanded; |
| 147 | } |
| 148 | } |
| 149 | window.customElements.define( |
| 150 | 'twpt-flatten-thread-quote', TwptFlattenThreadQuote); |