mirror of https://github.com/grafana/grafana
TextPanel: Adds proper editor for markdown and html (#25618)
parent
9a8289b6d9
commit
d21558231f
@ -0,0 +1,46 @@ |
||||
import React, { FC, useMemo } from 'react'; |
||||
import { css, cx } from 'emotion'; |
||||
import AutoSizer from 'react-virtualized-auto-sizer'; |
||||
import { CodeEditor, stylesFactory, useTheme } from '@grafana/ui'; |
||||
import { GrafanaTheme, StandardEditorProps } from '@grafana/data'; |
||||
|
||||
import { TextOptions } from './types'; |
||||
|
||||
export const TextPanelEditor: FC<StandardEditorProps<string, any, TextOptions>> = ({ value, onChange, context }) => { |
||||
const language = useMemo(() => context.options?.mode ?? 'markdown', [context]); |
||||
const theme = useTheme(); |
||||
const styles = getStyles(theme); |
||||
return ( |
||||
<div className={cx(styles.editorBox)}> |
||||
<AutoSizer disableHeight> |
||||
{({ width }) => { |
||||
if (width === 0) { |
||||
return null; |
||||
} |
||||
|
||||
return ( |
||||
<CodeEditor |
||||
value={value} |
||||
onBlur={onChange} |
||||
onSave={onChange} |
||||
language={language} |
||||
width={width} |
||||
showMiniMap={false} |
||||
height="200px" |
||||
/> |
||||
); |
||||
}} |
||||
</AutoSizer> |
||||
</div> |
||||
); |
||||
}; |
||||
|
||||
const getStyles = stylesFactory((theme: GrafanaTheme) => ({ |
||||
editorBox: css` |
||||
label: editorBox; |
||||
border: ${theme.border.width.sm} solid ${theme.colors.border2}; |
||||
border-radius: ${theme.border.radius.sm}; |
||||
margin: ${theme.spacing.xs} 0; |
||||
width: 100%; |
||||
`,
|
||||
})); |
||||
Loading…
Reference in new issue