#1024 td-editable component created

This commit is contained in:
Gerard 2019-02-08 15:08:36 +01:00
parent 0aefe73379
commit 77600d4d11
3 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,4 @@
<vn-horizontal class="text-container">
<span class="text" ng-transclude="text" vn-one></span>
</vn-horizontal>
<div class="field"></div>

View File

@ -0,0 +1,44 @@
import ngModule from '../../module';
import Component from '../../lib/component';
import './style.scss';
export default class Controller extends Component {
constructor($element, $scope, $transclude) {
super($element, $scope);
let element = $element[0];
element.tabIndex = 0;
element.addEventListener('focus', () => {
$transclude((tClone, tScope) => {
this.field = tClone;
this.tScope = tScope;
this.element.querySelector('.field').appendChild(this.field[0]);
}, null, 'field');
element.classList.add('selected');
});
element.addEventListener('focusout', event => {
this.lastEvent = event;
let target = event.relatedTarget;
while (target && target.parentNode != element)
target = target.parentNode;
if (!target) {
this.tScope.$destroy();
this.field.remove();
element.classList.remove('selected');
}
});
}
}
Controller.$inject = ['$element', '$scope', '$transclude'];
ngModule.component('vnTdEditable', {
template: require('./index.html'),
controller: Controller,
transclude: {
text: 'text',
field: '?field'
}
});

View File

@ -0,0 +1,16 @@
vn-td-editable {
cursor: pointer;
& > div.text-container{
width: 100%;
}
&.selected {
& > .text-container{
display: none;
}
}
vn-icon {
font-size: 1em;
}
}