mirror of
https://github.com/element-hq/element-web.git
synced 2024-11-30 23:31:28 +03:00
Cleaner clamping of value range
This commit is contained in:
parent
8d5965c33c
commit
26ccd6f07d
1 changed files with 5 additions and 10 deletions
|
@ -34,18 +34,13 @@ type IProps = {
|
||||||
|
|
||||||
export default class Slider extends React.Component<IProps> {
|
export default class Slider extends React.Component<IProps> {
|
||||||
_offset(values: number[], value: number): number {
|
_offset(values: number[], value: number): number {
|
||||||
const lowest = values[0];
|
const min = values[0];
|
||||||
const highest = values[values.length - 1];
|
const max = values[values.length - 1];
|
||||||
|
|
||||||
if (value < lowest) {
|
// Clamp value between min and max
|
||||||
return 0;
|
value = Math.min(Math.max(value, min), max);
|
||||||
}
|
|
||||||
|
|
||||||
if (value > highest) {
|
return (value - min) / (max - min) * 100;
|
||||||
return 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (value - values[0]) / (values[values.length - 1] - values[0]) * 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): React.ReactNode {
|
render(): React.ReactNode {
|
||||||
|
|
Loading…
Reference in a new issue