@yuno-payments/dashboard-design-system 0.0.112 → 0.0.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,17 +25,45 @@ export interface TimePickerProps extends Omit<TimePickerPrimitiveProps, "onChang
25
25
  * Callback fired when the time value changes
26
26
  */
27
27
  onChange?: (value: string) => void;
28
+ /**
29
+ * Picker mode
30
+ * - "native": HTML5 native input (default)
31
+ * - "dropdown": Custom dropdown with columns
32
+ * @default "native"
33
+ */
34
+ mode?: "native" | "dropdown";
35
+ /**
36
+ * Minute intervals (only for mode="dropdown")
37
+ * 0 = all minutes, 15 = every 15 minutes, etc.
38
+ * @default 0
39
+ */
40
+ divisorMinutes?: number;
41
+ /**
42
+ * Width of the picker (only for mode="dropdown")
43
+ * @default 140
44
+ */
45
+ width?: number | string;
28
46
  }
29
47
  /**
30
48
  * Time input picker with label, description, and error handling.
49
+ * Supports two modes: native HTML5 input or custom dropdown.
31
50
  *
32
51
  * @example
33
52
  * ```tsx
53
+ * // Native mode (default)
34
54
  * <TimePicker
35
55
  * label="Select time"
36
56
  * value={time}
37
57
  * onChange={(value) => setTime(value)}
38
58
  * />
59
+ *
60
+ * // Dropdown mode with 15-minute intervals
61
+ * <TimePicker
62
+ * mode="dropdown"
63
+ * divisorMinutes={15}
64
+ * value={time}
65
+ * onChange={(value) => setTime(value)}
66
+ * />
39
67
  * ```
40
68
  */
41
69
  declare const TimePicker: React.ForwardRefExoticComponent<TimePickerProps & React.RefAttributes<HTMLInputElement>>;
@@ -1,56 +1,212 @@
1
1
  import { j as e } from "../../../_virtual/jsx-runtime.js";
2
- import * as v from "react";
3
- import { useId as h } from "react";
4
- import { cn as c } from "../../../lib/utils.js";
5
- import { TimePicker as j } from "../../../vendor/shadcn/time-picker.js";
6
- import { Field as k, FieldLabel as P, FieldDescription as F, FieldError as g } from "../../../vendor/shadcn/field.js";
7
- const T = v.forwardRef(
2
+ import * as U from "react";
3
+ import { useId as B, useState as k, useRef as I, useEffect as S } from "react";
4
+ import { cn as s } from "../../../lib/utils.js";
5
+ import { Icon as W } from "../icon/icon.js";
6
+ import { TimePicker as q } from "../../../vendor/shadcn/time-picker.js";
7
+ import { Field as C, FieldLabel as E, FieldDescription as T, FieldError as R } from "../../../vendor/shadcn/field.js";
8
+ const G = Array.from({ length: 12 }, (t, n) => n + 1), J = ["AM", "PM"], K = (t) => {
9
+ if (t === 0)
10
+ return Array.from({ length: 60 }, (o, i) => i);
11
+ const n = 60 / t;
12
+ return Array.from({ length: n }, (o, i) => i * t);
13
+ }, u = (t) => t.toString().padStart(2, "0"), Q = (t) => {
14
+ const n = t >= 12 ? "PM" : "AM";
15
+ return { hour: t === 0 ? 12 : t > 12 ? t - 12 : t, meridiem: n };
16
+ }, X = (t, n) => t === 12 ? n === "AM" ? 0 : 12 : n === "PM" ? t + 12 : t, Y = U.forwardRef(
8
17
  ({
9
- className: o,
10
- label: s,
11
- error: i,
12
- description: r,
13
- orientation: m = "vertical",
14
- id: n,
15
- onChange: l,
16
- ...f
17
- }, x) => {
18
- const p = h(), t = n || p, d = !!i, a = /* @__PURE__ */ e.jsx(
19
- j,
20
- {
21
- ref: x,
22
- id: t,
23
- className: c(
24
- d && "border-destructive focus-visible:border-destructive",
25
- !(s || i || r) && o
26
- ),
27
- "aria-invalid": d ? !0 : void 0,
28
- "aria-describedby": r || i ? `${t}-description` : void 0,
29
- ...f,
30
- onChange: (u) => {
31
- l?.(u.target.value);
18
+ className: t,
19
+ label: n,
20
+ error: o,
21
+ description: i,
22
+ orientation: x = "vertical",
23
+ id: c,
24
+ onChange: m,
25
+ mode: b = "native",
26
+ divisorMinutes: g = 0,
27
+ width: l = 140,
28
+ value: f,
29
+ disabled: y,
30
+ ...p
31
+ }, M) => {
32
+ const N = B(), a = c || N, v = !!o;
33
+ if (b === "native") {
34
+ const d = /* @__PURE__ */ e.jsx(
35
+ q,
36
+ {
37
+ ref: M,
38
+ id: a,
39
+ value: f,
40
+ disabled: y,
41
+ className: s(
42
+ v && "border-destructive focus-visible:border-destructive",
43
+ !(n || o || i) && t
44
+ ),
45
+ "aria-invalid": v ? !0 : void 0,
46
+ "aria-describedby": i || o ? `${a}-description` : void 0,
47
+ ...p,
48
+ onChange: (P) => {
49
+ m?.(P.target.value);
50
+ }
32
51
  }
33
- }
34
- );
35
- return s || i || r ? /* @__PURE__ */ e.jsxs(
36
- k,
52
+ );
53
+ return n || o || i ? /* @__PURE__ */ e.jsxs(
54
+ C,
55
+ {
56
+ orientation: x,
57
+ "data-invalid": v,
58
+ className: s("w-full", t),
59
+ children: [
60
+ n && /* @__PURE__ */ e.jsx(E, { htmlFor: a, children: n }),
61
+ /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-2 flex-1", children: [
62
+ d,
63
+ i && !o && /* @__PURE__ */ e.jsx(T, { id: `${a}-description`, children: i }),
64
+ o && /* @__PURE__ */ e.jsx(R, { id: `${a}-description`, children: o })
65
+ ] })
66
+ ]
67
+ }
68
+ ) : d;
69
+ }
70
+ return /* @__PURE__ */ e.jsx(
71
+ Z,
37
72
  {
38
- orientation: m,
39
- "data-invalid": d,
40
- className: c("w-full", o),
41
- children: [
42
- s && /* @__PURE__ */ e.jsx(P, { htmlFor: t, children: s }),
43
- /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-2 flex-1", children: [
44
- a,
45
- r && !i && /* @__PURE__ */ e.jsx(F, { id: `${t}-description`, children: r }),
46
- i && /* @__PURE__ */ e.jsx(g, { id: `${t}-description`, children: i })
47
- ] })
48
- ]
73
+ value: f || "12:00",
74
+ onChange: m,
75
+ divisorMinutes: g,
76
+ width: l,
77
+ label: n,
78
+ error: o,
79
+ description: i,
80
+ disabled: y,
81
+ className: t
49
82
  }
50
- ) : a;
83
+ );
51
84
  }
52
85
  );
53
- T.displayName = "TimePicker";
86
+ Y.displayName = "TimePicker";
87
+ const Z = ({
88
+ value: t,
89
+ onChange: n,
90
+ divisorMinutes: o,
91
+ width: i,
92
+ label: x,
93
+ error: c,
94
+ description: m,
95
+ disabled: b,
96
+ className: g
97
+ }) => {
98
+ const [l, f] = k(!1), y = I(null), p = I(null), M = (r) => {
99
+ const [h, O] = r.split(":"), _ = parseInt(h, 10) || 0, L = parseInt(O, 10) || 0, { hour: V, meridiem: z } = Q(_);
100
+ return { hour: V, minute: L, meridiem: z };
101
+ }, { hour: N, minute: a, meridiem: v } = M(t), [d, P] = k(N), [j, A] = k(a), [w, D] = k(v), F = K(o);
102
+ S(() => {
103
+ const r = X(d, w), h = `${u(r)}:${u(j)}`;
104
+ n?.(h);
105
+ }, [d, j, w, n]), S(() => {
106
+ const r = (h) => {
107
+ p.current && !p.current.contains(h.target) && f(!1);
108
+ };
109
+ if (l)
110
+ return document.addEventListener("mousedown", r), () => document.removeEventListener("mousedown", r);
111
+ }, [l]);
112
+ const H = `${u(d)}:${u(j)} ${w}`, $ = /* @__PURE__ */ e.jsxs(
113
+ "div",
114
+ {
115
+ ref: p,
116
+ className: s("relative inline-block", g),
117
+ style: { width: typeof i == "number" ? `${i}px` : i },
118
+ children: [
119
+ /* @__PURE__ */ e.jsxs(
120
+ "button",
121
+ {
122
+ type: "button",
123
+ disabled: b,
124
+ onClick: () => !b && f(!l),
125
+ className: s(
126
+ "flex items-center justify-between w-full h-9 px-3 py-2",
127
+ "text-sm rounded-md border border-input bg-background",
128
+ "hover:bg-accent hover:text-accent-foreground",
129
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
130
+ "disabled:cursor-not-allowed disabled:opacity-50",
131
+ c && "border-destructive"
132
+ ),
133
+ children: [
134
+ /* @__PURE__ */ e.jsx("span", { children: H }),
135
+ /* @__PURE__ */ e.jsx(
136
+ W,
137
+ {
138
+ name: l ? "CaretUp" : "CaretDown",
139
+ size: "sm",
140
+ className: "ml-2"
141
+ }
142
+ )
143
+ ]
144
+ }
145
+ ),
146
+ l && /* @__PURE__ */ e.jsxs(
147
+ "div",
148
+ {
149
+ ref: y,
150
+ className: s(
151
+ "absolute z-50 mt-1 bg-popover border border-border rounded-md shadow-lg",
152
+ "flex divide-x divide-border"
153
+ ),
154
+ style: { width: "fit-content", minWidth: "200px" },
155
+ children: [
156
+ /* @__PURE__ */ e.jsx("div", { className: "flex flex-col overflow-y-auto max-h-[200px] min-w-[60px]", children: G.map((r) => /* @__PURE__ */ e.jsx(
157
+ "button",
158
+ {
159
+ type: "button",
160
+ onClick: () => P(r),
161
+ className: s(
162
+ "px-3 py-2 text-sm text-left hover:bg-accent",
163
+ d === r && "bg-primary text-primary-foreground hover:bg-primary"
164
+ ),
165
+ children: u(r)
166
+ },
167
+ r
168
+ )) }),
169
+ /* @__PURE__ */ e.jsx("div", { className: "flex flex-col overflow-y-auto max-h-[200px] min-w-[60px]", children: F.map((r) => /* @__PURE__ */ e.jsx(
170
+ "button",
171
+ {
172
+ type: "button",
173
+ onClick: () => A(r),
174
+ className: s(
175
+ "px-3 py-2 text-sm text-left hover:bg-accent",
176
+ j === r && "bg-primary text-primary-foreground hover:bg-primary"
177
+ ),
178
+ children: u(r)
179
+ },
180
+ r
181
+ )) }),
182
+ /* @__PURE__ */ e.jsx("div", { className: "flex flex-col min-w-[60px]", children: J.map((r) => /* @__PURE__ */ e.jsx(
183
+ "button",
184
+ {
185
+ type: "button",
186
+ onClick: () => D(r),
187
+ className: s(
188
+ "px-3 py-2 text-sm text-left hover:bg-accent",
189
+ w === r && "bg-primary text-primary-foreground hover:bg-primary"
190
+ ),
191
+ children: r
192
+ },
193
+ r
194
+ )) })
195
+ ]
196
+ }
197
+ )
198
+ ]
199
+ }
200
+ );
201
+ return x || c || m ? /* @__PURE__ */ e.jsxs(C, { orientation: "vertical", className: s("w-full", g), children: [
202
+ x && /* @__PURE__ */ e.jsx(E, { children: x }),
203
+ /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col gap-2 flex-1", children: [
204
+ $,
205
+ m && !c && /* @__PURE__ */ e.jsx(T, { children: m }),
206
+ c && /* @__PURE__ */ e.jsx(R, { children: c })
207
+ ] })
208
+ ] }) : $;
209
+ };
54
210
  export {
55
- T as TimePicker
211
+ Y as TimePicker
56
212
  };