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.

TextField.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. {...props}
  18. sx={props.style}
  19. label={props.showAnimation ? props.placeholder : ""}
  20. italic={props.italicPlaceholder && isFieldEmpty}
  21. >
  22. {props.children}
  23. </TextFieldStyled>
  24. </TextFieldContainer>
  25. );
  26. };
  27. TextField.propTypes = {
  28. history: PropTypes.shape({
  29. replace: PropTypes.func,
  30. push: PropTypes.func,
  31. location: PropTypes.shape({
  32. pathname: PropTypes.string,
  33. }),
  34. }),
  35. children: PropTypes.node,
  36. className: PropTypes.string,
  37. placeholder: PropTypes.string,
  38. style: PropTypes.any,
  39. showAnimation: PropTypes.bool,
  40. containerStyle: PropTypes.any,
  41. italicPlaceholder: PropTypes.bool,
  42. width: PropTypes.string,
  43. height: PropTypes.string,
  44. name: PropTypes.string,
  45. label: PropTypes.string,
  46. value: PropTypes.string,
  47. onChange: PropTypes.func,
  48. error: PropTypes.string,
  49. helperText: PropTypes.string,
  50. autoFocus: PropTypes.bool,
  51. fullWidth: PropTypes.bool,
  52. type: PropTypes.string,
  53. InputProps: PropTypes.shape({
  54. startAdornment: PropTypes.node,
  55. endAdornment: PropTypes.node,
  56. }),
  57. };
  58. TextField.defaultProps = {
  59. italicPlaceholder: false,
  60. showAnimation: false,
  61. };