shadcn-vue/apps/www/src/public/r/styles/default/AutoFormDependencies.json

19 lines
2.3 KiB
JSON

{
"name": "AutoFormDependencies",
"type": "registry:example",
"dependencies": [],
"registryDependencies": [
"auto-form",
"button",
"toast"
],
"files": [
{
"path": "example/AutoFormDependencies.vue",
"content": "<script setup lang=\"ts\">\nimport { AutoForm } from '@/registry/default/ui/auto-form'\nimport { Button } from '@/registry/default/ui/button'\nimport { toast } from '@/registry/default/ui/toast'\nimport { h } from 'vue'\nimport * as z from 'zod'\nimport { DependencyType } from '../ui/auto-form/interface'\n\nconst schema = z.object({\n age: z.number(),\n parentsAllowed: z.boolean().optional(),\n vegetarian: z.boolean().optional(),\n mealOptions: z.enum(['Pasta', 'Salad', 'Beef Wellington']).optional(),\n})\n\nfunction onSubmit(values: Record<string, any>) {\n toast({\n title: 'You submitted the following values:',\n 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))),\n })\n}\n</script>\n\n<template>\n <AutoForm\n class=\"w-2/3 space-y-6\"\n :schema=\"schema\"\n :field-config=\"{\n age: {\n description:\n 'Setting this below 18 will require parents consent.',\n },\n parentsAllowed: {\n label: 'Did your parents allow you to register?',\n },\n vegetarian: {\n label: 'Are you a vegetarian?',\n description:\n 'Setting this to true will remove non-vegetarian food options.',\n },\n mealOptions: {\n component: 'radio',\n },\n }\"\n :dependencies=\"[\n {\n sourceField: 'age',\n type: DependencyType.HIDES,\n targetField: 'parentsAllowed',\n when: (age) => age >= 18,\n },\n {\n sourceField: 'age',\n type: DependencyType.REQUIRES,\n targetField: 'parentsAllowed',\n when: (age) => age < 18,\n },\n {\n sourceField: 'vegetarian',\n type: DependencyType.SETS_OPTIONS,\n targetField: 'mealOptions',\n when: (vegetarian) => vegetarian,\n options: ['Pasta', 'Salad'],\n },\n ]\"\n @submit=\"onSubmit\"\n >\n <Button type=\"submit\">\n Submit\n </Button>\n </AutoForm>\n</template>\n",
"type": "registry:example",
"target": "AutoFormDependencies.vue"
}
]
}