RowOptionsButton.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React, { FC } from 'react';
  2. import { Icon, ModalsController } from '@grafana/ui';
  3. import { OnRowOptionsUpdate } from './RowOptionsForm';
  4. import { RowOptionsModal } from './RowOptionsModal';
  5. export interface RowOptionsButtonProps {
  6. title: string;
  7. repeat?: string | null;
  8. onUpdate: OnRowOptionsUpdate;
  9. }
  10. export const RowOptionsButton: FC<RowOptionsButtonProps> = ({ repeat, title, onUpdate }) => {
  11. const onUpdateChange = (hideModal: () => void) => (title: string, repeat?: string | null) => {
  12. onUpdate(title, repeat);
  13. hideModal();
  14. };
  15. return (
  16. <ModalsController>
  17. {({ showModal, hideModal }) => {
  18. return (
  19. <a
  20. className="pointer"
  21. onClick={() => {
  22. showModal(RowOptionsModal, { title, repeat, onDismiss: hideModal, onUpdate: onUpdateChange(hideModal) });
  23. }}
  24. >
  25. <Icon name="cog" />
  26. </a>
  27. );
  28. }}
  29. </ModalsController>
  30. );
  31. };
  32. RowOptionsButton.displayName = 'RowOptionsButton';