grafana/public/app/features/scenes/components/SceneCanvasText.tsx
Torkel Ödegaard 6ed35292fe
Variables: SceneVariable update process (#57784)
* First baby steps

* First baby steps

* No progress really

* Updates

* no progress

* refactoring

* Progress on sub menu and value selectors

* Some more tweaks

* Lots of progress

* Progress

* Updates

* Progress

* Tweaks

* Updates

* Updates to variable system

* Cleaner tests

* Update

* Some cleanup

* correct test name

* Renames and moves

* prop rename

* Fixed scene template interpolator

* More tests for SceneObjectBase and fixed issue in EventBus

* Updates

* More tweaks

* More refinements

* Fixed test

* Added test to EventBus

* Clone all scene object arrays

* Simplify

* tried to merge issue

* Update

* added more comments to interface

* temp progress

* Trying to simplify things, but struggling a bit

* Updated

* Tweaks

* Progress on fixing the select componenet and typing, and sharing code in a base class

* Updated

* Multi select

* Simpler loading state

* Update

* removed failOnConsole

* Removed old funcs

* Moved logic from update manage to MultiValueVariable

* Added tests for MultiValueVariable logic

* Made value a more abstract concept to support object values

* renamed func to getValueText

* Refactored and moved logic to VariableSet

* Added test for deactivation and query cancelling

* Tweaks

* Fixed lint issues
2022-11-09 08:02:24 +01:00

48 lines
1.4 KiB
TypeScript

import React, { CSSProperties } from 'react';
import { Field, Input } from '@grafana/ui';
import { SceneObjectBase } from '../core/SceneObjectBase';
import { SceneComponentProps, SceneLayoutChildState } from '../core/types';
import { sceneTemplateInterpolator } from '../variables/sceneTemplateInterpolator';
export interface SceneCanvasTextState extends SceneLayoutChildState {
text: string;
fontSize?: number;
align?: 'left' | 'center' | 'right';
}
export class SceneCanvasText extends SceneObjectBase<SceneCanvasTextState> {
public static Editor = Editor;
public static Component = ({ model }: SceneComponentProps<SceneCanvasText>) => {
const { text, fontSize = 20, align = 'left' } = model.useState();
const textInterpolated = sceneTemplateInterpolator(text, model);
const style: CSSProperties = {
fontSize: fontSize,
display: 'flex',
flexGrow: 1,
alignItems: 'center',
padding: 16,
justifyContent: align,
};
return <div style={style}>{textInterpolated}</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>
);
}