HelpToggle.tsx 850 B

123456789101112131415161718192021222324252627
  1. import { css, cx } from '@emotion/css';
  2. import React, { useState } from 'react';
  3. import { GrafanaTheme } from '@grafana/data';
  4. import { Icon, InfoBox, stylesFactory, useTheme } from '@grafana/ui';
  5. const getStyles = stylesFactory((theme: GrafanaTheme) => ({
  6. infoBox: css`
  7. margin-top: ${theme.spacing.xs};
  8. `,
  9. }));
  10. export const HelpToggle: React.FunctionComponent = ({ children }) => {
  11. const [isHelpVisible, setIsHelpVisible] = useState(false);
  12. const theme = useTheme();
  13. const styles = getStyles(theme);
  14. return (
  15. <>
  16. <button className="gf-form-label query-keyword pointer" onClick={(_) => setIsHelpVisible(!isHelpVisible)}>
  17. Help
  18. <Icon name={isHelpVisible ? 'angle-down' : 'angle-right'} />
  19. </button>
  20. {isHelpVisible && <InfoBox className={cx(styles.infoBox)}>{children}</InfoBox>}
  21. </>
  22. );
  23. };