@adyen/kyc-components
Version:
This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.
53 lines (52 loc) • 2.26 kB
JavaScript
try {
let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "f826ef62-124e-4fb7-a785-330bafd53b5b", e._sentryDebugIdIdentifier = "sentry-dbid-f826ef62-124e-4fb7-a785-330bafd53b5b");
} catch (e) {}
import { r as InputBase } from "./InputText-C30dZxS4.js";
import { useMemo } from "preact/hooks";
import { jsx } from "preact/jsx-runtime";
//#region src/components/ui/molecules/InputDate/InputDate.utils.ts
/**
* Returns either the date input is supported or not in the current browser
*/
var checkDateInputSupport = () => {
const input = document.createElement("input");
input.setAttribute("type", "date");
return input.type === "date";
};
/**
* Returns a formatted date
* @param value -
* @example
* formatDate('22111990');
* // '22/11/1990'
*/
var formatDate = (value) => {
const date = value.replace(/\D|\s/g, "").replace(/^(00)(.*)?/, "01$2").replace(/^(3[2-9])(.*)?/, "0$1$2").replace(/^([4-9])(.*)?/, "0$1").replace(/^([0-9]{2})(00)(.*)?/, "$101").replace(/^(3[01])(02)(.*)?/, "29$2").replace(/^([0-9]{2})([2-9]|1[3-9])(.*)?/, "$10$2").replace(/^([0-9]{2})([0-9]{2})([0-9])/, "$1/$2/$3").replace(/^([0-9]{2})([0-9])/, "$1/$2");
const [day = "", month = "", year = ""] = date.split("/");
if (year.length === 4 && day === "29" && month === "02" && (Number(year) % 4 !== 0 || year.substring(2, 4) === "00" && Number(year) % 400 !== 0)) return date.replace(/^29/, "28");
return date;
};
var formatDateObj = (date) => date.toJSON().slice(0, 10);
//#endregion
//#region src/components/ui/molecules/InputDate/InputDate.tsx
function InputDate(props) {
const isDateInputSupported = useMemo(checkDateInputSupport, []);
const { onInput } = props;
const handleInput = (e) => {
const { value } = e.currentTarget;
e.currentTarget.value = formatDate(value);
onInput(e);
};
if (isDateInputSupported) return /* @__PURE__ */ jsx(InputBase, {
...props,
type: "date"
});
return /* @__PURE__ */ jsx(InputBase, {
...props,
onInput: handleInput,
maxLength: 10
});
}
//#endregion
export { formatDateObj as n, InputDate as t };