From a0d1f39af040b16cbbd79b58ebfd7287642023e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 25 Jul 2019 16:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90switch=E7=BB=84=E4=BB=B6;?= =?UTF-8?q?=E4=BC=98=E5=8C=96input=E8=BE=93=E5=85=A5=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/input.wc | 41 ++++++----- src/form/next.js | 57 --------------- src/form/switch.wc | 174 +++++++++++++++++++++++++++++++++++++++++++++ src/icon/index.wc | 16 ++--- 4 files changed, 204 insertions(+), 84 deletions(-) delete mode 100644 src/form/next.js create mode 100644 src/form/switch.wc diff --git a/src/form/input.wc b/src/form/input.wc index c761969..123a30e 100644 --- a/src/form/input.wc +++ b/src/form/input.wc @@ -324,26 +324,29 @@ export default class Input { // 移动光标选择下拉选项 _moveSelect(ev) { - ev.preventDefault() - var step = ev.keyCode === 38 ? -1 : 1 - var items = Array.from(this.__LIST__.firstElementChild.children) - if (this.props.mvidx === null) { - this.props.mvidx = 0 - } else { - this.props.mvidx += step - } - if (this.props.mvidx < 0) { - this.props.mvidx = 0 - } else if (this.props.mvidx > items.length - 1) { - this.props.mvidx = items.length - 1 - } - items.forEach((it, i) => { - if (i === this.props.mvidx) { - it.setAttribute('focus', '') + var { list } = this.props + if (list && list.length) { + ev.preventDefault() + var step = ev.keyCode === 38 ? -1 : 1 + var items = Array.from(this.__LIST__.firstElementChild.children) + if (this.props.mvidx === null) { + this.props.mvidx = 0 } else { - it.removeAttribute('focus') + this.props.mvidx += step } - }) + if (this.props.mvidx < 0) { + this.props.mvidx = 0 + } else if (this.props.mvidx > items.length - 1) { + this.props.mvidx = items.length - 1 + } + items.forEach((it, i) => { + if (i === this.props.mvidx) { + it.setAttribute('focus', '') + } else { + it.removeAttribute('focus') + } + }) + } } // 触发列表选择 @@ -466,7 +469,7 @@ export default class Input { if (type === 'text') { this.__INPUT__.addEventListener('input', this._handleChange, false) this.__INPUT__.addEventListener('focus', this._parseSuggestion, false) - // this.__INPUT__.addEventListener('blur', this._handleBlur, false) + this.__INPUT__.addEventListener('blur', this._handleBlur, false) this.__LIST__.addEventListener('click', this._handleSelect, false) } } diff --git a/src/form/next.js b/src/form/next.js deleted file mode 100644 index b974baa..0000000 --- a/src/form/next.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 未来版表单组件 - * @author yutent - * @date 2019/07/04 12:03:09 - */ - -'use strict' - -export default class DoInput extends HTMLElement { - constructor() { - super() - - console.log('0000') - this.root = this.attachShadow({ mode: 'open' }) - this.root.innerHTML = ` - - - ` - } - - static get observedAttributes() { - return ['type'] - } - - get value() { - return this.__INPUT__.value - } - - set value(val) { - this.__INPUT__.value = val - } - - set type(val) { - // console.log('type', val) - this.__INPUT__.setAttribute('type', val) - this.setAttribute('type', val) - } - - connectedCallback() { - // console.log('----------', this, this.root.children) - this.__INPUT__ = this.root.children[1] - } - - attributeChangedCallback(...args) { - // console.log('======', args) - } -} - -customElements.define('do-input', DoInput) diff --git a/src/form/switch.wc b/src/form/switch.wc new file mode 100644 index 0000000..53fc162 --- /dev/null +++ b/src/form/switch.wc @@ -0,0 +1,174 @@ + + + + + diff --git a/src/icon/index.wc b/src/icon/index.wc index c33b431..25b0fcd 100644 --- a/src/icon/index.wc +++ b/src/icon/index.wc @@ -39,35 +39,35 @@ height: 20px; } :host([color='red']) { - color: nth($cr, 2); + color: nth($cr, 1); } :host([color='blue']) { - color: nth($cb, 2); + color: nth($cb, 1); } :host([color='green']) { - color: nth($cg, 2); + color: nth($cg, 1); } :host([color='teal']) { - color: nth($ct, 2); + color: nth($ct, 1); } :host([color='orange']) { - color: nth($co, 2); + color: nth($co, 1); } :host([color='dark']) { - color: nth($cd, 2); + color: nth($cd, 1); } :host([color='purple']) { - color: nth($cpp, 2); + color: nth($cpp, 1); } :host([color='grey']) { - color: nth($cgr, 2); + color: nth($cgr, 1); } @keyframes circle {