Package Exports
- hazo_collab_forms
- hazo_collab_forms/components
- hazo_collab_forms/lib
- hazo_collab_forms/utils
Readme
Hazo Collab Forms
React form components with integrated chat collaboration, built for Next.js with TypeScript and Tailwind CSS.
Features
- Integrated Chat Collaboration: Each form field supports real-time chat discussions via HazoChat
- Unified Form View: Multi-mode form display (Edit, Summary, Print, Approval) with shared context
- Read-Only Summary Views: Display form data in summary format with HazoCollabFormSummary component
- Advanced Field Controls: Visibility toggle, lock/unlock, field duplication, soft delete, and notes
- Notes Integration: Database-backed notes on fields via hazo_notes package (optional)
- Field Tooltips: Help tooltips with hover cards for field labels and data table columns
- Template Generator: Visual drag-and-drop builder for creating form configurations (HazoTemplateGenerator)
- Dynamic Field Management: Add, edit, and delete fields at runtime with dialog components
- Field Selector: Search and select fields from templates with HazoFieldSelectorDialog
- Role-Based Icon Controls: Configure control visibility and behavior per role with icons_behaviour system
- Unified Field Controls: Consistent icon controls across form and summary views with automatic kebab consolidation
- Prop-Based Controls: Enable/disable features via
enable_*props for full control - File Upload with Validation: Built-in file upload with custom validation callbacks
- Document Fields: File-only fields with HazoCollabFormDoc component
- Mandatory File Indicator: Visual indicators (red asterisk) for required file uploads
- Custom File Validators: Implement custom validation logic before file upload
- Form Sets: JSON-based dynamic form generation with full file upload support
- Data OK Workflows: Checkbox and multi-state validation with auto-hide/auto-lock features
- Hidden States: Restrict available data OK states per field or form (e.g., hide "Pending" for agents)
- Type-Safe: Written in TypeScript with comprehensive type definitions
- Tailwind CSS Styling: Fully customizable with Tailwind CSS classes
- shadcn/ui Components: Built on top of accessible Radix UI primitives
Installation
Step 1: Install the Package
npm install hazo_collab_formsStep 2: Install Peer Dependencies
# Core React dependencies (skip if already installed)
npm install react react-dom
# UI dependencies
npm install react-icons sonner lucide-react
npm install @radix-ui/react-dialog @radix-ui/react-label
# Hazo ecosystem packages (required for chat and notes functionality)
npm install hazo_chat hazo_ui hazo_auth hazo_config hazo_notesStep 3: Install shadcn/ui Components
This package requires shadcn/ui components. If you haven't initialized shadcn/ui yet:
npx shadcn@latest initThen install the required components:
# Core components (required for all form fields)
npx shadcn@latest add button label dialog tooltip sonner
# For HazoCollabFormCombo (dropdown/select)
npx shadcn@latest add popover command
# For HazoCollabFormDate (date picker)
npx shadcn@latest add calendar
# For file upload functionality (required when using accept_files prop)
npx shadcn@latest add accordion
# For HazoTemplateGenerator (visual form builder)
npx shadcn@latest add tabs resizable
# For field tooltips (optional - falls back to native title if not installed)
npx shadcn@latest add hover-card
# Optional but recommended
npx shadcn@latest add separator cardStep 4: Configure Next.js
Add to your next.config.js:
const nextConfig = {
transpilePackages: ['hazo_collab_forms'],
};
module.exports = nextConfig;Step 5: Configure Tailwind CSS
Add to tailwind.config.ts content array:
content: [
// ... your existing paths
"./node_modules/hazo_collab_forms/**/*.{js,ts,jsx,tsx}",
],Step 6: Create Config Files
Copy the template config files to your project root:
mkdir -p config
cp node_modules/hazo_collab_forms/templates/config/hazo_collab_forms_config.ini ./config/
cp node_modules/hazo_collab_forms/templates/*.ini ./This creates:
config/hazo_collab_forms_config.ini- Main package config (in config/ subdirectory)hazo_chat_config.ini- Chat functionality confighazo_auth_config.ini- Authentication config
Step 7: Verify Installation
npx hazo-collab-forms-verifyThis checks all dependencies, config files, and shadcn components are properly installed.
Quick Reference
One-Line Install (All Dependencies)
npm install hazo_collab_forms react react-dom react-icons sonner lucide-react \
@radix-ui/react-dialog @radix-ui/react-label hazo_chat hazo_ui hazo_auth hazo_config hazo_notesOne-Line shadcn Install (All Components)
npx shadcn@latest add button label dialog tooltip sonner popover command calendar accordion tabs resizable hover-card separator card sheet scroll-area checkbox selectUsage
Basic Example
'use client';
import { HazoCollabFormInputbox } from 'hazo_collab_forms';
import { useState } from 'react';
export default function MyForm() {
const [value, setValue] = useState('');
return (
<HazoCollabFormInputbox
label="Your Name"
value={value}
onChange={setValue}
field_data_id="user-name"
field_name="User Name"
hazo_chat_receiver_user_id="recipient-user-id"
/>
);
}File Upload with Validation
'use client';
import { HazoCollabFormInputbox } from 'hazo_collab_forms';
import { useState } from 'react';
export default function DocumentUpload() {
const [value, setValue] = useState('');
return (
<HazoCollabFormInputbox
label="Invoice Upload"
value={value}
onChange={setValue}
accept_files={true}
files_dir="public/uploads"
min_files={1} // Shows red asterisk (mandatory indicator)
max_files={5}
file_accept=".pdf"
file_validator={(file) => {
// Custom validation - filename pattern check
if (!file.name.match(/^INV-\d{4}\.pdf$/i)) {
return 'File name must match pattern: INV-0000.pdf';
}
// Size check (5MB limit)
if (file.size > 5 * 1024 * 1024) {
return 'File size must be under 5MB';
}
return null; // Accept file
}}
/>
);
}Advanced Field Control Icons
The package exports standalone control icons for building custom form workflows:
'use client';
import {
HazoCollabFormInputbox,
CollabFormVisibilityIcon,
CollabFormLockIcon,
CollabFormAddEntryIcon,
CollabFormDeleteEntryIcon,
CollabFormDeleteFieldIcon,
} from 'hazo_collab_forms';
import { useState } from 'react';
export default function AdvancedForm() {
const [value, setValue] = useState('');
const [visibility, setVisibility] = useState<'visible' | 'hidden'>('visible');
const [locked, setLocked] = useState(false);
return (
<div>
{/* Visibility Toggle */}
<CollabFormVisibilityIcon
label="Company Name"
visibility={visibility}
on_visibility_change={setVisibility}
/>
{/* Lock/Unlock Field */}
<CollabFormLockIcon
label="Company Name"
locked={locked}
on_lock_change={setLocked}
/>
{/* Add Entry - duplicate field */}
<CollabFormAddEntryIcon
label="Contact Person"
field_id="contact_person"
on_add_entry={(field_id) => console.log('Add entry:', field_id)}
/>
{/* Delete Entry - remove duplicated field */}
<CollabFormDeleteEntryIcon
label="Contact Person"
field_id="contact_person_2"
on_delete_entry={(field_id) => console.log('Delete entry:', field_id)}
/>
{/* Delete Field - soft delete */}
<CollabFormDeleteFieldIcon
label="Optional Field"
field_id="optional_field"
on_delete={(field_id) => console.log('Delete field:', field_id)}
/>
</div>
);
}Icon Components:
| Icon Component | Description |
|---|---|
CollabFormVisibilityIcon |
Toggle field visibility (show/hide) |
CollabFormLockIcon |
Toggle field lock (read-only mode) |
CollabFormAddEntryIcon |
Duplicate a field entry |
CollabFormDeleteEntryIcon |
Remove a duplicated entry |
CollabFormDeleteFieldIcon |
Soft delete a field |
Note: All controls are shown based on enable_* props. The consuming app decides which controls to render by passing the appropriate props.
Field-Level Controls in HazoCollabFormSet
When using HazoCollabFormSet with JSON-based field definitions, you can configure lock, visibility, and delete controls at the field level. This allows different fields to have different controls.
Cascade Priority:
- Field-level
FieldConfigproperties → overrides form-level defaults - Form-level
HazoCollabFormSetProps→ applies to all fields - Hardcoded fallback →
false(disabled)
'use client';
import { HazoCollabFormSet, FieldConfig } from 'hazo_collab_forms';
const fields: FieldConfig[] = [
{
id: "customer_name",
label: "Customer Name",
field_type: "field",
component_type: "HazoCollabFormInputbox",
value: "",
// Uses form-level defaults
},
{
id: "tax_file_number",
label: "Tax File Number",
field_type: "field",
component_type: "HazoCollabFormInputbox",
value: "",
enable_lock: true,
enable_visibility_toggle: true, // Field-level override
enable_delete: false
},
{
id: "internal_notes",
label: "Internal Notes",
field_type: "field",
component_type: "HazoCollabFormTextArea",
value: "",
enable_lock: false, // Hide lock on this field
enable_visibility_toggle: true,
enable_delete: true // Show delete on this field
}
];
export default function CustomerForm() {
return (
<HazoCollabFormSet
fields_set={{ name: "Customer Form", fields }}
enable_lock={true} // Default for all fields
enable_visibility_toggle={false} // Default for all fields
enable_delete={false} // Default for all fields
/>
);
}Available FieldConfig Control Properties:
enable_lock?: boolean- Show lock iconenable_visibility_toggle?: boolean- Show visibility toggle iconenable_delete?: boolean- Show delete iconenable_data_ok?: boolean- Show data OK controlenable_notes?: boolean- Show notes iconnotes_panel_style?: 'popover' | 'slide_panel'- Notes panel style (default: 'popover')notes_background_color?: string- Notes panel background (Tailwind class)notes_save_mode?: 'explicit' | 'auto'- Notes save behavior (default: 'explicit')enable_chat?: boolean- Show chat iconchat_read_only?: boolean- View-only chat mode (no input, just viewing)locked?: boolean- Initial lock statevisibility?: 'visible' | 'hidden'- Initial visibility state
Group-Level Control Propagation (Inheritance)
Groups can set enable_* props that automatically propagate to all child fields. This simplifies configuration when all fields in a group need the same controls.
Cascade Priority (highest to lowest):
- Field-level
enable_*in FieldConfig - Individual field override - Parent-group
enable_*- Inherited from parent group - Form-level
enable_*in HazoCollabFormSetProps - Applies to all fields - Hardcoded fallback -
false
Inheritable Control Props:
enable_lock- Lock/protect field controlenable_visibility_toggle- Show/hide field controlenable_delete- Delete field controlenable_data_ok- Data OK validation controlenable_notes- Notes controlenable_chat- Chat control (requireschat_group_idat form level)
const fields: FieldConfig[] = [
{
id: "tax_details",
label: "Tax Information",
field_type: "group",
// These propagate to all children
enable_lock: true,
enable_visibility_toggle: true,
enable_notes: true,
enable_chat: true,
sub_fields: [
// Inherits all enable_* from parent
{ id: "tfn", label: "Tax File Number", component_type: "HazoCollabFormInputbox", value: "" },
// Override: explicitly disable lock and chat
{ id: "abn", label: "ABN", component_type: "HazoCollabFormInputbox", value: "", enable_lock: false, enable_chat: false },
]
}
];Utility Function:
import { resolve_field_controls } from 'hazo_collab_forms';
// Resolve effective controls for a field considering inheritance
const resolved = resolve_field_controls(field, parent_group, form_settings);
// Returns: { enable_lock, enable_visibility_toggle, enable_delete, enable_data_ok, enable_notes, enable_chat }Unified Field Metadata Sync
Control field metadata (visibility, locked, deleted) from a parent component without remounting the form. This enables syncing state between form and summary views.
Props:
field_metadata?: Record<string, FieldMetadataInput>- External metadata for controlled syncon_field_metadata_change?: (change: FieldMetadataChange) => void- Unified callback for all metadata changes
Types:
interface FieldMetadataInput {
visibility?: 'visible' | 'hidden'; // or hidden?: boolean
locked?: boolean;
data_ok?: boolean | DataOkState; // or dataOk
deleted?: boolean;
}
interface FieldMetadataChange {
field_id: string;
visibility?: 'visible' | 'hidden';
locked?: boolean;
data_ok?: boolean | DataOkState;
deleted?: boolean;
}Usage Example:
import { HazoCollabFormSet } from 'hazo_collab_forms';
import type { FieldMetadataInput, FieldMetadataChange } from 'hazo_collab_forms';
import { useState } from 'react';
function MyForm({ fields }) {
const [fieldMetadata, setFieldMetadata] = useState<Record<string, FieldMetadataInput>>({
tax_file_number: { visibility: 'hidden', locked: true },
name: { visibility: 'visible', locked: false },
});
// Unified handler - called for any metadata change
const handleMetadataChange = (change: FieldMetadataChange) => {
setFieldMetadata(prev => ({
...prev,
[change.field_id]: { ...prev[change.field_id], ...change }
}));
};
return (
<HazoCollabFormSet
fields_set={fields}
enable_visibility_toggle={true}
enable_lock={true}
field_metadata={fieldMetadata}
on_field_metadata_change={handleMetadataChange}
/>
);
}Benefits:
- No component remount needed for metadata sync
- Parent has full control over metadata state
- Unified callback simplifies state management
- Backward compatible with existing callbacks (
on_visibility_change,on_lock_change, etc.)
Normalization Helper:
import { normalize_field_metadata_input } from 'hazo_collab_forms';
// Normalize input that uses alternative naming conventions
const input = { hidden: true, dataOk: 'ok', locked: true };
const normalized = normalize_field_metadata_input(input);
// Result: { visibility: 'hidden', data_ok: 'ok', locked: true }Read-Only Summary View
Display form data in a read-only summary format for review workflows:
'use client';
import { HazoCollabFormSummary, type FormSection } from 'hazo_collab_forms';
import { LuUser, LuFileText } from 'react-icons/lu';
const iconMap = {
LuUser: LuUser,
LuFileText: LuFileText,
};
const sections: FormSection[] = [
{
group_name: "Personal Details",
icon: "LuUser",
field_list: [
{ id: "name", label: "Full Name", component_type: "HazoCollabFormInputbox", value: "" },
{ id: "email", label: "Email", component_type: "HazoCollabFormInputbox", value: "" },
]
},
{
group_name: "Tax Details",
icon: "LuFileText",
field_list: [
{ id: "tfn", label: "Tax File Number", component_type: "HazoCollabFormInputbox", value: "" },
]
}
];
export default function FormSummaryPage() {
return (
<HazoCollabFormSummary
sections={sections}
form_data={{
name: "John Doe",
email: "john@example.com",
tfn: "123456789"
}}
render_icon={(iconName) => {
const Icon = iconMap[iconName];
return Icon ? <Icon className="h-5 w-5" /> : null;
}}
show_edit_buttons={true}
on_edit_section={(index) => router.push(`/edit/${index}`)}
/>
);
}With Full Controls:
<HazoCollabFormSummary
sections={sections}
form_data={formData}
field_metadata={fieldMetadata}
// Enable field controls - each enabled via props
// Use *_editable props to make controls clickable
enable_data_ok={true}
data_ok_mode="multi_state"
data_ok_editable={true}
enable_notes={true}
notes_panel_style="popover" // 'popover' (default) or 'slide_panel'
notes_background_color="bg-yellow-100" // Tailwind class
notes_save_mode="explicit" // 'explicit' (Save/Cancel) or 'auto' (save on blur)
enable_chat={true}
chat_group_id="review-session-123"
chat_read_only={false} // Set to true for view-only chat mode
enable_visibility_toggle={true}
visibility_editable={true}
enable_lock={true}
lock_editable={true}
enable_delete={true}
// Display settings
controls_display="popover"
show_edit_buttons={true}
on_edit_section={(index) => handleEdit(index)}
// Callbacks
on_data_ok_change={(fieldId, value) => console.log('Data OK changed:', fieldId, value)}
on_notes_change={(fieldId, notes) => console.log('Notes updated:', fieldId, notes)}
on_visibility_change={(fieldId, visibility) => console.log('Visibility changed:', fieldId, visibility)}
on_lock_change={(fieldId, locked) => console.log('Lock changed:', fieldId, locked)}
// Auto-actions
on_data_ok_hidden={true} // Auto-hide when marked OK
on_data_ok_protected={true} // Auto-lock when marked OK
/>Key Features:
- Composable design - enable only the features you need
- Section icons with custom rendering
- Edit navigation buttons
- Field controls: data_ok, notes, chat, lock, visibility, delete
- Two display modes: inline or popover
- Row-level controls on DataTables
- Auto-hide/auto-lock on data_ok change
- Chat read-only mode for view-only scenarios
Chat Read-Only Mode
Enable view-only chat mode where users can see chat history but cannot send new messages. Useful for archived forms, review-only views, or user permission scenarios.
Props:
chat_read_only?: boolean- Form-level setting (applies to all fields)- Field-level
chat_read_onlyin FieldConfig overrides form-level setting
// HazoCollabFormSet - all fields have view-only chat
<HazoCollabFormSet
fields_set={fields}
chat_group_id={groupId}
chat_read_only={true}
/>
// HazoCollabFormSummary - view-only chat
<HazoCollabFormSummary
sections={sections}
form_data={formData}
enable_chat={true}
chat_group_id={groupId}
chat_read_only={true}
/>
// Field-level override in FieldConfig
const fields: FieldConfig[] = [
{
id: "active_discussion",
label: "Active Discussion",
component_type: "HazoCollabFormInputbox",
chat_read_only: false // Can chat on this field
},
{
id: "archived_data",
label: "Archived Data",
component_type: "HazoCollabFormInputbox",
chat_read_only: true // View-only chat
}
];Field Tooltips
Add help tooltips to field labels and data table columns using the tooltip prop. Tooltips display on hover using shadcn's HoverCard component, with automatic fallback to native title attribute if HoverCard is not available.
Usage in Form Fields:
import { HazoCollabFormInputbox } from 'hazo_collab_forms';
<HazoCollabFormInputbox
label="Tax File Number"
tooltip="Your 9-digit tax identification number (TFN)"
value={tfn}
onChange={setTfn}
/>
// Or with full TooltipConfig
<HazoCollabFormInputbox
label="ABN"
tooltip={{
enabled: true,
content: "Australian Business Number - 11 digits",
position: "right" // optional
}}
value={abn}
onChange={setAbn}
/>Usage in Data Tables:
const columns: DataTableColumn[] = [
{
id: "amount",
label: "Amount",
type: "number",
tooltip: "Enter the invoice amount in AUD",
},
{
id: "date",
label: "Invoice Date",
type: "date",
tooltip: {
enabled: true,
content: "The date shown on the invoice document"
}
}
];Tooltip in FieldConfig:
const fields: FieldConfig[] = [
{
id: "gst_amount",
label: "GST Amount",
component_type: "HazoCollabFormInputbox",
tooltip: "10% of the invoice amount (automatically calculated if empty)",
value: ""
}
];Optional Dependency:
- Tooltips require
hover-cardshadcn component for best experience - Automatically falls back to native HTML title attribute if hover-card is not installed
- Install with:
npx shadcn@latest add hover-card
Template Generator
Visual form builder for creating HazoCollabFormSet configurations with drag-and-drop interface. Build complex form structures without writing JSON manually.
Basic Usage:
'use client';
import { HazoTemplateGenerator } from 'hazo_collab_forms';
import { useState } from 'react';
export default function TemplateBuilder() {
const [template, setTemplate] = useState({
sections: [],
icons_behaviour: {}
});
return (
<div className="h-screen">
<HazoTemplateGenerator
initial_template={template}
on_template_change={setTemplate}
on_save={(template) => {
console.log('Saved template:', template);
// Save to database or file
}}
on_cancel={() => router.push('/templates')}
/>
</div>
);
}Features:
- Visual Tree Editor: Organize sections, groups, and fields hierarchically
- Live Preview: See your form render in real-time as you build
- Property Editors: Configure field properties, validation, and controls
- Data Table Editor: Visual builder for complex data table configurations
- Icons Behaviour Editor: Configure role-based control visibility
- Template Library: Load and save reusable templates
- Import/Export: JSON import/export for version control
- Full-Screen Preview: Test your form in full-screen dialog
- Undo/Redo: Complete history navigation
Props:
| Prop | Type | Description |
|---|---|---|
initial_template |
Section[] | Starting template structure |
on_template_change |
callback | Called when template changes |
on_save |
callback | Save button handler |
on_cancel |
callback | Cancel button handler |
available_templates |
TemplateOption[] | Predefined templates to load |
on_load_template |
callback | Called when template is loaded |
preview_chat_group_id |
string | Chat group ID for live preview |
readonly |
boolean | Disable editing (view-only mode) |
show_import_export |
boolean | Show import/export buttons |
show_controls_tab |
boolean | Show advanced controls configuration |
Template Structure:
The generator produces standard HazoCollabFormSet configuration:
interface TemplateOutput {
sections: Section[];
icons_behaviour?: IconsBehaviour;
}Required shadcn Components:
- resizable (for panel layout)
- tabs (for editor interface)
- hover-card (optional, for tooltips)
Install with: npx shadcn@latest add resizable tabs
Unified Form View (HazoCollabFormView)
A unified component that combines edit, summary, print, and approval views with shared context. Switch between view modes without remounting, preserving state and field metadata.
Basic Usage:
'use client';
import { HazoCollabFormView, type ViewMode } from 'hazo_collab_forms';
import { useState } from 'react';
export default function UnifiedFormPage() {
const [viewMode, setViewMode] = useState<ViewMode>('edit');
const [formData, setFormData] = useState<Record<string, unknown>>({});
return (
<div>
{/* View mode switcher */}
<div className="flex gap-2 mb-4">
<button onClick={() => setViewMode('edit')}>Edit</button>
<button onClick={() => setViewMode('summary')}>Summary</button>
<button onClick={() => setViewMode('print')}>Print</button>
<button onClick={() => setViewMode('approval')}>Approval</button>
</div>
<HazoCollabFormView
sections={sections}
view_mode={viewMode}
form_data={formData}
on_form_data_change={setFormData}
icons_behaviour={iconsBehaviour}
active_role="tax_agent"
enable_chat={true}
chat_group_id="form-session-123"
/>
</div>
);
}View Modes:
| Mode | Description |
|---|---|
edit |
Full form editing with all field controls |
summary |
Read-only summary view for review |
print |
Print-optimized layout |
approval |
Review with data_ok approval workflow |
Key Props:
| Prop | Type | Description |
|---|---|---|
sections |
ViewSection[] | Form sections (same as HazoCollabFormSet) |
view_mode |
ViewMode | Current view mode |
form_data |
Record<string, unknown> | Form values |
on_form_data_change |
callback | Called when form data changes |
field_metadata |
Record<string, FieldMetadata> | Field metadata (visibility, lock, etc.) |
on_field_metadata_change |
callback | Called when metadata changes |
icons_behaviour |
IconsBehaviour | Role-based control configuration |
active_role |
string | Current user's role |
Context Hooks:
Access form state from nested components using hooks:
import {
useFormViewContext,
useViewMode,
useFormData,
useFieldMetadata,
useFieldValue,
useFieldMeta,
useApprovalStats,
} from 'hazo_collab_forms';
function FieldComponent({ fieldId }) {
const viewMode = useViewMode();
const value = useFieldValue(fieldId);
const { data_ok, locked, visibility } = useFieldMeta(fieldId);
const { total, approved, pending } = useApprovalStats();
// Render based on view mode and field state
}Role-Based Icon Controls (icons_behaviour)
Configure which control icons are visible and enabled based on user roles. Supports automatic consolidation into kebab (3-dots) menus and extraction of active controls.
JSON Configuration Options:
You can configure icons_behaviour in two ways:
- Embedded (original): Include icons_behaviour directly in the form JSON file
- Separate file (recommended): Store icons_behaviour in a dedicated JSON file for reuse across forms
Separate File Approach (v1.7.0+):
public/data/form-sets/
tax_form_individual_full.json # Sections only
icon_behaviour.json # Icons behaviour config (reusable)Load both files and pass icons_behaviour as a prop:
// Load form configuration
const sectionsResponse = await fetch('/data/form-sets/tax_form_individual_full.json');
const { sections } = await sectionsResponse.json();
const behaviourResponse = await fetch('/data/form-sets/icon_behaviour.json');
const icons_behaviour = await behaviourResponse.json();
// Pass to HazoCollabFormSet
<HazoCollabFormSet
section={section}
icons_behaviour={icons_behaviour}
active_role="tax_agent"
/>
// Pass to HazoCollabFormSummary
<HazoCollabFormSummary
sections={sections}
icons_behaviour={icons_behaviour}
active_role="tax_agent"
form_data={formData}
/>Prop Priority:
icons_behaviourprop (if provided)section.icons_behaviourorsections[0]?.icons_behaviour(backward compatible)
This separation allows:
- Reusing the same icon behavior across multiple forms
- Changing roles without modifying form structure
- Easier maintenance of large form configurations
Configuration Structure:
const icons_behaviour: IconsBehaviour = {
// Data OK display mode
data_ok_mode: 'multistate', // or 'checkbox'
// Controls that have borders
border_on: ['control_data_ok'],
// Display order (left to right)
icon_order: [
'control_data_ok',
'control_notes',
'control_chat',
'control_visibility',
'control_lock',
'control_delete'
],
// Always shown individually (never in kebab)
always_extracted: ['control_data_ok'],
// Extracted when they have activity
extracted_on_value: ['control_notes', 'control_chat'],
// Role definitions
roles: [
{
role_id: 'tax_agent',
role_name: 'Tax Agent',
role_description: 'Full access to all controls',
controls: {
control_data_ok: { visible: true, enabled: true },
control_notes: { visible: true, enabled: true },
control_chat: { visible: true, enabled: true },
control_visibility: { visible: true, enabled: true },
control_lock: { visible: true, enabled: true },
control_delete: { visible: true, enabled: false }
}
},
{
role_id: 'client',
role_name: 'Client',
role_description: 'Limited to chat and notes',
controls: {
control_chat: { visible: true, enabled: true },
control_notes: { visible: true, enabled: true },
control_data_ok: { visible: true, enabled: false },
control_visibility: { visible: false, enabled: false },
control_lock: { visible: false, enabled: false },
control_delete: { visible: false, enabled: false }
}
}
]
};Usage in HazoCollabFormSet:
<HazoCollabFormSet
fields_set={{
name: "Tax Return Form",
fields: [...],
icons_behaviour: icons_behaviour
}}
active_role="tax_agent" // Current user's role
/>Usage in HazoCollabFormSummary:
<HazoCollabFormSummary
sections={sections.map(section => ({
...section,
icons_behaviour: icons_behaviour
}))}
active_role="client"
form_data={formData}
/>Consolidation Rules (Automatic):
When 2+ non-extracted controls are visible, they consolidate into a kebab menu:
- Data OK: Always inline (hardcoded, never in kebab)
- Controls in always_extracted: Always inline
- Controls in extracted_on_value with activity: Extracted from kebab (shown inline)
control_notes: Extracted when notes existcontrol_chat: Extracted when messages exist
- Remaining visible controls: Kebab menu if 2+, otherwise inline
Field/Group Level Override:
Set show_icons: true on fields or groups to show icons according to the active role:
const fields: FieldConfig[] = [
{
id: "sensitive_group",
field_type: "group",
label: "Sensitive Information",
show_icons: true, // Show role-based icons for this group
sub_fields: [
{
id: "ssn",
label: "Social Security Number",
component_type: "HazoCollabFormInputbox",
show_icons: true, // Show role-based icons for this field
value: ""
}
]
}
];Benefits:
- Single configuration for entire form
- Consistent behavior across form and summary views
- Automatic UI optimization (kebab consolidation)
- Easy role switching without code changes
- Visual editor in Template Generator
Dynamic Field Dialogs
Add, edit, and manage form fields at runtime using dialog components.
HazoAddFieldDialog:
Add new fields or groups to your form dynamically:
import { HazoAddFieldDialog, type NewFieldDefinition } from 'hazo_collab_forms';
import { useState } from 'react';
export default function DynamicForm() {
const [isOpen, setIsOpen] = useState(false);
const handleAddField = (field: NewFieldDefinition) => {
console.log('New field:', field);
// Add field to your form sections
};
return (
<>
<button onClick={() => setIsOpen(true)}>Add Field</button>
<HazoAddFieldDialog
open={isOpen}
on_open_change={setIsOpen}
on_add={handleAddField}
parent_type="group" // 'section' | 'group'
parent_id="personal_info"
/>
</>
);
}HazoEditFieldDialog:
Edit existing field configurations:
import { HazoEditFieldDialog } from 'hazo_collab_forms';
<HazoEditFieldDialog
open={isEditOpen}
on_open_change={setIsEditOpen}
field={selectedField}
on_save={(updated) => updateField(updated)}
/>HazoFieldSelectorDialog:
Search and select fields from a template:
import { HazoFieldSelectorDialog } from 'hazo_collab_forms';
<HazoFieldSelectorDialog
open={isSelectorOpen}
on_open_change={setIsSelectorOpen}
template={formTemplate}
on_select={(selection) => {
// Handle selected fields
console.log('Selected:', selection);
}}
/>Shared Utilities
The package exports utility functions for working with form structures:
import {
// Field traversal
traverse_fields,
traverse_sections,
collect_field_ids,
collect_leaf_field_ids,
should_render_field,
is_field_empty,
get_field_value,
// Dependency checking
parse_dependency,
check_dependency,
// Field metadata normalization
normalize_field_metadata,
normalize_field_metadata_input,
} from 'hazo_collab_forms';
// Traverse all fields in sections
traverse_sections(sections, (field, path) => {
console.log(`Field: ${field.id} at path: ${path.join('/')}`);
});
// Check if field should render based on dependencies
const shouldRender = should_render_field(field, formData, {
check_dependencies: true,
show_empty_fields: false,
});
// Parse and check field dependencies
const dependency = parse_dependency(field.depends_on);
const isActive = check_dependency(dependency, formData);Components
Form Field Components
| Component | Description | Required shadcn |
|---|---|---|
HazoCollabFormInputbox |
Text input with validation | button, label, dialog, tooltip |
HazoCollabFormTextArea |
Multi-line text input | button, label, dialog, tooltip |
HazoCollabFormCheckbox |
Boolean toggle | button, label, dialog, tooltip |
HazoCollabFormCombo |
Dropdown select with search | + popover, command |
HazoCollabFormRadio |
Radio button group | button, label, dialog, tooltip |
HazoCollabFormDate |
Date or date-range picker | + calendar |
HazoCollabFormDoc |
Document/file-only field | button, label, dialog, tooltip, accordion |
HazoCollabFormGroup |
Field grouping container | button, label, dialog, tooltip |
HazoCollabFormDataTable |
Editable data table with aggregations | button, label, dialog, tooltip |
Form Container Components
| Component | Description | Required shadcn |
|---|---|---|
HazoCollabFormSet |
Complete form with field arrays | all components |
HazoCollabFormSummary |
Read-only summary view | button, label, popover |
HazoCollabFormView |
Unified multi-mode view (Edit/Summary/Print/Approval) | all components |
Builder & Dialog Components
| Component | Description | Required shadcn |
|---|---|---|
HazoTemplateGenerator |
Visual form builder | button, label, dialog, tooltip, tabs, resizable |
HazoAddFieldDialog |
Add new fields dynamically | dialog, popover, command |
HazoAddGroupDialog |
Add new groups dynamically | dialog |
HazoEditFieldDialog |
Edit field configurations | dialog, popover, command |
HazoFieldSelectorDialog |
Search and select fields | dialog, command |
Optional Features
| Feature | Required shadcn |
|---|---|
File Upload (accept_files prop) |
+ accordion (required) |
Field Tooltips (tooltip prop) |
+ hover-card (optional) |
Import Paths
// Default: All client-safe components and utilities
import { HazoCollabFormInputbox, cn } from 'hazo_collab_forms';
// Components only
import { HazoCollabFormInputbox } from 'hazo_collab_forms/components';
// Utilities only
import { cn, use_collab_chat } from 'hazo_collab_forms/utils';
// Server-only (config functions)
import { get_config } from 'hazo_collab_forms/lib';Troubleshooting
lucide-react Version Conflicts
Different Hazo packages require different versions of lucide-react. Add this to your package.json:
"overrides": {
"lucide-react": "^0.553.0"
}Missing shadcn Components
If you see errors about missing components, install the specific shadcn component:
npx shadcn@latest add [component-name]Important: If you're using file upload functionality (accept_files prop on any form field), you must install the accordion component:
npx shadcn@latest add accordionVerify Your Setup
Run the verification tool to check for common issues:
npx hazo-collab-forms-verifySee SETUP_CHECKLIST.md for detailed troubleshooting.
Development
Package Structure
- Root: ES module npm package
- test-app: Next.js application for testing
Commands
npm run build # Build the package
npm run dev:package # Watch mode for development
npm run dev:test-app # Build and run test app
npm run build:test-app # Build for production
npm run clean # Remove dist directoryTypeScript Configuration
tsconfig.json: Development (bundler module resolution)tsconfig.build.json: Build (Node16 for ES module output)
ES Module Exports
All exports use explicit .js extensions as required for ES modules:
export * from './lib/index.js';
export * from './components/index.js';License
MIT