Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new feature] Slider: add active-color、inactive-color prop #2374

Merged
merged 1 commit into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/slider/demo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@
<van-slider
v-model="value5"
bar-height="4px"
active-color="#f44"
@change="onChange"
/>
</demo-block>

<demo-block :title="$t('customButton')">
<van-slider v-model="value6">
<van-slider
v-model="value6"
active-color="#f44"
>
<div
slot="button"
class="custom-button"
Expand Down
13 changes: 11 additions & 2 deletions packages/slider/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ export default {
#### Custom style

```html
<van-slider v-model="value" bar-height="4px" />
<van-slider
v-model="value"
bar-height="4px"
active-color="#f44"
/>
```

#### Custom button

```html
<van-slider v-model="value">
<van-slider
v-model="value"
active-color="#f44"
>
<div
slot="button"
class="custom-button"
Expand All @@ -77,6 +84,8 @@ export default {
| min | Min value | `Number` | `0` |
| step | Step size | `Number` | `1` |
| bar-height | Height of bar | `String` | `2px` |
| active-color | Active color of bar | `String` | `#1989fa` |
| inactive-color | Inactive color of bar | `String` | `#e5e5e5` |

### Event

Expand Down
12 changes: 11 additions & 1 deletion packages/slider/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div
:class="b({ disabled })"
:style="style"
@click.stop="onClick"
>
<div
Expand Down Expand Up @@ -35,6 +36,8 @@ export default create({
min: Number,
value: Number,
disabled: Boolean,
activeColor: String,
inactiveColor: String,
max: {
type: Number,
default: 100
Expand All @@ -50,10 +53,17 @@ export default create({
},

computed: {
style() {
return {
background: this.inactiveColor
};
},

barStyle() {
return {
width: this.format(this.value) + '%',
height: this.barHeight
height: this.barHeight,
background: this.activeColor
};
}
},
Expand Down
24 changes: 12 additions & 12 deletions packages/slider/test/__snapshots__/demo.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,53 @@
exports[`renders demo correctly 1`] = `
<div>
<div>
<div class="van-slider">
<div class="van-slider__bar" style="width:50%;height:2px;">
<div class="van-slider" style="background:undefined;">
<div class="van-slider__bar" style="width:50%;height:2px;background:undefined;">
<div class="van-slider__button-wrapper">
<div class="van-slider__button"></div>
</div>
</div>
</div>
</div>
<div>
<div class="van-slider">
<div class="van-slider__bar" style="width:50%;height:2px;">
<div class="van-slider" style="background:undefined;">
<div class="van-slider__bar" style="width:50%;height:2px;background:undefined;">
<div class="van-slider__button-wrapper">
<div class="van-slider__button"></div>
</div>
</div>
</div>
</div>
<div>
<div class="van-slider van-slider--disabled">
<div class="van-slider__bar" style="width:50%;height:2px;">
<div class="van-slider van-slider--disabled" style="background:undefined;">
<div class="van-slider__bar" style="width:50%;height:2px;background:undefined;">
<div class="van-slider__button-wrapper">
<div class="van-slider__button"></div>
</div>
</div>
</div>
</div>
<div>
<div class="van-slider">
<div class="van-slider__bar" style="width:50%;height:2px;">
<div class="van-slider" style="background:undefined;">
<div class="van-slider__bar" style="width:50%;height:2px;background:undefined;">
<div class="van-slider__button-wrapper">
<div class="van-slider__button"></div>
</div>
</div>
</div>
</div>
<div>
<div class="van-slider">
<div class="van-slider__bar" style="width:50%;height:4px;">
<div class="van-slider" style="background:undefined;">
<div class="van-slider__bar" style="width:50%;height:4px;background:#f44;">
<div class="van-slider__button-wrapper">
<div class="van-slider__button"></div>
</div>
</div>
</div>
</div>
<div>
<div class="van-slider">
<div class="van-slider__bar" style="width:50%;height:2px;">
<div class="van-slider" style="background:undefined;">
<div class="van-slider__bar" style="width:50%;height:2px;background:#f44;">
<div class="van-slider__button-wrapper">
<div class="custom-button">
50
Expand Down
13 changes: 11 additions & 2 deletions packages/slider/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ export default {
#### 自定义样式

```html
<van-slider v-model="value" bar-height="4px" />
<van-slider
v-model="value"
bar-height="4px"
active-color="#f44"
/>
```

#### 自定义按钮

```html
<van-slider v-model="value">
<van-slider
v-model="value"
active-color="#f44"
>
<div
slot="button"
class="custom-button"
Expand All @@ -76,6 +83,8 @@ export default {
| min | 最小值 | `Number` | `0` | 1.1.0 |
| step | 步长 | `Number` | `1` | 1.1.0 |
| bar-height | 进度条高度 | `String` | `2px` | 1.1.0 |
| active-color | 进度条激活态颜色 | `String` | `#1989fa` | 1.5.1 |
| inactive-color | 进度条默认颜色 | `String` | `#e5e5e5` | 1.5.1 |

### Event

Expand Down