From 0d868693e05528a32ba710dd816a3adc8ce733f5 Mon Sep 17 00:00:00 2001 From: zernonia Date: Tue, 16 Apr 2024 23:51:40 +0800 Subject: [PATCH] chore: initial poc --- apps/www/.vitepress/theme/config/docs.ts | 12 +- apps/www/__registry__/index.ts | 14 ++ .../src/content/docs/components/auto-form.md | 7 + .../lib/registry/default/example/AutoForm.vue | 53 ++++++ .../registry/new-york/example/AutoForm.vue | 178 ++++++++++++++++++ .../new-york/ui/auto-form/AutoForm.vue | 63 +++++++ .../new-york/ui/auto-form/AutoFormField.vue | 62 ++++++ .../new-york/ui/auto-form/AutoFormLabel.vue | 14 ++ .../new-york/ui/auto-form/AutoFormObject.vue | 6 + .../new-york/ui/auto-form/constant.ts | 31 +++ .../new-york/ui/auto-form/fields/Boolean.vue | 35 ++++ .../new-york/ui/auto-form/fields/Date.vue | 59 ++++++ .../new-york/ui/auto-form/fields/Enum.vue | 53 ++++++ .../new-york/ui/auto-form/fields/Input.vue | 36 ++++ .../new-york/ui/auto-form/fields/Number.vue | 34 ++++ .../registry/new-york/ui/auto-form/index.ts | 2 + .../new-york/ui/auto-form/interface.ts | 55 ++++++ .../registry/new-york/ui/auto-form/utils.ts | 129 +++++++++++++ 18 files changed, 842 insertions(+), 1 deletion(-) create mode 100644 apps/www/src/content/docs/components/auto-form.md create mode 100644 apps/www/src/lib/registry/default/example/AutoForm.vue create mode 100644 apps/www/src/lib/registry/new-york/example/AutoForm.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormField.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormLabel.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormObject.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/constant.ts create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/fields/Boolean.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/fields/Date.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/fields/Enum.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/fields/Input.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/fields/Number.vue create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/index.ts create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/interface.ts create mode 100644 apps/www/src/lib/registry/new-york/ui/auto-form/utils.ts diff --git a/apps/www/.vitepress/theme/config/docs.ts b/apps/www/.vitepress/theme/config/docs.ts index 71fce55a..af1da0bd 100644 --- a/apps/www/.vitepress/theme/config/docs.ts +++ b/apps/www/.vitepress/theme/config/docs.ts @@ -8,7 +8,7 @@ export interface NavItem { } export type SidebarNavItem = NavItem & { - items: SidebarNavItem[] + items?: SidebarNavItem[] } export type NavItemWithChildren = NavItem & { @@ -134,6 +134,16 @@ export const docsConfig: DocsConfig = { }, ], }, + { + title: 'Auto Form', + items: [ + { + title: 'Test', + href: '/docs/components/auto-form', + items: [], + }, + ], + }, { title: 'Components', items: [ diff --git a/apps/www/__registry__/index.ts b/apps/www/__registry__/index.ts index 6d6a5395..95423f44 100644 --- a/apps/www/__registry__/index.ts +++ b/apps/www/__registry__/index.ts @@ -38,6 +38,13 @@ export const Index = { component: () => import("../src/lib/registry/default/example/AspectRatioDemo.vue").then((m) => m.default), files: ["../src/lib/registry/default/example/AspectRatioDemo.vue"], }, + "AutoForm": { + name: "AutoForm", + type: "components:example", + registryDependencies: ["button","form","input","toast"], + component: () => import("../src/lib/registry/default/example/AutoForm.vue").then((m) => m.default), + files: ["../src/lib/registry/default/example/AutoForm.vue"], + }, "AvatarDemo": { name: "AvatarDemo", type: "components:example", @@ -1278,6 +1285,13 @@ export const Index = { component: () => import("../src/lib/registry/new-york/example/AspectRatioDemo.vue").then((m) => m.default), files: ["../src/lib/registry/new-york/example/AspectRatioDemo.vue"], }, + "AutoForm": { + name: "AutoForm", + type: "components:example", + registryDependencies: ["button","form","input","toast"], + component: () => import("../src/lib/registry/new-york/example/AutoForm.vue").then((m) => m.default), + files: ["../src/lib/registry/new-york/example/AutoForm.vue"], + }, "AvatarDemo": { name: "AvatarDemo", type: "components:example", diff --git a/apps/www/src/content/docs/components/auto-form.md b/apps/www/src/content/docs/components/auto-form.md new file mode 100644 index 00000000..62909ac0 --- /dev/null +++ b/apps/www/src/content/docs/components/auto-form.md @@ -0,0 +1,7 @@ +--- +title: Auto Form +description: Building forms with VeeValidate and Zod. +primitive: https://vee-validate.logaretm.com/v4/guide/overview/ +--- + + diff --git a/apps/www/src/lib/registry/default/example/AutoForm.vue b/apps/www/src/lib/registry/default/example/AutoForm.vue new file mode 100644 index 00000000..f0d28536 --- /dev/null +++ b/apps/www/src/lib/registry/default/example/AutoForm.vue @@ -0,0 +1,53 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/example/AutoForm.vue b/apps/www/src/lib/registry/new-york/example/AutoForm.vue new file mode 100644 index 00000000..52925b3b --- /dev/null +++ b/apps/www/src/lib/registry/new-york/example/AutoForm.vue @@ -0,0 +1,178 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue new file mode 100644 index 00000000..0fd3cb65 --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoForm.vue @@ -0,0 +1,63 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormField.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormField.vue new file mode 100644 index 00000000..7fd847a2 --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormField.vue @@ -0,0 +1,62 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormLabel.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormLabel.vue new file mode 100644 index 00000000..aaddb7c5 --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormLabel.vue @@ -0,0 +1,14 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormObject.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormObject.vue new file mode 100644 index 00000000..b8525d60 --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/AutoFormObject.vue @@ -0,0 +1,6 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/constant.ts b/apps/www/src/lib/registry/new-york/ui/auto-form/constant.ts new file mode 100644 index 00000000..f35a2a0d --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/constant.ts @@ -0,0 +1,31 @@ +import FieldNumber from './fields/Number.vue' +import FieldInput from './fields/Input.vue' +import FieldBoolean from './fields/Boolean.vue' +import FieldDate from './fields/Date.vue' +import FieldEnum from './fields/Enum.vue' + +export const INPUT_COMPONENTS = { + date: FieldDate, + select: FieldEnum, + radio: FieldEnum, + checkbox: FieldBoolean, + switch: FieldBoolean, + textarea: FieldInput, + number: FieldNumber, + string: FieldInput, +} + +/** + * Define handlers for specific Zod types. + * You can expand this object to support more types. + */ +export const DEFAULT_ZOD_HANDLERS: { + [key: string]: keyof typeof INPUT_COMPONENTS +} = { + ZodString: 'string', + ZodBoolean: 'checkbox', + ZodDate: 'date', + ZodEnum: 'select', + ZodNativeEnum: 'select', + ZodNumber: 'number', +} diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Boolean.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Boolean.vue new file mode 100644 index 00000000..d1ad1a9d --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Boolean.vue @@ -0,0 +1,35 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Date.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Date.vue new file mode 100644 index 00000000..2127fdbf --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Date.vue @@ -0,0 +1,59 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Enum.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Enum.vue new file mode 100644 index 00000000..2489f6c8 --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Enum.vue @@ -0,0 +1,53 @@ + + + diff --git a/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Input.vue b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Input.vue new file mode 100644 index 00000000..9e400265 --- /dev/null +++ b/apps/www/src/lib/registry/new-york/ui/auto-form/fields/Input.vue @@ -0,0 +1,36 @@ + + +