npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-cc-input

v0.1.1

Published

React Native component to input a Credit Card data

Downloads

9

Readme

rn-cc-input

This package contains a React Native component to input a credit card data.
Example of code:

import React from 'react';
import {SafeAreaView} from 'react-native';
import CreditCard from 'rn-cc-input';
import styles from './styles';

export default () => (
    <SafeAreaView>
        <CreditCard style={[{margin:10}, styles.textInput]} />
    </SafeAreaView>
);

The display:
display example

Props

All props are optional. There are some props dealing with style. You must use them carefully to prevent the messed layout.

|Name |Type |Description |Default Value | |---------------------------|-----------------|--------------------------------------------------------|-------------------| |cardHolderText |string |The text that will be displayed on the card holder field|"Card holder name" | |ifValidNumberNext |boolean |When you type a value for a field and it reaches the max|false | | | |length for that field, the focus will move to the next || | | |field. But sometimes for card number, before it reaches || | | |the max length, the number has been considered as a || | | |valid value. If this prop is true, when the number is || | | |already valid, the focus will move to the next field || | | |(CVC field) even if it doesn't reach the max length yet.|| |numberText |string |The text that will be displayed on the card number field|"Card number" | |placeholderTextColor |ColorValue |The color of placeholder text on all fields || |placeholderTextColorError|ColorValue |The color of placeholder text on all fields when the || | | |input is invalid || |postalCodeText |string |The text that will be displayed on the postal code field|"Postal code" | |showCardHolder |boolean |Whether to show the card holder field or not |false | | | |(true is to show it) || |showPostalCode |boolean |Whether to show the postal code field or not |false | | | |(true is to show it) || |style |TextInput style|The style for input. All style properties that are || | | |applicable to View component will be set to the || | | |input's top container and the rest to all field inputs || | | |(card number, expiry date, CVV, holder name and postal || | | |code) || |styleArrow |View style |The style for the scrolling button. If the credit card || | | |input can't display all fields, there will be the || | | |scrolling button(s) to slide to the right and to the || | | |left || |styleArrowError |View style |The style for the scrolling button when the input is || | | |invalid || |styleError |TextInput style|The style for input. All style properties that are || | | |applicable to View component will be set to the || | | |input's top container and the rest to all field inputs || |styleField |TextInput style|The style for all field inputs. It overrides style || | | |props || |styleFieldError |TextInput style|The style for all field inputs when invalid. It || | | |overrides styleError prop || |styleIcon |Image style |The style for the card image ||

Properties and method of ref object

Properties
  • isValid is true if all fields are valid, false if any invalid field.
  • value can be null or an object whose the following properties:
      {
          number: string,
          expired: {
              month: number,
              year: number,
          },
          cvc: string,
          cardHolder: string,
          postalCode: string,
      }
Method
  • setValidationError(isError) is to set the validity status of credit card input. If isError is true then the status is invalid, the input appearance will use the error style specified in props.

The example of usage:

import React from 'react';
import {Button, SafeAreaView} from 'react-native';
import CreditCard from 'rn-cc-input';
import server from './server';

export default () => (
    const cc = React.useRef(null);

    <SafeAreaView>
        {
           //.... Here, there may be the other inputs for transaction 
        }
        <CreditCard ref={cc} />

        <Button title="Send" onPress={async () => {
            const ccInput = cc.current;
            if (ccInput.isValid) { //passes client-side validation
                ccInput.setValidationError(false);
                if (await server.sendTransaction({
                    ccData: ccInput.value,
                    //... collects the other input data
                })) {
                    //The transaction is succesfull. It may be redirected to another page
                }
                else {
                    //Not successfull. If it's because credit card data is invalid (exceeds the limit, wrong holder name, etc.)
                    //We can show the validity status
                    ccInput.setValidationError(true);
                }
            }
            else {
                ccInput.setValidationError(true);
            }
        }} />
    </SafeAreaView>
);