You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React, { useEffect, useState } from "react";
  2. import { TextFieldContainer, TextFieldStyled } from "./TextField.styled";
  3. import PropTypes from "prop-types";
  4. export const TextField = (props) => {
  5. const [isFieldEmpty, setIsFieldEmpty] = useState(true);
  6. // for italicPlaceholder
  7. useEffect(() => {
  8. if (props.value.length === 0) {
  9. setIsFieldEmpty(true);
  10. } else {
  11. setIsFieldEmpty(false);
  12. }
  13. }, [props.value]);
  14. return (
  15. <TextFieldContainer style={props.containerStyle} className={props.className}>
  16. <TextFieldStyled
  17. placeholder={props.placeholder}
  18. width={props.width}
  19. height={props.height}
  20. name={props.name}
  21. value={props.value}
  22. onChange={props.onChange}
  23. error={props.error}
  24. // helperText={props.helperText}
  25. autoFocus={props.autoFocus}
  26. fullWidth={props.fullWidth}
  27. type={props.type}
  28. textsize={props.textsize}
  29. font={props.font}
  30. InputProps={props.InputProps}
  31. sx={props.style}
  32. label={props.showAnimation ? props.placeholder : ""}
  33. italic={props.italicPlaceholder && isFieldEmpty}
  34. >
  35. {props.children}
  36. </TextFieldStyled>
  37. </TextFieldContainer>
  38. );
  39. };
  40. TextField.propTypes = {
  41. history: PropTypes.shape({
  42. replace: PropTypes.func,
  43. push: PropTypes.func,
  44. location: PropTypes.shape({
  45. pathname: PropTypes.string,
  46. }),
  47. }),
  48. children: PropTypes.node,
  49. className: PropTypes.string,
  50. placeholder: PropTypes.string,
  51. style: PropTypes.any,
  52. showAnimation: PropTypes.bool,
  53. containerStyle: PropTypes.any,
  54. italicPlaceholder: PropTypes.bool,
  55. width: PropTypes.string,
  56. height: PropTypes.string,
  57. name: PropTypes.string,
  58. label: PropTypes.string,
  59. value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  60. onChange: PropTypes.func,
  61. error: PropTypes.bool,
  62. helperText: PropTypes.string,
  63. autoFocus: PropTypes.bool,
  64. fullWidth: PropTypes.bool,
  65. type: PropTypes.string,
  66. textsize: PropTypes.string,
  67. font: PropTypes.string,
  68. InputProps: PropTypes.shape({
  69. startAdornment: PropTypes.node,
  70. endAdornment: PropTypes.node,
  71. style: PropTypes.any,
  72. }),
  73. };
  74. TextField.defaultProps = {
  75. italicPlaceholder: false,
  76. showAnimation: false,
  77. // font: "Open Sans"
  78. };