Revert Texfield

This commit is contained in:
gerard 2018-06-21 09:12:35 +02:00
parent 7f8ceb6d37
commit 7ceda630d4
4 changed files with 81 additions and 170 deletions

View File

@ -1,111 +1,46 @@
@import "colors";
vn-textfield { vn-textfield {
margin: 20px 0!important; .mdl-chip__action {
display: block; position: absolute;
width: auto;
.leftIcons, .rightIcons, .suffix{ top: 0px;
display: inline-flex; right: -6px;
color: $secondary-font-color; margin: 21px 0px;
& .material-icons{ background: white;
font-size: 20px!important opacity: 1;
z-index: 1;
color: #aaa;
} }
} .mdl-textfield {
.leftIcons{
margin-right: 3px;
}
.container{
width: 100%; width: 100%;
position: relative;
padding-bottom: 2px;
} }
.textField{ .mdl-textfield__error {
width: 100%;
display: inline-flex;
position: relative;
padding: 4px 0;
}
.infix {
position: relative;
display: block;
flex: auto;
width: 100%;
min-width: 0;
}
i.pointer {
visibility: hidden
}
i.visible {
visibility: visible; visibility: visible;
} white-space: nowrap;
label { overflow: hidden;
position: absolute; text-overflow: ellipsis;
bottom: 2px;
pointer-events: none;
color: $secondary-font-color;
transition-duration: .2s;
transition-timing-function: cubic-bezier(.4,0,.2,1);
}
input {
outline: none;
border: none;
font-family: "Helvetica","Arial",sans-serif;
display: block;
font-size: 16px;
width: 100%; width: 100%;
background: 0 0; }
color: inherit; .mdl-textfield.invalid {
.mdl-textfield__input {
&[type=number]{ border-color: #d50000;
-moz-appearance: textfield; box-shadow: none;
&::-webkit-outer-spin-button, }
&::-webkit-inner-spin-button{ .mdl-textfield__label::after {
-webkit-appearance: none; background-color: #d50000;
margin: 0;
} }
} }
} .mdl-textfield--floating-label.invalid .mdl-textfield__label {
color: #d50000;
.underline{
position: absolute;
bottom: 0;
height: 1px;
content: ' ';
pointer-events: none;
width: 100%;
background-color: rgba(0,0,0,.12);
}
.selected.underline{
background-color: rgb(255,152,0);
height: 2px;
left: 50%;
width: 0px!important;
transition-duration: 0.2s;
transition-timing-function: cubic-bezier(.4,0,.2,1);
}
&.not-empty{
& label {
bottom: 24px;
color: $main-01;
font-size: 12px; font-size: 12px;
top: 4px;
} }
.material-icons {
font-size: 18px;
float: right;
margin-right: 5px;
} }
.material-icons:hover {
div.selected{ color: rgba(0,0,0, .87);
&.container{
border-bottom: 0px;
}
& label {
bottom: 24px;
color: $main-01;
font-size: 12px;
}
& .selected.underline{
left: 0;
width: 100%!important;
}
} }
& > div.container > div.textField > div.infix.invalid{ & > div.container > div.textField > div.infix.invalid{

View File

@ -1,15 +1,9 @@
<div class="container" <div
ng-class="{selected: $ctrl.hasFocus}" class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"
ng-mouseenter="$ctrl.hasMouseIn = true" ng-mouseenter="$ctrl.hasMouseIn = true"
ng-mouseleave="$ctrl.hasMouseIn = false" ng-mouseleave="$ctrl.hasMouseIn = false">
style="display: inline-flex"
>
<div class="textField">
<div class="leftIcons">
</div>
<div class=" infix">
<input <input
class="mdl-textfield__input"
type="{{$ctrl.type}}" type="{{$ctrl.type}}"
name="{{$ctrl.name}}" name="{{$ctrl.name}}"
ng-model="$ctrl.value" ng-model="$ctrl.value"
@ -19,23 +13,17 @@
ng-focus="$ctrl.hasFocus = true" ng-focus="$ctrl.hasFocus = true"
ng-blur="$ctrl.hasFocus = false" ng-blur="$ctrl.hasFocus = false"
tabindex="{{$ctrl.input.tabindex}}"/> tabindex="{{$ctrl.input.tabindex}}"/>
<div class="mdl-chip__action">
<label class="label" translate>{{::$ctrl.label}}</label>
</div>
<div class="underline"></div>
<div class="selected underline"></div>
<div class="suffix">
<i class="material-icons pointer"
ng-class="{visible: !$ctrl.disabled && $ctrl.hasValue && ($ctrl.hasFocus || $ctrl.hasMouseIn)}"
ng-click="$ctrl.clear()">
clear
</i>
<i class="material-icons" <i class="material-icons"
ng-if="$ctrl.hasInfo" ng-if="$ctrl.hasInfo"
vn-tooltip="{{$ctrl.info}}"> vn-tooltip="{{$ctrl.info}}">
info_outline info_outline
</i> </i>
<i class="material-icons pointer"
ng-show="!$ctrl.disabled && $ctrl.hasValue && ($ctrl.hasFocus || $ctrl.hasMouseIn)"
ng-click="$ctrl.clear()">
clear
</i>
</div> </div>
<div class="rightIcons"></div> <label class="mdl-textfield__label" translate>{{::$ctrl.label}}</label>
</div>
</div> </div>

View File

@ -3,7 +3,7 @@ import Input from '../../lib/input';
import './style.scss'; import './style.scss';
export default class Textfield extends Input { export default class Textfield extends Input {
constructor($element, $scope, $attrs, vnTemplate, $transclude) { constructor($element, $scope, $attrs, vnTemplate) {
super($element, $scope); super($element, $scope);
vnTemplate.normalizeInputAttrs($attrs); vnTemplate.normalizeInputAttrs($attrs);
this._value = null; this._value = null;
@ -13,53 +13,41 @@ export default class Textfield extends Input {
this.info = $attrs.info || null; this.info = $attrs.info || null;
this.hasFocus = false; this.hasFocus = false;
this.hasMouseIn = false; this.hasMouseIn = false;
componentHandler.upgradeElement($element[0].firstChild);
if ($transclude) {
$transclude($scope.$parent, tClone => {
this.leftIcons = tClone[0];
}, null, 'leftIcons');
$transclude($scope.$parent, tClone => {
this.rightIcons = tClone[0];
}, null, 'rightIcons');
}
}
set leftIcons(value) {
for (let i = 0; i < value.children.length; i++) {
this.element.querySelector('.leftIcons').appendChild(value);
}
}
set rightIcons(value) {
for (let i = 0; i < value.children.length; i++) {
this.element.querySelector('.rightIcons').appendChild(value.children[i]);
}
}
set value(value) {
this._value = (value === undefined || value === '') ? null : value;
this.input.value = this._value;
this.hasValue = this._value !== null;
if (this.hasValue) this.element.classList.add('not-empty');
else this.element.classList.remove('not-empty');
this.mdlUpdate();
} }
get value() { get value() {
return this._value; return this._value;
} }
set value(value) {
this._value = (value === undefined || value === '') ? null : value;
this.input.value = this._value;
<<<<<<< HEAD
this.hasValue = this._value !== null;
if (this.hasValue) this.element.classList.add('not-empty');
else this.element.classList.remove('not-empty');
=======
this.hasValue = Boolean(this._value);
>>>>>>> parent of 97c994b... Bug #137 Refactorización Textfield
this.mdlUpdate();
}
set vnTabIndex(value) { set vnTabIndex(value) {
this.input.tabindex = value; this.input.tabindex = value;
} }
clear() { clear() {
this.value = null; this.value = null;
this.input.focus(); this.input.focus();
} }
mdlUpdate() {
let mdlElement = this.element.firstChild.MaterialTextfield;
if (mdlElement) mdlElement.updateClasses_();
}
} }
Textfield.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude']; Textfield.$inject = ['$element', '$scope', '$attrs', 'vnTemplate'];
ngModule.component('vnTextfield', { ngModule.component('vnTextfield', {
template: require('./textfield.html'), template: require('./textfield.html'),
transclude: {
leftIcons: '?tLeftIcons',
rightIcons: '?tRightIcons'
},
controller: Textfield, controller: Textfield,
bindings: { bindings: {
value: '=model', value: '=model',

View File

@ -18,7 +18,7 @@ describe('Component vnTextfield', () => {
$attrs = {}; $attrs = {};
$timeout = _$timeout_; $timeout = _$timeout_;
$element = angular.element('<div><input></div>'); $element = angular.element('<div><input></div>');
controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout, $transclude: null}); controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
})); }));
describe('value() setter', () => { describe('value() setter', () => {