A comprehensive React-based form system that provides dynamic form building, filtering, and table view capabilities. The system consists of four main components working together to create a flexible and powerful form management solution.
The core component that orchestrates the form system.
interface KyroBuilderProps {
formId: string; // Unique form identifier
variant?: string; // Form variant type
initialData?: Record<string, any>; // Initial form data
onBlur?: Function; // Blur event handler
onChange?: Function; // Change event handler
onKeyDown?: Function; // Key down event handler
onKeyUp?: Function; // Key up event handler
onFocus?: Function; // Focus event handler
filterInitData?: any; // Initial filter data
}
Features:
- Dynamic schema loading
- Form and table view integration
- Resizable split view
- Row selection handling
- Form state management
Handles the rendering and management of form fields.
interface FormBuilderProps {
config: any; // Form configuration
initialData?: Record<string, any>; // Initial form data
customEvent?: Function; // Custom event handler
onKeyDown?: Function; // Key down event handler
onKeyUp?: Function; // Key up event handler
onBlur?: Function; // Blur event handler
onFocus?: Function; // Focus event handler
filterSave?: Function; // Filter save handler
}
Features:
- Dynamic field rendering
- Validation system
- Error handling
- Form data management
- Multiple section support
Manages filter forms and their interactions.
interface FilterFormBuilderProps {
formId: string; // Form identifier
onSubmit: (formData: Record<string, any>) => void; // Submit handler
filterData?: any; // Initial filter data
}
Features:
- Filter-specific form handling
- Integration with main form builder
- Loading state management
- Schema-based filter generation
Handles data grid display and interactions.
interface TableBuilderProps {
formId: string; // Form identifier
onRowSelect: (row: any) => void; // Row selection handler
filterData?: any; // Filter data
}
Features:
- Dynamic column generation
- Data filtering
- Row selection
- Responsive grid layout
import { useRef } from 'react';
import { KyroBuilderRef } from './KyroBuilder';
import KyroBuilder from './KyroBuilder';
const MyPage = () => {
const kyroBuilderRef = useRef<KyroBuilderRef>(null);
const handleBlur = (fieldName: string, event: any) => {
const value = event.target.value;
const currentErrors = kyroBuilderRef.current?.getFormErrors() || {};
const updatedErrors = { ...currentErrors };
if (fieldName === 'model') {
if (value === '1') {
updatedErrors[fieldName] = 'You cant set the model to 1';
} else {
delete updatedErrors[fieldName];
}
}
kyroBuilderRef.current?.setFormErrors(updatedErrors);
};
const handleFocus = (fieldName: string, event: any) => {
console.log(`Field "${fieldName}" focused with value: ${event.target.value}`);
};
return (
<div>
<KyroBuilder
ref={kyroBuilderRef}
formId="products_data"
onBlur={handleBlur}
onFocus={handleFocus}
filterInitData={{ company: 'apple' }}
/>
</div>
);
};
interface KyroBuilderRef {
addField: (field: any) => void;
removeField: (fieldName: string) => void;
getFormData: () => Record<string, any>;
setFormErrors: (errors: Record<string, string | null>) => void;
getFormErrors: () => Record<string, string | null>;
}
interface ColumnConfig {
formid: string;
sectionid: string;
field: string;
title: string;
colsize: string;
type: string;
component: string;
required: number;
sortno: number;
active: number;
hint?: string;
placeholder?: string;
options?: any[];
defaultvalue?: any;
addattrs?: any;
}
The system supports multiple view types:
-
Combined Form and Table View
- Split screen with resizable panels
- Interactive row selection
- Form editing capabilities
-
Filter Form View
- Dedicated filtering interface
- Real-time filter applications
- Submit handler for filter changes
-
Table View
- Data grid display
- Column customization
- Row selection handling
The system manages several states:
- Form data state
- Error state
- Loading states
- Filter states
- Row selection state
Comprehensive event system including:
- Blur events
- Focus events
- Change events
- Key events
- Custom events
- React 18+
- react-data-grid
- @mui/material
- TypeScript 4.5+
- Always provide unique formIds
- Handle loading states appropriately
- Implement proper error handling
- Use TypeScript for better type safety
- Manage form refs correctly
- Handle validation appropriately
The system includes built-in error handling for:
- Schema loading errors
- Validation errors
- API errors
- Data loading errors