You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { CloseOutlined } from '@ant-design/icons';
  2. import { Input } from 'antd';
  3. import styles from './index.less';
  4. type ParameterInputData = {
  5. value?: any;
  6. showValue?: any;
  7. fromSelect?: boolean;
  8. } & Record<string, any>;
  9. interface ParameterInputProps {
  10. value?: ParameterInputData;
  11. onChange?: (value: ParameterInputData) => void;
  12. onClick?: () => void;
  13. canInput?: boolean;
  14. textArea?: boolean;
  15. placeholder?: string;
  16. allowClear?: boolean;
  17. }
  18. function ParameterInput({
  19. value,
  20. onChange,
  21. onClick,
  22. canInput = true,
  23. textArea = false,
  24. placeholder,
  25. allowClear,
  26. ...rest
  27. }: ParameterInputProps) {
  28. // console.log('ParameterInput', value);
  29. const valueObj =
  30. typeof value === 'string' ? { value: value, fromSelect: false, showValue: value } : value;
  31. if (valueObj && !valueObj.showValue) {
  32. valueObj.showValue = valueObj.value;
  33. }
  34. const isSelect = valueObj?.fromSelect;
  35. const InputComponent = textArea ? Input.TextArea : Input;
  36. return (
  37. <>
  38. {isSelect || !canInput ? (
  39. <div className={styles['parameter-input']} onClick={onClick}>
  40. {valueObj?.showValue ? (
  41. <div className={styles['parameter-input__content']}>
  42. <span className={styles['parameter-input__content__value']}>
  43. {valueObj?.showValue}
  44. </span>
  45. <CloseOutlined
  46. className={styles['parameter-input__content__close-icon']}
  47. onClick={() =>
  48. onChange?.({
  49. ...valueObj,
  50. fromSelect: false,
  51. value: undefined,
  52. showValue: undefined,
  53. })
  54. }
  55. />
  56. </div>
  57. ) : (
  58. <div className={styles['parameter-input__placeholder']}>{placeholder}</div>
  59. )}
  60. </div>
  61. ) : (
  62. <InputComponent
  63. {...rest}
  64. placeholder={placeholder}
  65. allowClear={allowClear}
  66. value={valueObj?.showValue}
  67. onChange={(e) =>
  68. onChange?.({
  69. ...valueObj,
  70. fromSelect: false,
  71. value: e.target.value,
  72. showValue: e.target.value,
  73. })
  74. }
  75. />
  76. )}
  77. </>
  78. );
  79. }
  80. export default ParameterInput;