jb-number-input-react
Version:
number input react component
71 lines (67 loc) • 3.3 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('jb-number-input'), require('jb-input-react')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'jb-number-input', 'jb-input-react'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JBNumberInput = {}, global.React, global.JBNumberInput, global.JBInputReact));
})(this, (function (exports, React, jbNumberInput, jbInputReact) { 'use strict';
// eslint-disable-next-line react/display-name
const JBNumberInput = React.forwardRef((props, ref) => {
const element = React.useRef(null);
const [refChangeCount, refChangeCountSetter] = React.useState(0);
React.useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
//to force rerender for events
React.useEffect(() => {
refChangeCountSetter(refChangeCount + 1);
}, [element.current]);
jbInputReact.useJBInputAttribute(element, props);
jbInputReact.useJBInputEvents(element, props);
React.useEffect(() => {
if (element?.current) {
element.current.minValue = props.minValue;
}
}, [props.minValue]);
React.useEffect(() => {
if (element.current) {
element.current.maxValue = props.maxValue;
}
}, [props.maxValue]);
React.useEffect(() => {
if (element.current && props.acceptNegative !== undefined) {
element.current.acceptNegative = props.acceptNegative;
}
}, [props.acceptNegative]);
React.useEffect(() => {
if (element.current) {
element.current.decimalPrecision = props.decimalPrecision;
}
}, [props.decimalPrecision]);
React.useEffect(() => {
if (element.current && typeof props.showControlButton == "boolean") {
element.current.showControlButton = props.showControlButton;
}
}, [props.showControlButton]);
React.useEffect(() => {
if (element.current && typeof props.showThousandSeparator == "boolean") {
element.current.showThousandSeparator = props.showThousandSeparator;
}
}, [props.showThousandSeparator]);
React.useEffect(() => {
if (element.current && typeof props.thousandSeparator == "string") {
element.current.thousandSeparator = props.thousandSeparator;
}
}, [props.thousandSeparator]);
React.useEffect(() => {
if (element.current && typeof props.step == "number") {
element.current.step = props.step;
}
}, [props.step]);
React.useEffect(() => {
if (element.current && typeof props.showPersianNumber == "boolean") {
element.current.showPersianNumber = props.showPersianNumber;
}
}, [props.showPersianNumber]);
return (React.createElement("jb-number-input", { ref: element, class: props.className }, props.children));
});
JBNumberInput.displayName = "JBNumberInput";
exports.JBNumberInput = JBNumberInput;
}));
//# sourceMappingURL=JBNumberInput.umd.js.map