You've already forked pure-component
新增 添加了使用示例;
完善了部分组件功能;
This commit is contained in:
28
index.js
28
index.js
@@ -117,7 +117,7 @@ class API {
|
||||
class UI {
|
||||
constructor(registry = null) {
|
||||
const that = this
|
||||
// TODO:搜索框
|
||||
// 搜索框
|
||||
this.Search = class Input extends HTMLElement {
|
||||
// 可用属性
|
||||
static observedAttributes = ['value', 'placeholder', 'disabled', 'max', 'wrap']
|
||||
@@ -148,6 +148,14 @@ class UI {
|
||||
// 属性变化
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
this[name] = newValue
|
||||
if (name == 'disabled') {
|
||||
this.input.querySelector('.search-input').setAttribute('disabled', eval(this.disabled))
|
||||
this.input.querySelector('.search-input').setAttribute('contenteditable', !eval(this.disabled))
|
||||
}
|
||||
|
||||
if (name == 'value') {
|
||||
this.input.querySelector('.search-input').value = newValue
|
||||
}
|
||||
}
|
||||
// 初始化
|
||||
init() {
|
||||
@@ -267,7 +275,7 @@ class UI {
|
||||
}
|
||||
// 清空输入框
|
||||
clear() {
|
||||
this.input.innerText = this.value = ''
|
||||
this.input.querySelector('.search-input').innerText = this.value = ''
|
||||
}
|
||||
// 绑定事件
|
||||
bindEvent() {
|
||||
@@ -317,7 +325,7 @@ class UI {
|
||||
input.querySelector('.search-input').addEventListener('focus', () => this.dispatchEvent(new CustomEvent('focus')))
|
||||
}
|
||||
}
|
||||
// TODO:下拉框
|
||||
// 下拉框
|
||||
this.Select = class Select extends HTMLElement {
|
||||
// 可用属性
|
||||
static observedAttributes = ['placeholder', 'list', 'value', 'current', 'disabled', 'focus']
|
||||
@@ -329,6 +337,7 @@ class UI {
|
||||
super()
|
||||
// 下拉框
|
||||
this.select = null
|
||||
this.ele = null
|
||||
// 下拉框列表
|
||||
this.list = '默认选项'
|
||||
this.dl = null
|
||||
@@ -354,6 +363,18 @@ class UI {
|
||||
// 属性变化
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
this[name] = newValue
|
||||
|
||||
if (name == 'disabled') {
|
||||
if (eval(this.disabled)) {
|
||||
this.ele.querySelector('.select-button').setAttribute('disabled', eval(this.disabled))
|
||||
} else {
|
||||
this.ele.querySelector('.select-button').removeAttribute('disabled')
|
||||
}
|
||||
} else if (name == 'value') {
|
||||
this.dl.innerHTML = ''
|
||||
this.addOption()
|
||||
this.button.innerText = this.placeholder || this.options[this.current].text
|
||||
}
|
||||
}
|
||||
// 重置
|
||||
reset() {
|
||||
@@ -483,6 +504,7 @@ class UI {
|
||||
this.select.appendChild(dl)
|
||||
shadow.appendChild(style)
|
||||
shadow.appendChild(this.select)
|
||||
this.ele = shadow
|
||||
|
||||
// 选项点击事件
|
||||
dl.addEventListener('click', e => {
|
||||
|
Reference in New Issue
Block a user