From b1339d6568b03c1a04f8bca95bbe0966e1c11cc8 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Tue, 29 Aug 2023 10:40:32 +0000 Subject: [PATCH 1/7] experiment --- package.json | 2 - src/components/ha-slider.js | 117 ------------------------------------ src/components/ha-slider.ts | 21 +++++++ yarn.lock | 74 +---------------------- 4 files changed, 22 insertions(+), 192 deletions(-) delete mode 100644 src/components/ha-slider.js create mode 100644 src/components/ha-slider.ts diff --git a/package.json b/package.json index 7251637e8dde..fbba8d2e41c4 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,6 @@ "@material/mwc-radio": "0.27.0", "@material/mwc-ripple": "0.27.0", "@material/mwc-select": "0.27.0", - "@material/mwc-slider": "0.27.0", "@material/mwc-switch": "0.27.0", "@material/mwc-tab": "0.27.0", "@material/mwc-tab-bar": "0.27.0", @@ -89,7 +88,6 @@ "@polymer/paper-input": "3.2.1", "@polymer/paper-item": "3.0.1", "@polymer/paper-listbox": "3.0.1", - "@polymer/paper-slider": "3.0.1", "@polymer/paper-tabs": "3.1.0", "@polymer/paper-toast": "3.0.1", "@polymer/polymer": "3.5.1", diff --git a/src/components/ha-slider.js b/src/components/ha-slider.js deleted file mode 100644 index 11cda48db133..000000000000 --- a/src/components/ha-slider.js +++ /dev/null @@ -1,117 +0,0 @@ -import "@polymer/paper-slider"; - -const PaperSliderClass = customElements.get("paper-slider"); -let subTemplate; - -export class HaSlider extends PaperSliderClass { - static get template() { - if (!subTemplate) { - subTemplate = PaperSliderClass.template.cloneNode(true); - - const superStyle = subTemplate.content.querySelector("style"); - - // append style to add mirroring of pin in RTL - superStyle.appendChild( - document.createTextNode(` - :host([dir="rtl"]) #sliderContainer.pin.expand > .slider-knob > .slider-knob-inner::after { - -webkit-transform: scale(1) translate(0, -17px) scaleX(-1) !important; - transform: scale(1) translate(0, -17px) scaleX(-1) !important; - } - - .pin > .slider-knob > .slider-knob-inner { - font-size: var(--ha-slider-pin-font-size, 15px); - line-height: normal; - cursor: pointer; - } - - .disabled.ring > .slider-knob > .slider-knob-inner { - background-color: var(--paper-slider-disabled-knob-color, var(--disabled-text-color)); - border: 2px solid var(--paper-slider-disabled-knob-color, var(--disabled-text-color)); - } - - .pin > .slider-knob > .slider-knob-inner::before { - top: unset; - margin-left: unset; - - bottom: calc(15px + var(--calculated-paper-slider-height)/2); - left: 50%; - width: 2.6em; - height: 2.6em; - - -webkit-transform-origin: left bottom; - transform-origin: left bottom; - -webkit-transform: rotate(-45deg) scale(0) translate(0); - transform: rotate(-45deg) scale(0) translate(0); - } - - .pin.expand > .slider-knob > .slider-knob-inner::before { - -webkit-transform: rotate(-45deg) scale(1) translate(7px, -7px); - transform: rotate(-45deg) scale(1) translate(7px, -7px); - } - - .pin > .slider-knob > .slider-knob-inner::after { - top: unset; - font-size: unset; - - bottom: calc(15px + var(--calculated-paper-slider-height)/2); - left: 50%; - margin-left: -1.3em; - width: 2.6em; - height: 2.5em; - - -webkit-transform-origin: center bottom; - transform-origin: center bottom; - -webkit-transform: scale(0) translate(0); - transform: scale(0) translate(0); - } - - .pin.expand > .slider-knob > .slider-knob-inner::after { - -webkit-transform: scale(1) translate(0, -10px); - transform: scale(1) translate(0, -10px); - } - - .slider-input { - width: 54px; - } - `) - ); - } - return subTemplate; - } - - _setImmediateValue(newImmediateValue) { - super._setImmediateValue( - this.step >= 1 - ? Math.round(newImmediateValue) - : Math.round(newImmediateValue * 100) / 100 - ); - } - - _calcStep(value) { - if (!this.step) { - return parseFloat(value); - } - - const numSteps = Math.round((value - this.min) / this.step); - const stepStr = this.step.toString(); - const stepPointAt = stepStr.indexOf("."); - if (stepPointAt !== -1) { - /** - * For small values of this.step, if we calculate the step using - * For non-integer values of this.step, if we calculate the step using - * `Math.round(value / step) * step` we may hit a precision point issue - * eg. 0.1 * 0.2 = 0.020000000000000004 - * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html - * - * as a work around we can round with the decimal precision of `step` - */ - const precision = 10 ** (stepStr.length - stepPointAt - 1); - return ( - Math.round((numSteps * this.step + this.min) * precision) / precision - ); - } - - return numSteps * this.step + this.min; - } -} -customElements.define("ha-slider", HaSlider); diff --git a/src/components/ha-slider.ts b/src/components/ha-slider.ts new file mode 100644 index 000000000000..2680c74ed7cc --- /dev/null +++ b/src/components/ha-slider.ts @@ -0,0 +1,21 @@ +import { customElement } from "lit/decorators"; +import { MdSlider } from "@material/web/slider/slider"; +import { css } from "lit"; + +@customElement("ha-slider") +export class HaSlider extends MdSlider { + static override styles = [ + css` + :host { + --md-sys-color-primary: var(--primary-color); + --md-sys-color-outline: var(--divider-color); + } + `, + ]; +} + +declare global { + interface HTMLElementTagNameMap { + "ha-slider": HaSlider; + } +} diff --git a/yarn.lock b/yarn.lock index 1a94c69db12c..4d77dfc14379 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2725,20 +2725,6 @@ __metadata: languageName: node linkType: hard -"@material/mwc-slider@npm:0.27.0": - version: 0.27.0 - resolution: "@material/mwc-slider@npm:0.27.0" - dependencies: - "@material/dom": =14.0.0-canary.53b3cad2f.0 - "@material/mwc-base": ^0.27.0 - "@material/mwc-ripple": ^0.27.0 - "@material/slider": =14.0.0-canary.53b3cad2f.0 - lit: ^2.0.0 - tslib: ^2.0.1 - checksum: 0e7f9d0d418731fb9ba1ffe99cc88e79a4116e92d048476dc24fa87688f13335945fcdc9fef6d6f699e0c6b16fea5ed7527f71193bcf1365177e7ba7a865b140 - languageName: node - linkType: hard - "@material/mwc-switch@npm:0.27.0": version: 0.27.0 resolution: "@material/mwc-switch@npm:0.27.0" @@ -2965,24 +2951,6 @@ __metadata: languageName: node linkType: hard -"@material/slider@npm:=14.0.0-canary.53b3cad2f.0": - version: 14.0.0-canary.53b3cad2f.0 - resolution: "@material/slider@npm:14.0.0-canary.53b3cad2f.0" - dependencies: - "@material/animation": 14.0.0-canary.53b3cad2f.0 - "@material/base": 14.0.0-canary.53b3cad2f.0 - "@material/dom": 14.0.0-canary.53b3cad2f.0 - "@material/elevation": 14.0.0-canary.53b3cad2f.0 - "@material/feature-targeting": 14.0.0-canary.53b3cad2f.0 - "@material/ripple": 14.0.0-canary.53b3cad2f.0 - "@material/rtl": 14.0.0-canary.53b3cad2f.0 - "@material/theme": 14.0.0-canary.53b3cad2f.0 - "@material/typography": 14.0.0-canary.53b3cad2f.0 - tslib: ^2.1.0 - checksum: 136d6c6f77e4fa586ac375b5a108be06a394f0c55fbb10e73eaa990cd6cb38d2787e278911705571b5336402690e0b88b5fe9de9916704db948247a6b6b0c1fb - languageName: node - linkType: hard - "@material/switch@npm:=14.0.0-canary.53b3cad2f.0": version: 14.0.0-canary.53b3cad2f.0 resolution: "@material/switch@npm:14.0.0-canary.53b3cad2f.0" @@ -3583,15 +3551,6 @@ __metadata: languageName: node linkType: hard -"@polymer/iron-range-behavior@npm:^3.0.0-pre.26": - version: 3.0.1 - resolution: "@polymer/iron-range-behavior@npm:3.0.1" - dependencies: - "@polymer/polymer": ^3.0.0 - checksum: da2405650bccc2071bebfd30f379e92d930bd95d306e2626da9d92a07b849f0e5cdc08430bfb03a6ae8f5644ab9364ff64252892da1b1ddc01d2f5f1f026e808 - languageName: node - linkType: hard - "@polymer/iron-resizable-behavior@npm:3.0.1, @polymer/iron-resizable-behavior@npm:^3.0.0-pre.26": version: 3.0.1 resolution: "@polymer/iron-resizable-behavior@npm:3.0.1" @@ -3653,7 +3612,7 @@ __metadata: languageName: node linkType: hard -"@polymer/paper-input@npm:3.2.1, @polymer/paper-input@npm:^3.0.0-pre.26": +"@polymer/paper-input@npm:3.2.1": version: 3.2.1 resolution: "@polymer/paper-input@npm:3.2.1" dependencies: @@ -3692,18 +3651,6 @@ __metadata: languageName: node linkType: hard -"@polymer/paper-progress@npm:^3.0.0-pre.26": - version: 3.0.1 - resolution: "@polymer/paper-progress@npm:3.0.1" - dependencies: - "@polymer/iron-flex-layout": ^3.0.0-pre.26 - "@polymer/iron-range-behavior": ^3.0.0-pre.26 - "@polymer/paper-styles": ^3.0.0-pre.26 - "@polymer/polymer": ^3.0.0 - checksum: 5ae0ce84d05ed777c40c27c82559cedc44f1b4ed523a675932cce4a4d6a82f772ee414b21c67db528ea316686c1ed84b53e1850bbb3a6f5c3964339e2c20289b - languageName: node - linkType: hard - "@polymer/paper-ripple@npm:^3.0.0-pre.26": version: 3.0.2 resolution: "@polymer/paper-ripple@npm:3.0.2" @@ -3714,23 +3661,6 @@ __metadata: languageName: node linkType: hard -"@polymer/paper-slider@npm:3.0.1": - version: 3.0.1 - resolution: "@polymer/paper-slider@npm:3.0.1" - dependencies: - "@polymer/iron-a11y-keys-behavior": ^3.0.0-pre.26 - "@polymer/iron-behaviors": ^3.0.0-pre.26 - "@polymer/iron-flex-layout": ^3.0.0-pre.26 - "@polymer/iron-form-element-behavior": ^3.0.0-pre.26 - "@polymer/paper-behaviors": ^3.0.0-pre.27 - "@polymer/paper-input": ^3.0.0-pre.26 - "@polymer/paper-progress": ^3.0.0-pre.26 - "@polymer/paper-styles": ^3.0.0-pre.26 - "@polymer/polymer": ^3.0.0 - checksum: ab915606df8150f77ad9e03c845ce5f600882cd7c0b3bb6a6ea77816ee1b40d01d5b3f72f0d8df6ce5e46fa9f0335d3930c8cc46a23cf8d8dfdbc0aeb9c181a4 - languageName: node - linkType: hard - "@polymer/paper-styles@npm:^3.0.0-pre.26": version: 3.0.1 resolution: "@polymer/paper-styles@npm:3.0.1" @@ -9654,7 +9584,6 @@ __metadata: "@material/mwc-radio": 0.27.0 "@material/mwc-ripple": 0.27.0 "@material/mwc-select": 0.27.0 - "@material/mwc-slider": 0.27.0 "@material/mwc-switch": 0.27.0 "@material/mwc-tab": 0.27.0 "@material/mwc-tab-bar": 0.27.0 @@ -9677,7 +9606,6 @@ __metadata: "@polymer/paper-input": 3.2.1 "@polymer/paper-item": 3.0.1 "@polymer/paper-listbox": 3.0.1 - "@polymer/paper-slider": 3.0.1 "@polymer/paper-tabs": 3.1.0 "@polymer/paper-toast": 3.0.1 "@polymer/polymer": 3.5.1 From ca590c58f911b16698529e3078d84a697cd43a53 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Sun, 8 Oct 2023 15:20:12 +0000 Subject: [PATCH 2/7] finish --- .../components/ha-control-circular-slider.ts | 2 +- .../pages/components/ha-hs-color-picker.ts | 6 +- src/components/ha-form/ha-form-integer.ts | 3 +- src/components/ha-labeled-slider.js | 90 ----------------- src/components/ha-labeled-slider.ts | 96 +++++++++++++++++++ .../ha-selector/ha-selector-color-temp.ts | 4 +- .../ha-selector/ha-selector-number.ts | 3 +- src/components/ha-slider.ts | 7 +- .../lights/light-color-rgb-picker.ts | 20 ++-- .../controls/more-info-media_player.ts | 3 +- .../hui-input-number-entity-row.ts | 5 +- .../hui-media-player-entity-row.ts | 3 +- .../entity-rows/hui-number-entity-row.ts | 3 +- .../media-browser/ha-bar-media-player.ts | 1 + src/state-summary/state-card-input_number.ts | 5 +- src/state-summary/state-card-number.js | 3 +- 16 files changed, 130 insertions(+), 124 deletions(-) delete mode 100644 src/components/ha-labeled-slider.js create mode 100644 src/components/ha-labeled-slider.ts diff --git a/gallery/src/pages/components/ha-control-circular-slider.ts b/gallery/src/pages/components/ha-control-circular-slider.ts index f85f210dd028..4a856fe31b15 100644 --- a/gallery/src/pages/components/ha-control-circular-slider.ts +++ b/gallery/src/pages/components/ha-control-circular-slider.ts @@ -49,11 +49,11 @@ export class DemoHaCircularSlider extends LitElement {
Current
${this.current} °C
Hue : ${this.value[0]}
Saturation : ${this.value[1]}
Color Brighness : ${this.brightness}