mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Clamp indicated value within value range
This commit is contained in:
parent
ba362b727c
commit
c99e1de803
1 changed files with 11 additions and 0 deletions
|
@ -34,6 +34,17 @@ type IProps = {
|
|||
|
||||
export default class Slider extends React.Component<IProps> {
|
||||
_offset(values: number[], value: number): number {
|
||||
const lowest = values[0];
|
||||
const highest = values[values.length - 1];
|
||||
|
||||
if (value < lowest) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (value > highest) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
return (value - values[0]) / (values[values.length - 1] - values[0]) * 100;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue