UNPKG

extended-dynamic-forms

Version:

Extended React JSON Schema Form (RJSF) v6 with custom components, widgets, templates, layouts, and form events

60 lines (58 loc) 2.13 kB
import { UiSchema } from '@rjsf/utils'; /** * Function type for dynamic uiSchema.items in RJSF fork * This enables O(n) performance for array conditionals */ export type ArrayItemsFunction = (itemData: any, index: number, formContext?: any) => UiSchema; /** * Function type for conditional logic applied to array items */ export type ArrayItemConditionalFn = (itemData: any, index: number, formContext?: any) => Partial<UiSchema>; /** * Creates a dynamic uiSchema.items function for array fields * * @param baseItemUiSchema - Base UI schema applied to all array items * @param conditionalLogic - Function that returns conditional UI schema modifications * @returns Function compatible with RJSF fork's dynamic uiSchema.items * * @example * ```typescript * const directorsUiSchema = { * items: createDynamicArrayItemsUiSchema( * { 'ui:order': ['name', 'hasShareholding', 'shareholdingPercentage'] }, * (itemData) => { * if (!itemData?.hasShareholding) { * return { shareholdingPercentage: { 'ui:widget': 'hidden' } }; * } * return {}; * } * ) * }; * ``` */ export declare function createDynamicArrayItemsUiSchema(baseItemUiSchema: UiSchema, conditionalLogic: ArrayItemConditionalFn): ArrayItemsFunction; /** * Safely merges UI schemas with proper handling of nested properties * * @param base - Base UI schema * @param overrides - Conditional UI schema overrides * @returns Merged UI schema */ export declare function mergeItemUiSchema(base: UiSchema, overrides: Partial<UiSchema>): UiSchema; /** * Helper to create common conditional patterns */ export declare const arrayItemPatterns: { /** * Show/hide a field based on a condition */ hideField: (fieldName: string, condition: (itemData: any) => boolean) => ArrayItemConditionalFn; /** * Make a field required based on a condition */ requireField: (fieldName: string, condition: (itemData: any) => boolean) => ArrayItemConditionalFn; /** * Apply styles to first/last items */ applyIndexStyles: (totalItems: number) => ArrayItemConditionalFn; };