2022-07-07 01:53:02 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { IconName, Input, ToolbarButton } from '@grafana/ui';
|
|
|
|
|
|
|
|
import { SceneObjectBase } from '../core/SceneObjectBase';
|
2022-07-19 10:46:49 -05:00
|
|
|
import { SceneComponentProps, SceneObjectStatePlain } from '../core/types';
|
2022-07-07 01:53:02 -05:00
|
|
|
|
2022-07-19 10:46:49 -05:00
|
|
|
export interface ToolbarButtonState extends SceneObjectStatePlain {
|
2022-07-07 01:53:02 -05:00
|
|
|
icon: IconName;
|
|
|
|
onClick: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SceneToolbarButton extends SceneObjectBase<ToolbarButtonState> {
|
2022-11-07 08:32:02 -06:00
|
|
|
public static Component = ({ model }: SceneComponentProps<SceneToolbarButton>) => {
|
2022-07-07 01:53:02 -05:00
|
|
|
const state = model.useState();
|
|
|
|
|
|
|
|
return <ToolbarButton onClick={state.onClick} icon={state.icon} />;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-19 10:46:49 -05:00
|
|
|
export interface SceneToolbarInputState extends SceneObjectStatePlain {
|
2022-07-07 01:53:02 -05:00
|
|
|
value?: string;
|
|
|
|
onChange: (value: number) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SceneToolbarInput extends SceneObjectBase<SceneToolbarInputState> {
|
2022-11-07 08:32:02 -06:00
|
|
|
public static Component = ({ model }: SceneComponentProps<SceneToolbarInput>) => {
|
2022-07-07 01:53:02 -05:00
|
|
|
const state = model.useState();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Input
|
|
|
|
defaultValue={state.value}
|
2022-07-14 19:08:40 -05:00
|
|
|
width={8}
|
2022-07-07 01:53:02 -05:00
|
|
|
onBlur={(evt) => {
|
|
|
|
model.state.onChange(parseInt(evt.currentTarget.value, 10));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|