UNPKG

@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

50 lines (42 loc) 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useProgressState = useProgressState; var _react = require("react"); var _utils = require("./__utils"); 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; } /** * Provides state for the `Progress` components. * @example * ```jsx * const progress = useProgressState(); * <Progress state={progress} /> * ``` */ function useProgressState() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$value = _ref.value, defaultValue = _ref$value === void 0 ? 0 : _ref$value, _ref$min = _ref.min, min = _ref$min === void 0 ? 0 : _ref$min, _ref$max = _ref.max, max = _ref$max === void 0 ? 100 : _ref$max, props = _objectWithoutProperties(_ref, _excluded); var value = (0, _utils.clamp)(defaultValue, min, max); var isIndeterminate = value == null; var percent = isIndeterminate ? null : (0, _utils.valueToPercent)(value, min, max); var state = (0, _react.useMemo)(function () { return { value: value, min: min, max: max, isIndeterminate: isIndeterminate, percent: percent }; }, [value, min, max, isIndeterminate, percent]); return state; } //# sourceMappingURL=progress-state.js.map