index.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export interface TriggerProps {
  4. triggerRender?: (props?: any) => React.ReactNode;
  5. componentName?: string;
  6. componentProps?: Record<string, any>;
  7. value?: any;
  8. inputValue?: string;
  9. placeholder?: string | string[];
  10. className?: string;
  11. style?: React.CSSProperties;
  12. [x: string]: any
  13. }
  14. /**
  15. * `Trigger` is a HOC that will cover the inner of components which have popups
  16. */
  17. class Trigger extends React.PureComponent<TriggerProps> {
  18. static propTypes = {
  19. /**
  20. * ({ value?: any, className?: string, style?: React.CSSProperties, ... }) => React.ReactNode
  21. */
  22. triggerRender: PropTypes.func.isRequired,
  23. /**
  24. * e.g. "AutoComplete", "DatePicker", ...
  25. */
  26. componentName: PropTypes.string,
  27. componentProps: PropTypes.object,
  28. value: PropTypes.any,
  29. inputValue: PropTypes.string,
  30. placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
  31. className: PropTypes.string,
  32. style: PropTypes.object,
  33. };
  34. render() {
  35. const { triggerRender, componentName, ...rest } = this.props;
  36. return triggerRender({ ...rest });
  37. }
  38. }
  39. export default Trigger;