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

46 lines (37 loc) 1.17 kB
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 */ export function isFloatingPointNumericCharacter(character) { return FLOATING_POINT_REGEX.test(character); } export var sanitize = value => 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 */ export 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); } export function getStepFactor(event) { var ratio = 1; if (event.metaKey || event.ctrlKey) { ratio = 0.1; } if (event.shiftKey) { ratio = 10; } return ratio; } export * from "./useSpinner"; //# sourceMappingURL=index.js.map