@timeax/form-palette 0.0.3 → 0.0.5

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.
Files changed (120) hide show
  1. package/{src/schema/adapter.ts → dist/adapters.d.mts} +118 -43
  2. package/dist/adapters.d.ts +292 -0
  3. package/dist/adapters.js +13283 -0
  4. package/dist/adapters.js.map +1 -0
  5. package/dist/adapters.mjs +13269 -0
  6. package/dist/adapters.mjs.map +1 -0
  7. package/dist/index.d.mts +3744 -0
  8. package/dist/index.d.ts +3744 -0
  9. package/dist/index.js +43014 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/index.mjs +42965 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/package.json +22 -7
  14. package/.scaffold-cache.json +0 -537
  15. package/src/.scaffold-cache.json +0 -544
  16. package/src/adapters/axios.ts +0 -117
  17. package/src/adapters/index.ts +0 -91
  18. package/src/adapters/inertia.ts +0 -187
  19. package/src/core/adapter-registry.ts +0 -87
  20. package/src/core/bound/bind-host.ts +0 -14
  21. package/src/core/bound/observe-bound-field.ts +0 -172
  22. package/src/core/bound/wait-for-bound-field.ts +0 -57
  23. package/src/core/context.ts +0 -23
  24. package/src/core/core-provider.tsx +0 -818
  25. package/src/core/core-root.tsx +0 -72
  26. package/src/core/core-shell.tsx +0 -44
  27. package/src/core/errors/error-strip.tsx +0 -71
  28. package/src/core/errors/index.ts +0 -2
  29. package/src/core/errors/map-error-bag.ts +0 -51
  30. package/src/core/errors/map-zod.ts +0 -39
  31. package/src/core/hooks/use-button.ts +0 -220
  32. package/src/core/hooks/use-core-context.ts +0 -20
  33. package/src/core/hooks/use-core-utility.ts +0 -0
  34. package/src/core/hooks/use-core.ts +0 -13
  35. package/src/core/hooks/use-field.ts +0 -497
  36. package/src/core/hooks/use-optional-field.ts +0 -28
  37. package/src/core/index.ts +0 -0
  38. package/src/core/registry/binder-registry.ts +0 -82
  39. package/src/core/registry/field-registry.ts +0 -187
  40. package/src/core/test.tsx +0 -17
  41. package/src/global.d.ts +0 -14
  42. package/src/index.ts +0 -68
  43. package/src/input/index.ts +0 -4
  44. package/src/input/input-field.tsx +0 -854
  45. package/src/input/input-layout-graph.ts +0 -230
  46. package/src/input/input-props.ts +0 -190
  47. package/src/lib/get-global-countries.ts +0 -87
  48. package/src/lib/utils.ts +0 -6
  49. package/src/presets/index.ts +0 -0
  50. package/src/presets/shadcn-preset.ts +0 -0
  51. package/src/presets/shadcn-variants/checkbox.tsx +0 -849
  52. package/src/presets/shadcn-variants/chips.tsx +0 -756
  53. package/src/presets/shadcn-variants/color.tsx +0 -284
  54. package/src/presets/shadcn-variants/custom.tsx +0 -227
  55. package/src/presets/shadcn-variants/date.tsx +0 -796
  56. package/src/presets/shadcn-variants/file.tsx +0 -764
  57. package/src/presets/shadcn-variants/keyvalue.tsx +0 -556
  58. package/src/presets/shadcn-variants/multiselect.tsx +0 -1132
  59. package/src/presets/shadcn-variants/number.tsx +0 -176
  60. package/src/presets/shadcn-variants/password.tsx +0 -737
  61. package/src/presets/shadcn-variants/phone.tsx +0 -628
  62. package/src/presets/shadcn-variants/radio.tsx +0 -578
  63. package/src/presets/shadcn-variants/select.tsx +0 -956
  64. package/src/presets/shadcn-variants/slider.tsx +0 -622
  65. package/src/presets/shadcn-variants/text.tsx +0 -343
  66. package/src/presets/shadcn-variants/textarea.tsx +0 -66
  67. package/src/presets/shadcn-variants/toggle.tsx +0 -218
  68. package/src/presets/shadcn-variants/treeselect.tsx +0 -784
  69. package/src/presets/ui/badge.tsx +0 -46
  70. package/src/presets/ui/button.tsx +0 -60
  71. package/src/presets/ui/calendar.tsx +0 -214
  72. package/src/presets/ui/checkbox.tsx +0 -115
  73. package/src/presets/ui/custom.tsx +0 -0
  74. package/src/presets/ui/dialog.tsx +0 -141
  75. package/src/presets/ui/field.tsx +0 -246
  76. package/src/presets/ui/input-mask.tsx +0 -739
  77. package/src/presets/ui/input-otp.tsx +0 -77
  78. package/src/presets/ui/input.tsx +0 -1011
  79. package/src/presets/ui/label.tsx +0 -22
  80. package/src/presets/ui/number.tsx +0 -1370
  81. package/src/presets/ui/popover.tsx +0 -46
  82. package/src/presets/ui/radio-group.tsx +0 -43
  83. package/src/presets/ui/scroll-area.tsx +0 -56
  84. package/src/presets/ui/select.tsx +0 -190
  85. package/src/presets/ui/separator.tsx +0 -28
  86. package/src/presets/ui/slider.tsx +0 -61
  87. package/src/presets/ui/switch.tsx +0 -32
  88. package/src/presets/ui/textarea.tsx +0 -634
  89. package/src/presets/ui/time-dropdowns.tsx +0 -350
  90. package/src/schema/core.ts +0 -429
  91. package/src/schema/field-map.ts +0 -0
  92. package/src/schema/field.ts +0 -224
  93. package/src/schema/index.ts +0 -0
  94. package/src/schema/input-field.ts +0 -260
  95. package/src/schema/presets.ts +0 -0
  96. package/src/schema/variant.ts +0 -216
  97. package/src/variants/core/checkbox.tsx +0 -54
  98. package/src/variants/core/chips.tsx +0 -22
  99. package/src/variants/core/color.tsx +0 -16
  100. package/src/variants/core/custom.tsx +0 -18
  101. package/src/variants/core/date.tsx +0 -25
  102. package/src/variants/core/file.tsx +0 -9
  103. package/src/variants/core/keyvalue.tsx +0 -12
  104. package/src/variants/core/multiselect.tsx +0 -28
  105. package/src/variants/core/number.tsx +0 -115
  106. package/src/variants/core/password.tsx +0 -35
  107. package/src/variants/core/phone.tsx +0 -16
  108. package/src/variants/core/radio.tsx +0 -38
  109. package/src/variants/core/select.tsx +0 -15
  110. package/src/variants/core/slider.tsx +0 -55
  111. package/src/variants/core/text.tsx +0 -114
  112. package/src/variants/core/textarea.tsx +0 -22
  113. package/src/variants/core/toggle.tsx +0 -50
  114. package/src/variants/core/treeselect.tsx +0 -11
  115. package/src/variants/helpers/selection-summary.tsx +0 -236
  116. package/src/variants/index.ts +0 -75
  117. package/src/variants/registry.ts +0 -38
  118. package/src/variants/select-shared.ts +0 -0
  119. package/src/variants/shared.ts +0 -126
  120. package/tsconfig.json +0 -14
@@ -1,350 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "@/lib/utils";
3
- import {
4
- Select,
5
- SelectTrigger,
6
- SelectValue,
7
- SelectContent,
8
- SelectItem,
9
- } from "@/presets/ui/select";
10
-
11
- export interface TimeDropdownsProps {
12
- /**
13
- * Current date-time value.
14
- * Only the time portion will be modified; date part is preserved.
15
- */
16
- value: Date | undefined;
17
-
18
- /**
19
- * Called whenever any of the time parts change.
20
- */
21
- onChange(next: Date | undefined): void;
22
-
23
- /**
24
- * Whether to show seconds dropdown.
25
- * Default: false.
26
- */
27
- showSeconds?: boolean;
28
-
29
- /**
30
- * Step between minutes in the dropdown.
31
- * Default: 5.
32
- */
33
- minuteStep?: number;
34
-
35
- /**
36
- * Step between seconds in the dropdown.
37
- * Default: 5.
38
- */
39
- secondStep?: number;
40
-
41
- /**
42
- * If true, show 12-hour clock with AM/PM toggle.
43
- * If false, show 24-hour clock (00–23).
44
- * Default: false (24-hour).
45
- */
46
- use12Hour?: boolean;
47
-
48
- /**
49
- * Optional label to show above or beside the dropdowns.
50
- */
51
- label?: React.ReactNode;
52
-
53
- /**
54
- * Custom className for the outer wrapper.
55
- */
56
- className?: string;
57
-
58
- /**
59
- * Custom className for each SelectTrigger (hours/minutes/seconds).
60
- */
61
- triggerClassName?: string;
62
-
63
- /**
64
- * Compact / normal layout toggle.
65
- * Just a quick spacing switch for now.
66
- */
67
- density?: "compact" | "normal";
68
- }
69
-
70
- function pad2(n: number): string {
71
- return n.toString().padStart(2, "0");
72
- }
73
-
74
- function buildMinuteOptions(step: number): string[] {
75
- const items: string[] = [];
76
- for (let m = 0; m < 60; m += step) {
77
- items.push(pad2(m));
78
- }
79
- return items;
80
- }
81
-
82
- function buildSecondOptions(step: number): string[] {
83
- const items: string[] = [];
84
- for (let s = 0; s < 60; s += step) {
85
- items.push(pad2(s));
86
- }
87
- return items;
88
- }
89
-
90
- function buildHourOptions24(): string[] {
91
- const items: string[] = [];
92
- for (let h = 0; h < 24; h++) {
93
- items.push(pad2(h));
94
- }
95
- return items;
96
- }
97
-
98
- function buildHourOptions12(): string[] {
99
- const items: string[] = [];
100
- for (let h = 1; h <= 12; h++) {
101
- items.push(h.toString());
102
- }
103
- return items;
104
- }
105
-
106
- /**
107
- * Safely create a new Date instance with updated time parts,
108
- * preserving the original date portion when possible.
109
- */
110
- function withTime(
111
- base: Date | undefined,
112
- opts: { hours?: number; minutes?: number; seconds?: number },
113
- ): Date {
114
- const src = base ? new Date(base.getTime()) : new Date();
115
- const h = opts.hours ?? src.getHours();
116
- const m = opts.minutes ?? src.getMinutes();
117
- const s = opts.seconds ?? src.getSeconds();
118
- src.setHours(h, m, s, 0);
119
- return src;
120
- }
121
-
122
- /**
123
- * Drop-in time dropdown cluster for use in the date popover.
124
- *
125
- * Renders hour / minute (and optionally second) Selects plus
126
- * an AM/PM toggle when `use12Hour` is true.
127
- */
128
- export const TimeDropdowns: React.FC<TimeDropdownsProps> = (props) => {
129
- const {
130
- value,
131
- onChange,
132
- showSeconds = false,
133
- minuteStep = 5,
134
- secondStep = 5,
135
- use12Hour = false,
136
- label,
137
- className,
138
- triggerClassName,
139
- density = "normal",
140
- } = props;
141
-
142
- const minuteOptions = React.useMemo(
143
- () => buildMinuteOptions(minuteStep),
144
- [minuteStep],
145
- );
146
- const secondOptions = React.useMemo(
147
- () => buildSecondOptions(secondStep),
148
- [secondStep],
149
- );
150
-
151
- const hourOptions = React.useMemo(
152
- () => (use12Hour ? buildHourOptions12() : buildHourOptions24()),
153
- [use12Hour],
154
- );
155
-
156
- // Derive current parts from value.
157
- let hours24 = value ? value.getHours() : 0;
158
- let minutes = value ? value.getMinutes() : 0;
159
- let seconds = value ? value.getSeconds() : 0;
160
-
161
- let hourDisplay: string;
162
- let period: "am" | "pm" | null = null;
163
-
164
- if (use12Hour) {
165
- period = hours24 >= 12 ? "pm" : "am";
166
- let h12 = hours24 % 12;
167
- if (h12 === 0) h12 = 12;
168
- hourDisplay = h12.toString();
169
- } else {
170
- hourDisplay = pad2(hours24);
171
- }
172
-
173
- const minuteDisplay = pad2(minutes);
174
- const secondDisplay = pad2(seconds);
175
-
176
- const baseTriggerClasses = cn(
177
- "h-8 w-[4.2rem] px-2 py-0 text-xs",
178
- "whitespace-nowrap",
179
- "border-input bg-background",
180
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
181
- );
182
-
183
- const triggerClasses = cn(
184
- baseTriggerClasses,
185
- triggerClassName,
186
- density === "compact" && "h-7 text-[0.7rem] px-1.5",
187
- );
188
-
189
- const gapClass = density === "compact" ? "gap-1" : "gap-2";
190
-
191
- const handleHourChange = (hStr: string) => {
192
- let nextHours24: number;
193
-
194
- if (use12Hour) {
195
- const h12 = parseInt(hStr, 10) || 0;
196
- if (!period) {
197
- // fallback: assume AM
198
- nextHours24 = h12 % 12;
199
- } else {
200
- if (period === "am") {
201
- nextHours24 = h12 % 12; // 12am → 0
202
- } else {
203
- nextHours24 = h12 % 12 + 12; // 12pm → 12, 1pm → 13
204
- }
205
- }
206
- } else {
207
- nextHours24 = parseInt(hStr, 10) || 0;
208
- }
209
-
210
- const nextDate = withTime(value, { hours: nextHours24 });
211
- onChange(nextDate);
212
- };
213
-
214
- const handleMinuteChange = (mStr: string) => {
215
- const m = parseInt(mStr, 10) || 0;
216
- const nextDate = withTime(value, { minutes: m });
217
- onChange(nextDate);
218
- };
219
-
220
- const handleSecondChange = (sStr: string) => {
221
- const s = parseInt(sStr, 10) || 0;
222
- const nextDate = withTime(value, { seconds: s });
223
- onChange(nextDate);
224
- };
225
-
226
- const handlePeriodChange = (p: string) => {
227
- if (!use12Hour) return;
228
- const nextPeriod = p === "pm" ? "pm" : "am";
229
-
230
- // Convert from current hours24 + new period.
231
- let h12 = hours24 % 12;
232
- if (h12 === 0) h12 = 12;
233
-
234
- let nextHours24: number;
235
- if (nextPeriod === "am") {
236
- nextHours24 = h12 % 12; // 12am → 0
237
- } else {
238
- nextHours24 = h12 % 12 + 12; // 12pm → 12, etc.
239
- }
240
-
241
- const nextDate = withTime(value, { hours: nextHours24 });
242
- onChange(nextDate);
243
- };
244
-
245
- return (
246
- <div
247
- className={cn(
248
- "flex w-full flex-col gap-2",
249
- density === "compact" && "gap-1",
250
- className,
251
- )}
252
- data-slot="time-dropdowns"
253
- >
254
- {label && (
255
- <div className="text-xs font-medium text-muted-foreground">
256
- {label}
257
- </div>
258
- )}
259
-
260
- <div
261
- className={cn(
262
- "flex w-full items-center",
263
- gapClass,
264
- )}
265
- data-slot="time-dropdowns-row"
266
- >
267
- {/* Hour */}
268
- <Select value={hourDisplay} onValueChange={handleHourChange}>
269
- <SelectTrigger
270
- className={triggerClasses}
271
- data-slot="time-hour"
272
- >
273
- <SelectValue placeholder="HH" />
274
- </SelectTrigger>
275
- <SelectContent>
276
- {hourOptions.map((h) => (
277
- <SelectItem key={h} value={h}>
278
- {use12Hour ? h.padStart(2, " ") : pad2(Number(h))}
279
- </SelectItem>
280
- ))}
281
- </SelectContent>
282
- </Select>
283
-
284
- {/* Minute */}
285
- <Select
286
- value={minuteDisplay}
287
- onValueChange={handleMinuteChange}
288
- >
289
- <SelectTrigger
290
- className={triggerClasses}
291
- data-slot="time-minute"
292
- >
293
- <SelectValue placeholder="MM" />
294
- </SelectTrigger>
295
- <SelectContent>
296
- {minuteOptions.map((m) => (
297
- <SelectItem key={m} value={m}>
298
- {m}
299
- </SelectItem>
300
- ))}
301
- </SelectContent>
302
- </Select>
303
-
304
- {/* Second (optional) */}
305
- {showSeconds && (
306
- <Select
307
- value={secondDisplay}
308
- onValueChange={handleSecondChange}
309
- >
310
- <SelectTrigger
311
- className={triggerClasses}
312
- data-slot="time-second"
313
- >
314
- <SelectValue placeholder="SS" />
315
- </SelectTrigger>
316
- <SelectContent>
317
- {secondOptions.map((s) => (
318
- <SelectItem key={s} value={s}>
319
- {s}
320
- </SelectItem>
321
- ))}
322
- </SelectContent>
323
- </Select>
324
- )}
325
-
326
- {/* AM/PM (optional) */}
327
- {use12Hour && (
328
- <Select
329
- value={period ?? "am"}
330
- onValueChange={handlePeriodChange}
331
- >
332
- <SelectTrigger
333
- className={cn(
334
- triggerClasses,
335
- "w-[3.8rem]",
336
- )}
337
- data-slot="time-period"
338
- >
339
- <SelectValue />
340
- </SelectTrigger>
341
- <SelectContent>
342
- <SelectItem value="am">AM</SelectItem>
343
- <SelectItem value="pm">PM</SelectItem>
344
- </SelectContent>
345
- </Select>
346
- )}
347
- </div>
348
- </div>
349
- );
350
- };