field.tsx 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* eslint-disable max-len */
  2. import withField from './hoc/withField';
  3. // Basic component
  4. import Input from '../input/index';
  5. import TextArea from '../input/textarea';
  6. import InputNumber from '../inputNumber/index';
  7. import Select from '../select/index';
  8. import { Checkbox } from '../checkbox/index';
  9. import CheckboxGroup from '../checkbox/checkboxGroup';
  10. import { Radio } from '../radio/index';
  11. import RadioGroup from '../radio/radioGroup';
  12. import DatePicker from '../datePicker/index';
  13. import Switch from '../switch/index';
  14. import Slider from '../slider/index';
  15. import TimePicker from '../timePicker/index';
  16. import TreeSelect from '../treeSelect/index';
  17. import Cascader from '../cascader/index';
  18. import Rating from '../rating/index';
  19. import AutoComplete from '../autoComplete/index';
  20. import Upload from '../upload/index';
  21. import TagInput from '../tagInput/index';
  22. import { FormCheckboxType, FormRadioType, FormSelectType } from './interface';
  23. const FormInput = withField(Input, { maintainCursor: true });
  24. const FormInputNumber = withField(InputNumber as any, { maintainCursor: true });
  25. const FormTextArea = withField(TextArea, { maintainCursor: true });
  26. const FormSelect = withField(Select) as typeof FormSelectType;
  27. // Select after withField is a new Component, without the Option attribute, it needs to be manually assigned once
  28. FormSelect.Option = Select.Option;
  29. FormSelect.OptGroup = Select.OptGroup;
  30. const FormCheckboxGroup = withField(CheckboxGroup);
  31. const FormCheckbox = withField(Checkbox, {
  32. valueKey: 'checked',
  33. valuePath: 'target.checked',
  34. shouldInject: false,
  35. }) as typeof FormCheckboxType;
  36. const FormRadioGroup = withField(RadioGroup, { valuePath: 'target.value' });
  37. const FormRadio = withField(Radio, {
  38. valueKey: 'checked',
  39. valuePath: 'target.checked',
  40. shouldInject: false,
  41. }) as typeof FormRadioType;
  42. const FormDatePicker = withField(DatePicker);
  43. const FormSwitch = withField(Switch, { valueKey: 'checked' });
  44. const FormSlider = withField(Slider);
  45. /**
  46. * Reasons for using ts-igonre:
  47. *
  48. * 1. TimePicker: The propTypes of the locale is defined as object (it is not necessary and too troublesome to write a complete shapeOf),
  49. * but the interface defines a complete type, the two cannot match, and ts will report an error, so skip it here.
  50. *
  51. * 2. Cascader: treeData { label, value } define in PropTypes.shapeOf alreaady declare isRequired, ts still throw error
  52. * 【Property is optional in type “InferProps<{ value: Validator<string | number>; label: Validator<any>; }>” but required in type CascaderData】
  53. * skip it here.
  54. * 3. TreeSelect: value same as cascader, skip it here
  55. *
  56. */
  57. // @ts-ignore-next-line
  58. const FormTimePicker = withField(TimePicker);
  59. // @ts-ignore-next-line
  60. const FormTreeSelect = withField(TreeSelect);
  61. // @ts-ignore-next-line
  62. const FormCascader = withField(Cascader);
  63. const FormRating = withField(Rating);
  64. const FormAutoComplete = withField(AutoComplete, { valueKey: 'value', onKeyChangeFnName: 'onChange' });
  65. const FormUpload = withField(Upload, { valueKey: 'fileList', valuePath: 'fileList', onKeyChangeFnName: 'onChange' });
  66. const FormTagInput = withField(TagInput);
  67. export {
  68. FormInput,
  69. FormInputNumber,
  70. FormTextArea,
  71. FormSelect,
  72. FormCheckboxGroup,
  73. FormCheckbox,
  74. FormRadioGroup,
  75. FormRadio,
  76. FormDatePicker,
  77. FormSwitch,
  78. FormSlider,
  79. FormTimePicker,
  80. FormTreeSelect,
  81. FormCascader,
  82. FormRating,
  83. FormAutoComplete,
  84. FormUpload,
  85. FormTagInput
  86. };