mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
feat(slider): make active dots have active color
This commit is contained in:
parent
8a2e695ab1
commit
53b24267b0
@ -12,11 +12,20 @@
|
|||||||
>
|
>
|
||||||
<div ref="railRef" class="n-slider-rail" @click="handleRailClick">
|
<div ref="railRef" class="n-slider-rail" @click="handleRailClick">
|
||||||
<div class="n-slider-rail__fill" :style="fillStyle" />
|
<div class="n-slider-rail__fill" :style="fillStyle" />
|
||||||
<div v-if="marks" class="n-slider-dots">
|
<div
|
||||||
|
v-if="marks"
|
||||||
|
class="n-slider-dots"
|
||||||
|
:class="{
|
||||||
|
'n-slider-dots--transition-disabled': dotTransitionDisabled
|
||||||
|
}"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
v-for="mark in computedMarks"
|
v-for="mark in computedMarks"
|
||||||
:key="mark.label"
|
:key="mark.label"
|
||||||
class="n-slider-dot"
|
class="n-slider-dot"
|
||||||
|
:class="{
|
||||||
|
'n-slider-dot--active': mark.active
|
||||||
|
}"
|
||||||
:style="{
|
:style="{
|
||||||
...mark.style
|
...mark.style
|
||||||
}"
|
}"
|
||||||
@ -261,6 +270,7 @@ export default {
|
|||||||
active: activeRef,
|
active: activeRef,
|
||||||
prevActive: prevActiveRef,
|
prevActive: prevActiveRef,
|
||||||
clicked: clickedRef,
|
clicked: clickedRef,
|
||||||
|
dotTransitionDisabled: ref(false),
|
||||||
// https://github.com/vuejs/vue-next/issues/2283
|
// https://github.com/vuejs/vue-next/issues/2283
|
||||||
handleRef1: ref(null),
|
handleRef1: ref(null),
|
||||||
handleRef2: ref(null),
|
handleRef2: ref(null),
|
||||||
@ -272,17 +282,21 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
computedMarks () {
|
computedMarks () {
|
||||||
const marks = []
|
const mergedMarks = []
|
||||||
for (const value of Object.keys(this.marks)) {
|
const { marks, max, min, range, mergedValue } = this
|
||||||
marks.push({
|
for (const key of Object.keys(marks)) {
|
||||||
label: this.marks[value],
|
const num = Number(key)
|
||||||
|
mergedMarks.push({
|
||||||
|
active: range
|
||||||
|
? mergedValue[0] <= num && mergedValue[1] >= num
|
||||||
|
: mergedValue >= num,
|
||||||
|
label: marks[key],
|
||||||
style: {
|
style: {
|
||||||
left:
|
left: ((num - min) / (max - min)) * 100 + '%'
|
||||||
((Number(value) - this.min) / (this.max - this.min)) * 100 + '%'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return marks
|
return mergedMarks
|
||||||
},
|
},
|
||||||
fillStyle () {
|
fillStyle () {
|
||||||
if (this.range) {
|
if (this.range) {
|
||||||
@ -351,6 +365,13 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
mergedValue (newValue, oldValue) {
|
mergedValue (newValue, oldValue) {
|
||||||
const { changeSource } = this
|
const { changeSource } = this
|
||||||
|
if (this.marks) {
|
||||||
|
if (this.dotTransitionDisabled) return
|
||||||
|
this.dotTransitionDisabled = true
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.dotTransitionDisabled = false
|
||||||
|
})
|
||||||
|
}
|
||||||
if (this.range && newValue) {
|
if (this.range && newValue) {
|
||||||
if (oldValue && oldValue[1] !== newValue[1]) {
|
if (oldValue && oldValue[1] !== newValue[1]) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
@ -28,7 +28,8 @@ export default c([
|
|||||||
dotWidth,
|
dotWidth,
|
||||||
dotBorderRadius,
|
dotBorderRadius,
|
||||||
indicatorBorderRadius,
|
indicatorBorderRadius,
|
||||||
fontSize
|
fontSize,
|
||||||
|
dotBorderActive
|
||||||
},
|
},
|
||||||
$global: {
|
$global: {
|
||||||
cubicBezierEaseInOut,
|
cubicBezierEaseInOut,
|
||||||
@ -50,8 +51,8 @@ export default c([
|
|||||||
raw: `
|
raw: `
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 18px;
|
top: 18px;
|
||||||
left: 0;
|
left: calc(${handleSize} / 2);
|
||||||
right: 0;
|
right: calc(${handleSize} / 2);
|
||||||
`
|
`
|
||||||
}, [
|
}, [
|
||||||
cB('slider-mark', {
|
cB('slider-mark', {
|
||||||
@ -137,11 +138,16 @@ export default c([
|
|||||||
cB('slider-dots', {
|
cB('slider-dots', {
|
||||||
raw: `
|
raw: `
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
|
||||||
top: 50%;
|
top: 50%;
|
||||||
right: 0;
|
left: calc(${handleSize} / 2);
|
||||||
|
right: calc(${handleSize} / 2);
|
||||||
`
|
`
|
||||||
}, [
|
}, [
|
||||||
|
cM('transition-disabled', [
|
||||||
|
cB('slider-dot', {
|
||||||
|
transition: 'none'
|
||||||
|
})
|
||||||
|
]),
|
||||||
cB('slider-dot', {
|
cB('slider-dot', {
|
||||||
raw: `
|
raw: `
|
||||||
transition:
|
transition:
|
||||||
@ -159,8 +165,12 @@ export default c([
|
|||||||
border: dotBorder,
|
border: dotBorder,
|
||||||
backgroundColor: dotColor,
|
backgroundColor: dotColor,
|
||||||
boxShadow: dotBoxShadow
|
boxShadow: dotBoxShadow
|
||||||
|
}, [
|
||||||
|
cM('active', {
|
||||||
|
border: dotBorderActive
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
|
])
|
||||||
]),
|
]),
|
||||||
cTB('slider-handle-indicator', {
|
cTB('slider-handle-indicator', {
|
||||||
raw: `
|
raw: `
|
||||||
|
@ -36,7 +36,8 @@ export default create({
|
|||||||
indicatorBoxShadow: boxShadow,
|
indicatorBoxShadow: boxShadow,
|
||||||
indicatorTextColor: textColor2Overlay,
|
indicatorTextColor: textColor2Overlay,
|
||||||
indicatorBorderRadius: borderRadius,
|
indicatorBorderRadius: borderRadius,
|
||||||
dotBorder: `2px solid ${primaryColorSuppl}`,
|
dotBorder: `2px solid ${railColorOverlay}`,
|
||||||
|
dotBorderActive: `2px solid ${primaryColorSuppl}`,
|
||||||
dotBoxShadow: null
|
dotBoxShadow: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,8 @@ export default create({
|
|||||||
indicatorBoxShadow: boxShadow,
|
indicatorBoxShadow: boxShadow,
|
||||||
indicatorTextColor: baseColor,
|
indicatorTextColor: baseColor,
|
||||||
indicatorBorderRadius: borderRadius,
|
indicatorBorderRadius: borderRadius,
|
||||||
dotBorder: `2px solid ${primaryColor}`,
|
dotBorder: `2px solid ${railColorOverlay}`,
|
||||||
|
dotBorderActive: `2px solid ${primaryColor}`,
|
||||||
dotBoxShadow: null
|
dotBoxShadow: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user