Skip to content

Commit fe544d9

Browse files
authored
Operator slider even values only (#1050)
1 parent 3f3e281 commit fe544d9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/components/pricing/PriceCalculator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ export default function PriceCalculator({ period, tier, selectedOption }) {
463463
<Slider
464464
min={0}
465465
max={pricing.seat.max * 2}
466-
step={1}
466+
step={2}
467467
defaultValue={clamp(operators, 0, pricing.seat.max * 2)}
468468
onChange={(value) => {
469469
setOperators(clamp(value, 0, pricing.seat.max * 2));

src/components/pricing/Slider.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import React, { useState, useEffect } from 'react';
22

3-
function exponentialScale(displayValue, min, max) {
3+
function exponentialScale(displayValue, min, max, step = 1) {
44
const scale = max / Math.log(max + 1);
55
let value = Math.exp(displayValue / scale) - 1;
66

7-
// Dynamically generate round numbers based on max value
7+
// If step is provided and greater than 1, ensure we only return values that are multiples of step
8+
if (step > 1) {
9+
// Round to the nearest step
10+
value = Math.round(value / step) * step;
11+
return Math.min(Math.max(value, min), max);
12+
}
13+
14+
// Dynamically generate round numbers based on max value (only when step is 1)
815
const roundNumbers = [];
916
const magnitude = Math.floor(Math.log10(max));
1017
const base = Math.pow(10, magnitude);
@@ -54,7 +61,12 @@ export default function Slider({ min, max, step, defaultValue, onChange, noExpon
5461
let newValue = parseFloat(parseFloat(event.target.value).toFixed(2));
5562
if (isExponential) {
5663
// Convert from visual scale back to actual value and snap to round numbers
57-
newValue = exponentialScale(newValue, min, max);
64+
newValue = exponentialScale(newValue, min, max, step);
65+
} else {
66+
// For non-exponential sliders, ensure step compliance
67+
if (step > 1) {
68+
newValue = Math.round(newValue / step) * step;
69+
}
5870
}
5971
// Ensure value doesn't go below min
6072
newValue = Math.max(min, newValue);

0 commit comments

Comments
 (0)