UNPKG

@renderlesskit/react

Version:

Collection of headless components/hooks that are accessible, composable, customizable from low level to build your own UI & Design System powered by Reakit

48 lines (42 loc) 1.33 kB
import { isNull } from "../utils"; /** * Handle Inequalities with received values * * minimum ≤ value ≤ maximum * minimum ≤ low ≤ maximum (if low is specified) * minimum ≤ high ≤ maximum (if high is specified) * minimum ≤ optimum ≤ maximum (if optimum is specified) * * @see https://html.spec.whatwg.org/multipage/form-elements.html#the-meter-element:attr-meter-max-3:~:text=following%20inequalities%20must%20hold */ export function clamp(value, min, max) { if (isNull(value)) return 0; return Math.min(Math.max(value, min), max); } export var calculateStatus = props => { var { value, optimum, min, max, low, high } = props; // This check always comes first if (isInRange(optimum, low, high)) { if (isInRange(value, low, high)) return "safe"; return "caution"; } if (isInRange(optimum, min, low)) { if (isInRange(value, min, low)) return "safe"; if (value > low && value <= high) return "caution"; return "danger"; } if (isInRange(optimum, high, max)) { if (isInRange(value, high, max)) return "safe"; if (value < high && value >= low) return "caution"; return "danger"; } // A safe return return "safe"; }; export var isInRange = (value, min, max) => value >= min && value <= max; //# sourceMappingURL=helpers.js.map