@react-awesome-query-builder/mui
Version:
User-friendly query builder for React. MUI 5 widgets
61 lines (59 loc) • 2.09 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import React, { useMemo } from "react";
import TextField from "@mui/material/TextField";
import FormControl from "@mui/material/FormControl";
import InputAdornment from "@mui/material/InputAdornment";
import { Utils } from "@react-awesome-query-builder/ui";
var _Utils$NumberFormat = Utils.NumberFormat,
NumericFormat = _Utils$NumberFormat.NumericFormat,
getNumberFormatProps = _Utils$NumberFormat.getNumberFormatProps;
export default (function (props) {
var value = props.value,
setValue = props.setValue,
readonly = props.readonly,
min = props.min,
max = props.max,
step = props.step,
placeholder = props.placeholder,
customProps = props.customProps,
prefix = props.prefix,
suffix = props.suffix;
var numericFormatProps = getNumberFormatProps(props, ["prefix", "suffix"]);
var handleChange = function handleChange(values) {
var val = values.floatValue;
setValue(val === undefined ? null : val);
};
var formattedValue = value == undefined ? "" : value;
var InputProps = useMemo(function () {
return {
readOnly: readonly,
startAdornment: prefix != undefined ? /*#__PURE__*/React.createElement(InputAdornment, {
position: "start"
}, prefix) : undefined,
endAdornment: suffix != undefined ? /*#__PURE__*/React.createElement(InputAdornment, {
position: "end"
}, suffix) : undefined
};
}, [readonly]);
// will not work without prop type="number"
// const inputProps = useMemo(
// () => ({
// min,
// max,
// }),
// [min, max, step]
// );
return /*#__PURE__*/React.createElement(FormControl, null, /*#__PURE__*/React.createElement(NumericFormat, _extends({
size: "small",
customInput: TextField,
value: formattedValue,
placeholder: !readonly ? placeholder : "",
InputProps: InputProps
//inputProps={inputProps}
,
disabled: readonly,
onValueChange: handleChange,
variant: "standard"
//type="number"
}, customProps, numericFormatProps)));
});