feat(Slider): add button-size prop

This commit is contained in:
陈嘉涵 2020-01-27 12:18:36 +08:00
parent 6ddd7ae69b
commit 1e9b8c8466
5 changed files with 41 additions and 4 deletions

View File

@ -103,6 +103,7 @@ export default {
| min | Min value | *number* | `0` | | min | Min value | *number* | `0` |
| step | Step size | *number* | `1` | | step | Step size | *number* | `1` |
| bar-height | Height of bar | *string \| number* | `2px` | | bar-height | Height of bar | *string \| number* | `2px` |
| button-size `v2.4.5` | Button size | *string \| number* | `24px` |
| active-color | Active color of bar | *string* | `#1989fa` | | active-color | Active color of bar | *string* | `#1989fa` |
| inactive-color | Inactive color of bar | *string* | `#e5e5e5` | | inactive-color | Inactive color of bar | *string* | `#e5e5e5` |
| disabled | Whether to disable slider | *boolean* | `false` | | disabled | Whether to disable slider | *boolean* | `false` |

View File

@ -105,8 +105,9 @@ Slider 垂直展示时,高度为 100% 父元素高度
| min | 最小值 | *number* | `0` | | min | 最小值 | *number* | `0` |
| step | 步长 | *number* | `1` | | step | 步长 | *number* | `1` |
| bar-height | 进度条高度,默认单位为`px` | *string \| number* | `2px` | | bar-height | 进度条高度,默认单位为`px` | *string \| number* | `2px` |
| button-size `v2.4.5` | 滑块按钮大小,默认单位为`px` | *string \| number* | `24px` |
| active-color | 进度条激活态颜色 | *string* | `#1989fa` | | active-color | 进度条激活态颜色 | *string* | `#1989fa` |
| inactive-color | 进度条默认颜色 | *string* | `#e5e5e5` | | inactive-color | 进度条非激活态颜色 | *string* | `#e5e5e5` |
| disabled | 是否禁用滑块 | *boolean* | `false` | | disabled | 是否禁用滑块 | *boolean* | `false` |
| vertical | 是否垂直展示 | *boolean* | `false` | | vertical | 是否垂直展示 | *boolean* | `false` |

View File

@ -10,6 +10,7 @@ export default createComponent({
props: { props: {
disabled: Boolean, disabled: Boolean,
vertical: Boolean, vertical: Boolean,
buttonSize: [Number, String],
activeColor: String, activeColor: String,
inactiveColor: String, inactiveColor: String,
min: { min: {
@ -44,6 +45,17 @@ export default createComponent({
range() { range() {
return this.max - this.min; return this.max - this.min;
}, },
buttonStyle() {
if (this.buttonSize) {
const size = addUnit(this.buttonSize);
return {
width: size,
height: size,
};
}
},
}, },
created() { created() {
@ -173,7 +185,9 @@ export default createComponent({
aria-orientation={this.vertical ? 'vertical' : 'horizontal'} aria-orientation={this.vertical ? 'vertical' : 'horizontal'}
class={bem('button-wrapper')} class={bem('button-wrapper')}
> >
{this.slots('button') || <div class={bem('button')} />} {this.slots('button') || (
<div class={bem('button')} style={this.buttonStyle} />
)}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`bar height 1`] = ` exports[`bar-height prop 1`] = `
<div class="van-slider"> <div class="van-slider">
<div class="van-slider__bar" style="width: 50%; height: 10px;"> <div class="van-slider__bar" style="width: 50%; height: 10px;">
<div role="slider" tabindex="0" aria-valuemin="0" aria-valuenow="50" aria-valuemax="100" aria-orientation="horizontal" class="van-slider__button-wrapper"> <div role="slider" tabindex="0" aria-valuemin="0" aria-valuenow="50" aria-valuemax="100" aria-orientation="horizontal" class="van-slider__button-wrapper">
@ -10,6 +10,16 @@ exports[`bar height 1`] = `
</div> </div>
`; `;
exports[`button-size prop 1`] = `
<div class="van-slider">
<div class="van-slider__bar" style="width: 50%; height: 2px;">
<div role="slider" tabindex="0" aria-valuemin="0" aria-valuenow="50" aria-valuemax="100" aria-orientation="horizontal" class="van-slider__button-wrapper">
<div class="van-slider__button" style="width: 10px; height: 10px;"></div>
</div>
</div>
</div>
`;
exports[`click bar 1`] = ` exports[`click bar 1`] = `
<div class="van-slider van-slider--disabled"> <div class="van-slider van-slider--disabled">
<div class="van-slider__bar" style="width: 50%; height: 2px;"> <div class="van-slider__bar" style="width: 50%; height: 2px;">

View File

@ -111,7 +111,7 @@ it('click vertical', () => {
restoreMock(); restoreMock();
}); });
it('bar height', () => { it('bar-height prop', () => {
const wrapper = mount(Slider, { const wrapper = mount(Slider, {
propsData: { propsData: {
value: 50, value: 50,
@ -122,6 +122,17 @@ it('bar height', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
it('button-size prop', () => {
const wrapper = mount(Slider, {
propsData: {
value: 50,
buttonSize: 10,
},
});
expect(wrapper).toMatchSnapshot();
});
it('should not emit change event when value not changed', () => { it('should not emit change event when value not changed', () => {
const wrapper = mount(Slider, { const wrapper = mount(Slider, {
propsData: { propsData: {