UNPKG

@stanfordspezi/spezi-web-design-system

Version:

Stanford Biodesign Digital Health Spezi Web Design System

58 lines (57 loc) 1.57 kB
import { jsxs as g, jsx as a } from "react/jsx-runtime"; import { c as p } from "./index-2NvaPZWc.mjs"; import { S as N, f as b, g as V, a as T, d as x } from "./Select-6uAWOsbr.mjs"; const u = [0, 30], l = (t, e) => { const n = t.toString().padStart(2, "0"), o = e.toString().padStart(2, "0"); return `${n}:${o}`; }, v = (t, e) => new Date(2e3, 0, 1, t, e).toLocaleTimeString(void 0, { hour: "numeric", minute: "2-digit" }), c = []; for (let t = 0; t < 24; t += 1) for (const e of u) c.push({ value: l(t, e), label: v(t, e), hours: t, minutes: e }); const w = ({ id: t, value: e, onChange: n, placeholder: o = "Select time", className: m, ...d }) => { const h = (r) => { const [S, f] = r.split(":"), s = Number.parseInt(S, 10), i = Number.parseInt(f, 10); Number.isNaN(s) || Number.isNaN(i) || s < 0 || s > 23 || !u.includes(i) || n({ hours: s, minutes: i }); }; return /* @__PURE__ */ g( N, { value: (() => { if (e && !(e.hours < 0 || e.hours > 23 || !u.includes(e.minutes))) return l(e.hours, e.minutes); })(), onValueChange: h, ...d, children: [ /* @__PURE__ */ a(b, { id: t, className: p("w-full", m), children: /* @__PURE__ */ a(V, { placeholder: o }) }), /* @__PURE__ */ a(T, { children: c.map((r) => /* @__PURE__ */ a( x, { value: r.value, itemText: r.label, children: r.label }, r.value )) }) ] } ); }; export { w as T };