diff --git a/apps/www/src/lib/registry/new-york/example/AutoForm.vue b/apps/www/src/lib/registry/new-york/example/AutoForm.vue index 6f0f04bb..5651ebfb 100644 --- a/apps/www/src/lib/registry/new-york/example/AutoForm.vue +++ b/apps/www/src/lib/registry/new-york/example/AutoForm.vue @@ -8,98 +8,19 @@ import { toast } from '@/lib/registry/new-york/ui/toast' import type { Config } from '@/lib/registry/new-york/ui/auto-form' import { AutoForm, AutoFormField } from '@/lib/registry/new-york/ui/auto-form' -enum Sports { - Football = 'Football/Soccer', - Basketball = 'Basketball', - Baseball = 'Baseball', - Hockey = 'Hockey (Ice)', - None = 'I don\'t like sports', -} - const schema = z.object({ - username: z - .string({ - required_error: 'Username is required.', - }) - .min(2, { - message: 'Username must be at least 2 characters.', - }), - - password: z - .string({ - required_error: 'Password is required.', - }) - .describe('Your secure password') - .min(8, { - message: 'Password must be at least 8 characters.', - }), - - favouriteNumber: z.coerce - .number({ - invalid_type_error: 'Favourite number must be a number.', - }) - .min(1, { - message: 'Favourite number must be at least 1.', - }) - .max(10, { - message: 'Favourite number must be at most 10.', - }) - .default(1) - .optional(), - - acceptTerms: z - .boolean() - .describe('Accept terms and conditions.') - .refine(value => value, { - message: 'You must accept the terms and conditions.', - path: ['acceptTerms'], - }), - - sendMeMails: z.boolean().optional(), - - birthday: z.coerce.date().optional(), - - color: z.enum(['red', 'green', 'blue']).optional(), - - // Another enum example - marshmallows: z - .enum(['not many', 'a few', 'a lot', 'too many']) - .describe('How many marshmallows fit in your mouth?'), - - // Native enum example - sports: z.nativeEnum(Sports).describe('What is your favourite sport?'), - - bio: z - .string() - .min(10, { - message: 'Bio must be at least 10 characters.', - }) - .max(160, { - message: 'Bio must not be longer than 30 characters.', - }) - .optional(), - - customParent: z.string().optional(), - - file: z.string().optional().describe('Text file'), - - subObject: z.object({ - subField: z.string().optional().default('Sub Field'), - numberField: z.number().optional().default(1), - - subSubObject: z - .object({ - subSubField: z.string().default('Sub Sub Field'), + guestListName: z.string(), + invitedGuests: z + .array( + z.object({ + name: z.string(), + age: z.coerce.number(), }), - }).describe('123 Description'), - - optionalSubObject: z - .object({ - optionalSubField: z.string(), - otherOptionalSubField: z.string(), - }) - .optional(), + ).default([ + { name: '123', age: 30 }, + ]).describe('How many guests'), + list: z.array(z.string()).describe('test the config'), }) const formSchema = toTypedSchema(schema) @@ -114,81 +35,30 @@ const onSubmit = handleSubmit((values) => { description: h('pre', { class: 'mt-2 w-[340px] rounded-md bg-slate-950 p-4' }, h('code', { class: 'text-white' }, JSON.stringify(values, null, 2))), }) }) - -const config - = reactive({ - username: { - label: '123', - description: 'Test description', - inputProps: { - id: '123', - }, - }, - password: { - inputProps: { - id: '345', - type: 'password', - }, - }, - acceptTerms: { - description: 'this is custom', - }, - sendMeMails: { - component: 'switch', - }, - color: { - enumProps: { - options: ['red', 'green', 'blue'], - placeholder: 'Choose a color', - }, - }, - marshmallows: { - component: 'radio', - }, - bio: { - component: 'textarea', - }, - file: { - component: 'file', - }, - - subObject: { - subField: { - label: 'custom labvel', - description: '123', - }, - subSubObject: { - subSubField: { - label: 'sub suuuub', - }, - }, - }, - }) as Config>