2
0

Base64InputRow.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React, { ChangeEvent, Component } from 'react';
  2. import styled from 'styled-components';
  3. type PropsType = {
  4. label?: string,
  5. type: string,
  6. value: string | number,
  7. setValue: (x: string | number) => void,
  8. unit?: string,
  9. placeholder?: string,
  10. width?: string,
  11. disabled?: boolean,
  12. isRequired?: boolean,
  13. };
  14. type StateType = {
  15. readOnly: boolean
  16. };
  17. export default class InputRow extends Component<PropsType, StateType> {
  18. state = {
  19. readOnly: true
  20. }
  21. handleChange = (e: ChangeEvent<HTMLInputElement>) => {
  22. this.props.setValue(e.target.value);
  23. }
  24. render() {
  25. let { label, value, type, unit, placeholder, width } = this.props;
  26. value = value.toString();
  27. value = atob(value);
  28. return (
  29. <StyledInputRow>
  30. <Label>{label} <Required>{this.props.isRequired ? ' *' : null}</Required></Label>
  31. <InputWrapper>
  32. <Input
  33. readOnly={this.state.readOnly} onFocus={() => this.setState({ readOnly: false })}
  34. disabled={this.props.disabled}
  35. placeholder={placeholder}
  36. width={width}
  37. type={type}
  38. value={value}
  39. onChange={this.handleChange}
  40. />
  41. {unit ? <Unit>{unit}</Unit> : null}
  42. </InputWrapper>
  43. </StyledInputRow>
  44. );
  45. }
  46. }
  47. const Required = styled.div`
  48. margin-left: 8px;
  49. color: #fc4976;
  50. `;
  51. const Unit = styled.div`
  52. margin-right: 8px;
  53. `;
  54. const InputWrapper = styled.div`
  55. display: flex;
  56. margin-bottom: -1px;
  57. align-items: center;
  58. `;
  59. const Input = styled.input`
  60. outline: none;
  61. border: none;
  62. font-size: 13px;
  63. background: #ffffff11;
  64. border: 1px solid #ffffff55;
  65. border-radius: 3px;
  66. width: ${(props: { disabled: boolean, width: string }) => props.width ? props.width : '270px'};
  67. color: ${(props: { disabled: boolean, width: string }) => props.disabled ? '#ffffff44' : 'white'};
  68. padding: 5px 10px;
  69. margin-right: 8px;
  70. height: 30px;
  71. `;
  72. const Label = styled.div`
  73. color: #ffffff;
  74. margin-bottom: 10px;
  75. display: flex;
  76. align-items: center;
  77. font-size: 13px;
  78. font-family: 'Work Sans', sans-serif;
  79. `;
  80. const StyledInputRow = styled.div`
  81. margin-bottom: 15px;
  82. margin-top: 20px;
  83. `;