@v-c/slider 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Handles/Handle.cjs +1 -1
- package/dist/Handles/Handle.d.ts +14 -2
- package/dist/Handles/Handle.js +9 -7
- package/dist/Handles/index.cjs +1 -1
- package/dist/Handles/index.d.ts +20 -4
- package/dist/Handles/index.js +6 -2
- package/dist/Slider.cjs +1 -1
- package/dist/Slider.d.ts +25 -14
- package/dist/Slider.js +2 -2
- package/dist/Tracks/Track.cjs +1 -1
- package/dist/Tracks/Track.js +2 -2
- package/dist/hooks/useOffset.cjs +1 -1
- package/dist/hooks/useOffset.d.ts +1 -1
- package/dist/hooks/useOffset.js +76 -63
- package/docs/debug.vue +1 -2
- package/docs/editable.vue +3 -4
- package/docs/handle.vue +11 -5
- package/docs/marks.vue +20 -10
- package/docs/multiple.vue +1 -5
- package/docs/range.vue +25 -12
- package/docs/sliderDemo.vue +33 -17
- package/docs/vertical.vue +25 -12
- package/package.json +1 -1
- package/src/Handles/Handle.tsx +10 -1
- package/src/Handles/index.tsx +10 -2
- package/src/Slider.tsx +17 -8
- package/src/Tracks/Track.tsx +2 -2
- package/src/hooks/useOffset.ts +48 -40
package/src/Tracks/Track.tsx
CHANGED
|
@@ -36,8 +36,6 @@ const Track = defineComponent({
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// ============================ Render ============================
|
|
39
|
-
const positionStyle: CSSProperties = {}
|
|
40
|
-
|
|
41
39
|
return () => {
|
|
42
40
|
const { prefixCls, index, onStartMove, replaceCls, start, end } = props
|
|
43
41
|
|
|
@@ -55,6 +53,8 @@ const Track = defineComponent({
|
|
|
55
53
|
},
|
|
56
54
|
classNames.track,
|
|
57
55
|
)
|
|
56
|
+
|
|
57
|
+
const positionStyle: CSSProperties = {}
|
|
58
58
|
switch (direction.value) {
|
|
59
59
|
case 'rtl':
|
|
60
60
|
positionStyle.right = `${offsetStart * 100}%`
|
package/src/hooks/useOffset.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { computed } from 'vue'
|
|
|
5
5
|
type FormatRangeValue = (value: number) => number
|
|
6
6
|
|
|
7
7
|
/** Format value align with step */
|
|
8
|
-
type FormatStepValue = (value: number) => number
|
|
8
|
+
type FormatStepValue = (value: number) => number | null
|
|
9
9
|
|
|
10
10
|
/** Format value align with step & marks */
|
|
11
11
|
type FormatValue = (value: number) => number
|
|
@@ -32,59 +32,58 @@ export type OffsetValues = (
|
|
|
32
32
|
export default function useOffset(
|
|
33
33
|
min: number,
|
|
34
34
|
max: number,
|
|
35
|
-
step: number,
|
|
35
|
+
step: number | null,
|
|
36
36
|
markList: InternalMarkObj[],
|
|
37
37
|
allowCross: boolean,
|
|
38
|
-
pushable: false | number,
|
|
38
|
+
pushable: false | number | null,
|
|
39
39
|
): [FormatValue, OffsetValues] {
|
|
40
40
|
const formatRangeValue = computed<FormatRangeValue>(() => {
|
|
41
41
|
return (val: number) => Math.max(min, Math.min(max, val))
|
|
42
42
|
}).value
|
|
43
43
|
|
|
44
|
-
const formatStepValue =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const stepValue = min + Math.round((formatRangeValue(val) - min) / step) * step
|
|
44
|
+
const formatStepValue: FormatStepValue = (val: number) => {
|
|
45
|
+
if (step !== null) {
|
|
46
|
+
const stepValue = min + Math.round((formatRangeValue(val) - min) / step) * step
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
// Cut number in case to be like 0.30000000000000004
|
|
49
|
+
const getDecimal = (num: number) => (String(num).split('.')[1] || '').length
|
|
50
|
+
const maxDecimal = Math.max(getDecimal(step), getDecimal(max), getDecimal(min))
|
|
51
|
+
const fixedValue = Number(stepValue.toFixed(maxDecimal))
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
return null
|
|
53
|
+
return min <= fixedValue && fixedValue <= max ? fixedValue : null
|
|
57
54
|
}
|
|
58
|
-
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
59
57
|
|
|
60
|
-
const formatValue =
|
|
61
|
-
|
|
62
|
-
const formatNextValue = formatRangeValue(val)
|
|
58
|
+
const formatValue = (val: number) => {
|
|
59
|
+
const formatNextValue = formatRangeValue(val)
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
// List align values
|
|
62
|
+
const alignValues = markList.map<number>(mark => mark && mark.value)
|
|
63
|
+
if (step !== null) {
|
|
64
|
+
const stepValue = formatStepValue(val)
|
|
65
|
+
if (stepValue !== null) {
|
|
66
|
+
alignValues.push(stepValue)
|
|
68
67
|
}
|
|
68
|
+
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
// min & max
|
|
71
|
+
alignValues.push(min, max)
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
// Align with marks
|
|
74
|
+
let closeValue = alignValues[0]
|
|
75
|
+
let closeDist = max - min
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
alignValues.forEach((alignValue) => {
|
|
78
|
+
const dist = Math.abs(formatNextValue - alignValue)
|
|
79
|
+
if (dist <= closeDist) {
|
|
80
|
+
closeValue = alignValue
|
|
81
|
+
closeDist = dist
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}).value
|
|
85
|
+
return closeValue
|
|
86
|
+
}
|
|
88
87
|
|
|
89
88
|
// ========================== Offset ==========================
|
|
90
89
|
// Single Value
|
|
@@ -106,16 +105,25 @@ export default function useOffset(
|
|
|
106
105
|
potentialValues.push(min, max)
|
|
107
106
|
|
|
108
107
|
// In case origin value is align with mark but not with step
|
|
109
|
-
|
|
108
|
+
const originStepValue = formatStepValue(originValue)
|
|
109
|
+
if (originStepValue !== null) {
|
|
110
|
+
potentialValues.push(originStepValue)
|
|
111
|
+
}
|
|
110
112
|
|
|
111
113
|
// Put offset step value also
|
|
112
114
|
const sign = offset > 0 ? 1 : -1
|
|
113
115
|
|
|
114
116
|
if (mode === 'unit') {
|
|
115
|
-
|
|
117
|
+
const allStepValues = formatStepValue(originValue + sign * step)
|
|
118
|
+
if (allStepValues !== null) {
|
|
119
|
+
potentialValues.push(allStepValues)
|
|
120
|
+
}
|
|
116
121
|
}
|
|
117
122
|
else {
|
|
118
|
-
|
|
123
|
+
const targetStepValue = formatStepValue(targetDistValue)
|
|
124
|
+
if (targetStepValue !== null) {
|
|
125
|
+
potentialValues.push(targetStepValue)
|
|
126
|
+
}
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
// Find close one
|