3.5.0 • Published 7 months ago

jb-input-react v3.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

JBInput React

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

text input react component with these benefits:

  • 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.

  • custom display for password and number input.

  • support typescript

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-input-react

in your jsx file

import {JBInput} from 'jb-input-react';
<JBInput label="label:" message="hint message under textbox"></JBInput>

events

    //when default property are defined best time for impl your config
    <JBInput onInit={(event) => {}}></JBInput>

    //when dom bound and rendered in browser dom 3 and you can access all property
    <JBInput onLoad={(event) => {}}></JBInput>

    //keyboard event
    <JBInput onKeyDown={(event) => console.log(event.target.value)}></JBInput>
    <JBInput onKeyUp={(event) => console.log(event.target.value)}></JBInput>
    <JBInput onKeyPress={(event) => console.log(event.target.value)}></JBInput>
    <JBInput onChange={(event) => console.log(event.target.value)}></JBInput>
    // when user press enter on type good for situation you want so submit form or call search function on user press enter. 
    <JBInput onEnter={(event) => console.log(event.target.value)}></JBInput>
    //focus event
    <JBInput onFocus={(event) => console.log(event.target.value)}></JBInput>
    <JBInput onBlur={(event) => console.log(event.target.value)}></JBInput>
    //input Event
    <JBInput onInput={(event) => console.log(event.target.value)}></JBInput>
    <JBInput onBeforeInput={(event) => console.log(event.target.value)}></JBInput>

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 == "سلام"},
            message: 'شما تنها میتوانید عبارت سلام را وارد کنید'
        },
    ]
    <JBInput validationList={validationList}></JBInput>

check validation

you can check if an input value meet your validation standad 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.

other props

props namedescription
disableddisable the input
inputmodeset input mode help mobile device to open proper keyboard for your input like url, search and numeric
directionset web-component direction default set is rtl but if you need ltr use

set custom style

since jb-input-react use jb-input underneath, read jb-input custom style section.

add custom element in input box

in JBInput you can put icon or any other custom html DOM in input box. to doing so you just have to place custom DOM in JBInput tag and add slot="start-section" or slot="end-section" to place it before or after input field.

<JBInput>
    <div slot="end-section">after</div>
    <div slot="start-section">before</div>
</JBInput>

Other Related Docs:

3.4.0

7 months ago

3.5.0

7 months ago

3.3.0

8 months ago

3.1.3

10 months ago

3.1.2

10 months ago

3.2.0

10 months ago

3.1.1

11 months ago

3.1.0

11 months ago

3.0.4

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago