Area.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {Input} from 'antd';
  2. import {FC} from 'react';
  3. import {Controller, UseControllerProps} from 'react-hook-form';
  4. import Label from './Label';
  5. import ModalFiledErrorTip from './ErrorTip';
  6. type Props = {
  7. label: string;
  8. height: number;
  9. required?: boolean;
  10. placeholder?: string;
  11. } & UseControllerProps<any, any>;
  12. const LDModalArea: FC<Props> = function({
  13. control,
  14. name,
  15. label,
  16. placeholder,
  17. required,
  18. height,
  19. }) {
  20. return (
  21. <div className="ld-modal-field">
  22. <Label required={required} name={name}>
  23. {label}
  24. </Label>
  25. <div className="ld-modal-field-wrapper">
  26. <Controller
  27. name={name}
  28. control={control}
  29. render={function({
  30. field: {value, onChange, ref},
  31. formState: {errors},
  32. }) {
  33. const errorTips = errors[name]?.message?.toString() ?? '';
  34. return (
  35. <>
  36. <Input.TextArea
  37. name={name}
  38. placeholder={placeholder ?? `请输入${label}`}
  39. data-testid={`field_${name}`}
  40. id={`field_${name}`}
  41. value={value}
  42. onChange={onChange}
  43. ref={ref}
  44. className="ld-modal-field-area"
  45. style={{height}}
  46. />
  47. <ModalFiledErrorTip message={errorTips} />
  48. </>
  49. );
  50. }}
  51. />
  52. </div>
  53. </div>
  54. );
  55. };
  56. export default LDModalArea;