/** * Form Components Demo * * This component demonstrates how to use the new reusable form components. * It shows examples of all the form field types and layout components. */ import React from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { FormField, FormSelect, FormCheckbox, FormRadio, FormDatePicker, FormSection, FormGrid, FormGridItem, SelectOption, CheckboxOption, RadioOption, } from './index'; // ============================================================================= // SCHEMA // ============================================================================= const demoFormSchema = z.object({ title: z.string().min(1, 'Title is required'), description: z.string().min(10, 'Description must be at least 10 characters'), category: z.string().min(1, 'Category is required'), priority: z.string().min(1, 'Priority is required'), tags: z.array(z.string()).min(1, 'At least one tag is required'), status: z.string().min(1, 'Status is required'), dueDate: z.date().optional(), isPublic: z.boolean().default(false), notifications: z.array(z.string()).default([]), }); type DemoFormData = z.infer; // ============================================================================= // OPTIONS DATA // ============================================================================= const categoryOptions: SelectOption[] = [ { value: 'feature', label: 'Feature Request' }, { value: 'bug', label: 'Bug Report' }, { value: 'improvement', label: 'Improvement' }, { value: 'documentation', label: 'Documentation' }, ]; const priorityOptions: RadioOption[] = [ { value: 'low', label: 'Low' }, { value: 'medium', label: 'Medium' }, { value: 'high', label: 'High' }, { value: 'urgent', label: 'Urgent' }, ]; const tagOptions: CheckboxOption[] = [ { value: 'frontend', label: 'Frontend' }, { value: 'backend', label: 'Backend' }, { value: 'ui', label: 'UI/UX' }, { value: 'database', label: 'Database' }, { value: 'security', label: 'Security' }, { value: 'performance', label: 'Performance' }, ]; const statusOptions: SelectOption[] = [ { value: 'draft', label: 'Draft' }, { value: 'in-progress', label: 'In Progress' }, { value: 'review', label: 'Under Review' }, { value: 'completed', label: 'Completed' }, ]; const notificationOptions: CheckboxOption[] = [ { value: 'email', label: 'Email Notifications' }, { value: 'push', label: 'Push Notifications' }, { value: 'sms', label: 'SMS Notifications' }, ]; // ============================================================================= // COMPONENT // ============================================================================= export function FormComponentsDemo() { const form = useForm({ resolver: zodResolver(demoFormSchema), defaultValues: { title: '', description: '', category: '', priority: 'medium', tags: [], status: 'draft', dueDate: undefined, isPublic: false, notifications: ['email'], }, }); const onSubmit = (data: DemoFormData) => { console.log('Form submitted:', data); alert('Form submitted! Check console for data.'); }; return (

Form Components Demo

Examples of using the new reusable form components

{/* Basic Information Section */} {/* Priority and Status Section */} {/* Tags and Settings Section */}
{/* Form Actions */}
{/* Form Data Display */}

Current Form Data

          {JSON.stringify(form.watch(), null, 2)}
        
); } export default FormComponentsDemo;