UNPKG

@julo-ui/otp-input

Version:

React Input Component for entering sequences of digits

110 lines (95 loc) 3.55 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/components/otp-input-field/OtpInputField.tsx var OtpInputField_exports = {}; __export(OtpInputField_exports, { default: () => OtpInputField_default }); module.exports = __toCommonJS(OtpInputField_exports); var import_system = require("@julo-ui/system"); // src/components/otp-input-field/use-otp-input-field.ts var import_dom_utils2 = require("@julo-ui/dom-utils"); // src/OtpInputProvider.tsx var import_context = require("@julo-ui/context"); // src/use-otp-input.ts var import_react = require("react"); var import_descendant = require("@chakra-ui/descendant"); var import_function_utils = require("@julo-ui/function-utils"); var import_dom_utils = require("@julo-ui/dom-utils"); var [ OtpInputDescendantsProvider, useOtpInputDescendantsContext, useOtpInputDescendants, useOtpInputDescendant ] = (0, import_descendant.createDescendantContext)(); // src/OtpInputProvider.tsx var import_jsx_runtime = require("react/jsx-runtime"); var [UseOtpInputProvider, useOtpInputContext] = (0, import_context.createContext)({ name: "UseOtpInputContext", providerName: "<UseOtpInputProvider />" }); // src/components/otp-input-field/use-otp-input-field.ts function useOtpInputField(props, ref = null) { const { getInputProps } = useOtpInputContext(); const { index, register } = useOtpInputDescendant(); return getInputProps({ ...props, ref: (0, import_dom_utils2.mergeRefs)(register, ref), index }); } // src/components/otp-input-field/styles.ts var import_react2 = require("@emotion/react"); var otpInputFieldCx = import_react2.css` width: 3rem; height: 2.875rem; padding: 0.75rem 0.8125rem; border: 1px solid var(--colors-neutrals-30); border-radius: var(--corner-md); text-align: center; &:focus, &:focus-visible { border-color: var(--colors-primary-20); } &:focus-visible { outline: none; } &:disabled { cursor: not-allowed; border-color: var(--colors-neutrals-50); background-color: var(--colors-neutrals-30); } &[aria-invalid='true'] { border-color: var(--colors-red-30); } `; // src/components/otp-input-field/OtpInputField.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var OtpInputField = (0, import_system.forwardRef)((props, ref) => { const { className, ...resProps } = props; const inputProps = useOtpInputField(resProps, ref); return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( import_system.julo.input, { className: (0, import_system.cx)("julo-otp-input__field", className), ...inputProps, __css: otpInputFieldCx } ); }); OtpInputField.displayName = "OtpInputField"; var OtpInputField_default = OtpInputField; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = {});