Field.d.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as React from 'react';
  2. import type { EventArgs, FormInstance, InternalFormInstance, InternalNamePath, Meta, NamePath, Rule, Store, StoreValue } from './interface';
  3. export type ShouldUpdate<Values = any> = boolean | ((prevValues: Values, nextValues: Values, info: {
  4. source?: string;
  5. }) => boolean);
  6. interface ChildProps {
  7. [name: string]: any;
  8. }
  9. export type MetaEvent = Meta & {
  10. destroy?: boolean;
  11. };
  12. export interface InternalFieldProps<Values = any> {
  13. children?: React.ReactElement | ((control: ChildProps, meta: Meta, form: FormInstance<Values>) => React.ReactNode);
  14. /**
  15. * Set up `dependencies` field.
  16. * When dependencies field update and current field is touched,
  17. * will trigger validate rules and render.
  18. */
  19. dependencies?: NamePath[];
  20. getValueFromEvent?: (...args: EventArgs) => StoreValue;
  21. name?: InternalNamePath;
  22. normalize?: (value: StoreValue, prevValue: StoreValue, allValues: Store) => StoreValue;
  23. rules?: Rule[];
  24. shouldUpdate?: ShouldUpdate<Values>;
  25. trigger?: string;
  26. validateTrigger?: string | string[] | false;
  27. /**
  28. * Trigger will after configured milliseconds.
  29. */
  30. validateDebounce?: number;
  31. validateFirst?: boolean | 'parallel';
  32. valuePropName?: string;
  33. getValueProps?: (value: StoreValue) => Record<string, unknown>;
  34. messageVariables?: Record<string, string>;
  35. initialValue?: any;
  36. onReset?: () => void;
  37. onMetaChange?: (meta: MetaEvent) => void;
  38. preserve?: boolean;
  39. /** @private Passed by Form.List props. Do not use since it will break by path check. */
  40. isListField?: boolean;
  41. /** @private Passed by Form.List props. Do not use since it will break by path check. */
  42. isList?: boolean;
  43. /** @private Pass context as prop instead of context api
  44. * since class component can not get context in constructor */
  45. fieldContext?: InternalFormInstance;
  46. }
  47. export interface FieldProps<Values = any> extends Omit<InternalFieldProps<Values>, 'name' | 'fieldContext'> {
  48. name?: NamePath<Values>;
  49. }
  50. export interface FieldState {
  51. resetCount: number;
  52. }
  53. declare function WrapperField<Values = any>({ name, ...restProps }: FieldProps<Values>): React.JSX.Element;
  54. export default WrapperField;