Skip to content

Commit eed3d1a

Browse files
committed
Merge branch 'feature/slider'
2 parents 03d1ee5 + 5abe6e1 commit eed3d1a

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed

src/components/DgFilter.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
round-checkbox.sortOption(v-for="(val, key) in sort", :label="key", :value="sort[key]", :isBlock="false", @input="onSortCheck(key, $event)")
1111
.control
1212
p.control-label LIMIT RANGE
13-
13+
multi-range-slider(:min="range['min']", :max="range['max']", v-model="range.value")
1414
</template>
1515

1616
<script>
1717
import RoundCheckbox from 'components/RoundCheckbox'
18+
import MultiRangeSlider from 'components/MultiRangeSlider'
1819
import Icon from 'components/Icon'
1920
2021
export default {
@@ -26,11 +27,17 @@ export default {
2627
sort: {
2728
ascending: false,
2829
descending: false
30+
},
31+
range: {
32+
min: 0,
33+
max: 10000,
34+
value: [0, 10000]
2935
}
3036
}
3137
},
3238
components: {
3339
RoundCheckbox,
40+
MultiRangeSlider,
3441
Icon
3542
},
3643
methods: {
@@ -72,6 +79,7 @@ export default {
7279
z-index: $popup-index
7380
cursor: pointer
7481
transition: background $medium
82+
width: 3em // fix firefox issue
7583
7684
.filter--active
7785
background: $cell-color

src/components/MultiRangeSlider.vue

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<template lang="pug">
2+
.multiRangeSlider
3+
input.multiRange.multiRange--min(name="min", type="range", :min="min", :max="max", :value="value[0]", @input="onChange")
4+
input.multiRange.multiRange--max(name="max", type="range", :min="min", :max="max", :value="value[1]", @input="onChange")
5+
.rangeBar(:style="barLenStyle")
6+
.rangeLabel
7+
label.label.label--min {{ toNumberAbbr(value[0]) }}
8+
label.label.label--max {{ toNumberAbbr(value[1]) }}
9+
</template>
10+
11+
<script>
12+
const rangeColor = '#15a4fa'
13+
14+
export default {
15+
props: {
16+
min: Number,
17+
max: Number,
18+
value: Array
19+
},
20+
computed: {
21+
rangePercentage () {
22+
return {
23+
start: `${this.value[0] / (this.max - this.min) * 100}%`,
24+
end: `${this.value[1] / (this.max - this.min) * 100}%`
25+
}
26+
},
27+
barLenStyle () {
28+
return {background: `linear-gradient(to right, transparent ${this.rangePercentage.start}, ${rangeColor} ${this.rangePercentage.start}, ${rangeColor} ${this.rangePercentage.end}, transparent ${this.rangePercentage.end}) no-repeat`}
29+
}
30+
},
31+
methods: {
32+
onChange (event) {
33+
let result = event.target.name === 'min'
34+
? [Math.min(event.target.value, this.value[1] - 1), this.value[1]]
35+
: [this.value[0], Math.max(this.value[0] - 1, event.target.value)]
36+
this.$emit('input', result)
37+
},
38+
toNumberAbbr (num) {
39+
return num < 1000 ? num : `${Math.floor(num / 1000)}k`
40+
}
41+
}
42+
}
43+
44+
</script>
45+
46+
<style lang="sass" scoped>
47+
@import '../sass/variables'
48+
@import '../sass/utils'
49+
50+
$track-color: $bg-color
51+
$range-color: $primary-color
52+
$knob-color: #fff
53+
$knob-size: 16px
54+
55+
.multiRangeSlider
56+
position: relative
57+
width: 100%
58+
59+
=bar
60+
position: absolute
61+
top: $knob-size / 4
62+
width: 100%
63+
height: $knob-size / 2
64+
border-radius: $knob-size / 2
65+
pointer-events: none
66+
67+
=knob
68+
width: $knob-size
69+
height: $knob-size
70+
border-radius: 50%
71+
background: $knob-color
72+
cursor: pointer
73+
z-index: 3
74+
75+
76+
.multiRange
77+
display: inline-block
78+
vertical-align: top
79+
width: 100%
80+
padding: 0
81+
margin: 0
82+
outline: none
83+
-webkit-appearance: none
84+
-moz-appearance: none
85+
background: none
86+
87+
&::-webkit-slider-thumb
88+
position: relative
89+
-webkit-appearance: none
90+
-moz-appearance: none
91+
+knob
92+
93+
&::-moz-range-thumb
94+
transform: scale(1)
95+
+knob
96+
97+
&::before
98+
content: ''
99+
+bar
100+
background: $track-color
101+
102+
.multiRange--min
103+
position: absolute
104+
105+
.multiRange--max
106+
position: relative
107+
108+
.rangeBar
109+
+bar
110+
z-index: 2
111+
112+
.rangeLabel
113+
@extend %clearfix
114+
115+
.label
116+
padding: 0.5em 0 0
117+
118+
.label--min
119+
float: left
120+
121+
.label--max
122+
float: right
123+
</style>

0 commit comments

Comments
 (0)