mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 16:45:43 -06:00
* Component that can cache and extract variable dependencies * Component that can cache and extract variable dependencies * Updates * Refactoring * Lots of refactoring and iterations of supporting both re-rendering and query re-execution * Updated SceneCanvasText * Updated name of file * Updated * Refactoring a bit * Added back getName * Added comment * minor fix * Minor fix * Merge fixes * Scene variable interpolation progress * Merge fixes * Added all format registeries * Progress on multi value support * Progress on multi value support * Updates * Progress on scoped vars * Fixed circular dependency * Updates * Some review fixes * Updated comment * Added forceRender function * Add back fail on console log * Update public/app/features/scenes/variables/interpolation/sceneInterpolator.test.ts * Moving functions from SceneObjectBase * fixing tests * Fixed e2e Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import React, { CSSProperties } from 'react';
|
|
|
|
import { Field, Input } from '@grafana/ui';
|
|
|
|
import { SceneObjectBase } from '../core/SceneObjectBase';
|
|
import { sceneGraph } from '../core/sceneGraph';
|
|
import { SceneComponentProps, SceneLayoutChildState } from '../core/types';
|
|
import { VariableDependencyConfig } from '../variables/VariableDependencyConfig';
|
|
|
|
export interface SceneCanvasTextState extends SceneLayoutChildState {
|
|
text: string;
|
|
fontSize?: number;
|
|
align?: 'left' | 'center' | 'right';
|
|
}
|
|
|
|
export class SceneCanvasText extends SceneObjectBase<SceneCanvasTextState> {
|
|
public static Editor = Editor;
|
|
|
|
protected _variableDependency = new VariableDependencyConfig(this, { statePaths: ['text'] });
|
|
|
|
public static Component = ({ model }: SceneComponentProps<SceneCanvasText>) => {
|
|
const { text, fontSize = 20, align = 'left', key } = model.useState();
|
|
|
|
const style: CSSProperties = {
|
|
fontSize: fontSize,
|
|
display: 'flex',
|
|
flexGrow: 1,
|
|
alignItems: 'center',
|
|
padding: 16,
|
|
justifyContent: align,
|
|
};
|
|
|
|
return (
|
|
<div style={style} data-testid={key}>
|
|
{sceneGraph.interpolate(model, text)}
|
|
</div>
|
|
);
|
|
};
|
|
}
|
|
|
|
function Editor({ model }: SceneComponentProps<SceneCanvasText>) {
|
|
const { fontSize } = model.useState();
|
|
|
|
return (
|
|
<Field label="Font size">
|
|
<Input
|
|
type="number"
|
|
defaultValue={fontSize}
|
|
onBlur={(evt) => model.setState({ fontSize: parseInt(evt.currentTarget.value, 10) })}
|
|
/>
|
|
</Field>
|
|
);
|
|
}
|