Skip to content

Commit

Permalink
fix responsive color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
ljmerza committed Mar 14, 2023
1 parent e02da18 commit bc9072c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
12 changes: 6 additions & 6 deletions dist/light-entity-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/light-entity-card.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "light-entity-card",
"version": "6.0.0",
"version": "6.0.1",
"description": "A light-entity card for Home Assistant Lovelace UI",
"keywords": [
"home-assistant",
Expand Down
33 changes: 18 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,30 @@ class LightEntityCard extends ScopedRegistryHost(LitElement) {
color = { h, s, l: 100 }
}

const colorPicker = new iro.ColorPicker(picker, {
width: 320,


this.colorPicker = new iro.ColorPicker(picker, {
color,
sliderSize: 0
});

colorPicker.on("color:change", color => this.setColorPicker(color.hsl, entity));
this.setColorPickerSize();
this.colorPicker.on("color:change", color => this.setColorPicker(color.hsl, entity));
}
}

setColorPickerSize() {
if(!this.colorPicker) return;

const elem = this.shadowRoot.querySelector('.light-entity-card');
const width = elem.offsetWidth;
const calcWidth = width - 50;
const maxWidth = 300;

const realWidth = maxWidth > calcWidth ? calcWidth : maxWidth
this.colorPicker.resize(realWidth);
}

static get properties() {
return {
hass: Object,
Expand Down Expand Up @@ -185,18 +199,7 @@ class LightEntityCard extends ScopedRegistryHost(LitElement) {
*/
updated() {
this._isUpdating = false;

// eslint-disable-next-line arrow-parens
this._shownStateObjects.forEach(stateObj => {
const id = this.generateColorPickerId(stateObj);
const colorpickerElement = this.shadowRoot.querySelectorAll(`#${id}`);

if (colorpickerElement.length) {
const h = (stateObj.attributes.hs_color && stateObj.attributes.hs_color[0]) || 0;
const s = (stateObj.attributes.hs_color && stateObj.attributes.hs_color[1] / 100) || 0;
colorpickerElement[0].desiredHsColor = { h, s };
}
});
this.setColorPickerSize();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const style = css`
display: flex;
justify-content: space-around;
margin-top: 10px;
margin-bottom: 10px;
margin-bottom: 20px;
}
.group .light-entity-card__color-picker {
Expand Down

0 comments on commit bc9072c

Please sign in to comment.