React Form Components Collection

react-form-elements

This npm package provides a set of form-related components for React. You can use these components to build forms with ease. The package includes the following components:

Form The Form component is used for creating forms and can contain various input fields. It supports the following components:

Input: A text input field. PasswordInput: A password input field. RadioGroup: A group of radio buttons. TextArea: A multi-line text input field. Checkbox: A checkbox input field.

Table of Contents

Installation

To install, you can use npm or yarn:

$ npm install --save @start-base/react-form-elements
$ yarn add @start-base/react-form-elements

Documentation

Make sure to add css file to your app root file

import '@start-base/react-form-elements/dist/lib/index.css';

Nextjs example can show all features how to use.

layout.js;

import { Inter } from 'next/font/google'
import './globals.css'
import '@start-base/react-form-elements/dist/lib/index.css';

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
  title: 'React Form Elements',
  description: 'React Form Elements Examples',
}

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    </html>
  )
}

Examples

Here’s an example of using the form elements in a React component:

'use client'
import React, { useState } from 'react';
import { Input, PasswordInput, RadioGroup, Checkbox, Form, TextArea } from '@start-base/react-form-elements';

export default function FormElements() {
  const [inputs, setInputs] = useState({});
  const onChange = (e) => {
    const { name, value, type } = e.target;

    setInputs((prevState) => ({
      ...prevState,
      [name]: type === 'checkbox' ? !prevState[name] : value,
    }));
  };

  return (
   <> 
   <h2>React Form Elements</h2>
    <Form>
      <Input
        label="Username"
        name="username"
        value={inputs.username}
        onChange={onChange}
     />
     <PasswordInput
       label="Password"
       name="password"
       value={inputs.password}
       onChange={onChange}
     />
     <TextArea
        name="textarea"
        onChange={onChange}
        label="Description"
        value={inputs.textarea}
      />
     <RadioGroup
        label="RadioGroup"
        value={inputs.country}
        name="country"
        onChange={onChange}
        options={[
          { label: 'Radio Option 1', value: 'default1' },
          { label: 'Radio Option 2', value: 'default2' },
        ]}
     />
     <Checkbox
        checked={inputs.agree}
        label="I understand and accept the terms and conditions and privacy policy."
        name="agree"
        onChange={onChange}
     />
   </Form></>
  )
}

Demos

For live demos of these components in action, please visit our CodeSandbox and Storybook demo pages.

GitHub

View Github


Related Posts

Recent Posts

ഇടുക്കിയിലെ മലയോര മേഖലകളിൽ രാത്രിയാത്ര നിരോധിച്ചു. രാത്രി ഏഴു മുതൽ രാവിലെ ആറു വരെയാണ് നിരോധനം

ഏന്തയാർ ഈസ്റ്റിൽ പ്രളയത്തിൽ തകർന്ന പാലത്തിന് പകരം പുതിയ പാലം നിർമ്മിക്കുവാൻ താത്ക്കാലിക പാലം പൊളിച്ച് നീക്കി

Explore the Investment Opportunities: A Comprehensive Guide to Different Types of Mutual Funds

Title: Understanding Mutual Funds: A Beginner's Guide to Investing

തീവ്രമഴ മുന്നറിയിപ്പിന്റെ പശ്ചാതലത്തിൽ സംസ്ഥാനം ജാഗ്രതയിൽ

250,000 അപേക്ഷകൾ വർദ്ധിച്ചതിനാൽ ട്രാൻസ്‌പോർട്ട് കമ്മീഷണർ പരിശോധന പുനരാരംഭിക്കും

ഏലക്കയിൽ കീടനാശിനി സാന്നിധ്യം; ആറര ലക്ഷത്തിലധികം ടിൻ അരവണ നശിപ്പിക്കാൻ ടെൻഡർ ക്ഷണിച്ച് ദേവസ്വം ബോർഡ്‌

ഭീമൻ പാറക്കഷണങ്ങൾ അടർന്ന് ദേശീയ പാതയിലേക്ക് വീഴുന്നത് പതിവാകുന്നു. കുട്ടിക്കാനത്തിനും മുണ്ടക്കയത്തിനുമിടയിൽ നിലനിൽക്കുന്നത് വൻ അപകട ഭീഷണി

ചക്രവാതച്ചുഴി:അതിശക്തമായ മഴ വരുന്നു

പ്ലസ് വൺ പ്രവേശനം. അക്ഷയയിൽ തിക്കി തിരക്കേണ്ട, നെറ്റിവിറ്റി/ജാതി തെളിയിക്കാൻ പത്താംതരം സർട്ടിഫിക്കറ്റ് മതി