From f4f798b1b4bae3073b669a562fd2b3a7880dffc3 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 15 May 2023 11:45:23 -0300 Subject: second form --- .../src/handlers/InputDate.tsx | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 packages/exchange-backoffice-ui/src/handlers/InputDate.tsx (limited to 'packages/exchange-backoffice-ui/src/handlers/InputDate.tsx') diff --git a/packages/exchange-backoffice-ui/src/handlers/InputDate.tsx b/packages/exchange-backoffice-ui/src/handlers/InputDate.tsx new file mode 100644 index 000000000..00dd59996 --- /dev/null +++ b/packages/exchange-backoffice-ui/src/handlers/InputDate.tsx @@ -0,0 +1,35 @@ +import { AbsoluteTime } from "@gnu-taler/taler-util"; +import { InputLine, UIFormProps } from "./InputLine.js"; +import { CalendarIcon } from "@heroicons/react/24/outline"; +import { VNode, h } from "preact"; +import { format, parse } from "date-fns"; + +export function InputDate( + props: { pattern?: string } & UIFormProps, +): VNode { + const pattern = props.pattern ?? "dd/MM/yyyy"; + return ( + + type="text" + after={{ + type: "icon", + icon: , + }} + converter={{ + fromStringUI: (v) => { + if (!v) return { t_ms: "never" }; + const t_ms = parse(v, pattern, Date.now()).getTime(); + return { t_ms }; + }, + toStringUI: (v) => { + return !v || !v.t_ms + ? "" + : v.t_ms === "never" + ? "never" + : format(v.t_ms, pattern); + }, + }} + {...props} + /> + ); +} -- cgit v1.2.3