blob: 65b2e31b7396323c7a2488117fd0a5aede10c0e7 [file] [log] [blame]
Adrià Vilanova Martínez2d9be8d2022-12-28 00:50:14 +01001import '@material/web/formfield/formfield.js';
2import '@material/web/switch/switch.js';
3
4import {css, html, LitElement, nothing} from 'lit';
5import {createRef, ref} from 'lit/directives/ref.js';
6
7import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js';
8import {kEventFlattenThreadsUpdated} from '../constants.js';
9
10export default class TwptThreadToolbarInject extends LitElement {
11 static properties = {
12 options: {type: Object},
13 };
14
15 static styles = [
16 SHARED_MD3_STYLES,
17 css`
18 :host {
19 display: flex;
20 flex-direction: row;
21 padding-top: 1.5rem;
22 padding-left: 0.25rem;
23 padding-right: 0.25rem;
24 padding-bottom: 0.5rem;
25 }
26 `,
27 ];
28
29 nestedViewRef = createRef();
30
31 constructor() {
32 super();
33 this.options = {};
34 }
35
36 renderFlattenRepliesSwitch() {
37 if (!this.options.flattenthreads) return nothing;
38
39 return html`
40 <md-formfield label="Nested view">
41 <md-switch ${ref(this.nestedViewRef)}
42 ?selected=${!this.options?.flattenthreads_switch_enabled}
43 @click=${this._flattenThreadsChanged}>
44 </md-formfield>
45 `;
46 }
47
48 render() {
49 return html`
50 ${this.renderFlattenRepliesSwitch()}
51 `;
52 }
53
54 _flattenThreadsChanged() {
55 const enabled = !this.nestedViewRef.value.selected;
56 const e = new CustomEvent(kEventFlattenThreadsUpdated, {
57 bubbles: true,
58 composed: true,
59 detail: {enabled},
60 });
61 this.dispatchEvent(e);
62 }
63}
64window.customElements.define(
65 'twpt-thread-toolbar-inject', TwptThreadToolbarInject);