jb-number-input-react
Version:
number input react component
67 lines (64 loc) • 2.68 kB
JavaScript
import React, { forwardRef, useRef, useState, useImperativeHandle, useEffect } from 'react';
import 'jb-number-input';
import { useJBInputAttribute, useJBInputEvents } from 'jb-input-react';
// eslint-disable-next-line react/display-name
const JBNumberInput = forwardRef((props, ref) => {
const element = useRef(null);
const [refChangeCount, refChangeCountSetter] = useState(0);
useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
//to force rerender for events
useEffect(() => {
refChangeCountSetter(refChangeCount + 1);
}, [element.current]);
useJBInputAttribute(element, props);
useJBInputEvents(element, props);
useEffect(() => {
if (element?.current) {
element.current.minValue = props.minValue;
}
}, [props.minValue]);
useEffect(() => {
if (element.current) {
element.current.maxValue = props.maxValue;
}
}, [props.maxValue]);
useEffect(() => {
if (element.current && props.acceptNegative !== undefined) {
element.current.acceptNegative = props.acceptNegative;
}
}, [props.acceptNegative]);
useEffect(() => {
if (element.current) {
element.current.decimalPrecision = props.decimalPrecision;
}
}, [props.decimalPrecision]);
useEffect(() => {
if (element.current && typeof props.showControlButton == "boolean") {
element.current.showControlButton = props.showControlButton;
}
}, [props.showControlButton]);
useEffect(() => {
if (element.current && typeof props.showThousandSeparator == "boolean") {
element.current.showThousandSeparator = props.showThousandSeparator;
}
}, [props.showThousandSeparator]);
useEffect(() => {
if (element.current && typeof props.thousandSeparator == "string") {
element.current.thousandSeparator = props.thousandSeparator;
}
}, [props.thousandSeparator]);
useEffect(() => {
if (element.current && typeof props.step == "number") {
element.current.step = props.step;
}
}, [props.step]);
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";
export { JBNumberInput };
//# sourceMappingURL=JBNumberInput.js.map