time input react component
npm install jb-time-input-reactcommand
npm i jb-time-input-react
`
`jsx
import {JBTimeInput} from 'jb-time-input-react'
`
$3
like any other javascript DOM element you can bind event to web component with DOM.addEventListener the supported event is:
`jsx
//when default property are defined best time for impl your config
{}}>
//when dom bound and rendered in browser dom 3 and you can access all property
{}}>
//keyboard event
console.log(event.target.value)}>
console.log(event.target.value)}>
console.log(event.target.value)}>
console.log(event.target.value)}>
// when user press enter on type good for situation you want so submit form or call search function on user press enter.
console.log(event.target.value)}>
//focus event
console.log(event.target.value)}>
console.log(event.target.value)}>
//input Event
console.log(event.target.value)}>
console.log(event.target.value)}>
`
$3
to set value of time input you have 2 way:
- by component as a prop:
`html
`
$3
jb-time-input use jb-validation inside to handle validation so for more information you can read it's documentation.
jb time input will check validation automatically and show error on user blur the input and hide error on user type and blur to use this feature you just have to set validation list of component.
`jsx
const validationList = [
//regex validator
{
validator: /^[1][1234].*$/g,
message:"hour must be between 11 and 14"
},
//callback function validator
{
validator:({displayValue,value,valueObject})=>{
//display value is the value user see
//value is the value developer get by dom.value
//valueObject is the {hour:number,minute:number,second:number} object contain inputted value in number
if(valueObject.minute<30){
return false;
}
return true;
},
message:'minute must be 30 to 60'
}
]
const ref = useRef();
`
you can trigger validation manually by calling checkValidity function and get validation result. for example you can call it when submit button clicked and check if value is valid or not.
`javascript
// if you set showError false you can get validation result but component wont show error to user by itself its good when you want show error in your own way
const showError = true;
const validationResult = ref.current.validation.checkValidity(showError);
if(validationResult.isAllValid){
alert('all validation are passed')
}else{
alert('validation error!');
}
`
you can also get validation result of your time input by following way:
`jsx
const onChange = (e)=>{
console.log(e.target.validation.resultSummary)
}
//you can check validation result in onChange or onInput or onEnter
`
$3
you can change some attribute in html like label or message configurable attribute are:
`jsx
`
$3
if you want to just input minute and hour and disable second in picker and input just set secondEnabled to false
`jsx
`
$3
if you want picker to show 02 instead of 2 when number is less than 10 just set frontalZero of time picker default is false.
`jsx
`
$3
if you want to tell user some units is optional and make it less visible by set light grey color the numbers in picker you can set optionalUnits
`jsx
//it could be 'hour' or 'minute' or 'second'
`
$3
if you want to show persian number instead of english number chars. you can set showPersianNumber:
`js
`
$3
jb-time-input use jb-input and jb-time-picker and jb-popover underneath so to change the styles of your component read custom style section of these components.
more than above here is the css variable that we use in jb-time-input itself:
| css variable name | description |
| ------------- | ------------- |
| --jb-time-input-margin | outer margin of web component default is 12px 0` |