How mithyalabs/react-forms-lite works
Project Type & Purpose
• This is an open-source React component library (“react-forms-lite”) focused on a modular form builder.
• It exports a single entrypoint (src/index.ts → ReactForm) that in turn composes a suite of field components (TextField, SelectField, Radio, etc.) plus utilities and styling.
File‐Structure Analysis
• src/
• index.ts → library entrypoint
• lib/ReactForm.tsx → top‐level component
• lib/ml-form-builder/… → folder of submodules:
– Utils.tsx, index.tsx (barrel)
– lib/CheckBox, ConditionalOperations, FieldArray, FileInput, PhoneField, PlainText, Radio, SelectField, Switch, TextField, Types, Constants (each with .tsx + .scss)
• rollup.config.js & vite.config.ts → build and dev server configurations
• dist/ → published artifacts (CJS, ESM, CSS, .d.ts)
• package.json → scripts, dependencies, exports
Key Architectural Elements & Relationships
• Consumer App
• Imports react-forms-lite from npm
• Renders <ReactForm …>
• ReactForm (entrypoint)
• Delegates to ml-form-builder index module
• Applies global styles (dist/index.css)
• ml-form-builder Module
• Exports field components & helpers
• Each field is atomic, imports its own SCSS module for styling
• Utils and Constants provide shared logic/data (e.g., country lists, conditional rules)
• Build Pipeline
• TypeScript compiler (tsconfig.json, tsconfig.node.json)
• Rollup bundles into dist/ (ESM & CJS), extracts CSS
• Vite config for local demo (index.html)
• Consumer Application
• NPM Registry (optional)
• Library ➔ ReactForm (entrypoint)
• ml-form-builder barrel
• Field Components (grouped)
• Utils / Constants
• SCSS Modules
• Build Tools (TypeScript, Rollup, Vite)
• Dist Artifacts (JS, CSS, .d.ts)
• Consumer → ReactForm import
• ReactForm → ml-form-builder index → individual field modules
• Field modules → SCSS modules
• Source files → Build Tools → Dist Artifacts
• Dist Artifacts → Consumer (via npm or bundler)
Architectural Patterns & Design Principles
• Component-based and atomic design: each form element isolated in its own folder.
• Barrel exports for neat public API (src/lib/ml-form-builder/index.tsx).
• Separation of concerns: styling co-located but compiled separately.
• Build optimization: dual module outputs (CJS + ESM) + type declarations.