[New] New functions: hover, selectable, auto-expand
This commit is contained in:
parent
c6639f5d63
commit
9fb030ae7e
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "strolch-wc-tree",
|
"name": "strolch-wc-tree",
|
||||||
"description": "Strolch Tree View WebComponent",
|
"description": "Strolch Tree View WebComponent",
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"authors": ["Robert von Burg"],
|
"authors": ["Robert von Burg"],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"strolch",
|
"strolch",
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.tree-item {
|
.tree-item {
|
||||||
padding-top: 5px;
|
|
||||||
width: calc(100% - 24px);
|
width: calc(100% - 24px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +26,9 @@
|
||||||
.item {
|
.item {
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.expandIcon {
|
.expandIcon {
|
||||||
|
@ -37,6 +39,7 @@
|
||||||
height: 24px;
|
height: 24px;
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
margin-bottom: -4px;
|
margin-bottom: -4px;
|
||||||
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-img {
|
.icon-img {
|
||||||
|
@ -45,36 +48,48 @@
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.selected {
|
.selected {
|
||||||
background-color: #c8c8c8;
|
background-color: #c8c8c8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item:hover {
|
||||||
|
background-color: #c8c8c8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabled {
|
||||||
|
color: darkgrey;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabled:hover {
|
||||||
|
background-color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Requests -->
|
<!-- Requests -->
|
||||||
|
|
||||||
<!-- Content -->
|
<!-- Content -->
|
||||||
<div class="tree-item">
|
<div class="tree-item">
|
||||||
<p class$="[[itemClass]]">
|
<p class$="[[itemClass]]" on-tap="onTitleTapped">
|
||||||
<iron-icon class="expandIcon"
|
<iron-icon class="expandIcon"
|
||||||
icon="{{_getExpandedIcon(funcObj, item, expanded)}}"
|
icon="{{_getExpandedIcon(funcObj, item, expanded)}}"
|
||||||
on-tap="onToggleExpand"></iron-icon>
|
on-tap="onToggleExpand"></iron-icon>
|
||||||
<span class="icon" title="{{item.state}}">
|
<span class="icon" title="{{item.state}}">
|
||||||
<template is="dom-if" if="[[_useIcon(funcObj, item)]]">
|
<template is="dom-if" if="[[_useIcon(funcObj, item)]]">
|
||||||
<img height="16" width="16" class="icon-img" src$="[[_getIcon(funcObj, item)]]" />
|
<img height="16" width="16" class="icon-img" src$="[[_getIcon(funcObj, item)]]"/>
|
||||||
</template>
|
</template>
|
||||||
<template is="dom-if" if="[[_useIronIcon(funcObj, item)]]">
|
<template is="dom-if" if="[[_useIronIcon(funcObj, item)]]">
|
||||||
<iron-icon size="16" icon="{{_getIronIcon(funcObj, item)}}"></iron-icon>
|
<iron-icon size="16" icon="{{_getIronIcon(funcObj, item)}}"></iron-icon>
|
||||||
</template>
|
</template>
|
||||||
</span>
|
</span>
|
||||||
<template is="dom-if" if="[[!titleHtml]]">
|
<template is="dom-if" if="[[!titleHtml]]">
|
||||||
<span class="title" on-tap="onTitleTapped">[[_getTitle(funcObj, item)]]</span>
|
<span class="title">[[_getTitle(funcObj, item)]]</span>
|
||||||
</template>
|
</template>
|
||||||
<template is="dom-if" if="[[titleHtml]]">
|
<template is="dom-if" if="[[titleHtml]]">
|
||||||
<span class="title" on-tap="onTitleTapped" inner-h-t-m-l="[[_getTitle(funcObj, item)]]"></span>
|
<span class="title" inner-h-t-m-l="[[_getTitle(funcObj, item)]]"></span>
|
||||||
</template>
|
</template>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -103,7 +118,7 @@
|
||||||
|
|
||||||
itemClass: {
|
itemClass: {
|
||||||
type: String,
|
type: String,
|
||||||
value: 'item'
|
computed: "computeItemClass(item, selected)"
|
||||||
},
|
},
|
||||||
|
|
||||||
titleHtml: {
|
titleHtml: {
|
||||||
|
@ -117,6 +132,10 @@
|
||||||
value: null,
|
value: null,
|
||||||
observer: 'itemChanged'
|
observer: 'itemChanged'
|
||||||
},
|
},
|
||||||
|
selected: {
|
||||||
|
type: Boolean,
|
||||||
|
value: false
|
||||||
|
},
|
||||||
expanded: {
|
expanded: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false
|
value: false
|
||||||
|
@ -124,25 +143,43 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Computations */
|
/* Computations */
|
||||||
|
computeItemClass: function (item, selected) {
|
||||||
|
var itemClass = selected ? "item selected" : "item";
|
||||||
|
if (item.selectable != null && item.selectable === false)
|
||||||
|
itemClass = itemClass + " disabled";
|
||||||
|
return itemClass;
|
||||||
|
},
|
||||||
|
|
||||||
/* Observers */
|
/* Observers */
|
||||||
observers: [
|
observers: [
|
||||||
'observeSelectedItem(selectedItem)'
|
'observeSelectedItem(selectedItem)'
|
||||||
],
|
],
|
||||||
itemChanged: function (newValue, oldValue) {
|
itemChanged: function (newValue, oldValue) {
|
||||||
if (newValue == null || oldValue == null || newValue.locator !== oldValue.locator)
|
if (newValue == null) {
|
||||||
this.itemClass = 'item';
|
this.selected = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isDifferentItem = oldValue == null || newValue.locator !== oldValue.locator;
|
||||||
|
if (isDifferentItem)
|
||||||
|
this.selected = false;
|
||||||
|
|
||||||
|
if (newValue.expand)
|
||||||
|
this.expanded = true;
|
||||||
},
|
},
|
||||||
observeSelectedItem: function (selectedItem) {
|
observeSelectedItem: function (selectedItem) {
|
||||||
if (selectedItem !== this.item) {
|
if (selectedItem !== this.item)
|
||||||
this.itemClass = 'item';
|
this.selected = false;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onToggleExpand: function (e) {
|
onToggleExpand: function (e) {
|
||||||
this.expanded = !this.expanded;
|
this.expanded = !this.expanded;
|
||||||
},
|
},
|
||||||
onTitleTapped: function (e) {
|
onTitleTapped: function (e) {
|
||||||
this.itemClass = 'item selected';
|
if (this.item.selectable != null && this.item.selectable === false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.selected = true;
|
||||||
|
this.itemClass = "item selected";
|
||||||
this.fire('strolch-wc-tree-item-selected', {
|
this.fire('strolch-wc-tree-item-selected', {
|
||||||
rootItem: this.rootItem,
|
rootItem: this.rootItem,
|
||||||
item: this.item
|
item: this.item
|
||||||
|
|
Loading…
Reference in New Issue