blob: ce8da4d4a1709c6764405b7e3c227f64ab1c35ea [file] [log] [blame]
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +01001import '@material/web/formfield/formfield.js';
Adrià Vilanova Martínez2144f4f2023-04-12 23:16:17 +02002import '@material/web/icon/icon.js';
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +01003import '@material/web/switch/switch.js';
4
Adrià Vilanova Martínez2144f4f2023-04-12 23:16:17 +02005import consoleCommonStyles from '!!raw-loader!../../../../static/css/common/console.css';
6import {css, html, LitElement, nothing, unsafeCSS} from 'lit';
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +01007import {createRef, ref} from 'lit/directives/ref.js';
8
9import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js';
10import {kEventFlattenThreadsUpdated} from '../constants.js';
11
12export default class TwptThreadToolbarInject extends LitElement {
13 static properties = {
14 options: {type: Object},
15 };
16
17 static styles = [
18 SHARED_MD3_STYLES,
Adrià Vilanova Martínez2144f4f2023-04-12 23:16:17 +020019 css`${unsafeCSS(consoleCommonStyles)}`,
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +010020 css`
21 :host {
22 display: flex;
Adrià Vilanova Martínez2144f4f2023-04-12 23:16:17 +020023 flex-flow: row wrap;
24 align-items: center;
25 row-gap: 0.5rem;
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +010026 padding-top: 1.5rem;
27 padding-left: 0.25rem;
28 padding-right: 0.25rem;
29 padding-bottom: 0.5rem;
30 }
Adrià Vilanova Martínez2144f4f2023-04-12 23:16:17 +020031
32 .badge-container {
33 padding-right: 0.5rem;
34 border-right: solid gray 1px;
35 margin-right: 0.5rem;
36 }
37
38 .TWPT-badge {
39 --icon-size: 17px;
40 }
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +010041 `,
42 ];
43
44 nestedViewRef = createRef();
45
46 constructor() {
47 super();
48 this.options = {};
49 }
50
Adrià Vilanova Martínez2144f4f2023-04-12 23:16:17 +020051 renderBadge() {
52 return html`
53 <div class="badge-container">
54 <div class="TWPT-badge">
55 <md-icon>repeat</md-icon>
56 </div>
57 </div>
58 `;
59 }
60
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +010061 renderFlattenRepliesSwitch() {
62 if (!this.options.flattenthreads) return nothing;
63
64 return html`
65 <md-formfield label="Nested view">
66 <md-switch ${ref(this.nestedViewRef)}
67 ?selected=${!this.options?.flattenthreads_switch_enabled}
68 @click=${this._flattenThreadsChanged}>
69 </md-formfield>
70 `;
71 }
72
73 render() {
74 return html`
Adrià Vilanova Martínez2144f4f2023-04-12 23:16:17 +020075 ${this.renderBadge()}
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +010076 ${this.renderFlattenRepliesSwitch()}
77 `;
78 }
79
80 _flattenThreadsChanged() {
81 const enabled = !this.nestedViewRef.value.selected;
82 const e = new CustomEvent(kEventFlattenThreadsUpdated, {
83 bubbles: true,
84 composed: true,
85 detail: {enabled},
86 });
87 this.dispatchEvent(e);
88 }
89}
90window.customElements.define(
91 'twpt-thread-toolbar-inject', TwptThreadToolbarInject);