Skip to content

colorFieldToInputSchema

colorFieldToInputSchema(props): ZodType

Defined in: packages/core/src/fields/color/inputSchema.ts:75

Builds a Zod schema for validating a colour field value in the admin form.

Accepts hex, rgb(), hsl() and oklch() notation — plus var(--token) when the field enables themeColors. Required fields add a .min(1) check so an empty field reports “required” rather than a notation complaint. Optional fields accept the empty string, since color() defaults defaultValue to "" and a cleared picker must round-trip.

Input props.

ColorField

The resolved colour field definition.

ZodType

A Zod string schema. Optional fields are wrapped in .optional() by applyBaseInputSchemaMeta and carry .default(field.defaultValue).

// Required — rejects "", "#fff" and "var(--primary)"
colorFieldToInputSchema({ field: color({ required: true }) })
// themeColors — additionally accepts "var(--primary)"
colorFieldToInputSchema({ field: color({ required: true, themeColors: true }) })