blob: f1da3b0d34ab67e0df9cbfbf7a3660cd59888e38 [file] [log] [blame]
Renovate botaa5fb8e2024-02-25 18:10:09 +00001import '@material/web/button/filled-tonal-button.js';
2import '@material/web/icon/icon.js';
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +01003import './QuoteAuthor.js';
4
5// Other components imported so they are also injected:
6import './ReplyButton.js';
7
Adrià Vilanova Martíneza03d03a2023-03-11 23:30:07 +01008import {msg} from '@lit/localize';
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +01009import * as DOMPurify from 'dompurify';
Adrià Vilanova Martíneza03d03a2023-03-11 23:30:07 +010010import {css, html} from 'lit';
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010011import {classMap} from 'lit/directives/class-map.js';
12import {unsafeHTML} from 'lit/directives/unsafe-html.js';
13
Adrià Vilanova Martíneza03d03a2023-03-11 23:30:07 +010014import {I18nLitElement} from '../../../../common/litI18nUtils.js';
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010015import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js';
16
Adrià Vilanova Martíneza03d03a2023-03-11 23:30:07 +010017export default class TwptFlattenThreadQuote extends I18nLitElement {
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010018 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ínez90257dd2023-02-14 22:08:56 +010043 max-height: 2.8rem;
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010044 overflow: hidden;
Adrià Vilanova Martínez90257dd2023-02-14 22:08:56 +010045 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ínez115e3d82023-01-10 21:50:06 +010047 }
48
49 .payload-container twpt-flatten-thread-quote-author {
50 float: right;
51 margin-left: 12px;
Renovate botaa5fb8e2024-02-25 18:10:09 +000052 margin-top: -8px;
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010053 }
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ínezdb38d7f2023-01-10 22:40:58 +010080 @media (hover: hover) {
81 @supports selector(:has(div)) {
Adrià Vilanova Martínezd5836732023-03-03 21:33:16 +010082 .quote-container:not(:hover) .buttons-row:not(:focus-within) {
Adrià Vilanova Martínezdb38d7f2023-01-10 22:40:58 +010083 opacity: 0;
84 }
85 }
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010086 }
87
Renovate botaa5fb8e2024-02-25 18:10:09 +000088 .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ínez115e3d82023-01-10 21:50:06 +010098 }
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íneza03d03a2023-03-11 23:30:07 +0100117 const lessMsg = msg('Less', {
Renovate botaa5fb8e2024-02-25 18:10:09 +0000118 desc:
119 'Button to collapse the quote message (used in the flatten threads feature).',
Adrià Vilanova Martíneza03d03a2023-03-11 23:30:07 +0100120 });
121 const moreMsg = msg('More', {
Renovate botaa5fb8e2024-02-25 18:10:09 +0000122 desc:
123 'Button to expand the quote message (used in the flatten threads feature).',
Adrià Vilanova Martíneza03d03a2023-03-11 23:30:07 +0100124 });
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +0100125 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 botaa5fb8e2024-02-25 18:10:09 +0000136 <md-filled-tonal-button
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +0100137 @click=${this.toggleExpanded}>
Renovate botaa5fb8e2024-02-25 18:10:09 +0000138 <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ínez115e3d82023-01-10 21:50:06 +0100143 </div>
144 </div>
145 `;
146 }
147
148 toggleExpanded() {
149 this._expanded = !this._expanded;
150 }
151}
152window.customElements.define(
153 'twpt-flatten-thread-quote', TwptFlattenThreadQuote);