feat: expand utility widgets (#6638)

This commit is contained in:
Thomas authored and GitHub committed 2026-08-20 16:26:04 +02:00
1 parent 53b518960c
commit 58a24569ce
86 files changed
+7660 -751

No files matched your search

+96
View File
@@ -52,6 +52,7 @@ interface SelectInput<TOptions extends readonly SelectOption[]> extends CommonIn
> {
options: TOptions;
searchable?: boolean;
withPlaceholder?: boolean;
}
interface DynamicSelectInput extends CommonInput<DynamicSelectOption | null> {
@@ -107,6 +108,34 @@ interface SliderInput extends CommonInput<number> {
step?: number;
}
export interface OptionTimezone {
id: string;
label: string;
timeZone: string;
}
interface TimezoneListInput extends CommonInput<OptionTimezone[]> {
maxValues?: number;
presets?: readonly OptionTimezone[];
timeZoneOptions: readonly { value: string; label: string }[];
}
export type DateTimeEventRecurrence = "none" | "yearly";
export interface OptionDateTimeEvent {
id: string;
label: string;
targetUtc: string;
timeZone: string;
startUtc?: string;
recurrence: DateTimeEventRecurrence;
}
interface DateTimeEventListInput extends CommonInput<OptionDateTimeEvent[]> {
maxValues?: number;
timeZoneOptions: readonly { value: string; label: string }[];
}
export interface OptionLocation {
name: string;
latitude: number;
@@ -163,6 +192,7 @@ const optionsFactory = {
options: input.options,
searchable: input.searchable ?? false,
withDescription: input.withDescription ?? false,
withPlaceholder: input.withPlaceholder ?? false,
}),
number: (input: NumberInput) => ({
type: "number" as const,
@@ -192,6 +222,72 @@ const optionsFactory = {
longitude: z.number(),
}),
}),
timezoneList: (input: TimezoneListInput) => {
const maxValues = input.maxValues ?? 6;
return {
type: "timezoneList" as const,
defaultValue: input.defaultValue ?? [],
maxValues,
presets: input.presets ?? [],
timeZoneOptions: input.timeZoneOptions,
withDescription: input.withDescription ?? false,
validate: z
.array(
z.object({
id: z.string().min(1),
label: z.string().trim().min(1).max(64),
timeZone: z.string().min(1),
}),
)
.max(maxValues)
.superRefine((values, ctx) => {
const ids = new Set<string>();
const timeZones = new Set<string>();
values.forEach((value, index) => {
if (ids.has(value.id)) {
ctx.addIssue({ code: "custom", path: [index, "id"], message: "Duplicate identifier" });
}
if (timeZones.has(value.timeZone)) {
ctx.addIssue({ code: "custom", path: [index, "timeZone"], message: "Duplicate timezone" });
}
ids.add(value.id);
timeZones.add(value.timeZone);
});
}),
};
},
dateTimeEventList: (input: DateTimeEventListInput) => {
const maxValues = input.maxValues ?? 20;
const dateTimeEventSchema = z.object({
id: z.string().min(1),
label: z.string().trim().min(1).max(64),
targetUtc: z.iso.datetime(),
timeZone: z.string().min(1),
startUtc: z.iso.datetime().optional(),
recurrence: z.enum(["none", "yearly"]),
});
return {
type: "dateTimeEventList" as const,
defaultValue: input.defaultValue ?? [],
maxValues,
timeZoneOptions: input.timeZoneOptions,
withDescription: input.withDescription ?? false,
validate: z
.array(dateTimeEventSchema)
.max(maxValues)
.superRefine((values, ctx) => {
const ids = new Set<string>();
values.forEach((value, index) => {
if (ids.has(value.id)) {
ctx.addIssue({ code: "custom", path: [index, "id"], message: "Duplicate identifier" });
}
ids.add(value.id);
});
}),
};
},
multiText: (input?: CommonInput<string[]> & { validate?: ZodType }) => ({
type: "multiText" as const,
defaultValue: input?.defaultValue ?? [],