Conditionally show widgets on light more info

This commit is contained in:
Paulus Schoutsen 2015-01-14 23:10:56 -08:00
parent fd6ff4c8d3
commit 3e4c0261b1
5 changed files with 70 additions and 16 deletions

View file

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """ """ DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "b32ea78a1157b29555410384fe251dc9" VERSION = "1da0ea4a1fbd7b74cf749841b86bbb2d"

File diff suppressed because one or more lines are too long

View file

@ -29,9 +29,29 @@
Polymer({ Polymer({
stateObj: {}, stateObj: {},
// observe: {
// 'stateObj.attributes': 'reposition'
// },
/**
* Whenever the attributes change, the more info component can
* hide or show elements. We will reposition the dialog.
* DISABLED FOR NOW - BAD UX
*/
// reposition: function(oldVal, newVal) {
// Only resize if already open
// if(this.$.dialog.opened) {
// this.job('resizeAfterLayoutChange', function() {
// this.$.dialog.resizeHandler();
// }.bind(this));
// }
// },
show: function(stateObj) { show: function(stateObj) {
this.stateObj = stateObj; this.stateObj = stateObj;
this.$.dialog.toggle(); this.job('showDialogAfterRender', function() {
this.$.dialog.toggle();
}.bind(this));
}, },
editClicked: function(ev) { editClicked: function(ev) {

View file

@ -13,10 +13,16 @@
} }
</style> </style>
<div id='moreInfo'></div> <div id='moreInfo' class='{{classNames}}'></div>
</template> </template>
<script> <script>
Polymer({ Polymer({
classNames: '',
observe: {
'stateObj.attributes': 'stateAttributesChanged',
},
stateObjChanged: function() { stateObjChanged: function() {
while (this.$.moreInfo.lastChild) { while (this.$.moreInfo.lastChild) {
this.$.moreInfo.removeChild(this.$.moreInfo.lastChild); this.$.moreInfo.removeChild(this.$.moreInfo.lastChild);
@ -25,8 +31,14 @@ Polymer({
var moreInfo = document.createElement("more-info-" + this.stateObj.moreInfoType); var moreInfo = document.createElement("more-info-" + this.stateObj.moreInfoType);
moreInfo.api = this.api; moreInfo.api = this.api;
moreInfo.stateObj = this.stateObj; moreInfo.stateObj = this.stateObj;
this.$.moreInfo.appendChild(moreInfo); this.$.moreInfo.appendChild(moreInfo);
} },
stateAttributesChanged: function(oldVal, newVal) {
this.classNames = Object.keys(newVal).map(
function(key) { return "has-" + key; }).join(' ');
},
}); });
</script> </script>
</polymer-element> </polymer-element>

View file

@ -8,6 +8,10 @@
<style> <style>
.brightness { .brightness {
margin-bottom: 8px; margin-bottom: 8px;
max-height: 0px;
overflow: hidden;
transition: max-height .5s ease-in;
} }
.brightness paper-slider::shadow #sliderKnobInner, .brightness paper-slider::shadow #sliderKnobInner,
@ -19,16 +23,32 @@
display: block; display: block;
width: 350px; width: 350px;
margin: 0 auto; margin: 0 auto;
max-height: 0px;
overflow: hidden;
transition: max-height .5s ease-in;
} }
:host-context(.has-brightness) .brightness {
max-height: 500px;
}
:host-context(.has-xy_color) color-picker {
max-height: 500px;
}
</style> </style>
<div> <div>
<div center horizontal layout class='brightness'> <div class='brightness'>
<div>Brightness</div> <div center horizontal layout>
<paper-slider <div>Brightness</div>
max="255" flex id='brightness' <paper-slider
on-core-change="{{brightnessSliderChanged}}"> max="255" flex id='brightness'
</paper-slider> on-core-change="{{brightnessSliderChanged}}">
</paper-slider>
</div>
</div> </div>
<color-picker id="colorpicker" width="350" height="200"> <color-picker id="colorpicker" width="350" height="200">
</color-picker> </color-picker>
</div> </div>
@ -48,7 +68,7 @@ Polymer({
brightnessChanged: function(oldVal, newVal) { brightnessChanged: function(oldVal, newVal) {
this.ignoreNextBrightnessEvent = true; this.ignoreNextBrightnessEvent = true;
this.$.brightness.value = newVal; this.$.brightness.value = newVal;
}, },
domReady: function() { domReady: function() {