mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[improvement] Switch: update style (#1065)
This commit is contained in:
parent
e4f39e187d
commit
acc2b1da29
@ -21,12 +21,27 @@
|
|||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block title="高级用法" padding>
|
<demo-block title="自定义大小" padding>
|
||||||
|
<van-switch
|
||||||
|
checked="{{ checked }}"
|
||||||
|
size="24px"
|
||||||
|
bind:change="onChange"
|
||||||
|
/>
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block title="自定义颜色" padding>
|
||||||
|
<van-switch
|
||||||
|
checked="{{ checked }}"
|
||||||
|
active-color="#4b0"
|
||||||
|
inactive-color="#f44"
|
||||||
|
bind:change="onChange"
|
||||||
|
/>
|
||||||
|
</demo-block>
|
||||||
|
|
||||||
|
<demo-block title="异步控制" padding>
|
||||||
<van-switch
|
<van-switch
|
||||||
checked="{{ checked2 }}"
|
checked="{{ checked2 }}"
|
||||||
size="36px"
|
size="36px"
|
||||||
active-color="#4b0"
|
|
||||||
inactive-color="#f44"
|
|
||||||
bind:change="onChange2"
|
bind:change="onChange2"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
@ -42,6 +42,23 @@
|
|||||||
@notify-font-size: 14px;
|
@notify-font-size: 14px;
|
||||||
@notify-line-height: 20px;
|
@notify-line-height: 20px;
|
||||||
|
|
||||||
|
// Switch
|
||||||
|
@switch-width: 2em;
|
||||||
|
@switch-height: 1em;
|
||||||
|
@switch-node-size: 1em;
|
||||||
|
@switch-node-z-index: 1;
|
||||||
|
@switch-node-background-color: @white;
|
||||||
|
@switch-node-box-shadow: 0 3px 1px 0 rgba(0, 0, 0, .05), 0 2px 2px 0 rgba(0, 0, 0, .1), 0 3px 3px 0 rgba(0, 0, 0, .05);
|
||||||
|
@switch-background-color: @white;
|
||||||
|
@switch-on-background-color: @blue;
|
||||||
|
@switch-transition-duration: .3s;
|
||||||
|
@switch-disabled-opacity: .4;
|
||||||
|
@switch-border: 1px solid rgba(0, 0, 0, .1);
|
||||||
|
|
||||||
|
// SwitchCell
|
||||||
|
@switch-cell-padding-top: 9px;
|
||||||
|
@switch-cell-padding-bottom: 9px;
|
||||||
|
|
||||||
// Toast
|
// Toast
|
||||||
@toast-max-width: 70%;
|
@toast-max-width: 70%;
|
||||||
@toast-font-size: 14px;
|
@toast-font-size: 14px;
|
||||||
|
@ -66,7 +66,7 @@ Page({
|
|||||||
| title | 左侧标题 | `String` | `''` |
|
| title | 左侧标题 | `String` | `''` |
|
||||||
| loading | 是否为加载状态 | `Boolean` | `false` |
|
| loading | 是否为加载状态 | `Boolean` | `false` |
|
||||||
| disabled | 是否为禁用状态 | `Boolean` | `false` |
|
| disabled | 是否为禁用状态 | `Boolean` | `false` |
|
||||||
| size | 开关尺寸 | `String` | `26px` |
|
| size | 开关尺寸 | `String` | `24px` |
|
||||||
| active-color | 开关打开时的背景色 | `String` | `#1989fa` |
|
| active-color | 开关打开时的背景色 | `String` | `#1989fa` |
|
||||||
| inactive-color | 开关关闭时的背景色 | `String` | `#fff` |
|
| inactive-color | 开关关闭时的背景色 | `String` | `#fff` |
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
@import '../common/style/var.less';
|
@import '../common/style/var.less';
|
||||||
|
|
||||||
.van-switch-cell {
|
.van-switch-cell {
|
||||||
padding-top: 8px;
|
padding-top: @switch-cell-padding-top;
|
||||||
padding-bottom: 8px;
|
padding-bottom: @switch-cell-padding-bottom;
|
||||||
|
|
||||||
&__switch {
|
&__switch {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
@ -13,7 +13,7 @@ VantComponent({
|
|||||||
inactiveColor: String,
|
inactiveColor: String,
|
||||||
size: {
|
size: {
|
||||||
type: String,
|
type: String,
|
||||||
value: '26px'
|
value: '24px'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -42,14 +42,27 @@ Page({
|
|||||||
<van-switch checked="{{ checked }}" loading />
|
<van-switch checked="{{ checked }}" loading />
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 高级用法
|
#### 自定义大小
|
||||||
|
|
||||||
|
```html
|
||||||
|
<van-switch checked="{{ checked }}" size="24px" />
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 自定义颜色
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-switch
|
<van-switch
|
||||||
size="36px"
|
|
||||||
checked="{{ checked }}"
|
checked="{{ checked }}"
|
||||||
active-color="#4b0"
|
active-color="#4b0"
|
||||||
inactive-color="#f44"
|
inactive-color="#f44"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 异步控制
|
||||||
|
|
||||||
|
```html
|
||||||
|
<van-switch
|
||||||
|
checked="{{ checked }}"
|
||||||
bind:change="onChange"
|
bind:change="onChange"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
@import '../common/style/var.less';
|
@import '../common/style/var.less';
|
||||||
|
|
||||||
.van-switch {
|
.van-switch {
|
||||||
height: 1em;
|
|
||||||
width: 1.8em;
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: relative;
|
position: relative;
|
||||||
border-radius: 1em;
|
width: @switch-width;
|
||||||
|
height: @switch-height;
|
||||||
|
border: @switch-border;
|
||||||
|
border-radius: @switch-node-size;
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
border: 1px solid rgba(0, 0, 0, .1);
|
background-color: @switch-background-color;
|
||||||
background-color: @white;
|
transition: background-color @switch-transition-duration;
|
||||||
transition: background-color .3s;
|
|
||||||
|
|
||||||
&__node {
|
&__node {
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: 1;
|
|
||||||
width: 1em;
|
|
||||||
height: 1em;
|
|
||||||
transition: .3s;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
background-color: @white;
|
width: @switch-node-size;
|
||||||
box-shadow: 0 3px 1px 0 rgba(0, 0, 0, .05), 0 2px 2px 0 rgba(0, 0, 0, .1), 0 3px 3px 0 rgba(0, 0, 0, .05);
|
height: @switch-node-size;
|
||||||
|
z-index: @switch-node-z-index;
|
||||||
|
transition: @switch-transition-duration;
|
||||||
|
box-shadow: @switch-node-box-shadow;
|
||||||
|
background-color: @switch-node-background-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__loading {
|
&__loading {
|
||||||
@ -31,14 +31,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&--on {
|
&--on {
|
||||||
background-color: @blue;
|
background-color: @switch-on-background-color;
|
||||||
|
|
||||||
.van-switch__node {
|
.van-switch__node {
|
||||||
transform: translateX(.8em);
|
transform: translateX(@switch-width - @switch-node-size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&--disabled {
|
&--disabled {
|
||||||
opacity: .4;
|
opacity: @switch-disabled-opacity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user