ipprotection-site-settings-control.mjs (2355B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 import { MozLitElement } from "chrome://global/content/lit-utils.mjs"; 6 import { html, classMap } from "chrome://global/content/vendor/lit.all.mjs"; 7 8 /** 9 * Custom element that implements a button for site settings in the panel. 10 */ 11 export default class IPPSiteSettingsControl extends MozLitElement { 12 CLICK_EVENT = "ipprotection-site-settings-control:click"; 13 14 static properties = { 15 site: { type: String }, 16 exceptionEnabled: { type: Boolean }, 17 }; 18 19 constructor() { 20 super(); 21 22 this.site = null; 23 this.exceptionEnabled = false; 24 } 25 26 get iconsrc() { 27 if (!this.exceptionEnabled) { 28 return "chrome://global/skin/icons/close-fill.svg"; 29 } 30 return "chrome://global/skin/icons/check-filled.svg"; 31 } 32 33 get descriptionL10n() { 34 if (!this.exceptionEnabled) { 35 return "ipprotection-site-settings-button-vpn-off"; 36 } 37 return "ipprotection-site-settings-button-vpn-on"; 38 } 39 40 handleClickSettings(event) { 41 event.preventDefault(); 42 43 this.dispatchEvent( 44 new CustomEvent(this.CLICK_EVENT, { 45 bubbles: true, 46 composed: true, 47 }) 48 ); 49 } 50 51 render() { 52 if (!this.site) { 53 return null; 54 } 55 56 let icon = this.iconsrc; 57 let descriptionL10n = this.descriptionL10n; 58 let l10nArgs = JSON.stringify({ sitename: this.site }); 59 60 return html` 61 <link 62 rel="stylesheet" 63 href="chrome://browser/content/ipprotection/ipprotection-site-settings-control.css" 64 /> 65 <moz-box-group> 66 <moz-box-item 67 slot="header" 68 id="site-settings-label" 69 class="site-settings" 70 data-l10n-id="ipprotection-site-settings-control" 71 ></moz-box-item> 72 <moz-box-button 73 @click=${this.handleClickSettings} 74 class=${classMap({ 75 "site-settings": true, 76 "exception-enabled": this.exceptionEnabled, 77 })} 78 data-l10n-id=${descriptionL10n} 79 data-l10n-args=${l10nArgs} 80 iconsrc=${icon} 81 ></moz-box-button> 82 </moz-box-group> 83 `; 84 } 85 } 86 87 customElements.define( 88 "ipprotection-site-settings-control", 89 IPPSiteSettingsControl 90 );