Extracted common Input and Button components

no issue

- Add new InputField common component for input fields with label
- Add new ActionButton common component for action <button>
This commit is contained in:
Rish 2020-04-27 13:49:59 +05:30
parent 61de34aac8
commit 100bfa7b5b
2 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import React from 'react';
const Styles = ({brandColor, disabled, style = {}}) => {
return {
button: {
display: 'inline-block',
padding: '0 1.8rem',
height: '44px',
border: '0',
fontSize: '1.5rem',
lineHeight: '42px',
fontWeight: '600',
textAlign: 'center',
textDecoration: 'none',
whiteSpace: 'nowrap',
borderRadius: '5px',
cursor: 'pointer',
transition: '.4s ease',
color: '#fff',
backgroundColor: disabled ? 'grey' : (brandColor || '#3eb0ef'),
boxShadow: 'none',
userSelect: 'none',
width: '100%',
marginBottom: '12px',
...(style.button || {}) // Override any custom style
}
};
};
function ActionButton({label, onClick, disabled, brandColor, style}) {
let Style = Styles({disabled, brandColor, style});
return (
<button onClick={e => onClick(e)} style={Style.button} disabled={disabled}>
{label}
</button>
);
}
export default ActionButton;

View File

@ -0,0 +1,47 @@
import React from 'react';
const Styles = ({style = {}}) => {
return {
input: {
display: 'block',
padding: '0 .6em',
width: '100%',
height: '44px',
outline: '0',
border: '1px solid #c5d2d9',
color: 'inherit',
textDecoration: 'none',
background: '#fff',
borderRadius: '9px',
fontSize: '14px',
marginBottom: '12px',
boxSizing: 'border-box',
...(style.input || {}) // Override any custom style
},
label: {
marginBottom: '3px',
fontSize: '12px',
fontWeight: '700',
...(style.label || {}) // Override any custom style
}
};
};
function InputField({name, label, type, value, placeholder, onChange, style}) {
const Style = Styles({style});
return (
<>
<label htmlFor={name} style={Style.label}> {label} </label>
<input
type={type}
name={name}
placeholder={placeholder}
value={value}
onChange={e => onChange(e, name)}
style={Style.input}
/>
</>
);
}
export default InputField;