react-server-actions
Version:
A package for working with actions in React and Next.js
30 lines • 1.51 kB
TypeScript
import { z } from 'zod';
/**
* Get the html5 validation attributes from a Zod schema field
* @param schema - The Zod schema
* @param path - The path to the field in the schema
* @returns The validation attributes for the field
* @note It would be cool to infer also the "type" attribute of the field, but this would not be consistent because a zod rule is not a 1-1 relation with an html input.
* For example, a zod.number() could be an <input type="number" /> but also a <select>. A z.date() could be represented by a <input type="date" /> but also a <input type="datetime-local" />.
* We could make a "guess" based on the zod rule, and then could be overriden by the user, but this would lead to confusion.
* So we leave it as a parameter for now.
*/
export declare function getZodValidationAttributes(schema: z.ZodTypeAny, path: string[], options?: {
inferTypeAttr?: boolean;
}): {
type: 'string' | 'number' | 'date' | 'boolean' | 'enum';
attrs: Record<string, string | number | boolean>;
};
/**
* Convert a date to an <input type="date"> default value
* @param date - The date to convert
* @returns The input default value
*/
export declare const dateToInputDefaultValue: (date: Date) => string | undefined;
/**
* Convert a date to an <input type="datetime-local"> default value
* @param date - The date to convert
* @returns The input default value
*/
export declare const datetimeToInputDefaultValue: (date: Date) => string;
//# sourceMappingURL=helpers.d.ts.map