@@ -28,24 +28,32 @@ const output = ref<HTMLSpanElement>()
2828const inputWidth = ref ()
2929
3030const double = computed (() => props .lowerValue !== undefined )
31+ const stepped = computed (() => props .step !== undefined )
3132
3233const outputStyle = computed (() => {
3334 if (props .lowerValue === undefined ) {
3435 const translateXValue = (props .modelValue - props .min ) / (props .max - props .min ) * inputWidth .value
35- return ` transform: translateX(${translateXValue }px) translateX(-${props . modelValue }%); `
36+ return ` transform: translateX(${translateXValue }px) translateX(-${translateXValue / inputWidth . value * 100 }%); `
3637 }
3738 const translateXValue = (props .modelValue + props .lowerValue - props .min ) / 2 / (props .max - props .min ) * inputWidth .value
3839 return ` transform: translateX(${translateXValue }px) translateX(-${props .lowerValue + ((props .modelValue - props .lowerValue ) / 2 )}%); `
3940})
4041
4142const rangeStyle = computed (() => {
42- const progressRight = (props .modelValue - props .min ) / (props .max - props .min ) * inputWidth .value - (double .value ? 12 : 0 )
43- const progressLeft = ((props .lowerValue ?? 0 ) - props .min ) / (props .max - props .min ) * inputWidth .value
43+ const range = props .max - props .min
44+
45+ const ratioRight = (props .modelValue - props .min ) / range
46+ const ratioLeft = ((props .lowerValue ?? 0 ) - props .min ) / range
47+
48+ const innerPadding = props .small ? 12 : 24
49+ const stepWidth = (inputWidth .value - innerPadding ) / (range / (props .step ?? 1 + 1 ))
50+ const paddingRight = double .value ? 32 * (1 - ratioRight ) : 0
4451
4552 return {
46- ' --progress-right' : ` ${progressRight + 24 }px ` ,
47- ... (double .value ? { ' --progress-left' : ` ${progressLeft + 12 }px ` } : {}),
48- }
53+ " --progress-right" : ` ${(ratioRight * inputWidth .value + paddingRight ).toFixed (2 )}px ` ,
54+ ... (double .value ? {" --progress-left" : ` ${(ratioLeft * inputWidth .value ).toFixed (2 )}px ` } : {}),
55+ ... (stepped .value ? {" --step-width" : ` ${Math .floor (stepWidth )}px ` } : {})
56+ };
4957})
5058
5159watch ([() => props .modelValue , () => props .lowerValue ], ([upper , lower ]) => {
@@ -97,6 +105,7 @@ onMounted(() => {
97105 data-fr-js-range =" true"
98106 :class =" {
99107 'fr-range--sm': small,
108+ 'fr-range--step': stepped,
100109 'fr-range--double': double,
101110 'fr-range-group--disabled': disabled,
102111 }"
@@ -171,3 +180,4 @@ onMounted(() => {
171180 </div >
172181 </div >
173182</template >
183+
0 commit comments