@airplane/views
Version:
A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.
49 lines (48 loc) • 1.68 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import React__default, { useRef, useCallback } from "react";
import { ComponentErrorBoundary } from "../errorBoundary/ComponentErrorBoundary.js";
import { useRegisterFormInput } from "../../state/components/form/useRegisterFormInput.js";
import { useInput } from "../../state/components/input/useInput.js";
import { useCodeInputState } from "../../state/components/text-input/useTextInputState.js";
import { useComponentId } from "../../state/components/useId.js";
const CodeInputComponent = /* @__PURE__ */ React__default.lazy(() => import("./CodeInputComponent.js"));
const CodeInput = ({
id,
defaultValue,
defaultDisabled,
validate,
required,
onChange,
...restProps
}) => {
id = useComponentId(id);
const ref = useRef({});
const focus = useCallback(() => {
var _a, _b;
(_b = (_a = ref.current) == null ? void 0 : _a.view) == null ? void 0 : _b.focus();
}, []);
const {
state,
dispatch
} = useCodeInputState(id, {
initialState: {
disabled: restProps.disabled ?? defaultDisabled,
value: restProps.value ?? defaultValue
},
focus
});
const {
inputProps
} = useInput({
validate,
required,
onChange
}, state, dispatch, (v) => v);
useRegisterFormInput(id, "text-input");
return /* @__PURE__ */ jsx(ComponentErrorBoundary, { componentName: CodeInput.displayName, children: /* @__PURE__ */ jsx(React__default.Suspense, { fallback: null, children: /* @__PURE__ */ jsx(CodeInputComponent, { innerRef: ref, required, ...inputProps, ...restProps }) }) });
};
CodeInput.displayName = "CodeInput";
export {
CodeInput
};
//# sourceMappingURL=CodeInput.js.map