native-es6-webkit
Version:
A UI Library of Native ES6 Web Components
76 lines (65 loc) • 3.69 kB
JavaScript
;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var BlueInputText = function (_HTMLElement) {
_inherits(BlueInputText, _HTMLElement);
function BlueInputText() {
_classCallCheck(this, BlueInputText);
var _this = _possibleConstructorReturn(this, (BlueInputText.__proto__ || Object.getPrototypeOf(BlueInputText)).call(this));
_this._length = 6;
_this.attachShadow({ mode: 'open' });
return _this;
}
_createClass(BlueInputText, [{
key: 'attributeChangedCallback',
value: function attributeChangedCallback(attrName, oldValue, newValue) {
if (attrName === 'disabled') {
this.disabled = newValue;
} else if (attrName === 'maxlength') {
this.maxlength = newValue;
}
}
}, {
key: 'connectedCallback',
value: function connectedCallback() {
this.shadowRoot.innerHTML = this.renderHTML(this._length);
}
}, {
key: 'renderHTML',
value: function renderHTML(_maxlength) {
return '\n <style>\n :host .blue-inputtext{\n font-size: 14px;\n line-height: 1;\n border: 1px solid #d7d7d7;\n outline: 0;\n height: 20px;\n width: 250px;\n padding: 5px;\n }\n\n :host .blue-inputtext:focus{\n border-color: #243b4a;\n }\n\n </style>\n <input type="text" class="blue-inputtext" maxlength="' + _maxlength + '"/>\n ';
}
}, {
key: 'disabled',
get: function get() {
return this.hasAttribute('disabled');
},
set: function set(value) {
var val = Boolean(value);
if (val) {
this.shadowRoot.querySelector('input').setAttribute('disabled');
} else {
this.shadowRoot.querySelector('input').removeAttribute('disabled');
}
}
}, {
key: 'maxlength',
get: function get() {
return this.getAttribute('maxlength');
},
set: function set(length) {
var len = +length;
this._length = len;
this.shadowRoot.innerHTML = this.renderHTML(this._length);
}
}], [{
key: 'observedAttributes',
get: function get() {
return ['disabled', 'maxlength'];
}
}]);
return BlueInputText;
}(HTMLElement);
customElements.define("b-inputtext", BlueInputText);