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)

59 lines (58 loc) 1.97 kB
import { jsx as r } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js"; import { useState as C, useRef as R, useMemo as i, useCallback as m } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js"; import x from "../../../../hooks/useTimezoneAwareDateFormatting.js"; import { CalendarInputButton as F } from "./components/CalendarInputButton.js"; import { CalendarInputPopover as L } from "./components/CalendarInputPopover.js"; import S from "../../../../core/Context/preact/useCoreContext.js"; import { DATE_FORMAT_DELIVERY_DATE as _ } from "../../../../constants/dateFormats.js"; function j({ clearable: l, value: t, onInput: o, isInvalid: u, timezone: D, isReadOnly: T }) { const { i18n: s } = S(), { dateFormat: p } = x(D), [c, n] = C(!1), f = R(null), h = i(() => t ? [new Date(t)] : void 0, [t]), O = i( () => t ? p(t, _) : s.get("common.inputs.select.placeholder"), [p, s, t] ), [d, g] = C(t), b = m( (e) => s.get("common.filters.types.date.calendar.label", { values: { monthOfYear: e.label } }), [s] ), A = m( (e) => { if (e) { const a = new Date(e).toISOString(); o(a), g(a), a !== d && n(!1); } }, [d, o] ), E = i(() => !!l && !!t, [l, t]), w = m( (e) => { e?.preventDefault?.(), e?.stopPropagation?.(), o(""), g(void 0), n(!1); }, [o] ); return /* @__PURE__ */ r("div", { children: [ /* @__PURE__ */ r( F, { label: O, isOpen: c, isInvalid: u, onClick: () => n((e) => !e), showClearButton: E, onClear: w, buttonRef: f, isReadOnly: T } ), /* @__PURE__ */ r( L, { isOpen: c, onClose: () => n(!1), originDate: h, onHighlight: A, getGridLabel: b, targetElement: f } ) ] }); } export { j as CalendarInput };