blob: 8060a07ee7dc7a971bc54239920519dcee7ee4b1 [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
8import * as DOMPurify from 'dompurify';
9import {css, html, LitElement} from 'lit';
10import {classMap} from 'lit/directives/class-map.js';
11import {unsafeHTML} from 'lit/directives/unsafe-html.js';
12
13import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js';
14
15export default class TwptFlattenThreadQuote extends LitElement {
16 static properties = {
17 prevMessage: {type: Object},
18 _expanded: {type: Boolean},
19 };
20
21 static styles = [
22 SHARED_MD3_STYLES,
23 css`
24 :host {
25 display: block;
26 }
27
28 .quote-container {
29 position: relative;
30 background-color: var(--TWPT-secondary-background, rgba(242, 242, 242, 0.502));
31 margin-bottom: 16px;
32 padding: 0 12px 12px 12px;
33 border-radius: 12px;
34 }
35
36 .payload-container {
37 padding-top: 12px;
38 }
39
40 .quote-container:not(.quote-container--expanded) .payload-container {
41 max-height: 4rem;
42 overflow: hidden;
43 }
44
45 .payload-container twpt-flatten-thread-quote-author {
46 float: right;
47 margin-left: 12px;
48 margin-top: -12px;
49 shape-outside: inset(0 10px 10px 0);
50 }
51
52 .payload {
53 display: inline;
54 }
55
56 .payload img {
57 max-width: 100%;
58 max-height: calc(100vh - 2*64px);
59 }
60
61 .payload blockquote {
62 border-left: 1px solid #757575;
63 margin: 0 0 0 4px;
64 padding: 0 0 0 4px;
65 }
66
67 .buttons-row {
68 position: absolute;
69 width: calc(100% - 24px);
70 display: flex;
71 flex-direction: row;
72 justify-content: center;
73 bottom: -20px;
74 transition: opacity .25s;
75 }
76
Adrià Vilanova Martínezdb38d7f2023-01-10 22:40:58 +010077 @media (hover: hover) {
78 @supports selector(:has(div)) {
79 .quote-container:not(:hover) .buttons-row:not(:has(md-tonal-button:focus)) {
80 opacity: 0;
81 }
82 }
Adrià Vilanova Martínez115e3d82023-01-10 21:50:06 +010083 }
84
85 .buttons-row md-tonal-button {
86 --md-tonal-button-container-color: var(--TWPT-dark-flatten-replies-more-bg, rgba(222, 222, 222, 0.9));
87 --md-tonal-button-label-text-color: var(--TWPT-md-sys-color-on-surface);
88 --md-tonal-button-hover-label-text-color: var(--TWPT-md-sys-color-on-surface);
89 --md-tonal-button-focus-label-text-color: var(--TWPT-md-sys-color-on-surface);
90 --md-tonal-button-pressed-label-text-color: var(--TWPT-md-sys-color-on-surface);
91 --md-tonal-button-with-icon-icon-color: var(--TWPT-md-sys-color-on-surface);
92 --md-tonal-button-with-icon-hover-icon-color: var(--TWPT-md-sys-color-on-surface);
93 --md-tonal-button-with-icon-focus-icon-color: var(--TWPT-md-sys-color-on-surface);
94 --md-tonal-button-with-icon-pressed-icon-color: var(--TWPT-md-sys-color-on-surface);
95 }
96 `,
97 ];
98
99 constructor() {
100 super();
101 this.prevMessage = {};
102 this._expanded = false;
103 }
104
105 getTrustedPayload() {
106 return DOMPurify.sanitize(this.prevMessage?.payload ?? '');
107 }
108
109 render() {
110 const containerClasses = classMap({
111 'quote-container': true,
112 'quote-container--expanded': this._expanded,
113 });
114 return html`
115 <div class=${containerClasses}>
116 <div class="payload-container">
117 <twpt-flatten-thread-quote-author
118 .prevMessage=${this.prevMessage}>
119 </twpt-flatten-thread-quote-author>
120 <div class="payload">
121 ${unsafeHTML(this.getTrustedPayload())}
122 </div>
123 </div>
124 <div class="buttons-row">
125 <md-tonal-button
126 icon="${this._expanded ? 'expand_less' : 'expand_more'}"
127 label="${this._expanded ? 'Less' : 'More'}"
128 @click=${this.toggleExpanded}>
129 </md-tonal-button>
130 </div>
131 </div>
132 `;
133 }
134
135 toggleExpanded() {
136 this._expanded = !this._expanded;
137 }
138}
139window.customElements.define(
140 'twpt-flatten-thread-quote', TwptFlattenThreadQuote);