|
| 1 | +/** |
| 2 | + * OccupancySensorCapability |
| 3 | + * |
| 4 | + * A bubble showing an occupancy sensor icon. |
| 5 | + * |
| 6 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | + */ |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const BaseComponent = require('../base-component'); |
| 13 | +const fluent = require('../../fluent'); |
| 14 | + |
| 15 | +const template = document.createElement('template'); |
| 16 | +template.innerHTML = ` |
| 17 | + <style> |
| 18 | + :host { |
| 19 | + display: block; |
| 20 | + contain: content; |
| 21 | + text-align: center; |
| 22 | + color: white; |
| 23 | + font-size: 1.6rem; |
| 24 | + cursor: default; |
| 25 | + } |
| 26 | +
|
| 27 | + .webthing-occupancy-sensor-capability-icon { |
| 28 | + width: 12.4rem; |
| 29 | + height: 12.4rem; |
| 30 | + border-radius: 6.4rem; |
| 31 | + border: 0.2rem solid white; |
| 32 | + background-size: 6.4rem; |
| 33 | + background-repeat: no-repeat; |
| 34 | + transform: translate(0); |
| 35 | + background-color: #89b6d6; |
| 36 | + background-image: url('/images/component-icons/occupancy-sensor-not-occupied.svg'); |
| 37 | + background-position: center 2rem; |
| 38 | + } |
| 39 | +
|
| 40 | + .webthing-occupancy-sensor-capability-icon.occupied { |
| 41 | + background-color: white; |
| 42 | + background-image: url('/images/component-icons/occupancy-sensor-occupied.svg'); |
| 43 | + } |
| 44 | +
|
| 45 | + .webthing-occupancy-sensor-capability-label { |
| 46 | + font-weight: bold; |
| 47 | + text-transform: uppercase; |
| 48 | + padding-top: 8.75rem; |
| 49 | + font-size: 1.2rem; |
| 50 | + } |
| 51 | +
|
| 52 | + .webthing-occupancy-sensor-capability-icon.occupied |
| 53 | + .webthing-occupancy-sensor-capability-label { |
| 54 | + color: #5d9bc7; |
| 55 | + font-size: 1.4rem; |
| 56 | + } |
| 57 | + </style> |
| 58 | + <div id="icon" class="webthing-occupancy-sensor-capability-icon"> |
| 59 | + <div id="label" class="webthing-occupancy-sensor-capability-label">--</div> |
| 60 | + </div> |
| 61 | +`; |
| 62 | + |
| 63 | +class OccupancySensorCapability extends BaseComponent { |
| 64 | + constructor() { |
| 65 | + super(template); |
| 66 | + |
| 67 | + this._icon = this.shadowRoot.querySelector('#icon'); |
| 68 | + this._label = this.shadowRoot.querySelector('#label'); |
| 69 | + |
| 70 | + this._occupied = false; |
| 71 | + } |
| 72 | + |
| 73 | + connectedCallback() { |
| 74 | + this.occupied = typeof this.dataset.occupied !== 'undefined' ? this.dataset.occupied : null; |
| 75 | + } |
| 76 | + |
| 77 | + get occupied() { |
| 78 | + return this._occupied; |
| 79 | + } |
| 80 | + |
| 81 | + set occupied(value) { |
| 82 | + this._occupied = Boolean(value); |
| 83 | + |
| 84 | + if (value === null) { |
| 85 | + this._icon.classList.remove('occupied'); |
| 86 | + this._label.innerText = fluent.getMessage('ellipsis'); |
| 87 | + } else if (this._occupied) { |
| 88 | + this._icon.classList.add('occupied'); |
| 89 | + this._label.innerText = fluent.getMessage('occupied'); |
| 90 | + } else { |
| 91 | + this._icon.classList.remove('occupied'); |
| 92 | + this._label.innerText = fluent.getMessage('not-occupied'); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +window.customElements.define('webthing-occupancy-sensor-capability', OccupancySensorCapability); |
| 98 | +module.exports = OccupancySensorCapability; |
0 commit comments