Area.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import css from './index.module.css';
  2. import {Row, Col, Input} from 'antd';
  3. import classNames from 'classnames';
  4. import {FC} from 'react';
  5. import {Controller, UseControllerProps} from 'react-hook-form';
  6. type Props = {
  7. label: string;
  8. placeholder?: string;
  9. width: string;
  10. height: string;
  11. } & UseControllerProps<any, any>;
  12. const OperationField: FC<Props> = function({
  13. control,
  14. name,
  15. label,
  16. placeholder,
  17. height,
  18. }) {
  19. return (
  20. <Row className='width-full' gutter={12}>
  21. <Col span={6} offset={2}>
  22. <label className={css.textRight} htmlFor={`operation_${name}`}>{label}</label>
  23. </Col>
  24. <Col span={12}>
  25. <Controller
  26. name={name}
  27. control={control}
  28. render={function({field: {value, onChange, ref}, formState: {errors}}) {
  29. const errorTips = errors[name]?.message?.toString() ?? '';
  30. return (
  31. <>
  32. <Input.TextArea
  33. name={name}
  34. placeholder={placeholder ?? `请输入${label}`}
  35. id={`operation_${name}`}
  36. value={value}
  37. onChange={onChange}
  38. ref={ref}
  39. className={css.areaFiled}
  40. style={{height}}
  41. />
  42. <p className={classNames([css.errorTips, {[css.errorTipsHidden]: !errorTips}])}>
  43. {errorTips}
  44. </p>
  45. </>
  46. );
  47. }}
  48. />
  49. </Col>
  50. </Row>
  51. );
  52. };
  53. export default OperationField;