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

64 lines (52 loc) 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useMeterState = void 0; var _utils = require("../utils"); var _helpers = require("./helpers"); var _excluded = ["value", "min", "max"]; function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var useMeterState = function useMeterState() { var _sealed$low, _sealed$high, _sealed$optimum; var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var _props$value = props.value, defaultValue = _props$value === void 0 ? 0 : _props$value, _props$min = props.min, min = _props$min === void 0 ? 0 : _props$min, _props$max = props.max, max = _props$max === void 0 ? 1 : _props$max, sealed = _objectWithoutProperties(props, _excluded); var initialLow = (_sealed$low = sealed.low) !== null && _sealed$low !== void 0 ? _sealed$low : min; var initialHigh = (_sealed$high = sealed.high) !== null && _sealed$high !== void 0 ? _sealed$high : max; var initialOptimum = (_sealed$optimum = sealed.optimum) !== null && _sealed$optimum !== void 0 ? _sealed$optimum : (0, _utils.getOptimumValue)(initialLow, initialHigh); var value = (0, _helpers.clamp)(defaultValue, min, max); var optimum = (0, _helpers.clamp)(initialOptimum, min, max); var low = (0, _helpers.clamp)(initialLow, min, max); var high = (0, _helpers.clamp)(initialHigh, min, max); // More inequalities handled // low ≤ high (if both low and high are specified) if (low >= high) low = high; if (high <= low) high = low; var status = (0, _helpers.calculateStatus)({ value: value, min: min, max: max, low: low, optimum: optimum, high: high }); var percent = (0, _utils.valueToPercent)(value, min, max); return { value: value, min: min, max: max, low: low, optimum: optimum, high: high, status: status, percent: percent }; }; exports.useMeterState = useMeterState; //# sourceMappingURL=MeterState.js.map