Base64InputRow.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if (type === 'b64') {
  27. type = 'string-input';
  28. } else if (type === 'b64-pass') {
  29. type = 'password';
  30. }
  31. if (value === undefined) {
  32. value = '';
  33. }
  34. value = value.toString();
  35. value = atob(value);
  36. return (
  37. <StyledInputRow>
  38. <Label>{label} <Required>{this.props.isRequired ? ' *' : null}</Required></Label>
  39. <InputWrapper>
  40. <Input
  41. readOnly={this.state.readOnly} onFocus={() => this.setState({ readOnly: false })}
  42. disabled={this.props.disabled}
  43. placeholder={placeholder}
  44. width={width}
  45. type={type}
  46. value={value}
  47. onChange={this.handleChange}
  48. />
  49. {unit ? <Unit>{unit}</Unit> : null}
  50. </InputWrapper>
  51. </StyledInputRow>
  52. );
  53. }
  54. }
  55. const Required = styled.div`
  56. margin-left: 8px;
  57. color: #fc4976;
  58. `;
  59. const Unit = styled.div`
  60. margin-right: 8px;
  61. `;
  62. const InputWrapper = styled.div`
  63. display: flex;
  64. margin-bottom: -1px;
  65. align-items: center;
  66. `;
  67. const Input = styled.input`
  68. outline: none;
  69. border: none;
  70. font-size: 13px;
  71. background: #ffffff11;
  72. border: 1px solid #ffffff55;
  73. border-radius: 3px;
  74. width: ${(props: { disabled: boolean, width: string }) => props.width ? props.width : '270px'};
  75. color: ${(props: { disabled: boolean, width: string }) => props.disabled ? '#ffffff44' : 'white'};
  76. padding: 5px 10px;
  77. margin-right: 8px;
  78. height: 30px;
  79. `;
  80. const Label = styled.div`
  81. color: #ffffff;
  82. margin-bottom: 10px;
  83. display: flex;
  84. align-items: center;
  85. font-size: 13px;
  86. font-family: 'Work Sans', sans-serif;
  87. `;
  88. const StyledInputRow = styled.div`
  89. margin-bottom: 15px;
  90. margin-top: 20px;
  91. `;