withPicker.tsx 739 B

123456789101112131415161718192021222324252627282930313233
  1. import React, { Component } from 'react';
  2. export interface IProps {
  3. backendSrv: any;
  4. handlePicked: (data) => void;
  5. value?: string;
  6. }
  7. export default function withPicker(WrappedComponent) {
  8. return class WithPicker extends Component<IProps, any> {
  9. constructor(props) {
  10. super(props);
  11. this.toggleLoading = this.toggleLoading.bind(this);
  12. this.state = {
  13. isLoading: false,
  14. };
  15. }
  16. toggleLoading(isLoading) {
  17. this.setState(prevState => {
  18. return {
  19. ...prevState,
  20. isLoading: isLoading,
  21. };
  22. });
  23. }
  24. render() {
  25. return <WrappedComponent toggleLoading={this.toggleLoading} isLoading={this.state.isLoading} {...this.props} />;
  26. }
  27. };
  28. }