withPicker.tsx 761 B

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