@hitachivantara/uikit-react-core
Version:
Core React components for the NEXT Design System.
53 lines (52 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const Context = require("../../../Context.cjs");
const TextValue_styles = require("./TextValue.styles.cjs");
const Input = require("../../../../Input/Input.cjs");
const TextValue = ({
id,
value = "",
initialTouched = false
}) => {
const { classes } = TextValue_styles.useClasses();
const { labels, dispatchAction, readOnly } = Context.useQueryBuilderContext();
const [touched, setTouched] = React.useState(initialTouched);
const isValid = value != null && value.toString().trim() !== "";
let status = isValid ? "valid" : "invalid";
status = !touched ? "standBy" : status;
return /* @__PURE__ */ jsxRuntime.jsx(
Input.HvInput,
{
className: classes.location,
label: labels.rule.value.text.label,
required: true,
status,
statusMessage: labels.rule.value.text.validation.required,
value,
inputProps: {
autoComplete: "off"
},
onChange: (t, v) => {
dispatchAction({
type: "set-value",
id,
value: v
});
},
onBlur: () => {
setTouched(true);
},
onKeyDown: (e) => {
if (e.key === "Enter") {
e.preventDefault();
}
},
placeholder: "—",
readOnly
}
);
};
React.memo(TextValue);
exports.TextValue = TextValue;