Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TextField.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React, { useEffect, useState } from "react";
  2. import { TextFieldContainer, TextFieldStyled } from "./TextField.styled";
  3. import PropTypes from "prop-types";
  4. import selectedTheme from "../../../themes";
  5. export const TextField = React.forwardRef((props, ref) => {
  6. const [isFieldEmpty, setIsFieldEmpty] = useState(true);
  7. // for italicPlaceholder
  8. useEffect(() => {
  9. if (props?.value?.length === 0) {
  10. setIsFieldEmpty(true);
  11. } else {
  12. setIsFieldEmpty(false);
  13. }
  14. }, [props.value]);
  15. console.log(props);
  16. return (
  17. <TextFieldContainer
  18. style={props.containerStyle}
  19. className={props.className}
  20. height={props.height}
  21. >
  22. <TextFieldStyled
  23. {...props.attributes}
  24. inputRef={ref}
  25. inputProps={props.inputProps}
  26. placeholder={props.placeholder}
  27. width={props.width}
  28. height={props.height}
  29. id={props.id}
  30. name={props.name}
  31. value={props.value}
  32. onChange={props.onChange}
  33. error={props.error}
  34. multiline={props.multiline}
  35. minRows={props.minRows}
  36. // helperText={props.helperText}
  37. autoFocus={props.autoFocus}
  38. fullWidth={props.fullWidth}
  39. type={props.type}
  40. textsize={props.textsize}
  41. font={props.font}
  42. InputProps={props.InputProps}
  43. sx={props.style}
  44. label={props.showAnimation ? props.placeholder : ""}
  45. onFocus={props.onFocus}
  46. onBlur={props.onBlur}
  47. italicplaceholder={
  48. props.italicPlaceholder && isFieldEmpty ? "true" : "false"
  49. }
  50. focused={props.focused}
  51. >
  52. {props.children}
  53. </TextFieldStyled>
  54. </TextFieldContainer>
  55. );
  56. });
  57. TextField.displayName = "TextField";
  58. TextField.propTypes = {
  59. history: PropTypes.shape({
  60. replace: PropTypes.func,
  61. push: PropTypes.func,
  62. location: PropTypes.shape({
  63. pathname: PropTypes.string,
  64. }),
  65. }),
  66. children: PropTypes.node,
  67. className: PropTypes.string,
  68. placeholder: PropTypes.string,
  69. style: PropTypes.any,
  70. showAnimation: PropTypes.bool,
  71. containerStyle: PropTypes.any,
  72. italicPlaceholder: PropTypes.bool,
  73. width: PropTypes.string,
  74. height: PropTypes.string,
  75. name: PropTypes.string,
  76. label: PropTypes.string,
  77. value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  78. onChange: PropTypes.func,
  79. id: PropTypes.number,
  80. error: PropTypes.bool,
  81. helperText: PropTypes.string,
  82. autoFocus: PropTypes.bool,
  83. fullWidth: PropTypes.bool,
  84. type: PropTypes.string,
  85. textsize: PropTypes.string,
  86. font: PropTypes.string,
  87. ref: PropTypes.any,
  88. minRows: PropTypes.number,
  89. multiline: PropTypes.bool,
  90. onFocus: PropTypes.func,
  91. onBlur: PropTypes.func,
  92. focused: PropTypes.bool,
  93. inputProps: PropTypes.any,
  94. InputProps: PropTypes.shape({
  95. startAdornment: PropTypes.node,
  96. endAdornment: PropTypes.node,
  97. style: PropTypes.any,
  98. }),
  99. attributes: PropTypes.any,
  100. };
  101. TextField.defaultProps = {
  102. italicPlaceholder: false,
  103. showAnimation: false,
  104. height: "48px",
  105. font: selectedTheme.fonts.textFont,
  106. };