InputRow.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React, { ChangeEvent, Component } from "react";
  2. import Tooltip from "@material-ui/core/Tooltip";
  3. import styled from "styled-components";
  4. type PropsType = {
  5. label?: string;
  6. info?: string;
  7. type: string;
  8. value: string | number;
  9. setValue?: (x: string | number) => void;
  10. unit?: string;
  11. placeholder?: string;
  12. width?: string;
  13. disabled?: boolean;
  14. isRequired?: boolean;
  15. className?: string;
  16. };
  17. type StateType = {
  18. readOnly: boolean;
  19. };
  20. export default class InputRow extends Component<PropsType, StateType> {
  21. state = {
  22. readOnly: true,
  23. };
  24. handleChange = (e: ChangeEvent<HTMLInputElement>) => {
  25. if (this.props.type === "number") {
  26. this.props.setValue(parseFloat(e.target.value));
  27. } else {
  28. this.props.setValue(e.target.value);
  29. }
  30. };
  31. render() {
  32. let { label, value, type, unit, placeholder, width, info } = this.props;
  33. return (
  34. <StyledInputRow className={this.props.className}>
  35. {(label || info) && (
  36. <Label>
  37. {label}
  38. {info && (
  39. <Tooltip
  40. title={
  41. <div
  42. style={{
  43. fontFamily: "Work Sans, sans-serif",
  44. fontSize: "12px",
  45. fontWeight: "normal",
  46. padding: "5px 6px",
  47. }}
  48. >
  49. {info}
  50. </div>
  51. }
  52. placement="top"
  53. >
  54. <StyledInfoTooltip>
  55. <i className="material-icons">help_outline</i>
  56. </StyledInfoTooltip>
  57. </Tooltip>
  58. )}
  59. {this.props.isRequired && <Required>{" *"}</Required>}
  60. </Label>
  61. )}
  62. <InputWrapper>
  63. <Input
  64. readOnly={this.state.readOnly}
  65. onFocus={() => this.setState({ readOnly: false })}
  66. disabled={this.props.disabled}
  67. placeholder={placeholder}
  68. width={width}
  69. type={type}
  70. value={value}
  71. onChange={this.handleChange}
  72. />
  73. {unit ? <Unit>{unit}</Unit> : null}
  74. </InputWrapper>
  75. </StyledInputRow>
  76. );
  77. }
  78. }
  79. const Required = styled.div`
  80. margin-left: 8px;
  81. color: #fc4976;
  82. `;
  83. const Unit = styled.div`
  84. padding: 0 10px;
  85. background: #ffffff05;
  86. height: 35px;
  87. display: flex;
  88. align-items: center;
  89. justify-content: center;
  90. border-left: 1px solid #ffffff55;
  91. `;
  92. const InputWrapper = styled.div`
  93. display: flex;
  94. margin-bottom: -1px;
  95. align-items: center;
  96. border: 1px solid #ffffff55;
  97. border-radius: 3px;
  98. `;
  99. const Input = styled.input<{ disabled: boolean; width: string }>`
  100. outline: none;
  101. border: none;
  102. font-size: 13px;
  103. background: #ffffff11;
  104. cursor: ${(props) => (props.disabled ? "not-allowed" : "")};
  105. width: ${(props) => (props.width ? props.width : "270px")};
  106. color: ${(props) => (props.disabled ? "#ffffff44" : "white")};
  107. padding: 5px 10px;
  108. height: 35px;
  109. `;
  110. const Label = styled.div`
  111. color: #ffffff;
  112. margin-bottom: 10px;
  113. display: flex;
  114. align-items: center;
  115. font-size: 13px;
  116. font-family: "Work Sans", sans-serif;
  117. `;
  118. const StyledInputRow = styled.div`
  119. margin-bottom: 15px;
  120. margin-top: 22px;
  121. `;
  122. const StyledInfoTooltip = styled.div`
  123. display: inline-block;
  124. position: relative;
  125. margin-right: 2px;
  126. > i {
  127. display: flex;
  128. align-items: center;
  129. position: absolute;
  130. top: -10px;
  131. font-size: 10px;
  132. color: #858faaaa;
  133. cursor: pointer;
  134. :hover {
  135. color: #aaaabb;
  136. }
  137. }
  138. `;