@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
190 lines (152 loc) • 6.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
isNull: true,
clamp: true,
clampValue: true,
getOptimumValue: true,
valueToPercent: true,
isFunction: true,
isTouch: true,
dataAttr: true,
ariaAttr: true,
cx: true,
kebabCase: true,
splitStateProps: true
};
exports.ariaAttr = void 0;
exports.clamp = clamp;
exports.clampValue = clampValue;
exports.dataAttr = exports.cx = void 0;
exports.getOptimumValue = getOptimumValue;
exports.isFunction = isFunction;
exports.isNull = void 0;
exports.isTouch = isTouch;
exports.kebabCase = kebabCase;
exports.splitStateProps = splitStateProps;
exports.valueToPercent = valueToPercent;
var _reakitUtils = require("reakit-utils");
var _utils = require("@chakra-ui/utils");
var _date = require("./date");
Object.keys(_date).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _date[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _date[key];
}
});
});
var _useControllableState = require("./useControllableState");
Object.keys(_useControllableState).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useControllableState[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _useControllableState[key];
}
});
});
var _useControlledState = require("./useControlledState");
Object.keys(_useControlledState).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useControlledState[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _useControlledState[key];
}
});
});
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
// Null Assertion
var isNull = function isNull(value) {
return value == null;
};
exports.isNull = isNull;
function clamp(value) {
var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity;
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
return Math.min(Math.max(value, min), max);
}
/**
* Clamps a value to ensure it stays within the min and max range.
*
* @param value the value to clamp
* @param min the minimum value
* @param max the maximum value
*
* @see https://github.com/chakra-ui/chakra-ui/blob/c38892760257b9bbf1b63c05f7f9ccf1684a90b0/packages/utils/src/number.ts
*/
function clampValue(value, min, max) {
if (isNull(value)) return value;
(0, _utils.warn)({
condition: max < min,
message: "clamp: max cannot be less than min"
});
return Math.min(Math.max(value, min), max);
}
/**
* The candidate optimum point is the midpoint between the minimum value and
* the maximum value.
*
* @see https://html.spec.whatwg.org/multipage/form-elements.html#the-meter-element:attr-meter-high-8:~:text=boundary.-,The%20optimum%20point
*/
function getOptimumValue(min, max) {
return max < min ? min : min + (max - min) / 2;
}
/**
* Convert a value to percentage based on lower and upper bound values
*
* @param value the value in number
* @param min the minimum value
* @param max the maximum value
*/
function valueToPercent(value, min, max) {
return (value - min) * 100 / (max - min);
} // Function assertions
function isFunction(value) {
return typeof value === "function";
}
function isTouch() {
return Boolean("ontouchstart" in window || window.navigator.maxTouchPoints > 0 || // @ts-ignore
window.navigator.msMaxTouchPoints > 0);
}
var dataAttr = function dataAttr(condition) {
return condition ? "" : undefined;
};
exports.dataAttr = dataAttr;
var ariaAttr = function ariaAttr(condition) {
return condition ? true : undefined;
};
exports.ariaAttr = ariaAttr;
var cx = function cx() {
for (var _len = arguments.length, classNames = new Array(_len), _key = 0; _key < _len; _key++) {
classNames[_key] = arguments[_key];
}
return classNames.filter(Boolean).join(" ");
};
exports.cx = cx;
function kebabCase(string) {
return string.toLowerCase().replace(/[^a-z0-9]/g, "-");
} // Split state props
function splitStateProps(props, keys) {
var _splitProps = (0, _reakitUtils.splitProps)(props, keys),
_splitProps2 = _slicedToArray(_splitProps, 2),
stateProps = _splitProps2[0],
otherProps = _splitProps2[1];
return [stateProps, otherProps];
}
//# sourceMappingURL=index.js.map