index.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React from 'react';
  2. import TextField, { HelperText, Input as Field } from '@material/react-text-field';
  3. import classNames from 'classnames';
  4. import Icon from '../Icon';
  5. import '@material/react-text-field/dist/text-field.css';
  6. import './styles.scss';
  7. type InputProps = {
  8. label: string,
  9. helperText?: string,
  10. value: string|number,
  11. onChange: (e: any) => void,
  12. textarea?: boolean,
  13. onKeyDown? : (e: any) => void,
  14. type?: 'text'|'number',
  15. style?: 'display'|'regular',
  16. icon?: string,
  17. };
  18. const Input = ({
  19. label,
  20. helperText,
  21. textarea,
  22. value,
  23. onChange,
  24. onKeyDown,
  25. type = 'text',
  26. style = 'regular',
  27. icon,
  28. }: InputProps) => {
  29. const fieldClasses = classNames(
  30. 'cbk-input',
  31. {
  32. 'cbk-input--prefilled': value!=='',
  33. [`cbk-input-${style}`]: true,
  34. 'mdc-text-field--no-label': style === 'display',
  35. }
  36. );
  37. return (
  38. <div className='cbk-input-container'>
  39. {
  40. icon &&
  41. <Icon
  42. icon={icon}
  43. width={46}
  44. fill='#9E9E9E'
  45. ></Icon>
  46. }
  47. <TextField
  48. label={label}
  49. helperText={helperText ? (<HelperText>{helperText || ''}</HelperText>) : undefined}
  50. textarea={textarea}
  51. className={fieldClasses}
  52. fullWidth={style === 'display'}
  53. >
  54. <Field
  55. value={value}
  56. //@ts-ignore
  57. onChange={onChange}
  58. onKeyDown={onKeyDown}
  59. type={type}
  60. min={0}
  61. rows={1}
  62. placeholder={style === 'display' ? label : ''}
  63. />
  64. </TextField>
  65. </div>
  66. )};
  67. export default Input;