feat: add AR page options schema
This commit is contained in:
parent
559a487efb
commit
82b0db671c
34
app/schemas/projects/ar-page.ts
Normal file
34
app/schemas/projects/ar-page.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
import { AR_PAGE_DEFAULTS, BUTTON_CUSTOM_LIMITS } from '~/data/projects/constants';
|
||||||
|
import { hexColor } from '~/schemas/color';
|
||||||
|
import type { ArPageSettings, ButtonCustomSize } from '~/types/project';
|
||||||
|
|
||||||
|
function px(key: keyof typeof BUTTON_CUSTOM_LIMITS) {
|
||||||
|
const { label, min, max } = BUTTON_CUSTOM_LIMITS[key];
|
||||||
|
const message = `${label} must be ${min} to ${max} px`;
|
||||||
|
return z.number({ error: message }).int(message).min(min, message).max(max, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buttonCustomSchema = z.object({
|
||||||
|
height: px('height'),
|
||||||
|
width: px('width').nullable(),
|
||||||
|
paddingX: px('paddingX'),
|
||||||
|
radius: px('radius'),
|
||||||
|
borderWidth: px('borderWidth'),
|
||||||
|
borderColor: hexColor,
|
||||||
|
}) satisfies z.ZodType<ButtonCustomSize>;
|
||||||
|
|
||||||
|
export const arPageSchema = z.object({
|
||||||
|
bars: z.boolean(),
|
||||||
|
modelName: z.boolean(),
|
||||||
|
logoBacking: z.boolean(),
|
||||||
|
thobLogo: z.boolean(),
|
||||||
|
buttonSize: z.enum(['sm', 'md', 'lg', 'full', 'custom']),
|
||||||
|
buttonCustom: buttonCustomSchema,
|
||||||
|
}) satisfies z.ZodType<ArPageSettings>;
|
||||||
|
|
||||||
|
// Saved options over the defaults; anything missing or invalid keeps its default
|
||||||
|
export function readArPage(value: unknown): ArPageSettings {
|
||||||
|
const result = arPageSchema.partial().safeParse(value);
|
||||||
|
return { ...AR_PAGE_DEFAULTS, ...(result.success ? result.data : {}) };
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user