blob: 39e831015c3565fb5999b59ee5a439049dddb12d [file] [log] [blame]
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +01001import '@material/web/button/tonal-button.js';
2
3import './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;
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ínezdb38d7f2023-01-10 22:40:58 +010081 @media (hover: hover) {
82 @supports selector(:has(div)) {
Adrià Vilanova Martínezd5836732023-03-03 21:33:16 +010083 .quote-container:not(:hover) .buttons-row:not(:focus-within) {
Adrià Vilanova Martínezdb38d7f2023-01-10 22:40:58 +010084 opacity: 0;
85 }
86 }
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010087 }
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íneza03d03a2023-03-11 23:30:07 +0100118 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ínez115e3d82023-01-10 21:50:06 +0100124 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íneza03d03a2023-03-11 23:30:07 +0100137 label="${this._expanded ? lessMsg : moreMsg}"
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +0100138 @click=${this.toggleExpanded}>
139 </md-tonal-button>
140 </div>
141 </div>
142 `;
143 }
144
145 toggleExpanded() {
146 this._expanded = !this._expanded;
147 }
148}
149window.customElements.define(
150 'twpt-flatten-thread-quote', TwptFlattenThreadQuote);