Adrià Vilanova MartÃnez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 1 | import '@material/web/formfield/formfield.js'; |
| 2 | import '@material/web/switch/switch.js'; |
| 3 | |
| 4 | import {css, html, LitElement, nothing} from 'lit'; |
| 5 | import {createRef, ref} from 'lit/directives/ref.js'; |
| 6 | |
| 7 | import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js'; |
| 8 | import {kEventFlattenThreadsUpdated} from '../constants.js'; |
| 9 | |
| 10 | export 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 | } |
| 64 | window.customElements.define( |
| 65 | 'twpt-thread-toolbar-inject', TwptThreadToolbarInject); |