Giter Site home page Giter Site logo

awesome-react-modules / react-pincode Goto Github PK

View Code? Open in Web Editor NEW
29.0 2.0 28.0 2.09 MB

A NPM module which auto fills City, District and State fields when a valid Zip Code in entered!

Home Page: https://www.npmjs.com/package/react-pincode

CSS 4.73% JavaScript 71.96% HTML 22.98% Shell 0.33%
react-pincode pincode city reactjs npm npm-module npm-package axios javascript npm-install

react-pincode's Introduction

React Pincode

React Pincode is a published NPM module that can be integrated inside any ReactJS application. It is used to extract Area, City, District, and State information as soon as the user enters valid Pin-Code. On entering a valid Pin-Code, a GET request is made to the Indian Postal Service API and the useful information is extracted and results are displayed in the respective fields. If an invalid Pincode is entered an error is thrown which can be customized by a user using a specific prop.

Table of Contents

About

The four input fields are wrapped inside an <div> element and each input field is also wrapped inside <div>. So that a user can style it according to the need in the project.

Whenever the wrong Pincode is entered red border appears on the pin code input field and on entering a right pin code, city, district and state input fields get automatically filled with correct data

Note

This will only work for Indian Pincodes.

Working

import Pincode from 'react-pincode';

JS

import React, { useState, useEffect } from 'react';
import Pincode from 'react-pincode';

function App() {
  const [pincodeData, setPincodeData] = useState('');
  return (
    <div className="App">
      <Pincode
        invalidError="Please check pincode"
        lengthError="check length"
        getData={(data) => setPincodeData(data)}
      />
    </div>
  );
}

Playground

Find Codepen Implementation of the module here

Pincode Props

  1. Props for changing CSS properties
Name Description
Container Container which wraps all the three Input Field
pincodeContainer Container which wraps pincode Input Field
cityContainer Container which wraps City Input Field
districtContainer Container which wraps District Input Field
stateContainer Container which wraps State Input Field
pincodeInput Props for styling pincode input field
cityInput Props for styling city input field
stateInput Props for styling state input field
showArea Props for displaying Area input (default: true)
showState Props for displaying State input (default: true)
showDistrict Props for displaying District input (default: true)
showCity Props for displaying City input (default: true)
  1. Props for changing error message.

By deafult,

  • For an Invalid Pincode - "Invalid PIN Code"
  • If Pincode length is not valid - "ZIP code must be of 6 digits"
Name Description
invalidError Props for changing invalid error message.
lenghtError Props for changing invalid length message.

Example

JS

import React, { Component } from 'react';
import Pincode from "react-pincode";

export default class Example extends Component {
  render() {
    return (
      <div>
        <Pincode  cityInput={{width:'200px'}}/>
        // This will set the length of city input field to 200px. You can play with rest of the props to style it according to your need.
      </div>
    )
  }
}
export default Example;

Development and Testing

  1. Set-up the React-Pincode module by dowloading its dependencies, using npm install command.
  2. Build the module using npm run build
  3. Link the module for testing using npm link command.
  4. Change your directory to test-server directory, using cd test-server
  5. Install the dependecies using npm install
  6. Now run npm link react-pincode
  7. Congratulations! You have set-up the test server for react-pincode. Now just run npm start from test-server directory to launch the test-server.
  8. You don't need to stop this server, the changes made in the module will be reflected automatically each time you build them using npm run build
  9. To watch a video on installation (Click on the thumbnail): Watch the video

Contributing

Please read Contributing Guidelines for information on how to contribute to React-Pincode.

Development Guidelines

  1. Write clean and readable code with proper formatting.
  2. Create a branch and push your code in the branch.
  3. Please follow PR template to create one.
  4. Please read our Code of Conduct .

Owner

Apoorv Taneja

react-pincode's People

Contributors

abhushanaj avatar adityabisoi avatar aman-codes avatar arpit9667 avatar dependabot[bot] avatar jamesjose03 avatar plxity avatar shreyakapoor08 avatar siddhishree avatar xtremilicious avatar yellowwoods12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-pincode's Issues

Addition of Maps feature

Is your feature request related to a problem? Please describe.
Google Maps can be added to the existing project for displaying the location of the query.

Describe the solution you'd like
A button would pop up on a valid Pincode input, which would redirect to a new webpage (Google Maps) showing the city generated from the query.

Additional context
Currently, no Google Maps API will be required.

The interface would look like this:

Screenshot from 2020-05-23 20-42-27

@plxity @yellowwoods12 @AdityaSrivast Please assign this issue to me.

Addition of Actions

Add appropriate actions to do the following tasks:

  • Actions to detect stale issues and PR and give labels to them. ( Issue and PR which are unattended for long time)
  • Auto Assign reviewers to PR created so they get notified about them.
  • Detect any foul language/behaviour.

@plxity @yellowwoods12 Do you think it's a good idea to add these to the repo??

Add a customization prop to drop the UI modifications

Adding recent changes in the UI of the module not only adds classes on top of the minimal component but also makes it difficult to modify for users who are looking for a minimal design.

One proposed solution here can be to pass a prop with the component that informs the component whether the UI should be kept minimal or not. If yes then just drop the on-top classes and render a simple UI otherwise proper UI will be rendered.

This is one solution of the above problem. There are possible alternatives to it and it would be great if one can come up with them in the comments before asking for assigning up this issue.

Adding Contributions.md

Can I work on this, so that the participants can get a clear understanding of how to contribute to the website.

Add TOC to README.md

  • The README is a long one. Adding a Table of Contents will make it easier for navigating through it.

feat: add places for better accuracy

Currently, the city field displays district data from API end-point, which is inaccurate.
From the API end-point, we can add more fields-

Field : Parameter

Town/City : name
District : district
State : state

Where field is the displayed data and parameter are data from API.

Create a validation check for pincodes

As of now, when a wrong pincode is entered the input field turns red. There is no type check for various kind of wrong inpiuts. For example, a pincode must be of 6 digits. So if some number less than or greater than that is entered an alert should display.
Similarly if alphabets are entered then a specific alert should display for it as well and so on.

Add CONTRIBUTING.md

I am a GSSOC participant and I would like to add CONTRIBUTING.md file to include the following mentioned features

  • How to clone the repository
  • Adding reference to the original repository
  • Updating local copy of repository
  • Creating a new branch
  • Pushing commits
  • If possible we can also include some pictures in it for a better look
  • It should also include the link to the pull request template, bug report and feature request template
  • Update README.md to include the link of CONTRIBUTING.md

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.