diff --git a/packages/switch/demo/index.vue b/packages/switch/demo/index.vue
index f3ca7e351..5fcee272e 100644
--- a/packages/switch/demo/index.vue
+++ b/packages/switch/demo/index.vue
@@ -13,7 +13,13 @@
-
+
diff --git a/packages/switch/en-US.md b/packages/switch/en-US.md
index f7c54e1da..07742bf9f 100644
--- a/packages/switch/en-US.md
+++ b/packages/switch/en-US.md
@@ -41,7 +41,13 @@ export default {
#### Advanced usage
```html
-
+
```
```js
@@ -73,6 +79,8 @@ export default {
| loading | Whether to show loading icon | `Boolean` | `false` |
| disabled | Whether to disable switch | `Boolean` | `false` |
| size | Size of switch | `String` | `30px` |
+| active-color | Background color when active | `String` | `#1989fa` |
+| inactive-color | Background color when inactive | `String` | `#fff` |
### Event
diff --git a/packages/switch/index.vue b/packages/switch/index.vue
index 32e705a00..b79d9e780 100644
--- a/packages/switch/index.vue
+++ b/packages/switch/index.vue
@@ -23,6 +23,8 @@ export default create({
value: Boolean,
loading: Boolean,
disabled: Boolean,
+ activeColor: String,
+ inactiveColor: String,
size: {
type: String,
default: '30px'
@@ -32,7 +34,8 @@ export default create({
computed: {
style() {
return {
- fontSize: this.size
+ fontSize: this.size,
+ backgroundColor: this.value ? this.activeColor : this.inactiveColor
};
}
},
diff --git a/packages/switch/test/__snapshots__/demo.spec.js.snap b/packages/switch/test/__snapshots__/demo.spec.js.snap
index 38c8843d8..44196c044 100644
--- a/packages/switch/test/__snapshots__/demo.spec.js.snap
+++ b/packages/switch/test/__snapshots__/demo.spec.js.snap
@@ -3,28 +3,28 @@
exports[`renders demo correctly 1`] = `
-
-
-
-
+
diff --git a/packages/switch/zh-CN.md b/packages/switch/zh-CN.md
index f0e272f36..2d4e13283 100644
--- a/packages/switch/zh-CN.md
+++ b/packages/switch/zh-CN.md
@@ -36,7 +36,13 @@ export default {
#### 高级用法
```html
-
+
```
```js
@@ -69,6 +75,8 @@ export default {
| loading | 是否为加载状态 | `Boolean` | `false` | - |
| disabled | 是否为禁用状态 | `Boolean` | `false` | - |
| size | 开关尺寸 | `String` | `30px` | 1.0.0 |
+| active-color | 打开时的背景色 | `String` | `#1989fa` | 1.3.11 |
+| inactive-color | 关闭时的背景色 | `String` | `#fff` | 1.3.11 |
### Event
diff --git a/packages/vant-css/src/switch.css b/packages/vant-css/src/switch.css
index 5afdf960f..0a1985896 100644
--- a/packages/vant-css/src/switch.css
+++ b/packages/vant-css/src/switch.css
@@ -2,13 +2,14 @@
.van-switch {
height: 1em;
- width: 1.6em;
+ width: 1.8em;
display: inline-block;
position: relative;
- background: $white;
+ border-radius: 1em;
box-sizing: content-box;
border: 1px solid rgba(0, 0, 0, .1);
- border-radius: 1em;
+ background-color: $white;
+ transition: background-color .3s;
&__node {
top: 0;
@@ -34,7 +35,7 @@
background-color: $blue;
.van-switch__node {
- transform: translateX(.6em);
+ transform: translateX(.8em);
}
}