Skip to main content
Version: 1.0.3

Dynamic Form

A highly flexible and intelligent form component that dynamically shows or hides fields based on user selections. Perfect for complex forms with conditional logic, multi-section layouts, and real-time validation. Features include conditional field rendering, section organization, real-time validation, multiple themes, and comprehensive debugging tools.

Example Usage

Registration Form

Complete your registration information below - watch fields appear based on your selections

Personal Information

Tell us about yourself

Account Type

Choose your account type

Account Security

Secure your account

Subscribe to Newsletter

8 of 11 fields visible

Installation

ignix add component dynamicForm

Interfaces

export type FieldValue = string | boolean | number | undefined;
export type FormValues = Record<string, FieldValue>;
export type ValidationErrors = Record<string, string>;

export type ConditionalOperator =
| 'equals'
| 'notEquals'
| 'includes'
| 'greaterThan'
| 'lessThan'
| 'contains'
| 'startsWith'
| 'endsWith'
| 'boolean';

export interface Condition {
/** Field to check for the condition */
field: string;

/** Operator to use for comparison */
operator: ConditionalOperator;

/** Value to compare against */
value: FieldValue | FieldValue[];
}

export interface ConditionalField {
/** ID of the field to show conditionally */
fieldId: string;

/** Condition that must be met to show this field */
condition: Condition;

/** Whether this field becomes required when shown */
required?: boolean;

/** Whether to preserve the field's value when hidden */
preserveValue?: boolean;
}

export interface FieldOption {
/** Option value (stored in form data) */
value: string;

/** Display label for the option */
label: string;

/** Optional description shown below the label */
description?: string;

/** Icon to display with the option */
icon?: React.ElementType;
}

export interface DynamicFormField {
/** Unique identifier for the field */
id: string;

/** Field name used in form data object */
name: string;

/** Display label for the field */
label: string;

/** Input type with extended options */
type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' |
'textarea' | 'select' | 'checkbox' | 'radio' | 'date' |
'range' | 'color';

/** Placeholder text for the input */
placeholder?: string;

/** Whether the field is required */
required?: boolean;

/** Options for select, radio, or checkbox fields */
options?: FieldOption[];

/** Custom validation function (receives current value and all form values) */
validation?: (value: FieldValue, allValues?: FormValues) => string | undefined;

/** Default value for the field */
defaultValue?: FieldValue;

/** Column span for grid layout */
colSpan?: 'full' | 'half' | 'third' | 'quarter';

/** Icon component to display with the field */
icon?: React.ElementType;

/** Conditions for showing this field */
conditions?: Condition[];

/** Fields that depend on this field's value */
conditionalFields?: ConditionalField[];

/** Email-specific validation options */
emailValidation?: {
pattern?: boolean;
customPattern?: RegExp;
domain?: string[];
message?: string;
};

/** Number-specific validation options */
numberValidation?: {
min?: number;
max?: number;
integer?: boolean;
message?: string;
};

/** Text-specific validation options */
textValidation?: {
minLength?: number;
maxLength?: number;
pattern?: RegExp;
message?: string;
};

/** Custom color for color input or field accent */
color?: string;

/** Gradient string for special styling */
gradient?: string;

/** Custom icon color */
iconColor?: string;
}

export interface Notification {
/** Unique identifier for the notification */
id: string;

/** Type of notification affecting styling */
type: 'success' | 'error' | 'info' | 'warning' | 'magic';

/** Message to display */
message: string;

/** Duration in milliseconds before auto-dismiss */
duration?: number;

/** Custom icon for the notification */
icon?: React.ElementType;
}

Props

DynamicForm Props

PropTypeDefaultDescription
fieldsDynamicFormField[]RequiredArray of field configurations defining the form structure
initialDataFormValues{}Initial data to pre-populate the form
onSubmit(data: FormValues) => Promise<void> | voidCalled when form is submitted
onCancel() => voidTriggered when cancel button is clicked
onChange(data: FormValues, visibleFields: string[]) => voidTriggered when any field value changes
variant"default" | "vibrant" | "pastel" | "neon" | "earthy" | "ocean" | "sunset" | "forest" | "galaxy" | "candy""default"Visual theme variant for the form
cardVariant"default" | "glass" | "border" | "elevated" | "neon" | "vibrant""default"Style of the form card container
inputVariantstring"default"Visual variant for input fields
buttonVariantstring"default"Visual variant for submit button
buttonAnimationVariantstringAnimation style for the submit button
submitButtonLabelstring"Submit"Custom label for submit button
cancelButtonLabelstring"Cancel"Custom label for cancel button
isLoadingbooleanfalseShows loading state when fetching initial data
isSubmittingbooleanfalseControls submitting state
showCancelButtonbooleantrueWhether to display cancel button
animateFieldChangesbooleantrueAnimate fields when visibility changes
animationIntensity'subtle' | 'moderate' | 'high''moderate'Intensity of animations
showSuccessNotificationbooleantrueShow success notification after submission
successNotificationDurationnumber3000Duration of success notification
successNotificationMessagestring'✨ Form submitted successfully!'Success message
theme'light' | 'dark' | 'system''system'Theme preference
colorScheme'default' | 'vibrant' | 'pastel' | 'neon' | 'earthy' | 'ocean' | 'sunset' | 'forest''default'Color scheme variant
debugbooleanfalseEnables debug panel
classNamestringExtra classes for root element
containerClassNamestringExtra classes for inner container

DynamicHeader Props

PropTypeDefaultDescription
titlestring | React.ReactNodeHeader title
descriptionstringDescription text
iconReact.ReactNodeIcon displayed next to title
childrenReact.ReactNodeCustom header content
classNamestringExtra CSS classes
titleClassNamestringCustom classes for title
descriptionClassNamestringCustom classes for description
iconClassNamestringCustom classes for icon container
containerClassNamestringCustom container classes
titleVariantTypographyVariants'h4'Typography style for title
titleWeight'light' | 'normal' | 'medium' | 'semibold' | 'bold''bold'Title font weight
titleColorTypographyColorOptions'default'Title text color
descriptionVariant'body' | 'body-small' | 'caption' | 'muted''muted'Description typography
iconSizenumber24Icon size
animatedbooleantrueAnimate header on mount
gradientbooleanfalseApply gradient text to title

DynamicContent Props

PropTypeDefaultDescription
childrenReact.ReactNodeRequiredForm fields or sections
classNamestringExtra container classes
animateChangesbooleantrueAnimate field visibility
cardVariantCardVariant"default"Card visual style
showFieldCountbooleantrueDisplay number of visible fields

DynamicField Props

PropTypeDefaultDescription
fieldDynamicFormFieldRequiredField configuration
classNamestringExtra classes
showLabelbooleantrueDisplay field label
animationVariant'fade' | 'slide' | 'scale' | 'rotate''fade'Field appearance animation

DynamicSection Props

PropTypeDefaultDescription
titlestringSection title
descriptionstringSection description
childrenReact.ReactNodeRequiredFields inside section
classNamestringAdditional classes
conditionCondition | Condition[]Visibility condition
defaultCollapsedbooleanfalseStart collapsed
collapsiblebooleanfalseAllow collapse toggle
showWhenEmptybooleanfalseShow section even if empty
gradientbooleanfalseApply gradient background
iconReact.ElementTypeSection icon

DynamicNavigation Props

PropTypeDefaultDescription
submitButtonLabelstring"Submit"Custom submit label
cancelButtonLabelstring"Cancel"Custom cancel label
showCancelButtonbooleantrueShow cancel button
onCancel() => voidCancel callback
classNamestringExtra classes
position'bottom' | 'sticky''bottom'Navigation bar position
animatedbooleantrueAnimate navigation
childrenReact.ReactNodeCustom navigation UI

DynamicNotification Props

PropTypeDefaultDescription
type'success' | 'error' | 'info' | 'warning' | 'magic'RequiredNotification type
messagestringRequiredNotification message
onClose() => voidRequiredClose callback
durationnumber3000Auto close duration
classNamestringExtra classes
iconReact.ElementTypeCustom icon

DynamicDebugger Props

PropTypeDefaultDescription
classNamestringAdditional debugger classes

ThemeToggle Props

PropTypeDefaultDescription
classNamestringAdditional classes for toggle button