Outlined TextField - MukeshKumar101/IPL_Auction GitHub Wiki
To create an outlined textbox as a generic component
* Create a functional component
* It receives props from the parent component
* The values are set in the Input tag and label
* Prototypes are set to the input for checking the type
-
@param - props
-
props contain id, type, value, disabled, onChange, checked, onCheckbox, fieldName, and placeholder
-
sample props
const input = [
{
type: 'text',
value: 'John',
placeholder: " ",
onChange: function
},
{
type: 'radio',
value: '0' or '1',
checked: function,
onChange: function
},
{
type: 'checkbox'
onCheckbox: function,
onChange: function
}
Note:
The label acts as a placeholder in the outlined textbox. so, we will give placeholder as an empty string and give exact field name in the label tag.
- sample usage
<input
id={id}
type={type}
value={value}
checked={checked}
disabled={disabled}
placeholder={placeholder}
onChange={onChange}
fieldName={fieldName}
/>
import React from "react";
import PropTypes from 'prop-types';
const Input = (props) => {
const { id, type, value, checked, disabled, placeholder, onChange, fieldName } = props;
return (
<div>
<div>
<input
id={id}
type={type}
value={value}
checked={checked}
disabled={disabled}
placeholder={placeholder}
onChange={onChange}
/>
<label>{fieldName}</label>
</div>
</div>
);
};
Input.propTypes = {
type: PropTypes.string,
checked: PropTypes.bool,
disabled: PropTypes.bool,
value: PropTypes.string,
onChange: PropTypes.func,
placeholder: PropTypes.string,
};
export default Input;