From cb535460350bd510dd4b2b7d6bc3c6ec5f5bcdf1 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Wed, 10 May 2023 00:53:37 -0300
Subject: almost first document

---
 .../exchange-backoffice-ui/src/forms/InputDate.tsx | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 packages/exchange-backoffice-ui/src/forms/InputDate.tsx

(limited to 'packages/exchange-backoffice-ui/src/forms/InputDate.tsx')

diff --git a/packages/exchange-backoffice-ui/src/forms/InputDate.tsx b/packages/exchange-backoffice-ui/src/forms/InputDate.tsx
new file mode 100644
index 000000000..c9e1421f8
--- /dev/null
+++ b/packages/exchange-backoffice-ui/src/forms/InputDate.tsx
@@ -0,0 +1,36 @@
+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<AbsoluteTime>,
+): VNode {
+  const pattern = props.pattern ?? "dd/MM/yyyy";
+  return (
+    <InputLine<AbsoluteTime>
+      type="text"
+      after={{
+        type: "icon",
+        icon: <CalendarIcon class="h-6 w-6" />,
+      }}
+      converter={{
+        fromStringUI: (v) => {
+          if (!v) return { t_ms: "never" };
+          console.log("from", v);
+          const t_ms = parse(v, pattern, Date.now()).getTime();
+          return { t_ms };
+        },
+        toStringUI: (v) => {
+          return v === undefined
+            ? ""
+            : v.t_ms === "never"
+            ? "never"
+            : format(v.t_ms, pattern);
+        },
+      }}
+      {...props}
+    />
+  );
+}
-- 
cgit v1.2.3

