Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Allow multiple same properties in single thing #1249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions static/js/components/base-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BaseComponent extends HTMLElement {
}

this.shadowRoot.appendChild(templateClone);
BaseComponent.count++;
}

connectedCallback() {
Expand All @@ -44,4 +45,5 @@ class BaseComponent extends HTMLElement {
}
}

BaseComponent.count = 0;
module.exports = BaseComponent;
23 changes: 11 additions & 12 deletions static/js/components/property/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

const BaseComponent = require('../base-component');

const template = document.createElement('template');
template.innerHTML = `
class BooleanProperty extends BaseComponent {
constructor() {
const template = document.createElement('template');
template.innerHTML = `
<style>
:host {
display: inline-block;
Expand Down Expand Up @@ -73,23 +75,20 @@ template.innerHTML = `
<div id="container" class="webthing-boolean-property-container">
<div id="contents" class="webthing-boolean-property-contents">
<form id="form" class="webthing-boolean-property-form">
<input type="checkbox" id="checkbox"
class="webthing-boolean-property-checkbox">
<label id="label" for="checkbox"
class="webthing-boolean-property-label">
<input type="checkbox" id="checkbox-${BaseComponent.count}"
class="webthing-boolean-property-checkbox"/>
<label class="webthing-boolean-property-label" for='checkbox-${BaseComponent.count}'>
</label>
</form>
</div>
</div>
<div id="name" class="webthing-boolean-property-name"></div>
`;

class BooleanProperty extends BaseComponent {
constructor() {
super(template);

this._input = this.shadowRoot.querySelector('#checkbox');
this._name = this.shadowRoot.querySelector('#name');
this._input =
this.shadowRoot.querySelector('.webthing-boolean-property-checkbox');
this._name =
this.shadowRoot.querySelector('.webthing-boolean-property-name');

this._onClick = this.__onClick.bind(this);
this._onKeyUp = this.__onKeyUp.bind(this);
Expand Down
25 changes: 13 additions & 12 deletions static/js/components/property/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

const BaseComponent = require('../base-component');

const template = document.createElement('template');
template.innerHTML = `
class SwitchProperty extends BaseComponent {
constructor() {
const template = document.createElement('template');
template.innerHTML = `
<style>
:host {
display: inline-block;
Expand Down Expand Up @@ -62,7 +64,7 @@ template.innerHTML = `
transition: 0.1s;
}

.webthing-switch-property-switch:checked + #slider::after {
.webthing-switch-property-switch:checked + .webthing-switch-property-slider::after {
transform: translate(3.65rem, 0.35rem);
}

Expand All @@ -83,25 +85,24 @@ template.innerHTML = `
<div id="container" class="webthing-switch-property-container">
<div id="contents" class="webthing-switch-property-contents">
<form>
<input type="checkbox" id="switch"
<input type="checkbox" id="switch-${BaseComponent.count}"
class="webthing-switch-property-switch">
<label id="slider" for="switch" class="webthing-switch-property-slider">
<label id="slider-${BaseComponent.count}" for="switch-${BaseComponent.count}" class="webthing-switch-property-slider">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the input might need to be nested within the label to allow the dropping of the for property which would otherwise be subject to an id conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the next patch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got your point but I fear we still need IDs : see comments at bottom of : https://stackoverflow.com/questions/41811551/custom-styling-for-checkbox-with-input-within-label

I have updated the patch to make it smaller and easier to review, once OK I will generalize this to other widgets.

</label>
</form>
<div id="label" class="webthing-switch-property-label"></div>
</div>
</div>
<div id="name" class="webthing-switch-property-name"></div>
`;

class SwitchProperty extends BaseComponent {
constructor() {
super(template);

this._input = this.shadowRoot.querySelector('#switch');
this._name = this.shadowRoot.querySelector('#name');
this._label = this.shadowRoot.querySelector('#label');

this._input =
this.shadowRoot.querySelector('.webthing-switch-property-switch');
this._name =
this.shadowRoot.querySelector('.webthing-switch-property-name');
this._label =
this.shadowRoot.querySelector('.webthing-switch-property-label');
this._onClick = this.__onClick.bind(this);
this._onKeyUp = this.__onKeyUp.bind(this);
}
Expand Down