@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.
- package/{src/schema/adapter.ts → dist/adapters.d.mts} +118 -43
- package/dist/adapters.d.ts +292 -0
- package/dist/adapters.js +13283 -0
- package/dist/adapters.js.map +1 -0
- package/dist/adapters.mjs +13269 -0
- package/dist/adapters.mjs.map +1 -0
- package/dist/index.d.mts +3744 -0
- package/dist/index.d.ts +3744 -0
- package/dist/index.js +43014 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +42965 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +22 -7
- package/.scaffold-cache.json +0 -537
- package/src/.scaffold-cache.json +0 -544
- package/src/adapters/axios.ts +0 -117
- package/src/adapters/index.ts +0 -91
- package/src/adapters/inertia.ts +0 -187
- package/src/core/adapter-registry.ts +0 -87
- package/src/core/bound/bind-host.ts +0 -14
- package/src/core/bound/observe-bound-field.ts +0 -172
- package/src/core/bound/wait-for-bound-field.ts +0 -57
- package/src/core/context.ts +0 -23
- package/src/core/core-provider.tsx +0 -818
- package/src/core/core-root.tsx +0 -72
- package/src/core/core-shell.tsx +0 -44
- package/src/core/errors/error-strip.tsx +0 -71
- package/src/core/errors/index.ts +0 -2
- package/src/core/errors/map-error-bag.ts +0 -51
- package/src/core/errors/map-zod.ts +0 -39
- package/src/core/hooks/use-button.ts +0 -220
- package/src/core/hooks/use-core-context.ts +0 -20
- package/src/core/hooks/use-core-utility.ts +0 -0
- package/src/core/hooks/use-core.ts +0 -13
- package/src/core/hooks/use-field.ts +0 -497
- package/src/core/hooks/use-optional-field.ts +0 -28
- package/src/core/index.ts +0 -0
- package/src/core/registry/binder-registry.ts +0 -82
- package/src/core/registry/field-registry.ts +0 -187
- package/src/core/test.tsx +0 -17
- package/src/global.d.ts +0 -14
- package/src/index.ts +0 -68
- package/src/input/index.ts +0 -4
- package/src/input/input-field.tsx +0 -854
- package/src/input/input-layout-graph.ts +0 -230
- package/src/input/input-props.ts +0 -190
- package/src/lib/get-global-countries.ts +0 -87
- package/src/lib/utils.ts +0 -6
- package/src/presets/index.ts +0 -0
- package/src/presets/shadcn-preset.ts +0 -0
- package/src/presets/shadcn-variants/checkbox.tsx +0 -849
- package/src/presets/shadcn-variants/chips.tsx +0 -756
- package/src/presets/shadcn-variants/color.tsx +0 -284
- package/src/presets/shadcn-variants/custom.tsx +0 -227
- package/src/presets/shadcn-variants/date.tsx +0 -796
- package/src/presets/shadcn-variants/file.tsx +0 -764
- package/src/presets/shadcn-variants/keyvalue.tsx +0 -556
- package/src/presets/shadcn-variants/multiselect.tsx +0 -1132
- package/src/presets/shadcn-variants/number.tsx +0 -176
- package/src/presets/shadcn-variants/password.tsx +0 -737
- package/src/presets/shadcn-variants/phone.tsx +0 -628
- package/src/presets/shadcn-variants/radio.tsx +0 -578
- package/src/presets/shadcn-variants/select.tsx +0 -956
- package/src/presets/shadcn-variants/slider.tsx +0 -622
- package/src/presets/shadcn-variants/text.tsx +0 -343
- package/src/presets/shadcn-variants/textarea.tsx +0 -66
- package/src/presets/shadcn-variants/toggle.tsx +0 -218
- package/src/presets/shadcn-variants/treeselect.tsx +0 -784
- package/src/presets/ui/badge.tsx +0 -46
- package/src/presets/ui/button.tsx +0 -60
- package/src/presets/ui/calendar.tsx +0 -214
- package/src/presets/ui/checkbox.tsx +0 -115
- package/src/presets/ui/custom.tsx +0 -0
- package/src/presets/ui/dialog.tsx +0 -141
- package/src/presets/ui/field.tsx +0 -246
- package/src/presets/ui/input-mask.tsx +0 -739
- package/src/presets/ui/input-otp.tsx +0 -77
- package/src/presets/ui/input.tsx +0 -1011
- package/src/presets/ui/label.tsx +0 -22
- package/src/presets/ui/number.tsx +0 -1370
- package/src/presets/ui/popover.tsx +0 -46
- package/src/presets/ui/radio-group.tsx +0 -43
- package/src/presets/ui/scroll-area.tsx +0 -56
- package/src/presets/ui/select.tsx +0 -190
- package/src/presets/ui/separator.tsx +0 -28
- package/src/presets/ui/slider.tsx +0 -61
- package/src/presets/ui/switch.tsx +0 -32
- package/src/presets/ui/textarea.tsx +0 -634
- package/src/presets/ui/time-dropdowns.tsx +0 -350
- package/src/schema/core.ts +0 -429
- package/src/schema/field-map.ts +0 -0
- package/src/schema/field.ts +0 -224
- package/src/schema/index.ts +0 -0
- package/src/schema/input-field.ts +0 -260
- package/src/schema/presets.ts +0 -0
- package/src/schema/variant.ts +0 -216
- package/src/variants/core/checkbox.tsx +0 -54
- package/src/variants/core/chips.tsx +0 -22
- package/src/variants/core/color.tsx +0 -16
- package/src/variants/core/custom.tsx +0 -18
- package/src/variants/core/date.tsx +0 -25
- package/src/variants/core/file.tsx +0 -9
- package/src/variants/core/keyvalue.tsx +0 -12
- package/src/variants/core/multiselect.tsx +0 -28
- package/src/variants/core/number.tsx +0 -115
- package/src/variants/core/password.tsx +0 -35
- package/src/variants/core/phone.tsx +0 -16
- package/src/variants/core/radio.tsx +0 -38
- package/src/variants/core/select.tsx +0 -15
- package/src/variants/core/slider.tsx +0 -55
- package/src/variants/core/text.tsx +0 -114
- package/src/variants/core/textarea.tsx +0 -22
- package/src/variants/core/toggle.tsx +0 -50
- package/src/variants/core/treeselect.tsx +0 -11
- package/src/variants/helpers/selection-summary.tsx +0 -236
- package/src/variants/index.ts +0 -75
- package/src/variants/registry.ts +0 -38
- package/src/variants/select-shared.ts +0 -0
- package/src/variants/shared.ts +0 -126
- 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
|
-
};
|