@proveanything/smartlinks-form-renderer
Version:
A flexible React component for rendering forms from JSON schema with conditional logic and storage configuration
171 lines (163 loc) • 6.24 kB
TypeScript
import React$1 from 'react';
interface SchemaFormFieldCondition {
targetFieldId: string;
operator: 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'greater_than' | 'less_than' | 'is_empty' | 'is_not_empty';
value?: any;
logicalOperator?: 'AND' | 'OR';
}
interface TableColumn {
id: string;
title: string;
type: 'string' | 'number' | 'boolean' | 'date';
required?: boolean;
width?: string;
}
interface SchemaFormField {
type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'table';
title?: string;
description?: string;
default?: any;
enum?: any[];
enumNames?: string[];
format?: 'email' | 'date' | 'date-time' | 'uri' | 'textarea' | 'file' | 'select' | 'radio' | 'combobox' | 'checkbox' | 'switch' | 'checkboxes' | 'multiselect';
minimum?: number;
maximum?: number;
minLength?: number;
maxLength?: number;
pattern?: string;
items?: SchemaFormField;
properties?: Record<string, SchemaFormField>;
required?: string[];
conditions?: SchemaFormFieldCondition[];
showWhen?: 'all' | 'any';
columns?: TableColumn[];
minRows?: number;
maxRows?: number;
}
interface SchemaFormUIConfig {
'ui:widget'?: 'text' | 'textarea' | 'select' | 'radio' | 'checkboxes' | 'file' | 'email' | 'date' | 'number' | 'checkbox' | 'switch' | 'combobox' | 'multiselect' | 'table';
'ui:placeholder'?: string;
'ui:help'?: string;
'ui:options'?: {
label?: boolean;
rows?: number;
accept?: string;
};
'ui:order'?: string[];
}
interface SchemaFormUISchema {
[key: string]: SchemaFormUIConfig | SchemaFormUISchema;
}
interface SchemaFormConfig {
id?: string;
title: string;
description: string;
schema: {
type: 'object';
properties: Record<string, SchemaFormField>;
required?: string[];
};
uiSchema: SchemaFormUISchema;
storage: Record<string, 'private' | 'public' | 'proof' | 'personal'>;
settings: {
allowMultipleSubmissions: boolean;
requireAuthentication: boolean;
showProgressBar: boolean;
submitButtonText: string;
successMessage: string;
};
styling: {
theme: 'default' | 'modern' | 'minimal';
primaryColor: string;
backgroundColor: string;
};
fieldOrder?: string[];
createdAt?: string;
updatedAt?: string;
}
interface TableInputProps$1 {
columns: TableColumn[];
value: Record<string, any>[];
onChange: (value: Record<string, any>[]) => void;
minRows?: number;
maxRows?: number;
className?: string;
}
interface SchemaFormRendererProps {
config: SchemaFormConfig;
onSubmit: (data: Record<string, any>) => void;
isSubmitting?: boolean;
className?: string;
initialData?: Record<string, any>;
components?: {
Button?: React.ComponentType<any>;
Input?: React.ComponentType<any>;
Textarea?: React.ComponentType<any>;
Select?: React.ComponentType<any>;
Checkbox?: React.ComponentType<any>;
RadioGroup?: React.ComponentType<any>;
Switch?: React.ComponentType<any>;
Label?: React.ComponentType<any>;
TableInput?: React.ComponentType<TableInputProps$1>;
};
}
declare const SchemaFormRenderer: React$1.FC<SchemaFormRendererProps>;
declare const evaluateFieldConditions: (conditions?: SchemaFormFieldCondition[], showWhen?: "all" | "any", formData?: Record<string, any>) => boolean;
interface TableInputProps {
columns: TableColumn[];
value: Record<string, any>[];
onChange: (value: Record<string, any>[]) => void;
minRows?: number;
maxRows?: number;
className?: string;
}
declare const TableInput: React$1.FC<TableInputProps>;
declare const Button: React$1.FC<React$1.ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: string;
}>;
declare const Input: React$1.FC<React$1.InputHTMLAttributes<HTMLInputElement>>;
declare const Textarea: React$1.FC<React$1.TextareaHTMLAttributes<HTMLTextAreaElement>>;
declare const Label: React$1.FC<React$1.LabelHTMLAttributes<HTMLLabelElement>>;
declare const Select: React$1.FC<React$1.SelectHTMLAttributes<HTMLSelectElement> & {
placeholder?: string;
onValueChange?: (value: string) => void;
}>;
declare const Checkbox: React$1.FC<React$1.InputHTMLAttributes<HTMLInputElement> & {
onCheckedChange?: (checked: boolean) => void;
}>;
declare const Switch: React$1.FC<React$1.InputHTMLAttributes<HTMLInputElement> & {
onCheckedChange?: (checked: boolean) => void;
}>;
declare const RadioGroup: React$1.FC<{
value?: string;
onValueChange?: (value: string) => void;
children: React$1.ReactNode;
className?: string;
}>;
declare const RadioGroupItem: React$1.FC<React$1.InputHTMLAttributes<HTMLInputElement>>;
declare const DefaultComponents_d_Button: typeof Button;
declare const DefaultComponents_d_Checkbox: typeof Checkbox;
declare const DefaultComponents_d_Input: typeof Input;
declare const DefaultComponents_d_Label: typeof Label;
declare const DefaultComponents_d_RadioGroup: typeof RadioGroup;
declare const DefaultComponents_d_RadioGroupItem: typeof RadioGroupItem;
declare const DefaultComponents_d_Select: typeof Select;
declare const DefaultComponents_d_Switch: typeof Switch;
declare const DefaultComponents_d_TableInput: typeof TableInput;
declare const DefaultComponents_d_Textarea: typeof Textarea;
declare namespace DefaultComponents_d {
export {
DefaultComponents_d_Button as Button,
DefaultComponents_d_Checkbox as Checkbox,
DefaultComponents_d_Input as Input,
DefaultComponents_d_Label as Label,
DefaultComponents_d_RadioGroup as RadioGroup,
DefaultComponents_d_RadioGroupItem as RadioGroupItem,
DefaultComponents_d_Select as Select,
DefaultComponents_d_Switch as Switch,
DefaultComponents_d_TableInput as TableInput,
DefaultComponents_d_Textarea as Textarea,
};
}
export { DefaultComponents_d as DefaultComponents, SchemaFormRenderer, evaluateFieldConditions };
export type { SchemaFormConfig, SchemaFormField, SchemaFormFieldCondition, SchemaFormRendererProps, SchemaFormUIConfig, SchemaFormUISchema, TableColumn, TableInputProps$1 as TableInputProps };