diff --git a/src/form/button.wc b/src/form/button.wc
index 3edefc2..fcf7069 100644
--- a/src/form/button.wc
+++ b/src/form/button.wc
@@ -10,6 +10,7 @@
overflow: hidden;
display: inline-block;
user-select: none;
+ -moz-user-select: none;
color: nth($cd, 2);
cursor: pointer;
@@ -306,7 +307,7 @@ export default class Button {
this._handleClick = ev => {
if (this.props.loading || this.props.disabled) {
// 阻止事件冒泡, 避免用户自己绑定click事件不受这2个值的限制
- ev.cancelBubble = true
+ ev.stopPropagation()
return
}
this.dispatchEvent(new CustomEvent('active'))
diff --git a/src/form/checkbox.wc b/src/form/checkbox.wc
new file mode 100644
index 0000000..e69de29
diff --git a/src/form/index.js b/src/form/index.js
index c6afe62..19a2e33 100644
--- a/src/form/index.js
+++ b/src/form/index.js
@@ -9,59 +9,6 @@ import 'css/form.scss'
const log = console.log
Anot.ui.form = '0.1.0'
-// 按钮
-Anot.component('button', {
- __init__(props, state, next) {
- state.text = this.text()
- state.style = { 'border-radius': props.radius }
- this.classList.add('do-fn-noselect')
- this.classList.add('do-button')
- this.classList.add(props.color || 'grey')
- this.setAttribute(':click', 'onClick')
- this.setAttribute(':class', '{disabled: disabled}')
- this.setAttribute(':css', 'style')
-
- if (props.size) {
- this.classList.add(props.size)
- }
- if (props.hasOwnProperty('disabled')) {
- state.disabled = true
- }
- delete props.disabled
- delete props.color
- delete props.size
-
- next()
- },
- render(slots) {
- let icon = ''
- if (this.props.icon) {
- icon = ``
- }
- return `${icon}`
- },
- state: {
- text: '',
- disabled: false,
- style: {}
- },
- props: {
- click: Anot.PropsTypes.isFunction()
- },
- skip: ['style'],
-
- watch: {},
- methods: {
- onClick() {
- if (this.disabled) {
- return
- }
- if (typeof this.props.click === 'function') {
- this.props.click(this.props.prop)
- }
- }
- }
-})
// 单选按钮
Anot.component('radio', {
@@ -122,48 +69,6 @@ Anot.component('radio', {
}
})
-// 开关
-Anot.component('switch', {
- __init__(props, state, next) {
- if (props.hasOwnProperty('disabled')) {
- state.disabled = true
- }
- if (props.hasOwnProperty('checked')) {
- if (state.value === null) {
- state.value = true
- }
- }
- state.value = !!state.value
-
- this.classList.add('do-switch')
- this.classList.add('do-fn-noselect')
- this.classList.add(props.color || 'grey')
- this.setAttribute(':class', '{disabled: disabled, checked: value}')
- this.setAttribute(':click', 'onClick')
-
- delete props.disabled
- delete props.color
- next()
- },
- render() {
- return `
-
- `
- },
- state: {
- value: null,
- disabled: false
- },
- methods: {
- onClick() {
- if (this.disabled) {
- return
- }
- this.value = !this.value
- }
- }
-})
-
// 多选
Anot.component('checkbox', {
__init__(props, state, next) {
@@ -239,81 +144,4 @@ Anot.component('checkbox', {
}
})
-// 文本输入框
-Anot.component('input', {
- __init__(props, state, next) {
- if (props.hasOwnProperty('disabled')) {
- state.disabled = true
- }
- if (props.iconR) {
- state.pos = 'right'
- props.icon = props.iconR
- delete props.iconR
- }
- this.classList.add('do-input')
- this.classList.add('do-fn-noselect')
- this.classList.add(props.color || 'grey')
- if (props.icon) {
- this.classList.add('icon-' + state.pos)
- }
- this.setAttribute(':class', '{disabled: disabled, active: active}')
- this.setAttribute(':css', '{width: props.width}')
-
- delete props.disabled
- delete props.color
- next()
- },
- render() {
- let { icon, placeholder } = this.props
- let holder = `
- `
- let input = `
- `
- let ico = icon ? `` : ''
-
- return holder + input + ico
- },
- state: {
- pos: 'left', // icon position
- value: '',
- disabled: false,
- active: false
- },
- skip: ['pos'],
- props: {
- type: 'text',
- width: 180,
- placeholder: '',
- default: '',
- submit: Anot.PropsTypes.isFunction() // on key `ENTER`
- },
- methods: {
- onFocus() {
- this.active = true
- },
- onBlur() {
- this.active = false
- },
- onKeyup(ev) {
- if (this.disabled) {
- return
- }
- if (ev.keyCode === 13) {
- if (typeof this.props.submit === 'function') {
- this.props.submit()
- }
- }
- }
- }
-})
-
export default Anot
diff --git a/src/form/input.wc b/src/form/input.wc
index 123a30e..1064208 100644
--- a/src/form/input.wc
+++ b/src/form/input.wc
@@ -387,7 +387,7 @@ export default class Input {
// 回车事件
this._handleSubmit = ev => {
if (this.disabled || this.readonly) {
- ev.cancelBubble = true
+ ev.stopPropagation()
return
}
// up: 38, down: 40
diff --git a/src/form/radio.wc b/src/form/radio.wc
new file mode 100644
index 0000000..72c6001
--- /dev/null
+++ b/src/form/radio.wc
@@ -0,0 +1,234 @@
+
+
+
+
+
+
+
diff --git a/src/form/switch.wc b/src/form/switch.wc
index 53fc162..eb14cb4 100644
--- a/src/form/switch.wc
+++ b/src/form/switch.wc
@@ -109,8 +109,12 @@ export default class Switch {
this.__SWITCH__ = this.root.lastElementChild
}
- get type() {
- return 'radio'
+ get value() {
+ return this.props.checked
+ }
+
+ set value(val) {
+ this.checked = val
}
get checked() {
@@ -142,12 +146,15 @@ export default class Switch {
}
mounted() {
- this.__SWITCH__.addEventListener(
+ this.addEventListener(
'click',
ev => {
- ev.preventDefault()
+ if (this.disabled) {
+ return
+ }
if (!this.disabled) {
this.checked = !this.checked
+ this.dispatchEvent(new CustomEvent('input'))
}
},
false
@@ -160,12 +167,9 @@ export default class Switch {
}
switch (name) {
case 'checked':
- this.checked = !!val
- break
-
case 'disabled':
if (val === '') {
- this.disabled = true
+ this[name] = true
}
break
}