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

jb-payment-input-react

v2.2.2

Published

payment input react component

Downloads

141

Readme

JBPaymentInput React component

this component is React.js wrapper for jb-payment-input web component

payment info input react component with this benefit:

  • easy to add custom regex or function validation.

  • multiple validation with different message.

  • support both RTL and LTR.

  • add label and message in UX friendly format.

  • customizable ui with css variable so you can have multiple style in different scope of your app.

  • support both card number and shaba number

Demo : Demo: codeSandbox preview for just see the demo and codeSandbox editor if you want to see and play with code

install

using npm

npm i jb-payment-input-react

in your jsx file

import {JBPaymentInput} from 'jb-payment-input-react';
<JBPaymentInput  label="card number" inputType="CARD"></JBPaymentInput>
<JBPaymentInput  label="shaba number" inputType="SHABA"></JBPaymentInput>

events

  • onChange
    <JBPaymentInput onChange={(event) => console.log(event.target.value)}></JBPaymentInput>
  • onKeyUp
    <JBPaymentInput onKeyUp={(event) => console.log(event.target.value)}></JBPaymentInput>
  • onEnter
    //when user press Enter button
    <JBPaymentInput onEnter={(event) => console.log(event.target.value)}></JBPaymentInput>
  • onKeydown
    <JBPaymentInput onKeydown={(event) => console.log(event.target.value)}></JBPaymentInput>
  • onFocus
    <JBPaymentInput onFocus={(event) => console.log(event.target.value)}></JBPaymentInput>
  • onBlur
    <JBPaymentInput onBlur={(event) => console.log(event.target.value)}></JBPaymentInput>

set validation

you can set validation to your input by creating a validationList array and passing in to validationList props:

    const validationList = [
        {
            validator: /.{3}/g,
            message: 'عنوان حداقل باید سه کاکتر طول داشته باشد'
        },
        //you can use function as a validator too
        {
            validator: ({displayValue,value})=>{return value !== "50413731111111"},
            message: 'this id card in banned'
        },
        {
            validator: ({displayValue,value})=>{
                if(value.startsWith('11111111')){
                    return 'we dont accept foo bank cards'
                }
                if(displayValue.startsWith('2222 2222')){
                    return 'we dont accept bar bank cards'
                }
                if(value.startsWith('3333')){
                    return false
                }
                return true
            },
            message: 'default message when return false'
        },
    ]
    <JBPaymentInput validationList={validationList}></JBPaymentInput>

check validation

you can check if an input value meet your validation standard by creating a ref of the element using React.createRef().

    const elementRef = React.createRef();
    const isValid = elementRef.current.validation.checkValidity(true).isAllValid;

if isValid is true the value of input is valid.

separator (divider) string

payment input by default use space to separate part of card number or shaba number. for example it will show 1234123412341234 as 1234 1234 1234 1234 but you can change it to what char or even string you want for eample devide it by - and you will see 1234-1234-1234-1234.
to make this happen you just have to set separator prop in jsx.

<jbPaymentInput separator="-"></jbPaymentInput>

other props

this component support all attributes comes from jb-input-react

set custom style

in some cases in your project you need to change default style of web-component for example you need zero margin or different border-radius and etc.
if you want to set a custom style to this web-component all you need is to set css variable in parent scope of web-component. since jb-payment-input use jb-input underneath, read jb-input custom style list.

Other Related Docs: