@adaptui/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
39 lines (34 loc) • 1.71 kB
JavaScript
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; }
import { useMemo } from "react";
import { clamp, valueToPercent } from "./__utils";
/**
* Provides state for the `Progress` components.
* @example
* ```jsx
* const progress = useProgressState();
* <Progress state={progress} />
* ```
*/
export function useProgressState() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
{
value: defaultValue = 0,
min = 0,
max = 100
} = _ref,
props = _objectWithoutProperties(_ref, _excluded);
var value = clamp(defaultValue, min, max);
var isIndeterminate = value == null;
var percent = isIndeterminate ? null : valueToPercent(value, min, max);
var state = useMemo(() => ({
value,
min,
max,
isIndeterminate,
percent
}), [value, min, max, isIndeterminate, percent]);
return state;
}
//# sourceMappingURL=progress-state.js.map