RawQuery.tsx 884 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { css, cx } from '@emotion/css';
  2. import Prism, { Grammar } from 'prismjs';
  3. import React from 'react';
  4. import { GrafanaTheme2 } from '@grafana/data/src';
  5. import { useTheme2 } from '@grafana/ui/src';
  6. export interface Props {
  7. query: string;
  8. lang: {
  9. grammar: Grammar;
  10. name: string;
  11. };
  12. }
  13. export function RawQuery({ query, lang }: Props) {
  14. const theme = useTheme2();
  15. const styles = getStyles(theme);
  16. const highlighted = Prism.highlight(query, lang.grammar, lang.name);
  17. return (
  18. <div
  19. className={cx(styles.editorField, 'prism-syntax-highlight')}
  20. aria-label="selector"
  21. dangerouslySetInnerHTML={{ __html: highlighted }}
  22. />
  23. );
  24. }
  25. const getStyles = (theme: GrafanaTheme2) => {
  26. return {
  27. editorField: css({
  28. fontFamily: theme.typography.fontFamilyMonospace,
  29. fontSize: theme.typography.bodySmall.fontSize,
  30. }),
  31. };
  32. };