@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
81 lines (65 loc) • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {
isFloatingPointNumericCharacter: true,
sanitize: true,
isValidNumericKeyboardEvent: true,
getStepFactor: true
};
exports.getStepFactor = getStepFactor;
exports.isFloatingPointNumericCharacter = isFloatingPointNumericCharacter;
exports.isValidNumericKeyboardEvent = isValidNumericKeyboardEvent;
exports.sanitize = void 0;
var _useSpinner = require("./useSpinner");
Object.keys(_useSpinner).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _useSpinner[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _useSpinner[key];
}
});
});
var FLOATING_POINT_REGEX = /^[Ee0-9+\-.]$/;
/**
* Determine if a character is a DOM floating point character
* @see https://www.w3.org/TR/2012/WD-html-markup-20120329/datatypes.html#common.data.float
*/
function isFloatingPointNumericCharacter(character) {
return FLOATING_POINT_REGEX.test(character);
}
var sanitize = function sanitize(value) {
return value.split("").filter(isFloatingPointNumericCharacter).join("");
};
/**
* Determine if the event is a valid numeric keyboard event.
* We use this so we can prevent non-number characters in the input
*/
exports.sanitize = sanitize;
function isValidNumericKeyboardEvent(event) {
if (event.key == null) return true;
var isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
if (isModifierKey) {
return true;
}
var isSingleCharacterKey = event.key.length === 1;
if (!isSingleCharacterKey) {
return true;
}
return isFloatingPointNumericCharacter(event.key);
}
function getStepFactor(event) {
var ratio = 1;
if (event.metaKey || event.ctrlKey) {
ratio = 0.1;
}
if (event.shiftKey) {
ratio = 10;
}
return ratio;
}
//# sourceMappingURL=index.js.map