index.tsx 1.3 KB

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