0.1.1 • Published 8 years ago

react-native-credit-card-form v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

React Native Credit Card Form

Easy (and good looking) credit-card form for your React Native Project 💳 💳

Features

  • Skeuomorphic credit-card 💳 (credits to: react-native-credit-card)
  • Credit-card input validations while you're typing
  • Credit-card input formatting
  • Works on both Android and iOS

Usage

npm i -s react-native-credit-card-form

then add these lines in your react-native codebase

import CreditCardForm from 'react-native-credit-card-form';

<CreditCardForm onChange={this._onChange} />

API

PropertyTypeDescription
autoFocusPropTypes.boolAutomatically focus Card Number field on render
onChangePropTypes.funcWill receive a formData object every time the form changes
labelsPropTypes.objectDefaults to { number: "CARD NUMBER", expiry: "EXPIRY", cvc: "CVC/CCV" }
placeholdersPropTypes.objectDefaults to { number: "1234 5678 1234 5678", expiry: "MM/YY", cvc: "CVC" }
cardViewSizePropTypes.objectSize of the credit-card view.Defaults to { width: 300, height: 180 } (managed by react-native-credit-card)
imageFrontPropTypes.numberImage for the credit-card view e.g. require("./card.png")
imageBackPropTypes.numberImage for the credit-card view e.g. require("./card.png")
labelStyleText.propTypes.styleStyle for credit-card form's labels
inputStyleText.propTypes.styleStyle for credit-card form's textInput
inputContainerStyleView.propTypes.styleStyle for textInput's container Defaults to: { borderBottomWidth: 1, borderBottomColor: "black" }
validColorPropTypes.stringColor that will be applied for valid text input
invalidColorPropTypes.stringColor that will be applied for invalid text input
placeholderColorPropTypes.stringColor that will be applied for text input placeholder

onChange

will receives a formData object every keypress. e.g.

{
  valid: true, // will be true once all field's statuses are "valid"
  focused: "number", // will be one of "number", "expiry", and "cvc"
  values: { // will be in the sanitized and formatted form
  	number: "4242 4242",
  	expiry: "06/19",
  	cvc: "300",
  	type: "visa", // will be one of null, "visa", "master-card", "american-express", "diners-club", "discover", "jcb", "unionpay", "maestro"
  },
  status: {  // will be one of "incomplete", "invalid", and "valid"
	number: "incomplete",
	expiry: "incomplete"
	cvc: "incomplete"
  },
};

Example

In the example directory, do:

npm install
react-native run-ios
# or
react-native run-android

Missing something?

Submit a pull request :D

TODO

  • Add eslint
  • Add some unit tests for the formatter/validator logic
  • Add props to resize credit-card view
  • Accept initialValues
  • Support Name and postal code field
  • Handles orientation changes

License

MIT