UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

90 lines (89 loc) 2.68 kB
import { jsx as i } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js"; import { useMemo as v, useCallback as I } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js"; import { useWizardFormContext as O } from "../../../hooks/form/wizard/WizardFormContext.js"; import R from "./FormField.js"; import $ from "../FormFields/InputBase.js"; import { VisibleField as j } from "./VisibleField.js"; import k from "../../../core/Context/preact/useCoreContext.js"; import { Controller as z } from "../../../hooks/form/Controller.js"; function Q({ className: g, dropdown: C, fieldName: r, isRequired: a, isReadOnly: c, label: x, onDropdownInput: F, onInput: l, supportText: T, type: h, validate: m, min: q, maxLength: V, minLength: t, dropdownPosition: y, hideOptionalLabel: M }) { const { control: b, fieldsConfig: e } = O(), { i18n: d } = k(), s = v(() => a ?? e[r]?.required, [e, r, a]), f = v(() => c ?? e[r]?.readOnly, [e, r, c]), w = I( (o, n) => { l?.(o), n(o.currentTarget.value); }, [l] ), B = I( (o) => { const n = t && o?.length < t; return !o && !s ? { valid: !0 } : n ? { valid: !1, message: d.get("common.errors.minLength", { values: { minLength: t } }) } : m?.(o) ?? { valid: !0 }; }, [d, s, t, m] ); return /* @__PURE__ */ i(j, { name: r, children: /* @__PURE__ */ i( R, { label: x, optional: !s && !M, supportText: T, className: g, testId: r ? `form-field-${r}` : void 0, children: /* @__PURE__ */ i( z, { name: r, control: b, rules: { validate: B, required: s }, render: ({ field: o, fieldState: n }) => { const p = !!n.error && n.isTouched; return /* @__PURE__ */ i( $, { ...o, value: o.value, maxLength: V, minLength: t, name: r, isValid: !n.error, isInvalid: p, errorMessage: n.error?.message, errorTestId: r ? `field-error-${r}` : void 0, onDropdownInput: (...u) => { F?.(...u), p && o.triggerValidation(); }, onInput: (u) => w(u, o.onInput), type: h, min: q, dropdown: C, dropdownPosition: y, readonly: f } ); } } ) } ) }); } export { Q as FormTextInput };