Skip to content

gs-ysingh/react-components

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

React Components Library

A collection of reusable, type-safe React components built with TypeScript. This monorepo contains production-ready components designed for modern web applications.

πŸ“¦ Components

1. Form Component

A flexible and powerful form component with built-in validation, error handling, and support for multi-step forms.

Features:

  • 🎯 Type-safe - Built with TypeScript
  • πŸ”§ Flexible field types - Text, email, password, textarea, select, checkbox, date, number
  • βœ… Built-in validation - With custom validation support
  • πŸ”„ Multi-step forms - Step-by-step form flows with progress indicators
  • πŸ“± Responsive - Mobile-friendly design
  • 🎨 Customizable - Easy to style and configure
  • ⏳ Loading states - Built-in loading states for async operations

Location: /form

πŸ“– View Form Documentation

2. DataTable Component

A sortable data table component with a clean interface for displaying tabular data.

Features:

  • πŸ“Š Sortable columns - Click headers to sort ascending/descending
  • 🎨 Styled headers - Distinctive header styling
  • πŸ“± Responsive - Horizontal scroll on smaller screens
  • πŸ”€ Type support - Handles numbers and strings intelligently
  • πŸ’¨ Performant - Memoized sorting for optimal performance
  • ⚠️ Empty state handling - User-friendly empty data display

Location: /data-table

3. Infinite Scroll List

A performant infinite scroll component using the Intersection Observer API.

Features:

  • πŸš€ High performance - Uses Intersection Observer API
  • 🎨 Customizable - Custom item rendering and loader components
  • βš™οΈ Configurable threshold - Control when to trigger loading
  • πŸ”„ Loading states - Built-in loading indicators
  • πŸ“¦ Generic typing - Works with any data type
  • 🎯 Memory efficient - Only loads data as needed

Location: /infinite-scroll

πŸš€ Getting Started

Each component is a standalone React application. Navigate to the specific component directory to run it.

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation & Running

Form Component

cd form
npm install
npm start

Open http://localhost:3000 to view it in the browser.

DataTable Component

cd data-table
npm install
npm start

Open http://localhost:3000 to view it in the browser.

Infinite Scroll Component

cd infinite-scroll
npm install
npm start

Open http://localhost:3000 to view it in the browser.

πŸ“– Usage Examples

Form Component

import { Form, FormField } from './Form';

const MyComponent = () => {
  const fields: FormField[] = [
    {
      name: 'email',
      label: 'Email Address',
      type: 'email',
      required: true,
      placeholder: 'Enter your email'
    },
    {
      name: 'password',
      label: 'Password',
      type: 'password',
      required: true,
      validation: {
        minLength: 8,
        custom: (value) => {
          if (!/[A-Z]/.test(value)) {
            return 'Password must contain at least one uppercase letter';
          }
          return null;
        }
      }
    }
  ];

  const handleSubmit = (data: Record<string, any>) => {
    console.log('Form submitted:', data);
  };

  return (
    <Form
      fields={fields}
      onSubmit={handleSubmit}
      submitLabel="Sign In"
      showReset={false}
    />
  );
};

DataTable Component

import DataTable from './DataTable';

const MyComponent = () => {
  const tableData = {
    columns: [
      { label: 'Name', key: 'name' },
      { label: 'Age', key: 'age' },
      { label: 'City', key: 'city' }
    ],
    rows: [
      { name: 'John Doe', age: 28, city: 'New York' },
      { name: 'Jane Smith', age: 34, city: 'San Francisco' },
      { name: 'Bob Johnson', age: 45, city: 'Chicago' }
    ]
  };

  return <DataTable data={tableData} />;
};

Infinite Scroll Component

import InfiniteScrollList from './InfiniteScrollList';

const MyComponent = () => {
  const [items, setItems] = useState<string[]>([]);
  const [hasMore, setHasMore] = useState(true);
  const [isLoading, setIsLoading] = useState(false);

  const loadMore = async () => {
    setIsLoading(true);
    // Simulate API call
    const newItems = await fetchMoreItems();
    setItems(prev => [...prev, ...newItems]);
    setHasMore(newItems.length > 0);
    setIsLoading(false);
  };

  return (
    <InfiniteScrollList
      items={items}
      hasMore={hasMore}
      loadMore={loadMore}
      isLoading={isLoading}
      renderItem={(item, index) => (
        <div key={index}>{item}</div>
      )}
      threshold={300}
    />
  );
};

πŸ—οΈ Project Structure

react-components/
β”œβ”€β”€ form/                          # Form component
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ Form/
β”‚   β”‚   β”‚   β”œβ”€β”€ Form.tsx          # Main form component
β”‚   β”‚   β”‚   └── index.ts
β”‚   β”‚   β”œβ”€β”€ App.tsx
β”‚   β”‚   β”œβ”€β”€ SimpleFormExample.tsx  # Basic form example
β”‚   β”‚   └── MultiStepFormExample.tsx # Multi-step form example
β”‚   β”œβ”€β”€ package.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ data-table/                    # DataTable component
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ DataTable/
β”‚   β”‚   β”‚   └── DataTable.tsx     # Main table component
β”‚   β”‚   └── App.tsx
β”‚   └── package.json
β”‚
└── infinite-scroll/               # Infinite scroll component
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ InfiniteScrollList/
    β”‚   β”‚   └── InfiniteScrollList.tsx # Main scroll component
    β”‚   └── App.tsx
    └── package.json

πŸ› οΈ Technology Stack

  • React 18.2.0
  • TypeScript 4.4.4+
  • React Scripts 5.0.1
  • Modern React Hooks (useState, useEffect, useMemo, useCallback, useRef)
  • Intersection Observer API (for infinite scroll)

🎨 Customization

All components are designed to be easily customizable:

  • Styling: Each component accepts className props and uses inline styles that can be overridden
  • Behavior: Configurable through props
  • Validation: Custom validation functions supported (Form component)
  • Rendering: Custom render functions supported (Infinite Scroll component)

πŸ§ͺ Testing

Each component directory includes test scripts:

npm test

πŸ—οΈ Building for Production

npm run build

This creates an optimized production build in the build folder.

πŸ“ Available Scripts

In each component directory, you can run:

  • npm start - Runs the app in development mode
  • npm test - Launches the test runner
  • npm run build - Builds the app for production
  • npm run eject - Ejects from Create React App (one-way operation)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is open source and available for use in your projects.

πŸ”— Repository

  • Repository: react-components
  • Owner: gs-ysingh
  • Branch: main

πŸ“§ Contact

For questions or feedback, please open an issue in the repository.


Built with ❀️ using React and TypeScript

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors